Author: azrael-ru
Date: 2010-02-01 19:26:27 +0100 (Mon, 01 Feb 2010)
New Revision: 27388

Added:
   plugins/sfCcPlugin/LICENSE
   plugins/sfCcPlugin/README
   plugins/sfCcPlugin/config/
   plugins/sfCcPlugin/config/sfCcPluginConfiguration.class.php
   plugins/sfCcPlugin/lib/
   plugins/sfCcPlugin/lib/sfCcPlugin.php
Log:
initial beta release

Added: plugins/sfCcPlugin/LICENSE
===================================================================
--- plugins/sfCcPlugin/LICENSE                          (rev 0)
+++ plugins/sfCcPlugin/LICENSE  2010-02-01 18:26:27 UTC (rev 27388)
@@ -0,0 +1,7 @@
+Copyright (c) 2010 Maxim Tsepkov
+
+Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
of the Software, and to permit persons to whom the Software is furnished to do 
so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
\ No newline at end of file

Added: plugins/sfCcPlugin/README
===================================================================
--- plugins/sfCcPlugin/README                           (rev 0)
+++ plugins/sfCcPlugin/README   2010-02-01 18:26:27 UTC (rev 27388)
@@ -0,0 +1,16 @@
+This plugin allows you trigger "symfony cc" from browser by pressing ctrl + F5
+
+Everytime when browser loads page ignoring local cache, Symfony will detect it 
and clear its cache as well.
+Cleaning performs at early stage of system life cycle long before templates 
rendering but AFTER caching autoload.
+
+The plugin does nothing if environment is not equal 'dev'.
+
+Intall:
+
+./symfony plugin:install -s beta sfCcPlugin
+
+Then enable it in your /config/ProjectConfiguration.class.php
+    $this->enablePlugins('sfCcPlugin');
+    
+That's it.
+Feel free to contact me.
\ No newline at end of file

Added: plugins/sfCcPlugin/config/sfCcPluginConfiguration.class.php
===================================================================
--- plugins/sfCcPlugin/config/sfCcPluginConfiguration.class.php                 
        (rev 0)
+++ plugins/sfCcPlugin/config/sfCcPluginConfiguration.class.php 2010-02-01 
18:26:27 UTC (rev 27388)
@@ -0,0 +1,35 @@
+<?php
+/**
+ * It is a bad idea to place plugin logic into this class.
+ * But I didn't find any other way that won't require additional configuration.
+ * May be we can make use of event system somehow?
+ *
+ * @author Maxim Tsepkov (azrael.com [at] gmail.com)
+ *
+ */
+class sfCcPluginConfiguration extends sfPluginConfiguration
+{
+  public function initialize()
+  {
+    // we do not want to run in cli
+    if (!empty($_SERVER['argc'])) return;
+
+    // We should avoid nesting when task tries to init the plugin again
+    // thus in turn plugin runs the task again, and so on
+    static $called = false;
+    if(  $called != false ) return;
+    else $called = true;
+
+    // We do not want to let users clear cache everytime
+    // @todo make it configurable
+    if( $this->configuration->getEnvironment() != 'dev' ) return;
+
+    // Is there a 'Symfony' way to do this?
+    if( ( !empty($_SERVER['HTTP_CACHE_CONTROL']) && 
$_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache' )
+     || ( !empty($_SERVER['HTTP_PRAGMA'])        && $_SERVER['HTTP_PRAGMA']    
    == 'no-cache' )
+    )
+    {
+      sfCcPlugin::execute($this->configuration);
+    }
+  }
+}

Added: plugins/sfCcPlugin/lib/sfCcPlugin.php
===================================================================
--- plugins/sfCcPlugin/lib/sfCcPlugin.php                               (rev 0)
+++ plugins/sfCcPlugin/lib/sfCcPlugin.php       2010-02-01 18:26:27 UTC (rev 
27388)
@@ -0,0 +1,20 @@
+<?php
+class sfCcPlugin
+{
+  static public function execute(sfProjectConfiguration $configuration)
+  {
+    // Symfony doesn't change current directory to rootDir,
+    // but tasks needs to be in project directory
+    $cwd = getcwd();
+    chdir( $configuration->getRootDir() );
+
+    // Symfony devs should hide this magic number to 
sfFormatter::DEFAULT_LINE_SIZE
+    // sfFormatter will perform 2 system calls to try to autodetect shell 
width.
+    // User should be able avoid autodetection, but pass default value
+    $task = new sfCacheClearTask($configuration->getEventDispatcher(), new 
sfFormatter(78));
+    $task->run();
+
+    // restore things back
+    chdir($cwd);
+  }
+}
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to