Author: caefer
Date: 2010-03-26 14:44:14 +0100 (Fri, 26 Mar 2010)
New Revision: 28800

Added:
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceLocalAbstract.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceRemoteAbstract.class.php
Modified:
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceDoctrine.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceFile.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceHTTP.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceMock.class.php
   
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourcePropel.class.php
Log:

refactoring: centralised lots of duplicate code in two abstract classes
sfImageSourceLocalAbstract contains code for dealing with files on the local 
filesystem
while sfImageSourceRemoteAbstract specialises it and stubs stat() and 
url_stat() as they
can not handle resources not on the local filesystem.



Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceDoctrine.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceDoctrine.class.php
        2010-03-26 13:04:28 UTC (rev 28799)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceDoctrine.class.php
        2010-03-26 13:44:14 UTC (rev 28800)
@@ -18,111 +18,9 @@
  * @subpackage source
  * @author     Christian Schaefer <[email protected]>
  */
-class sfImageSourceDoctrine implements sfImageSourceInterface
+class sfImageSourceDoctrine extends sfImageSourceLocalAbstract implements 
sfImageSourceInterface
 {
   /**
-   * resource context
-   *
-   * @var resource
-   */
-  public $context;
-
-  /**
-   * resource handle
-   *
-   * @var resource
-   */
-  private $resource;
-
-  /**
-   * mock image absolute path
-   *
-   * @var string
-   */
-  private $filename;
-
-  /**
-   * Close an resource
-   *
-   * @return void
-   */
-  public function stream_close()
-  {
-    return fclose($this->resource);
-  }
-
-  /**
-   * Tests for end-of-file on a file pointer
-   *
-   * @return bool
-   */
-  public function stream_eof()
-  {
-    return feof($this->resource);
-  }
-
-  /**
-   * Flushes the output
-   *
-   * @return bool
-   */
-  public function stream_flush()
-  {
-    return fflush($this->resource);
-  }
-
-
-  /**
-   * Opens file or URL
-   *
-   * @param string $path
-   * @param string $mode
-   * @param int $options
-   * @param string &$opened_path
-   * @return bool
-   */
-  public function stream_open($path , $mode , $options , &$opened_path)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    $this->resource = fopen($this->filename, $mode);
-    return false !== $this->resource;
-  }
-
-  /**
-   * Read from stream
-   *
-   * @param int $count
-   * @return string
-   */
-  public function stream_read($count)
-  {
-    return fread($this->resource, $count);
-  }
-
-  /** 
-   * Retrieve information about a file resource
-   * 
-   * @return array 
-   */ 
-  public function stream_stat()
-  {
-    return fstat($this->resource);
-  }
-
-  /**
-   * Retrieve information about a file
-   *
-   * @param string $path
-   * @param int $flags
-   * @return array
-   */
-  public function url_stat($path , $flags)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    return stat($this->filename);
-  }
-
-  /**
    * Returns an sfImageSource:// URL pointing to a file which path is stored 
on a Doctrine object
    *
    * @param  array  $parameters Current request parameters (expected: type, 
attribute, id)
@@ -146,7 +44,7 @@
    * @param  string $path The given stream URL
    * @return string
    */
-  private function translatePathToFilename($path)
+  protected function translatePathToFilename($path)
   {
     if(!is_null($this->filename))
     {

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceFile.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceFile.class.php
    2010-03-26 13:04:28 UTC (rev 28799)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceFile.class.php
    2010-03-26 13:44:14 UTC (rev 28800)
@@ -18,111 +18,9 @@
  * @subpackage source
  * @author     Christian Schaefer <[email protected]>
  */
-class sfImageSourceFile implements sfImageSourceInterface
+class sfImageSourceFile extends sfImageSourceLocalAbstract implements 
sfImageSourceInterface
 {
   /**
-   * resource context
-   *
-   * @var resource
-   */
-  public $context;
-
-  /**
-   * resource handle
-   *
-   * @var resource
-   */
-  private $resource;
-
-  /**
-   * mock image absolute path
-   *
-   * @var string
-   */
-  private $filename;
-
-  /**
-   * Close an resource
-   *
-   * @return void
-   */
-  public function stream_close()
-  {
-    return fclose($this->resource);
-  }
-
-  /**
-   * Tests for end-of-file on a file pointer
-   *
-   * @return bool
-   */
-  public function stream_eof()
-  {
-    return feof($this->resource);
-  }
-
-  /**
-   * Flushes the output
-   *
-   * @return bool
-   */
-  public function stream_flush()
-  {
-    return fflush($this->resource);
-  }
-
-
-  /**
-   * Opens file or URL
-   *
-   * @param string $path
-   * @param string $mode
-   * @param int $options
-   * @param string &$opened_path
-   * @return bool
-   */
-  public function stream_open($path , $mode , $options , &$opened_path)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    $this->resource = fopen($this->filename, $mode);
-    return false !== $this->resource;
-  }
-
-  /**
-   * Read from stream
-   *
-   * @param int $count
-   * @return string
-   */
-  public function stream_read($count)
-  {
-    return fread($this->resource, $count);
-  }
-
-  /** 
-   * Retrieve information about a file resource
-   * 
-   * @return array 
-   */ 
-  public function stream_stat()
-  {
-    return fstat($this->resource);
-  }
-
-  /**
-   * Retrieve information about a file
-   *
-   * @param string $path
-   * @param int $flags
-   * @return array
-   */
-  public function url_stat($path , $flags)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    return stat($this->filename);
-  }
-
-  /**
    * Returns an sfImageSource:// URL pointing to a file on the local filesystem
    *
    * @param  array  $parameters Current request parameters (expected: filepath)
@@ -146,7 +44,7 @@
    * @param  string $path The given stream URL
    * @return string
    */
-  private function translatePathToFilename($path)
+  protected function translatePathToFilename($path)
   {
     if(!is_null($this->filename))
     {

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceHTTP.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceHTTP.class.php
    2010-03-26 13:04:28 UTC (rev 28799)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceHTTP.class.php
    2010-03-26 13:44:14 UTC (rev 28800)
@@ -18,109 +18,9 @@
  * @subpackage source
  * @author     Christian Schaefer <[email protected]>
  */
-class sfImageSourceHTTP implements sfImageSourceInterface
+class sfImageSourceHTTP extends sfImageSourceRemoteAbstract implements 
sfImageSourceInterface
 {
   /**
-   * resource context
-   *
-   * @var resource
-   */
-  public $context = null;
-
-  /**
-   * resource handle
-   *
-   * @var resource
-   */
-  private $resource;
-
-  /**
-   * Close an resource
-   *
-   * @return void
-   */
-  public function stream_close()
-  {
-    return fclose($this->resource);
-  }
-
-  /**
-   * Tests for end-of-file on a file pointer
-   *
-   * @return bool
-   */
-  public function stream_eof()
-  {
-    return feof($this->resource);
-  }
-
-  /**
-   * Flushes the output
-   *
-   * @return bool
-   */
-  public function stream_flush()
-  {
-    return fflush($this->resource);
-  }
-
-  /**
-   * Opens file or URL
-   *
-   * @param string $path
-   * @param string $mode
-   * @param int $options
-   * @param string &$opened_path
-   * @return bool
-   */
-  public function stream_open($path , $mode , $options , &$opened_path)
-  {
-    $this->resource = fopen($this->translatePathToFilename($path), $mode);
-    return false !== $this->resource;
-  }
-
-  /**
-   * Read from stream
-   *
-   * @param int $count
-   * @return string
-   */
-  public function stream_read($count)
-  {
-    return fread($this->resource, $count);
-  }
-
-  /** 
-   * Retrieve information about a file resource
-   *
-   * ATTENTION! stat() does not work with http streams but is only needed 
because
-   * it is called internally by file_exists() which is used by sfImage. 
Returning
-   * an empty array is sufficient to this call.
-   *
-   * @return array 
-   */ 
-  public function stream_stat()
-  {
-    return array();
-  }
-
-  /**
-   * Retrieve information about a file
-   *
-   * ATTENTION! stat() does not work with http streams but is only needed 
because
-   * it is called internally by file_exists() which is used by sfImage. 
Returning
-   * an empty array is sufficient to this call.
-   *
-   * @param string $path
-   * @param int $flags
-   * @return array
-   */
-  public function url_stat($path , $flags)
-  {
-    return array();
-  }
-
-  /**
    * Returns an sfImageSource:// URL pointing to a file read over HTTP
    *
    * @param  array  $parameters Current request parameters (expected: 
protocol, domain, filepath)
@@ -144,7 +44,7 @@
    * @param  string $path The given stream URL
    * @return string
    */
-  private function translatePathToFilename($path)
+  protected function translatePathToFilename($path)
   {
     $options = sfConfig::get('thumbnailing_source_image_stream_param');
     $path = parse_url($path);

Added: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceLocalAbstract.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceLocalAbstract.class.php
                           (rev 0)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceLocalAbstract.class.php
   2010-03-26 13:44:14 UTC (rev 28800)
@@ -0,0 +1,124 @@
+<?php
+/**
+ * This file is part of the sfImageTransformExtraPlugin package.
+ * (c) 2010 Christian Schaefer <[email protected]>>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @package    sfImageTransformExtraPlugin
+ * @author     Christian Schaefer <[email protected]>
+ * @version    SVN: $Id: sfRawFileCache.class.php 63 2010-03-09 04:34:28Z 
caefer $
+ */
+
+/**
+ * Maps sfImageSource:// URLs to an local image file
+ *
+ * @package    sfImageTransformExtraPlugin
+ * @subpackage source
+ * @author     Christian Schaefer <[email protected]>
+ */
+abstract class sfImageSourceLocalAbstract implements sfImageSourceInterface
+{
+  /**
+   * resource context
+   *
+   * @var resource
+   */
+  public $context;
+
+  /**
+   * resource handle
+   *
+   * @var resource
+   */
+  private $resource;
+
+  /**
+   * mock image absolute path
+   *
+   * @var string
+   */
+  private $filename;
+
+  /**
+   * Close an resource
+   *
+   * @return void
+   */
+  public function stream_close()
+  {
+    return fclose($this->resource);
+  }
+
+  /**
+   * Tests for end-of-file on a file pointer
+   *
+   * @return bool
+   */
+  public function stream_eof()
+  {
+    return feof($this->resource);
+  }
+
+  /**
+   * Flushes the output
+   *
+   * @return bool
+   */
+  public function stream_flush()
+  {
+    return fflush($this->resource);
+  }
+
+
+  /**
+   * Opens file or URL
+   *
+   * @param string $path
+   * @param string $mode
+   * @param int $options
+   * @param string &$opened_path
+   * @return bool
+   */
+  public function stream_open($path , $mode , $options , &$opened_path)
+  {
+    $this->filename = $this->translatePathToFilename($path);
+    $this->resource = fopen($this->filename, $mode);
+    return false !== $this->resource;
+  }
+
+  /**
+   * Read from stream
+   *
+   * @param int $count
+   * @return string
+   */
+  public function stream_read($count)
+  {
+    return fread($this->resource, $count);
+  }
+
+  /** 
+   * Retrieve information about a file resource
+   * 
+   * @return array 
+   */ 
+  public function stream_stat()
+  {
+    return fstat($this->resource);
+  }
+
+  /**
+   * Retrieve information about a file
+   *
+   * @param string $path
+   * @param int $flags
+   * @return array
+   */
+  public function url_stat($path , $flags)
+  {
+    $this->filename = $this->translatePathToFilename($path);
+    return stat($this->filename);
+  }
+}

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceMock.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceMock.class.php
    2010-03-26 13:04:28 UTC (rev 28799)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceMock.class.php
    2010-03-26 13:44:14 UTC (rev 28800)
@@ -18,108 +18,9 @@
  * @subpackage source
  * @author     Christian Schaefer <[email protected]>
  */
-class sfImageSourceMock implements sfImageSourceInterface
+class sfImageSourceMock extends sfImageSourceLocalAbstract implements 
sfImageSourceInterface
 {
   /**
-   * resource context
-   *
-   * @var resource
-   */
-  public $context;
-
-  /**
-   * resource handle
-   *
-   * @var resource
-   */
-  private $resource;
-
-  /**
-   * mock image absolute path
-   *
-   * @var string
-   */
-  private $filename = '/../../data/caefer.jpg';
-
-  /**
-   * Close an resource
-   *
-   * @return void
-   */
-  public function stream_close()
-  {
-    return fclose($this->resource);
-  }
-
-  /**
-   * Tests for end-of-file on a file pointer
-   *
-   * @return bool
-   */
-  public function stream_eof()
-  {
-    return feof($this->resource);
-  }
-
-  /**
-   * Flushes the output
-   *
-   * @return bool
-   */
-  public function stream_flush()
-  {
-    return fflush($this->resource);
-  }
-
-  /**
-   * Opens file or URL
-   *
-   * @param string $path
-   * @param string $mode
-   * @param int $options
-   * @param string &$opened_path
-   * @return bool
-   */
-  public function stream_open($path , $mode , $options , &$opened_path)
-  {
-    $this->resource = fopen($this->translatePathToFilename($path), $mode);
-    return false !== $this->resource;
-  }
-
-  /**
-   * Read from stream
-   *
-   * @param int $count
-   * @return string
-   */
-  public function stream_read($count)
-  {
-    return fread($this->resource, $count);
-  }
-
-  /** 
-   * Retrieve information about a file resource
-   * 
-   * @return array 
-   */ 
-  public function stream_stat()
-  {
-    return fstat($this->resource);
-  }
-
-  /**
-   * Retrieve information about a file
-   *
-   * @param string $path
-   * @param int $flags
-   * @return array
-   */
-  public function url_stat($path , $flags)
-  {
-    return stat($this->translatePathToFilename($path));
-  }
-
-  /**
    * Returns an sfImageSource:// URL pointing to a single mock file within 
this plugin
    *
    * @param  array  $parameters Current request parameters (expected: ~)
@@ -137,8 +38,8 @@
    * @param  string $path The given stream URL
    * @return string
    */
-  private function translatePathToFilename($path)
+  protected function translatePathToFilename($path)
   {
-    return dirname(__FILE__).$this->filename;
+    return dirname(__FILE__).'/../../data/caefer.jpg';
   }
 }

Modified: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourcePropel.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourcePropel.class.php
  2010-03-26 13:04:28 UTC (rev 28799)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourcePropel.class.php
  2010-03-26 13:44:14 UTC (rev 28800)
@@ -18,111 +18,9 @@
  * @subpackage source
  * @author     Christian Schaefer <[email protected]>
  */
-class sfImageSourcePropel implements sfImageSourceInterface
+class sfImageSourcePropel extends sfImageSourceLocalAbstract implements 
sfImageSourceInterface
 {
   /**
-   * resource context
-   *
-   * @var resource
-   */
-  public $context;
-
-  /**
-   * resource handle
-   *
-   * @var resource
-   */
-  private $resource;
-
-  /**
-   * mock image absolute path
-   *
-   * @var string
-   */
-  private $filename;
-
-  /**
-   * Close an resource
-   *
-   * @return void
-   */
-  public function stream_close()
-  {
-    return fclose($this->resource);
-  }
-
-  /**
-   * Tests for end-of-file on a file pointer
-   *
-   * @return bool
-   */
-  public function stream_eof()
-  {
-    return feof($this->resource);
-  }
-
-  /**
-   * Flushes the output
-   *
-   * @return bool
-   */
-  public function stream_flush()
-  {
-    return fflush($this->resource);
-  }
-
-
-  /**
-   * Opens file or URL
-   *
-   * @param string $path
-   * @param string $mode
-   * @param int $options
-   * @param string &$opened_path
-   * @return bool
-   */
-  public function stream_open($path , $mode , $options , &$opened_path)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    $this->resource = fopen($this->filename, $mode);
-    return false !== $this->resource;
-  }
-
-  /**
-   * Read from stream
-   *
-   * @param int $count
-   * @return string
-   */
-  public function stream_read($count)
-  {
-    return fread($this->resource, $count);
-  }
-
-  /** 
-   * Retrieve information about a file resource
-   * 
-   * @return array 
-   */ 
-  public function stream_stat()
-  {
-    return fstat($this->resource);
-  }
-
-  /**
-   * Retrieve information about a file
-   *
-   * @param string $path
-   * @param int $flags
-   * @return array
-   */
-  public function url_stat($path , $flags)
-  {
-    $this->filename = $this->translatePathToFilename($path);
-    return stat($this->filename);
-  }
-
-  /**
    * Returns an sfImageSource:// URL pointing to a file which path is stored 
on a Propel object
    *
    * @param  array  $parameters Current request parameters (expected: type, 
attribute, id)
@@ -146,7 +44,7 @@
    * @param  string $path The given stream URL
    * @return string
    */
-  private function translatePathToFilename($path)
+  protected function translatePathToFilename($path)
   {
     if(!is_null($this->filename))
     {

Added: 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceRemoteAbstract.class.php
===================================================================
--- 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceRemoteAbstract.class.php
                          (rev 0)
+++ 
plugins/sfImageTransformExtraPlugin/trunk/lib/source/sfImageSourceRemoteAbstract.class.php
  2010-03-26 13:44:14 UTC (rev 28800)
@@ -0,0 +1,58 @@
+<?php
+/**
+ * This file is part of the sfImageTransformExtraPlugin package.
+ * (c) 2010 Christian Schaefer <[email protected]>>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @package    sfImageTransformExtraPlugin
+ * @author     Christian Schaefer <[email protected]>
+ * @version    SVN: $Id: sfRawFileCache.class.php 63 2010-03-09 04:34:28Z 
caefer $
+ */
+
+/**
+ * Maps sfImageSource:// URLs to a remote image file
+ *
+ * This class only overrides the two stat methods and returns empty arrays.
+ * stat/fstat is internally used by file_exists() which is called by sfImage.
+ * It doesn't rely on stat information but on a positiv return.
+ * Unfortunately stat and fstat do not work with URLs other than on the local
+ * filesystem therefor these methods are faked in this class.
+ *
+ * @package    sfImageTransformExtraPlugin
+ * @subpackage source
+ * @author     Christian Schaefer <[email protected]>
+ */
+abstract class sfImageSourceRemoteAbstract extends sfImageSourceLocalAbstract 
implements sfImageSourceInterface
+{
+  /** 
+   * Retrieve information about a file resource
+   *
+   * ATTENTION! stat() does not work with http streams but is only needed 
because
+   * it is called internally by file_exists() which is used by sfImage. 
Returning
+   * an empty array is sufficient to this call.
+   *
+   * @return array 
+   */ 
+  public function stream_stat()
+  {
+    return array();
+  }
+
+  /**
+   * Retrieve information about a file
+   *
+   * ATTENTION! stat() does not work with http streams but is only needed 
because
+   * it is called internally by file_exists() which is used by sfImage. 
Returning
+   * an empty array is sufficient to this call.
+   *
+   * @param string $path
+   * @param int $flags
+   * @return array
+   */
+  public function url_stat($path , $flags)
+  {
+    return array();
+  }
+}

-- 
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