Development

Changeset 5439

You must first sign up to be able to contribute.

Changeset 5439

Show
Ignore:
Timestamp:
10/09/07 03:45:58 (6 years ago)
Author:
xavier
Message:

replaced tabs with spaces + reindent ("stick to sf coding standards")

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfAccessibleFormPlugin/lib/helper/AccessibleFormHelper.php

    r4100 r5439  
    11<?php 
    2  
    32function accessible_form_tag($route, $options = array()) 
    43{ 
    5  $response = sfContext::getInstance()->getResponse(); 
     4  $response = sfContext::getInstance()->getResponse(); 
    65  $response->addJavascript('/sfAccessibleFormPlugin/js/jquery'); 
    76  $response->addJavascript('/sfAccessibleFormPlugin/js/cmxform'); 
    8   $response->addStylesheet('/sfAccessibleFormPlugin/css/accessible_form'); 
    9    
    10   $options = _parse_attributes($options); 
    11   if (array_key_exists('class',$options))  
    12   { 
    13     $options['class'] .= ' cmxform'; 
    14   } 
    15   else  
    16   { 
    17     $options['class'] = 'cmxform'; 
    18   } 
    19   return form_tag($route, $options); 
     7  $response->addStylesheet('/sfAccessibleFormPlugin/css/accessible_form'); 
     8 
     9  $options = _parse_attributes($options); 
     10 
     11  if (array_key_exists('class',$options))  
     12  { 
     13    $options['class'] .= ' cmxform'; 
     14  } 
     15  else  
     16  { 
     17    $options['class'] = 'cmxform'; 
     18  } 
     19 
     20  return form_tag($route, $options); 
    2021} 
  • plugins/sfAmazonS3FSPlugin/lib/BasesfAmazonS3.class.php

    r4123 r5439  
    3434 * </code> 
    3535 *  
    36  * @package    sfAmazonS3 
    37  * @version      SVN: $Id: BasesfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jwage $ 
    38  * @author       Jonathan H. Wage <jonwage@gmail.com> 
     36 * @package     sfAmazonS3 
     37 * @version    SVN: $Id: BasesfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jwage $ 
     38 * @author      Jonathan H. Wage <jonwage@gmail.com> 
    3939 */ 
    4040class BasesfAmazonS3 
    4141{ 
    42     /** 
    43      * Action 
    44      * 
    45      * Name of the action last performed 
    46      *  
    47      * @var string 
    48      * @access public 
    49      */ 
    50     public $action; 
    51      
    52     /** 
    53      * Service Url 
    54      * 
    55      * Amazon S3 Web Service Url used in HTTP requests 
    56      *  
    57      * @var string 
    58      * @access public 
    59      */ 
    60     public $serviceUrl = 'http://s3.amazonaws.com/'; 
    61      
    62     /** 
    63      * Access Key Id 
    64      *  
    65      * Amazon S3 Web Services access key id 
    66      *  
    67      * @var string 
    68      * @access public 
    69      */ 
    70     public $accessKeyId; 
    71      
    72     /** 
    73      * Secret Key  
    74      * 
    75      * Amazon S3 Web Services secret key 
    76      *  
    77      * @var string 
    78      * @access public 
    79      */ 
    80     public $secretKey; 
    81      
    82     /** 
    83      * Response String  
    84      *  
    85      * Http resonse string 
    86      *  
    87      * @var string 
    88      * @access public 
    89      */ 
    90     public $responseString; 
    91      
    92     /** 
    93      * Response Code 
    94      *  
    95      * @var mixed 
    96      * @access public 
    97      */ 
    98     public $responseCode; 
    99      
    100     /** 
    101      * Parsed Xml  
    102      *  
    103      * @var array 
    104      * @access public 
    105      */ 
    106     public $parsedXml; 
    107      
    108     /** 
    109      * BasesfAmazonS3 Constructor 
    110      *  
    111      * Requires an $accessKeyId and $secretKey in order to be initialized. 
    112      * 
    113      * <code> 
    114      * <?php 
    115      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    116      * ?> 
    117      * </code> 
    118      *  
    119      * @param string $accessKeyId Access key id provided by Amazon when you sign up for a AmazonS3 account 
    120      * @param string $secretKey Secret key provided by Amazon when you sign up for a AmazonS3 account 
    121      */ 
    122     public function __construct($accessKeyId = null, $secretKey  = null) 
    123     {    
    124         // If params passed then setup class, otherwise throw exception 
    125         if( $accessKeyId AND $secretKey ) 
     42  /** 
     43   * Action 
     44   * 
     45   * Name of the action last performed 
     46   *  
     47   * @var string 
     48   * @access public 
     49   */ 
     50  public $action; 
     51     
     52  /** 
     53   * Service Url 
     54   * 
     55   * Amazon S3 Web Service Url used in HTTP requests 
     56   *  
     57   * @var string 
     58   * @access public 
     59   */ 
     60  public $serviceUrl = 'http://s3.amazonaws.com/'; 
     61     
     62  /** 
     63   * Access Key Id 
     64   *  
     65   * Amazon S3 Web Services access key id 
     66   *  
     67   * @var string 
     68   * @access public 
     69   */ 
     70  public $accessKeyId; 
     71     
     72  /** 
     73   * Secret Key  
     74   * 
     75   * Amazon S3 Web Services secret key 
     76   *  
     77   * @var string 
     78   * @access public 
     79   */ 
     80  public $secretKey; 
     81     
     82  /** 
     83   * Response String  
     84   *  
     85   * Http resonse string 
     86   *  
     87   * @var string 
     88   * @access public 
     89   */ 
     90  public $responseString; 
     91     
     92  /** 
     93   * Response Code 
     94   *  
     95   * @var mixed 
     96   * @access public 
     97   */ 
     98  public $responseCode; 
     99     
     100  /** 
     101   * Parsed Xml  
     102   *  
     103   * @var array 
     104   * @access public 
     105   */ 
     106  public $parsedXml; 
     107     
     108  /** 
     109   * BasesfAmazonS3 Constructor 
     110   *  
     111   * Requires an $accessKeyId and $secretKey in order to be initialized. 
     112   * 
     113   * <code> 
     114   * <?php 
     115   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     116   * ?> 
     117   * </code> 
     118   *  
     119   * @param string $accessKeyId Access key id provided by Amazon when you sign up for a AmazonS3 account 
     120   * @param string $secretKey Secret key provided by Amazon when you sign up for a AmazonS3 account 
     121   */ 
     122  public function __construct($accessKeyId = null, $secretKey  = null) 
     123  {    
     124    // If params passed then setup class, otherwise throw exception 
     125    if( $accessKeyId AND $secretKey ) 
     126    { 
     127      $this->accessKeyId = $accessKeyId; 
     128      $this->secretKey = $secretKey; 
     129    } 
     130    else 
     131    { 
     132      throw new Exception('You must instantiate BasesfAmazonS3 plugin class with your aws access key id and secret key.'); 
     133    } 
     134  } 
     135 
     136  public static function getInstance() 
     137  { 
     138    static $sfAmazonS3; 
     139 
     140    if (!isset($sfAmazonS3)) 
     141    { 
     142      // Get instance 
     143      $className = sfConfig::get('app_amazon_s3_class_name'); 
     144      $sfAmazonS3 = new $className(sfConfig::get('app_amazon_s3_aws_access_key_id'), sfConfig::get('app_amazon_s3_secret_access_key'));   
     145    } 
     146 
     147    return $sfAmazonS3; 
     148  } 
     149 
     150 
     151  /** 
     152   * Create Amazon S3 Bucket 
     153   * 
     154   * Method for create a blank bucket on Amazon S3, bucket name must be inique across all of Amazon 
     155   * <code> 
     156   * <?php 
     157   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     158   * $sfAmazonS3->createBucket('name', 'private'); // 2nd argument can be public-read, public-read-write, private, authenticated-users-read 
     159   * ?> 
     160   * </code> 
     161   * 
     162   * @param string $bucket Unique name of your bucket to create 
     163   * @param string $acl Amazon S3 permission setting (private, public-read, public-read-write, authenticated-users-read) 
     164   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     165   */ 
     166  public function createBucket($bucket, $acl = 'private') 
     167  { 
     168    $this->action = 'create_bucket'; 
     169 
     170    $httpDate = gmdate("D, d M Y G:i:s T"); 
     171    $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$bucket"; 
     172    $signature = $this->getSignedString($stringToSign); 
     173 
     174    $req = new HTTP_Request($this->serviceUrl . $bucket); 
     175    $req->setMethod("PUT"); 
     176    $req->addHeader("Date", $httpDate); 
     177    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     178    $req->addHeader("x-amz-acl", $acl); 
     179 
     180    return $this->sendHttpRequest($req, 200);  
     181  } 
     182     
     183  /** 
     184   * Delete Amazon S3 Bucket 
     185   * 
     186   * Method for emptying and deleting a bucket on Amazon S3 
     187   * 
     188   * <code> 
     189   * <?php 
     190   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     191   * $sfAmazonS3->deleteBucket('bucket_name'); 
     192   * ?> 
     193   * </code> 
     194   *  
     195   * @param string $bucket Name of the bucket you wish to delete 
     196   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     197   */ 
     198  public function deleteBucket($bucket) 
     199  { 
     200    $this->emptyBucket($bucket); 
     201    $this->action = 'delete_bucket'; 
     202 
     203    $httpDate = gmdate("D, d M Y G:i:s T"); 
     204    $stringToSign = "DELETE\n\n\n$httpDate\n/$bucket"; 
     205    $signature = $this->getSignedString($stringToSign); 
     206 
     207    $req = new HTTP_Request($this->serviceUrl . $bucket); 
     208    $req->setMethod("DELETE"); 
     209    $req->addHeader("Date", $httpDate); 
     210    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     211 
     212    return $this->sendHttpRequest($req, 204);  
     213  } 
     214  
     215  /** 
     216   * Empty Amazon S3 Bucket 
     217   * 
     218   * Method for emptying a bucket on Amazon S3. This method pulls all the objects in the bucket and calls the delete method on each bucket object 
     219   * 
     220   * <code> 
     221   * <?php 
     222   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     223   * $sfAmazonS3->emptyBucket('bucket name'); 
     224   * ?> 
     225   * </code> 
     226   *  
     227   * @param string $bucket Name of the bucket you wish to empty 
     228   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     229   */ 
     230  public function emptyBucket($bucket) 
     231  { 
     232    $this->action = 'empty_bucket'; 
     233 
     234    if ($this->listBucketKeys($bucket)) 
     235    { 
     236      $more = $this->parsedXml->IsTruncated; // determine of all keys in bucket are returned on this list call 
     237      $keys = $this->parsedXml->Contents; 
     238 
     239      // set up array for catching keys that aren't successfully deleted and set the initial count of these to 0 
     240      $not_deleted_keys = array(); 
     241      $not_deleted_count = 0; 
     242 
     243      foreach ($keys as $current) 
     244      { 
     245        //try up to 3 times to delete current key 
     246        $tries=1; 
     247        while (!$this->deleteBucketObject($bucket, $current->Key) && $tries <= 3) 
    126248        { 
    127             $this->accessKeyId = $accessKeyId; 
    128             $this->secretKey = $secretKey; 
    129         } else { 
    130             throw new Exception('You must instantiate BasesfAmazonS3 plugin class with your aws access key id and secret key.'); 
     249          $tries++; 
    131250        } 
    132     } 
     251 
     252        //capture any keys that aren't deleted 
     253        if ($tries > 3) 
     254        { 
     255          $not_deleted_keys[$not_deleted_count] = $current->Key; 
     256          $not_deleted_count++; 
     257        } 
     258      } 
     259    } 
     260    else 
     261    { 
     262      throw new Exception('listBucketKeys() failed'); 
     263    } 
     264 
     265    // call emptyBucket if not all keys were returned with last list call 
     266    if ($more == "true") 
     267    { 
     268      $this->emptyBucket($bucket); 
     269    } 
     270 
     271    return true; 
     272  } 
    133273     
    134     public static function getInstance() 
    135     { 
    136       static $sfAmazonS3; 
     274  /** 
     275   * List Amazon S3 Buckets 
     276   * 
     277   * Method for retrieving a list of all the buckets in your Amazon S3 account 
     278   * 
     279   * <code> 
     280   * <?php 
     281   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     282   * $buckets = $sfAmazonS3->listBuckets(); 
     283   * print_r($buckets); 
     284   * ?> 
     285   * </code> 
     286   *  
     287   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     288   */ 
     289  public function listBuckets() 
     290  { 
     291    $this->action = 'list_buckets'; 
     292 
     293    $httpDate = gmdate("D, d M Y G:i:s T"); 
     294    $stringToSign="GET\n\n\n$httpDate\n/"; 
     295    $signature = $this->getSignedString($stringToSign); 
     296 
     297    $req = new HTTP_Request($this->serviceUrl); 
     298    $req->addHeader("Date", $httpDate); 
     299    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     300 
     301    if ($this->sendHttpRequest($req, 200)) 
     302    { 
     303      return $this->getActionData(); 
     304    } 
     305    else 
     306    { 
     307      return false; 
     308    } 
     309  } 
     310 
     311  /** 
     312   * List Bucket Objects 
     313   *   
     314    * <code> 
     315   * <?php 
     316   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     317   * $bucketObjects = $sfAmazonS3->listBucketObjects('bucket name'); 
     318   * print_r($bucketObjects); 
     319   * ?> 
     320   * </code> 
     321   *  
     322   * @param mixed $bucket  
     323   * @param mixed $marker  
     324   * @param mixed $prefix  
     325   * @param mixed $delimiter  
     326   * @param int $maxKeys  
     327   * @access public 
     328   * @return void 
     329   */ 
     330  public function listBucketObjects($bucket, $marker = FALSE, $prefix = FALSE, $delimiter = FALSE, $maxKeys = 1000) 
     331  { 
     332    return $this->listBucketKeys($bucket, $marker, $prefix, $delimiter, $maxKeys); 
     333  } 
     334 
     335  /** 
     336   * List Buckets Keys/Objects 
     337   * 
     338   * Method for retrieving all the objects in a specified bucket 
     339    
     340   * <code> 
     341   * <?php 
     342   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     343   * $bucketObjects = $sfAmazonS3->listBucketKeys('bucket name'); 
     344   * print_r($bucketObjects); 
     345   * ?> 
     346   * </code> 
     347   *  
     348   * @param string $bucket Name of the bucket 
     349   * @param bool $marker  
     350   * @param bool $prefix  
     351   * @param bool $delimiter  
     352   * @param int $maxKeys  
     353   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     354   */ 
     355  public function listBucketKeys($bucket, $marker = FALSE, $prefix = FALSE, $delimiter = FALSE, $maxKeys = 1000) 
     356  { 
     357    $this->action = 'list_bucket_keys'; 
     358 
     359    $httpDate = gmdate("D, d M Y G:i:s T"); 
     360    $stringToSign = "GET\n\n\n$httpDate\n/$bucket"; 
     361    $signature = $this->getSignedString($stringToSign); 
     362 
     363    $req = new HTTP_Request($this->serviceUrl.$bucket."?max-keys={$maxKeys}&marker={$marker}&prefix={$prefix}&delimiter={$delimiter}"); 
     364    $req->addHeader("Date", $httpDate); 
     365    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     366 
     367    if ($this->sendHttpRequest($req, 200)) 
     368    { 
     369      return $this->getActionData(); 
     370    } 
     371    else 
     372    { 
     373      return false; 
     374    } 
     375  } 
     376 
     377  /** 
     378   * Get Amazon S3 Bucket Acl(permissions) 
     379   * 
     380   * Method for retrieving the current ACL for a specified bucket 
     381   * 
     382   * <code> 
     383   * <?php 
     384   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     385   * echo $sfAmazonS3->getBucketAcl('bucket name'); // public-read, public-read-write, private, authenticated-users-read 
     386   * ?> 
     387   * </code> 
     388   *  
     389   * @param string $bucket Name of the bucket 
     390   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     391   */ 
     392  public function getBucketAcl($bucket) 
     393  { 
     394    $this->action = 'get_bucket_acl'; 
     395 
     396    $httpDate = gmdate("D, d M Y G:i:s T"); 
     397    $stringToSign = "GET\n\n\n$httpDate\n/$bucket/?acl"; 
     398    $signature = $this->getSignedString($stringToSign); 
     399 
     400    $req = new HTTP_Request($this->serviceUrl.$bucket.'/?acl'); 
     401    $req->setMethod("GET"); 
     402    $req->addHeader("Date", $httpDate); 
     403    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     404 
     405    if ($this->sendHttpRequest($req, 200)) 
     406    { 
     407      return $this->getActionData(); 
     408    } 
     409    else 
     410    { 
     411      return false; 
     412    } 
     413  } 
     414 
     415  /** 
     416   * Set Amazon S3 Bucket Acl(permissions) 
     417   * 
     418   * Method for setting the current Acl fpr a speficied bucket 
     419   *  
     420   * <code> 
     421   * <?php 
     422   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     423   * $sfAmazonS3->setBucketAcl('bucket name', 'public-read'); // public-read, public-read-write, private, authenticated-users-read 
     424   * ?> 
     425   * </code> 
     426   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     427   */ 
     428  public function setBucketAcl($bucket, $acl) 
     429  { 
     430    $this->action = 'set_bucket_acl'; 
     431 
     432    $httpDate = gmdate("D, d M Y G:i:s T"); 
     433    $stringToSign = "PUT\n\n\n{$httpDate}\nx-amz-acl:$acl\n/$bucket/?acl"; 
     434    $signature = $this->getSignedString($stringToSign); 
     435 
     436    $req = new HTTP_Request($this->serviceUrl.$bucket.'/?acl'); 
     437    $req->setMethod("PUT"); 
     438    $req->addHeader("Date", $httpDate); 
     439    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     440    $req->addHeader("x-amz-acl", $acl); 
     441 
     442    return $this->sendHttpRequest($req, 200); 
     443  } 
     444 
     445  /** 
     446   * Put Object(file, binary data, etc.) in Amazon S3 Bucket 
     447   * 
     448   * Method for uploading a file to a bucket on Amazon S3 
     449   * 
     450   * <code> 
     451   * <?php 
     452   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     453   * echo $sfAmazonS3->putObjectInBucket('bucket name', 'file_key', '/path/to/file', 'content/type', 'private'); // public-read, public-read-write, private, authenticated-users-read 
     454   * ?> 
     455   * </code> 
     456   *  
     457   * @param string $bucket Name of the bucket to put the object in 
     458   * @param string $key Key to identify the object 
     459   * @param string $fileName Name of the file to be displayed 
     460   * @param string $filePath Absolute path to the file that is to be uploaded to bucket 
     461   * @param string $contentType The MIME type for the file 
     462   * @param string $acl The ACL(permissions) for the file 
     463   * @param array $metaDataArray Array of meta data information for the object 
     464   * @param bool $md5 True/False for whether or not to MD5 the contents of the file 
     465   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     466   */ 
     467  public function putObjectInBucket($bucket, $key, $fileName, $filePath, $contentType, $acl = 'private', $metaDataArray = array(), $md5 = false) 
     468  { 
     469    $metaDataArray = !is_array($metaDataArray) ? array():$metaDataArray; 
     470    $this->action = 'put_object_in_bucket'; 
     471 
     472    sort($metaDataArray); 
     473    $resource = $bucket."/".urlencode($key); 
     474 
     475    $req = new HTTP_Request($this->serviceUrl.$resource); 
     476    $body = file_get_contents($filePath); 
     477    $req->setBody($body); 
     478    $req->setMethod("PUT"); 
     479    $httpDate = gmdate("D, d M Y G:i:s T"); 
     480    $req->addHeader("Date", $httpDate); 
     481    $req->addHeader("Content-Type", $contentType); 
     482    $req->addHeader("Content-Length", strlen($body)); 
     483    $req->addHeader("x-amz-acl", $acl); 
     484 
     485    if ($md5) 
     486    { 
     487      $MD5 = $this->hex2b64(md5_file($filePath)); 
     488      $req->addHeader("Content-MD5", $MD5); 
     489    } 
     490    else 
     491    { 
     492      $MD5 = ''; 
     493    } 
     494 
     495    $stringToSign = "PUT\n$MD5\n$contentType\n$httpDate\nx-amz-acl:$acl\n"; 
     496 
     497    /*  
     498    foreach($metaDataArray as $current) 
     499    { 
     500      if( $current != "" ) 
     501      { 
     502        $header = trim(substr($current, 0, strpos($current,':'))); 
     503        $meta = trim(substr($current, strpos($current, ':') +1, strlen($current))); 
     504 
     505        $req->addHeader("x-amz-meta-$header", $meta); 
     506 
     507        $stringToSign .= "x-amz-meta-$header:$meta\n"; 
     508      } 
     509    } 
     510    */ 
     511 
     512    $stringToSign .= "/$resource"; 
     513    $signature = $this->getSignedString($stringToSign);   
     514    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     515    $req->addHeader("Content-Disposition", "filename=\"".$fileName."\"");  
     516 
     517    return $this->sendHttpRequest($req, 200); 
     518  } 
     519 
     520  /** 
     521   * Stream Object to Amazon S3 Bucket 
     522   * 
     523   * This is not much different than the putObjectInBucket(), instead of using an http request to put the file, it uses curl. 
     524   * 
     525   * @param string $bucket Name of the bucket to put the object in 
     526   * @param string $key Name/key of the object 
     527   * @param string $filePath Absolute path to the file that is to be uploaded to bucket 
     528   * @param string $contentType The MIME type for the file 
     529   * @param string $acl The ACL(permissions) for the file 
     530   * @param array $metaDataArray Array of meta data information for the object 
     531   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     532   */ 
     533  public function streamObjectToBucket($bucket, $key, $filePath, $contentType, $acl = 'public', $metaDataArray = array()) 
     534  { 
     535    $metaDataArray = !is_array($metaDataArray) ? array():$metaDataArray; 
     536    $this->action = 'stream_object_to_bucket'; 
     537 
     538    $stream_inst = new sfAmazonS3ObjectStream(); 
     539    $stream_inst->data = fopen($filePath, "r"); 
     540    $streamFunction = array($stream_inst, "doStream"); 
     541 
     542    sort($metaDataArray); 
     543    $resource = "$bucket/$key"; 
     544    $resource = urlencode($resource); 
     545    $httpDate = gmdate("D, d M Y G:i:s T"); 
     546 
     547    $curl_inst = curl_init(); 
     548 
     549    curl_setopt ($curl_inst, CURLOPT_CONNECTTIMEOUT, 30); 
     550    curl_setopt ($curl_inst, CURLOPT_LOW_SPEED_LIMIT, 1); 
     551    curl_setopt ($curl_inst, CURLOPT_LOW_SPEED_TIME, 180); 
     552    curl_setopt ($curl_inst, CURLOPT_NOSIGNAL, 1); 
     553    curl_setopt ($curl_inst, CURLOPT_READFUNCTION, $streamFunction); 
     554    curl_setopt ($curl_inst, CURLOPT_URL, $this->serviceUrl . $resource); 
     555    curl_setopt ($curl_inst, CURLOPT_UPLOAD, true); 
     556    curl_setopt ($curl_inst, CURLINFO_CONTENT_LENGTH_UPLOAD, $contentLength); 
     557 
     558    $header[] = "Date: $httpDate"; 
     559    $header[] = "Content-Type: $contentType"; 
     560    $header[] = "Content-Length: $contentLength"; 
     561    $header[] = "Expect: "; 
     562    $header[] = "Transfer-Encoding: "; 
     563    $header[] = "x-amz-acl: $acl"; 
     564 
     565    $stringToSign="PUT\n$MD5\n$contentType\n$httpDate\nx-amz-acl:$acl\n"; 
     566 
     567    foreach ($metaDataArray as $current) 
     568    { 
     569      if ($current != "") 
     570      { 
     571        $stringToSign .= "x-amz-meta-$current\n"; 
     572        $header = substr($current,0,strpos($current,':')); 
     573        $meta = substr($current,strpos($current,':')+1,strlen($current)); 
     574        $header[] = "x-amz-meta-$header: $meta"; 
     575      } 
     576    } 
     577 
     578    $stringToSign .= "/$resource"; 
     579    $signature = $this->getSignedString($stringToSign); 
     580    $header[] = "Authorization: AWS $this->accessKeyId:$signature"; 
     581 
     582    curl_setopt($curl_inst, CURLOPT_HTTPHEADER, $header); 
     583    curl_setopt($curl_inst, CURLOPT_RETURNTRANSFER, 1); 
     584 
     585    $result = curl_exec ($curl_inst); 
     586 
     587    $this->responseString = $result; 
     588    $this->responseCode = curl_getinfo($curl_inst, CURLINFO_HTTP_CODE); 
     589    fclose($stream_inst->data); 
     590    curl_close($curl_inst); 
     591 
     592    return $this->validateResponseCode(200); 
     593  } 
    137594     
    138       if( !isset($sfAmazonS3) ) 
     595  /** 
     596   * Delete Bucket Object 
     597   * 
     598   * <code> 
     599   * <?php 
     600   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     601   * $sfAmazonS3->deleteBucketObject('bucket', 'key'); 
     602   * ?> 
     603   * </code> 
     604   *  
     605   * Method to delete a object/file from an Amazon S3 bucket 
     606   * 
     607   * @param string $bucket Name of the bucket 
     608   * @param string $key Name/key of the object 
     609   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     610   */ 
     611  public function deleteBucketObject($bucket, $key) 
     612  { 
     613    $this->action = 'delete_bucket_object'; 
     614 
     615    $httpDate = gmdate("D, d M Y G:i:s T"); 
     616    $resource = $bucket."/".urlencode($key); 
     617    $stringToSign = "DELETE\n\n\n$httpDate\n/$resource"; 
     618    $signature = $this->getSignedString($stringToSign); 
     619 
     620    $req = new HTTP_Request($this->serviceUrl.$resource); 
     621    $req->setMethod("DELETE"); 
     622    $req->addHeader("Date", $httpDate); 
     623    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     624 
     625    return $this->sendHttpRequest($req, 204); 
     626  } 
     627 
     628  /* 
     629   * Get Object Acl(permissions) 
     630   * 
     631   * Method for retrieving the current object acl 
     632   * 
     633   * <code> 
     634   * <?php 
     635   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     636   * echo $sfAmazonS3->getBucketObjectAcl('bucket', 'key'); 
     637   * ?> 
     638   * </code> 
     639   *  
     640   * @param string $bucket Name of the bucket 
     641   * @param string @key Name/key of the object  
     642   */ 
     643  public function getBucketObjectAcl($bucket, $key) 
     644  { 
     645    $this->action = 'get_bucket_object_acl'; 
     646 
     647    $httpDate = gmdate("D, d M Y G:i:s T"); 
     648    $resource = $bucket."/".urlencode($key); 
     649    $stringToSign = "GET\n\n\n$httpDate\n/$resource?acl"; 
     650    $signature = $this->getSignedString($stringToSign); 
     651 
     652    $req = new HTTP_Request($this->serviceUrl.$resource.'?acl'); 
     653    $req->setMethod("GET"); 
     654    $req->addHeader("Date", $httpDate); 
     655    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     656 
     657    if ($this->sendHttpRequest($req, 200)) 
     658    { 
     659      return $this->getActionData(); 
     660    } 
     661    else 
     662    { 
     663      return false;   
     664    } 
     665  } 
     666 
     667  /** 
     668   * Set Bucket Object Acl 
     669   * 
     670   * Method for setting the Acl(permissions) for a bucket object 
     671   * 
     672   * <code> 
     673   * <?php 
     674   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     675   * $sfAmazonS3->setBucketObjectAcl('bucket', 'key', 'private'); 
     676   * ?> 
     677   * </code> 
     678   *  
     679   * @param string $bucket Name of the bucket 
     680   * @param string $key Name/key of the object 
     681   * @param string $acl String for the object acl(private, public-read-write, public-read, authenticated-users-read) 
     682   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     683   */ 
     684  public function setBucketObjectAcl($bucket, $key, $acl) 
     685  { 
     686    $this->action = 'set_bucket_object_acl'; 
     687 
     688    $httpDate = gmdate("D, d M Y G:i:s T"); 
     689    $resource = $bucket."/".urlencode($key); 
     690    $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$resource?acl"; 
     691    $signature = $this->getSignedString($stringToSign); 
     692 
     693    $req = new HTTP_Request($this->serviceUrl.$resource.'?acl'); 
     694    $req->setMethod("PUT"); 
     695    $req->addHeader("Date", $httpDate); 
     696    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     697    $req->addHeader("x-amz-acl", $acl); 
     698 
     699    return $this->sendHttpRequest($req, 200); 
     700  } 
     701 
     702  /** 
     703   * Get Bucket Object Meta Data 
     704   * 
     705   * Method for retrieving all the meta data information for a object file 
     706   * 
     707   * <code> 
     708   * <?php 
     709   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     710   * $metaData = $sfAmazonS3->getBucketObjectMetaData('bucket', 'key'); 
     711   * print_r($metaData); 
     712   * ?> 
     713   * </code> 
     714   *  
     715   * @param string $bucket Name of the bucket 
     716   * @param string $key Name/key of the object 
     717   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     718   */ 
     719  public function getBucketObjectMetaData($bucket, $key) 
     720  { 
     721    $this->action = 'get_bucket_object_meta_data'; 
     722 
     723    $httpDate = gmdate("D, d M Y G:i:s T"); 
     724    $resource = $bucket."/".urlencode($key); 
     725    $stringToSign = "HEAD\n\n\n$httpDate\n/$resource"; 
     726    $signature = $this->getSignedString($stringToSign); 
     727 
     728    $req = new HTTP_Request($this->serviceUrl.$resource); 
     729    $req->setMethod("HEAD"); 
     730    $req->addHeader("Date", $httpDate); 
     731    $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
     732 
     733    if ($this->sendHttpRequest($req, 200)) 
     734    { 
     735      return $this->getActionData(); 
     736    } 
     737    else 
     738    { 
     739      return false; 
     740    } 
     741  } 
     742 
     743  /** 
     744   * Get Bucket Object As String 
     745   * 
     746   * Method for retrieving the contents of a object as a string 
     747   * 
     748   * <code> 
     749   * <?php 
     750   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     751   * header('Content-type: image/jpeg'); 
     752   * echo $sfAmazonS3->getBucketObjectAsString('bucket', 'key'); 
     753   * ?> 
     754   * </code> 
     755   *  
     756   * @param string $bucket Name of the bucket 
     757   * @param string $key Name/key of the object 
     758   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     759   */ 
     760  public function getBucketObjectAsString($bucket, $key) 
     761  { 
     762    $this->action = 'get_bucket_object_as_string'; 
     763 
     764    $httpDate = gmdate("D, d M Y G:i:s T"); 
     765    $resource = $bucket."/".urlencode($key); 
     766    $stringToSign = "GET\n\n\n{$httpDate}\n/$resource"; 
     767    $signature = $this->getSignedString($stringToSign); 
     768 
     769    $req = new HTTP_Request($this->serviceUrl.$resource); 
     770    $req->setMethod("GET"); 
     771    $req->addHeader("Date", $httpDate); 
     772    $req->addHeader("Authorization", "AWS ".$this->accessKeyId.":".$signature); 
     773 
     774    if ($this->sendHttpRequest($req, 200)) 
     775    { 
     776      return $this->getActionData(); 
     777    } 
     778    else 
     779    { 
     780      return false; 
     781    } 
     782  } 
     783 
     784  /** 
     785   * Get Bucket Object Query Url 
     786   * 
     787   * Method for getting the url to a specified object 
     788   * 
     789   * <code> 
     790   * <?php 
     791   * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
     792   * echo $sfAmazonS3->getBucketObjectQueryUrl('bucket', 'file key', 3600); // link lives for 1 hour 
     793   * ?> 
     794   * </code> 
     795   *  
     796   * @param string $bucket Name of bucket 
     797   * @param string $key Name/key of object 
     798   * @param int $expires Unix timestamp for when the link will expire 
     799   * @return string $queryString 
     800   */ 
     801  public function getBucketObjectQueryUrl($bucket, $key, $expires) 
     802  { 
     803    $expires = time() + $expires; 
     804    $resource = $bucket."/".urlencode($key); 
     805    $stringToSign = "GET\n\n\n$expires\n/$resource"; 
     806    $signature = urlencode($this->getSignedString($stringToSign)); 
     807    $queryString = $this->serviceUrl."$resource?AWSAccessKeyId=$this->accessKeyId&Expires=$expires&Signature=$signature"; 
     808 
     809    return $queryString;          
     810  } 
     811 
     812  /** 
     813   * Get Bucket Object Query Url Link 
     814   * 
     815   * Method for getting an html link for a bucket object 
     816   * 
     817   * @param string $bucket Name of bucket 
     818   * @param string $key Name/key of object 
     819   * @param int $expires Unix timestamp for when the link will expire 
     820   * @return string $link 
     821   */ 
     822  public function getBucketObjectQueryLink($bucket, $key, $expires) 
     823  { 
     824    $link = '<a href="'.$this->getBucketObjectQueryUrl($bucket, $key, $expires).'">'.$bucket.'/'.$key.'</a>'; 
     825 
     826    return $link; 
     827  } 
     828 
     829  /** 
     830   * Get Action Data 
     831   * 
     832   * Method for getting the processed data returned from the GET actions above 
     833   * 
     834   * @return mixed $result 
     835   */ 
     836  protected function getActionData() 
     837  { 
     838    switch ($this->action) 
     839    { 
     840      case 'list_buckets': 
     841        return $this->getBucketsArray(); 
     842      break; 
     843 
     844      case 'list_bucket_keys': 
     845        return $this->getBucketKeysArray(); 
     846      break; 
     847 
     848      case 'get_bucket_object_as_string': 
     849        return $this->responseString; 
     850      break; 
     851 
     852      case 'get_bucket_acl': 
     853        return $this->getBucketACLString(); 
     854      break; 
     855 
     856      case 'get_bucket_object_acl': 
     857        return $this->getBucketObjectACLString(); 
     858      break; 
     859 
     860      case 'get_bucket_object_meta_data': 
     861        return $this->headers; 
     862      break; 
     863    } 
     864  } 
     865 
     866  /** 
     867   * Send Http Request 
     868   * 
     869   * Standard function for sending the http request for an action. Sets some class vars after sending the request and validates that the request was successful 
     870   * 
     871   * @param object $httpRequest  
     872   * @param integer $successCode Code required for the http request to be successful 
     873   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     874   */ 
     875  protected function sendHttpRequest($httpRequest, $successCode) 
     876  { 
     877    $httpRequest->sendRequest(); 
     878 
     879    $this->responseCode = $httpRequest->getResponseCode(); 
     880    $this->responseString = $httpRequest->getResponseBody(); 
     881    $this->headers = $httpRequest->getResponseHeader(); 
     882    $this->parsedXml = simplexml_load_string($this->responseString); 
     883 
     884    return $this->validateResponseCode($successCode); 
     885  } 
     886 
     887  /** 
     888   * Validate Response Code 
     889   * 
     890   * Method for validating a http request was successful 
     891   * 
     892   * @param int @successCode 
     893   * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
     894   */ 
     895  protected function validateResponseCode($successCode) 
     896  { 
     897    if ($this->responseCode == $successCode) 
     898    { 
     899      return true; 
     900    } 
     901    else 
     902    { 
     903      throw new Exception($this->responseCode.' - '.$this->responseString); 
     904    } 
     905  } 
     906 
     907  /** 
     908   * Hex to Base 64 Converter 
     909   * 
     910   * @param string $string String to convert and return 
     911   * @return string $b64raw 
     912   */ 
     913  protected function hex2b64($string) 
     914  { 
     915    $raw = ''; 
     916 
     917    for ($i=0; $i < strlen($string); $i+=2) 
     918    { 
     919      $raw .= chr(hexdec(substr($string, $i, 2))); 
     920    } 
     921 
     922    $b64raw = base64_encode($raw); 
     923 
     924    return $b64raw; 
     925  } 
     926 
     927  /** 
     928   * Get Signed String 
     929   *  
     930   * Method for signing a unique string used in each action http request 
     931   * 
     932   * @param string $string  
     933   * @return string $signedString 
     934   */ 
     935  protected function getSignedString($string) 
     936  { 
     937    $hasher = new Crypt_HMAC($this->secretKey, "sha1"); 
     938    $signedString = $this->hex2b64($hasher->hash($string)); 
     939    return $signedString; 
     940  } 
     941 
     942  /** 
     943   * Get Buckets Array 
     944   * 
     945   * Processes the parsed xml in to a formatted array of buckets 
     946   * 
     947   * @return array $buckets 
     948   */ 
     949  protected function getBucketsArray() 
     950  { 
     951    $buckets = array(); 
     952 
     953    foreach ($this->parsedXml->Buckets->Bucket AS $key => $bucket) 
     954    { 
     955      $buckets[] = array('Name'         => (string)$bucket->Name, 
     956                         'CreationDate' => (string)$bucket->CreationDate); 
     957    } 
     958 
     959    return $buckets; 
     960  } 
     961 
     962  /** 
     963   * Get Bucket Keys Array 
     964   *  
     965   * Processes the parsed xml in to a formatted array of bucket keys/objects 
     966   * 
     967   * @return array $bucketKeys 
     968   */ 
     969  protected function getBucketKeysArray() 
     970  { 
     971    $bucketKeys = array(); 
     972 
     973    foreach ($this->parsedXml->Contents AS $key) 
     974    { 
     975      $bucketKeys[] = array('Key'          => (string)$key->Key, 
     976                            'LastModified' => (string)$key->LastModified, 
     977                            'ETag'         => (string)$key->Etag, 
     978                            'Size'         => (string)$key->Size, 
     979                            'Owner'        => array('ID' => (string)$key->Owner->ID, 'DisplayName' => (string)$key->Owner->DisplayName), 
     980                            'StorageClass' => (string)$key->StorageClass); 
     981    } 
     982 
     983    return $bucketKeys; 
     984  } 
     985 
     986  /** 
     987   * Get Bucket ACL String 
     988   * 
     989   * Since no method existed to simple return the string ACL that was passed when setting, I had to hack up this logic to determine what it is based on the xml 
     990   * 
     991   * @return string  
     992   */ 
     993  protected function getBucketACLString() 
     994  { 
     995    $string = ''; 
     996 
     997    foreach ($this->parsedXml->AccessControlList->Grant AS $perm) 
     998    { 
     999      if ($perm->Grantee->URI) 
    1391000      { 
    140         // Get instance 
    141         $className = sfConfig::get('app_amazon_s3_class_name'); 
    142         $sfAmazonS3 = new $className(sfConfig::get('app_amazon_s3_aws_access_key_id'), sfConfig::get('app_amazon_s3_secret_access_key'));  
     1001        $string .= (string)str_replace('http://acs.amazonaws.com/groups/global/', '', $perm->Grantee->URI); 
     1002        $string .= (string)$perm->Permission; 
    1431003      } 
    144  
    145       return $sfAmazonS3; 
    146     } 
    147  
    148  
    149     /** 
    150      * Create Amazon S3 Bucket 
    151      * 
    152      * Method for create a blank bucket on Amazon S3, bucket name must be inique across all of Amazon 
    153      * <code> 
    154      * <?php 
    155      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    156      * $sfAmazonS3->createBucket('name', 'private'); // 2nd argument can be public-read, public-read-write, private, authenticated-users-read 
    157      * ?> 
    158      * </code> 
    159      * 
    160      * @param string $bucket Unique name of your bucket to create 
    161      * @param string $acl Amazon S3 permission setting (private, public-read, public-read-write, authenticated-users-read) 
    162      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    163      */ 
    164     public function createBucket($bucket, $acl = 'private') 
    165     { 
    166         $this->action = 'create_bucket'; 
    167          
    168         $httpDate = gmdate("D, d M Y G:i:s T"); 
    169         $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$bucket"; 
    170         $signature = $this->getSignedString($stringToSign); 
    171          
    172         $req = new HTTP_Request($this->serviceUrl . $bucket); 
    173         $req->setMethod("PUT"); 
    174         $req->addHeader("Date", $httpDate); 
    175         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    176         $req->addHeader("x-amz-acl", $acl); 
    177          
    178         return $this->sendHttpRequest($req, 200);  
    179     } 
    180      
    181     /** 
    182      * Delete Amazon S3 Bucket 
    183      * 
    184      * Method for emptying and deleting a bucket on Amazon S3 
    185      * 
    186      * <code> 
    187      * <?php 
    188      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    189      * $sfAmazonS3->deleteBucket('bucket_name'); 
    190      * ?> 
    191      * </code> 
    192      *  
    193      * @param string $bucket Name of the bucket you wish to delete 
    194      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    195      */ 
    196     public function deleteBucket($bucket) 
    197     { 
    198         $this->emptyBucket($bucket); 
    199   
    200         $this->action = 'delete_bucket'; 
    201          
    202         $httpDate = gmdate("D, d M Y G:i:s T"); 
    203         $stringToSign = "DELETE\n\n\n$httpDate\n/$bucket"; 
    204         $signature = $this->getSignedString($stringToSign); 
    205          
    206         $req = new HTTP_Request($this->serviceUrl . $bucket); 
    207         $req->setMethod("DELETE"); 
    208         $req->addHeader("Date", $httpDate); 
    209         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    210          
    211         return $this->sendHttpRequest($req, 204);  
    212     } 
    213   
    214     /** 
    215      * Empty Amazon S3 Bucket 
    216      * 
    217      * Method for emptying a bucket on Amazon S3. This method pulls all the objects in the bucket and calls the delete method on each bucket object 
    218      * 
    219      * <code> 
    220      * <?php 
    221      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    222      * $sfAmazonS3->emptyBucket('bucket name'); 
    223      * ?> 
    224      * </code> 
    225      *  
    226      * @param string $bucket Name of the bucket you wish to empty 
    227      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    228      */ 
    229     public function emptyBucket($bucket) 
    230     { 
    231         $this->action = 'empty_bucket'; 
    232          
    233         if( $this->listBucketKeys($bucket) ) 
    234         { 
    235             $more = $this->parsedXml->IsTruncated; // determine of all keys in bucket are returned on this list call 
    236             $keys = $this->parsedXml->Contents; 
    237              
    238             // set up array for catching keys that aren't successfully deleted and set the initial count of these to 0 
    239             $not_deleted_keys = array(); 
    240             $not_deleted_count = 0; 
    241             foreach($keys as $current) 
    242             { 
    243                 //try up to 3 times to delete current key 
    244                 $tries=1; 
    245                 while(!$this->deleteBucketObject($bucket, $current->Key) && $tries <= 3) 
    246                 { 
    247                     $tries++; 
    248                 } 
    249                  
    250                 //capture any keys that aren't deleted 
    251                 if( $tries > 3 ) 
    252                 { 
    253                      $not_deleted_keys[$not_deleted_count] = $current->Key; 
    254                     $not_deleted_count++; 
    255                 } 
    256             } 
    257         } else { 
    258             throw new Exception('listBucketKeys() failed'); 
    259         } 
    260   
    261         // call emptyBucket if not all keys were returned with last list call 
    262         if( $more == "true" ) 
    263         { 
    264             $this->emptyBucket($bucket); 
    265         } 
    266          
    267         return true; 
    268     } 
    269      
    270     /** 
    271      * List Amazon S3 Buckets 
    272      * 
    273      * Method for retrieving a list of all the buckets in your Amazon S3 account 
    274      * 
    275      * <code> 
    276      * <?php 
    277      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    278      * $buckets = $sfAmazonS3->listBuckets(); 
    279      * print_r($buckets); 
    280      * ?> 
    281      * </code> 
    282      *  
    283      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    284      */ 
    285     public function listBuckets() 
    286     { 
    287         $this->action = 'list_buckets'; 
    288          
    289         $httpDate = gmdate("D, d M Y G:i:s T"); 
    290         $stringToSign="GET\n\n\n$httpDate\n/"; 
    291         $signature = $this->getSignedString($stringToSign); 
    292          
    293         $req = new HTTP_Request($this->serviceUrl); 
    294         $req->addHeader("Date", $httpDate); 
    295         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    296          
    297         if( $this->sendHttpRequest($req, 200) ) 
    298         { 
    299             return $this->getActionData(); 
    300         } else { 
    301             return false; 
    302         } 
    303     } 
    304      
    305     /** 
    306      * List Bucket Objects 
    307      *   
    308      * <code> 
    309      * <?php 
    310      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    311      * $bucketObjects = $sfAmazonS3->listBucketObjects('bucket name'); 
    312      * print_r($bucketObjects); 
    313      * ?> 
    314      * </code> 
    315      *  
    316      * @param mixed $bucket  
    317      * @param mixed $marker  
    318      * @param mixed $prefix  
    319      * @param mixed $delimiter  
    320      * @param int $maxKeys  
    321      * @access public 
    322      * @return void 
    323      */ 
    324     public function listBucketObjects($bucket, $marker = FALSE, $prefix = FALSE, $delimiter = FALSE, $maxKeys = 1000) 
    325     { 
    326         return $this->listBucketKeys($bucket, $marker, $prefix, $delimiter, $maxKeys); 
    327     } 
    328      
    329     /** 
    330      * List Buckets Keys/Objects 
    331      * 
    332      * Method for retrieving all the objects in a specified bucket 
    333       
    334      * <code> 
    335      * <?php 
    336      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    337      * $bucketObjects = $sfAmazonS3->listBucketKeys('bucket name'); 
    338      * print_r($bucketObjects); 
    339      * ?> 
    340      * </code> 
    341      *  
    342      * @param string $bucket Name of the bucket 
    343      * @param bool $marker  
    344      * @param bool $prefix  
    345      * @param bool $delimiter  
    346      * @param int $maxKeys  
    347      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    348      */ 
    349     public function listBucketKeys($bucket, $marker = FALSE, $prefix = FALSE, $delimiter = FALSE, $maxKeys = 1000) 
    350     { 
    351         $this->action = 'list_bucket_keys'; 
    352          
    353         $httpDate = gmdate("D, d M Y G:i:s T"); 
    354         $stringToSign = "GET\n\n\n$httpDate\n/$bucket"; 
    355         $signature = $this->getSignedString($stringToSign); 
    356          
    357         $req = new HTTP_Request($this->serviceUrl.$bucket."?max-keys={$maxKeys}&marker={$marker}&prefix={$prefix}&delimiter={$delimiter}"); 
    358         $req->addHeader("Date", $httpDate); 
    359         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    360          
    361         if( $this->sendHttpRequest($req, 200) ) 
    362         { 
    363           return $this->getActionData(); 
    364         } else { 
    365           return false; 
    366         } 
    367     } 
    368   
    369     /** 
    370      * Get Amazon S3 Bucket Acl(permissions) 
    371      * 
    372      * Method for retrieving the current ACL for a specified bucket 
    373      * 
    374      * <code> 
    375      * <?php 
    376      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    377      * echo $sfAmazonS3->getBucketAcl('bucket name'); // public-read, public-read-write, private, authenticated-users-read 
    378      * ?> 
    379      * </code> 
    380      *  
    381      * @param string $bucket Name of the bucket 
    382      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    383      */ 
    384     public function getBucketAcl($bucket) 
    385     { 
    386         $this->action = 'get_bucket_acl'; 
    387          
    388         $httpDate = gmdate("D, d M Y G:i:s T"); 
    389         $stringToSign = "GET\n\n\n$httpDate\n/$bucket/?acl"; 
    390         $signature = $this->getSignedString($stringToSign); 
    391          
    392         $req = new HTTP_Request($this->serviceUrl.$bucket.'/?acl'); 
    393         $req->setMethod("GET"); 
    394         $req->addHeader("Date", $httpDate); 
    395         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    396          
    397         if( $this->sendHttpRequest($req, 200) ) 
    398         { 
    399           return $this->getActionData(); 
    400         } else { 
    401           return false; 
    402         } 
    403     } 
    404      
    405     /** 
    406      * Set Amazon S3 Bucket Acl(permissions) 
    407      * 
    408      * Method for setting the current Acl fpr a speficied bucket 
    409      *  
    410      * <code> 
    411      * <?php 
    412      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    413      * $sfAmazonS3->setBucketAcl('bucket name', 'public-read'); // public-read, public-read-write, private, authenticated-users-read 
    414      * ?> 
    415      * </code> 
    416      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    417      */ 
    418     public function setBucketAcl($bucket, $acl) 
    419     { 
    420         $this->action = 'set_bucket_acl'; 
    421          
    422         $httpDate = gmdate("D, d M Y G:i:s T"); 
    423         $stringToSign = "PUT\n\n\n{$httpDate}\nx-amz-acl:$acl\n/$bucket/?acl"; 
    424         $signature = $this->getSignedString($stringToSign); 
    425          
    426         $req = new HTTP_Request($this->serviceUrl.$bucket.'/?acl'); 
    427         $req->setMethod("PUT"); 
    428         $req->addHeader("Date", $httpDate); 
    429         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    430         $req->addHeader("x-amz-acl", $acl); 
    431          
    432         return $this->sendHttpRequest($req, 200); 
    433     } 
    434      
    435     /** 
    436      * Put Object(file, binary data, etc.) in Amazon S3 Bucket 
    437      * 
    438      * Method for uploading a file to a bucket on Amazon S3 
    439      * 
    440      * <code> 
    441      * <?php 
    442      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    443      * echo $sfAmazonS3->putObjectInBucket('bucket name', 'file_key', '/path/to/file', 'content/type', 'private'); // public-read, public-read-write, private, authenticated-users-read 
    444      * ?> 
    445      * </code> 
    446      *  
    447      * @param string $bucket Name of the bucket to put the object in 
    448      * @param string $key Key to identify the object 
    449      * @param string $fileName Name of the file to be displayed 
    450      * @param string $filePath Absolute path to the file that is to be uploaded to bucket 
    451      * @param string $contentType The MIME type for the file 
    452      * @param string $acl The ACL(permissions) for the file 
    453      * @param array $metaDataArray Array of meta data information for the object 
    454      * @param bool $md5 True/False for whether or not to MD5 the contents of the file 
    455      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    456      */ 
    457     public function putObjectInBucket($bucket, $key, $fileName, $filePath, $contentType, $acl = 'private', $metaDataArray = array(), $md5 = false) 
    458     { 
    459         $metaDataArray = !is_array($metaDataArray) ? array():$metaDataArray; 
    460         $this->action = 'put_object_in_bucket'; 
    461          
    462         sort($metaDataArray); 
    463         $resource = $bucket."/".urlencode($key); 
    464          
    465         $req = new HTTP_Request($this->serviceUrl.$resource); 
    466         $body = file_get_contents($filePath); 
    467         $req->setBody($body); 
    468         $req->setMethod("PUT"); 
    469         $httpDate = gmdate("D, d M Y G:i:s T"); 
    470         $req->addHeader("Date", $httpDate); 
    471         $req->addHeader("Content-Type", $contentType); 
    472         $req->addHeader("Content-Length", strlen($body)); 
    473         $req->addHeader("x-amz-acl", $acl); 
    474          
    475         if( $md5 ) 
    476         { 
    477             $MD5 = $this->hex2b64(md5_file($filePath)); 
    478             $req->addHeader("Content-MD5", $MD5); 
    479         } else { 
    480             $MD5 = ''; 
    481         } 
    482          
    483         $stringToSign = "PUT\n$MD5\n$contentType\n$httpDate\nx-amz-acl:$acl\n"; 
    484          
    485         /*  
    486         foreach($metaDataArray as $current) 
    487         { 
    488             if( $current != "" ) 
    489             { 
    490                 $header = trim(substr($current, 0, strpos($current,':'))); 
    491                 $meta = trim(substr($current, strpos($current, ':') +1, strlen($current))); 
    492  
    493                 $req->addHeader("x-amz-meta-$header", $meta); 
    494  
    495                 $stringToSign .= "x-amz-meta-$header:$meta\n"; 
    496             } 
    497         } 
    498         */ 
    499  
    500         $stringToSign .= "/$resource"; 
    501          
    502         $signature = $this->getSignedString($stringToSign);     
    503          
    504         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    505          
    506         $req->addHeader("Content-Disposition", "filename=\"".$fileName."\"");  
    507          
    508         return $this->sendHttpRequest($req, 200); 
    509     } 
    510      
    511     /** 
    512      * Stream Object to Amazon S3 Bucket 
    513      * 
    514      * This is not much different than the putObjectInBucket(), instead of using an http request to put the file, it uses curl. 
    515      * 
    516      * @param string $bucket Name of the bucket to put the object in 
    517      * @param string $key Name/key of the object 
    518      * @param string $filePath Absolute path to the file that is to be uploaded to bucket 
    519      * @param string $contentType The MIME type for the file 
    520      * @param string $acl The ACL(permissions) for the file 
    521      * @param array $metaDataArray Array of meta data information for the object 
    522      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    523      */ 
    524     public function streamObjectToBucket($bucket, $key, $filePath, $contentType, $acl = 'public', $metaDataArray = array()) 
    525     { 
    526         $metaDataArray = !is_array($metaDataArray) ? array():$metaDataArray; 
    527         $this->action = 'stream_object_to_bucket'; 
    528          
    529         $stream_inst = new sfAmazonS3ObjectStream(); 
    530         $stream_inst->data = fopen($filePath, "r"); 
    531         $streamFunction = array($stream_inst, "doStream"); 
    532              
    533         sort($metaDataArray); 
    534         $resource = "$bucket/$key"; 
    535         $resource = urlencode($resource); 
    536         $httpDate = gmdate("D, d M Y G:i:s T"); 
    537      
    538         $curl_inst = curl_init(); 
    539      
    540         curl_setopt ($curl_inst, CURLOPT_CONNECTTIMEOUT, 30); 
    541         curl_setopt ($curl_inst, CURLOPT_LOW_SPEED_LIMIT, 1); 
    542         curl_setopt ($curl_inst, CURLOPT_LOW_SPEED_TIME, 180); 
    543         curl_setopt ($curl_inst, CURLOPT_NOSIGNAL, 1); 
    544         curl_setopt ($curl_inst, CURLOPT_READFUNCTION, $streamFunction); 
    545         curl_setopt ($curl_inst, CURLOPT_URL, $this->serviceUrl . $resource); 
    546         curl_setopt ($curl_inst, CURLOPT_UPLOAD, true); 
    547         curl_setopt ($curl_inst, CURLINFO_CONTENT_LENGTH_UPLOAD, $contentLength); 
    548      
    549         $header[] = "Date: $httpDate"; 
    550         $header[] = "Content-Type: $contentType"; 
    551         $header[] = "Content-Length: $contentLength"; 
    552         $header[] = "Expect: "; 
    553         $header[] = "Transfer-Encoding: "; 
    554         $header[] = "x-amz-acl: $acl"; 
    555      
    556         $stringToSign="PUT\n$MD5\n$contentType\n$httpDate\nx-amz-acl:$acl\n"; 
    557              
    558         foreach($metaDataArray as $current) 
    559         { 
    560             if( $current != "" ) 
    561             { 
    562                 $stringToSign .= "x-amz-meta-$current\n"; 
    563                 $header = substr($current,0,strpos($current,':')); 
    564                 $meta = substr($current,strpos($current,':')+1,strlen($current)); 
    565                 $header[] = "x-amz-meta-$header: $meta"; 
    566             } 
    567         } 
    568          
    569         $stringToSign .= "/$resource"; 
    570         $signature = $this->getSignedString($stringToSign); 
    571         $header[] = "Authorization: AWS $this->accessKeyId:$signature"; 
    572          
    573         curl_setopt($curl_inst, CURLOPT_HTTPHEADER, $header); 
    574         curl_setopt($curl_inst, CURLOPT_RETURNTRANSFER, 1); 
    575          
    576         $result = curl_exec ($curl_inst); 
    577          
    578         $this->responseString = $result; 
    579         $this->responseCode = curl_getinfo($curl_inst, CURLINFO_HTTP_CODE); 
    580         fclose($stream_inst->data); 
    581         curl_close($curl_inst); 
    582          
    583         return $this->validateResponseCode(200); 
    584     } 
    585      
    586     /** 
    587      * Delete Bucket Object 
    588      * 
    589      * <code> 
    590      * <?php 
    591      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    592      * $sfAmazonS3->deleteBucketObject('bucket', 'key'); 
    593      * ?> 
    594      * </code> 
    595      *  
    596      * Method to delete a object/file from an Amazon S3 bucket 
    597      * 
    598      * @param string $bucket Name of the bucket 
    599      * @param string $key Name/key of the object 
    600      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    601      */ 
    602     public function deleteBucketObject($bucket, $key) 
    603     { 
    604         $this->action = 'delete_bucket_object'; 
    605          
    606         $httpDate = gmdate("D, d M Y G:i:s T"); 
    607         $resource = $bucket."/".urlencode($key); 
    608         $stringToSign = "DELETE\n\n\n$httpDate\n/$resource"; 
    609         $signature = $this->getSignedString($stringToSign); 
    610          
    611         $req = new HTTP_Request($this->serviceUrl.$resource); 
    612         $req->setMethod("DELETE"); 
    613         $req->addHeader("Date", $httpDate); 
    614         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    615          
    616         return $this->sendHttpRequest($req, 204); 
    617     } 
    618      
    619     /* 
    620      * Get Object Acl(permissions) 
    621      * 
    622      * Method for retrieving the current object acl 
    623      * 
    624      * <code> 
    625      * <?php 
    626      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    627      * echo $sfAmazonS3->getBucketObjectAcl('bucket', 'key'); 
    628      * ?> 
    629      * </code> 
    630      *  
    631      * @param string $bucket Name of the bucket 
    632      * @param string @key Name/key of the object  
    633      */ 
    634     public function getBucketObjectAcl($bucket, $key) 
    635     { 
    636         $this->action = 'get_bucket_object_acl'; 
    637          
    638         $httpDate = gmdate("D, d M Y G:i:s T"); 
    639         $resource = $bucket."/".urlencode($key); 
    640         $stringToSign = "GET\n\n\n$httpDate\n/$resource?acl"; 
    641         $signature = $this->getSignedString($stringToSign); 
    642          
    643         $req = new HTTP_Request($this->serviceUrl.$resource.'?acl'); 
    644         $req->setMethod("GET"); 
    645         $req->addHeader("Date", $httpDate); 
    646         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    647          
    648         if( $this->sendHttpRequest($req, 200) ) 
    649         { 
    650           return $this->getActionData(); 
    651         } else { 
    652           return false;  
    653         } 
    654     } 
    655      
    656     /** 
    657      * Set Bucket Object Acl 
    658      * 
    659      * Method for setting the Acl(permissions) for a bucket object 
    660      * 
    661      * <code> 
    662      * <?php 
    663      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    664      * $sfAmazonS3->setBucketObjectAcl('bucket', 'key', 'private'); 
    665      * ?> 
    666      * </code> 
    667      *  
    668      * @param string $bucket Name of the bucket 
    669      * @param string $key Name/key of the object 
    670      * @param string $acl String for the object acl(private, public-read-write, public-read, authenticated-users-read) 
    671      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    672      */ 
    673     public function setBucketObjectAcl($bucket, $key, $acl) 
    674     { 
    675         $this->action = 'set_bucket_object_acl'; 
    676          
    677         $httpDate = gmdate("D, d M Y G:i:s T"); 
    678         $resource = $bucket."/".urlencode($key); 
    679         $stringToSign = "PUT\n\n\n$httpDate\nx-amz-acl:$acl\n/$resource?acl"; 
    680         $signature = $this->getSignedString($stringToSign); 
    681          
    682         $req = new HTTP_Request($this->serviceUrl.$resource.'?acl'); 
    683         $req->setMethod("PUT"); 
    684         $req->addHeader("Date", $httpDate); 
    685         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    686         $req->addHeader("x-amz-acl", $acl); 
    687          
    688         return $this->sendHttpRequest($req, 200); 
    689     } 
    690      
    691     /** 
    692      * Get Bucket Object Meta Data 
    693      * 
    694      * Method for retrieving all the meta data information for a object file 
    695      * 
    696      * <code> 
    697      * <?php 
    698      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    699      * $metaData = $sfAmazonS3->getBucketObjectMetaData('bucket', 'key'); 
    700      * print_r($metaData); 
    701      * ?> 
    702      * </code> 
    703      *  
    704      * @param string $bucket Name of the bucket 
    705      * @param string $key Name/key of the object 
    706      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    707      */ 
    708     public function getBucketObjectMetaData($bucket, $key) 
    709     { 
    710         $this->action = 'get_bucket_object_meta_data'; 
    711          
    712         $httpDate = gmdate("D, d M Y G:i:s T"); 
    713         $resource = $bucket."/".urlencode($key); 
    714         $stringToSign = "HEAD\n\n\n$httpDate\n/$resource"; 
    715         $signature = $this->getSignedString($stringToSign); 
    716          
    717         $req = new HTTP_Request($this->serviceUrl.$resource); 
    718         $req->setMethod("HEAD"); 
    719         $req->addHeader("Date", $httpDate); 
    720         $req->addHeader("Authorization", "AWS " . $this->accessKeyId . ":" . $signature); 
    721          
    722         if( $this->sendHttpRequest($req, 200) ) 
    723         { 
    724           return $this->getActionData(); 
    725         } else { 
    726           return false; 
    727         } 
    728     } 
    729      
    730     /** 
    731      * Get Bucket Object As String 
    732      * 
    733      * Method for retrieving the contents of a object as a string 
    734      * 
    735      * <code> 
    736      * <?php 
    737      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    738      * header('Content-type: image/jpeg'); 
    739      * echo $sfAmazonS3->getBucketObjectAsString('bucket', 'key'); 
    740      * ?> 
    741      * </code> 
    742      *  
    743      * @param string $bucket Name of the bucket 
    744      * @param string $key Name/key of the object 
    745      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    746      */ 
    747     public function getBucketObjectAsString($bucket, $key) 
    748     { 
    749         $this->action = 'get_bucket_object_as_string'; 
    750          
    751         $httpDate = gmdate("D, d M Y G:i:s T"); 
    752         $resource = $bucket."/".urlencode($key); 
    753         $stringToSign = "GET\n\n\n{$httpDate}\n/$resource"; 
    754         $signature = $this->getSignedString($stringToSign); 
    755          
    756         $req = new HTTP_Request($this->serviceUrl.$resource); 
    757         $req->setMethod("GET"); 
    758         $req->addHeader("Date", $httpDate); 
    759         $req->addHeader("Authorization", "AWS ".$this->accessKeyId.":".$signature); 
    760          
    761         if( $this->sendHttpRequest($req, 200) ) 
    762         { 
    763           return $this->getActionData(); 
    764         } else { 
    765           return false; 
    766         } 
    767     } 
    768      
    769     /** 
    770      * Get Bucket Object Query Url 
    771      * 
    772      * Method for getting the url to a specified object 
    773      * 
    774      * <code> 
    775      * <?php 
    776      * $sfAmazonS3 = new BasesfAmazonS3('accessKeyId', 'secretKey'); 
    777      * echo $sfAmazonS3->getBucketObjectQueryUrl('bucket', 'file key', 3600); // link lives for 1 hour 
    778      * ?> 
    779      * </code> 
    780      *  
    781      * @param string $bucket Name of bucket 
    782      * @param string $key Name/key of object 
    783      * @param int $expires Unix timestamp for when the link will expire 
    784      * @return string $queryString 
    785      */ 
    786     public function getBucketObjectQueryUrl($bucket, $key, $expires) 
    787     { 
    788         $expires = time() + $expires; 
    789         $resource = $bucket."/".urlencode($key); 
    790         $stringToSign = "GET\n\n\n$expires\n/$resource"; 
    791         $signature = urlencode($this->getSignedString($stringToSign)); 
    792         $queryString = $this->serviceUrl."$resource?AWSAccessKeyId=$this->accessKeyId&Expires=$expires&Signature=$signature"; 
    793          
    794         return $queryString;          
    795     } 
    796      
    797     /** 
    798      * Get Bucket Object Query Url Link 
    799      * 
    800      * Method for getting an html link for a bucket object 
    801      * 
    802      * @param string $bucket Name of bucket 
    803      * @param string $key Name/key of object 
    804      * @param int $expires Unix timestamp for when the link will expire 
    805      * @return string $link 
    806      */ 
    807     public function getBucketObjectQueryLink($bucket, $key, $expires) 
    808     { 
    809         $link = '<a href="'.$this->getBucketObjectQueryUrl($bucket, $key, $expires).'">'.$bucket.'/'.$key.'</a>'; 
    810          
    811         return $link; 
    812     } 
    813      
    814     /** 
    815      * Get Action Data 
    816      * 
    817      * Method for getting the processed data returned from the GET actions above 
    818      * 
    819      * @return mixed $result 
    820      */ 
    821     protected function getActionData() 
    822     { 
    823         switch($this->action) 
    824         { 
    825             case 'list_buckets': 
    826                 return $this->getBucketsArray(); 
    827             break; 
    828              
    829             case 'list_bucket_keys': 
    830                 return $this->getBucketKeysArray(); 
    831             break; 
    832   
    833             case 'get_bucket_object_as_string': 
    834                 return $this->responseString; 
    835             break; 
    836   
    837             case 'get_bucket_acl': 
    838                 return $this->getBucketACLString(); 
    839             break; 
    840   
    841             case 'get_bucket_object_acl': 
    842                 return $this->getBucketObjectACLString(); 
    843             break; 
    844   
    845             case 'get_bucket_object_meta_data': 
    846                 return $this->headers; 
    847             break; 
    848         } 
    849     } 
    850      
    851     /** 
    852      * Send Http Request 
    853      * 
    854      * Standard function for sending the http request for an action. Sets some class vars after sending the request and validates that the request was successful 
    855      * 
    856      * @param object $httpRequest  
    857      * @param integer $successCode Code required for the http request to be successful 
    858      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    859      */ 
    860     protected function sendHttpRequest($httpRequest, $successCode) 
    861     { 
    862         $httpRequest->sendRequest(); 
    863   
    864         $this->responseCode = $httpRequest->getResponseCode(); 
    865         $this->responseString = $httpRequest->getResponseBody(); 
    866         $this->headers = $httpRequest->getResponseHeader(); 
    867         $this->parsedXml = simplexml_load_string($this->responseString); 
    868          
    869         return $this->validateResponseCode($successCode); 
    870     } 
    871      
    872     /** 
    873      * Validate Response Code 
    874      * 
    875      * Method for validating a http request was successful 
    876      * 
    877      * @param int @successCode 
    878      * @return mixed $response Returns true if the call was successful, otherwise throws an exception 
    879      */ 
    880     protected function validateResponseCode($successCode) 
    881     { 
    882         if( $this->responseCode == $successCode ) 
    883         { 
    884             return true; 
    885         } else { 
    886             throw new Exception($this->responseCode.' - '.$this->responseString); 
    887         } 
    888     } 
    889      
    890     /** 
    891      * Hex to Base 64 Converter 
    892      * 
    893      * @param string $string String to convert and return 
    894      * @return string $b64raw 
    895      */ 
    896     protected function hex2b64($string) 
    897     { 
    898         $raw = ''; 
    899         for ($i=0; $i < strlen($string); $i+=2) 
    900         { 
    901             $raw .= chr(hexdec(substr($string, $i, 2))); 
    902         } 
    903          
    904         $b64raw = base64_encode($raw); 
    905          
    906         return $b64raw; 
    907     } 
    908      
    909     /** 
    910      * Get Signed String 
    911      *  
    912      * Method for signing a unique string used in each action http request 
    913      * 
    914      * @param string $string  
    915      * @return string $signedString 
    916      */ 
    917     protected function getSignedString($string) 
    918     { 
    919         $hasher = new Crypt_HMAC($this->secretKey, "sha1"); 
    920          
    921         $signedString = $this->hex2b64($hasher->hash($string)); 
    922          
    923         return $signedString; 
    924     } 
    925      
    926     /** 
    927      * Get Buckets Array 
    928      * 
    929      * Processes the parsed xml in to a formatted array of buckets 
    930      * 
    931      * @return array $buckets 
    932      */ 
    933     protected function getBucketsArray() 
    934     { 
    935         $buckets = array();     
    936          
    937         foreach($this->parsedXml->Buckets->Bucket AS $key => $bucket) 
    938         { 
    939             $buckets[] = array('Name'                     =>     (string)$bucket->Name, 
    940                                                  'CreationDate'     =>     (string)$bucket->CreationDate); 
    941         } 
    942   
    943         return $buckets; 
    944     } 
    945      
    946     /** 
    947      * Get Bucket Keys Array 
    948      *  
    949      * Processes the parsed xml in to a formatted array of bucket keys/objects 
    950      * 
    951      * @return array $bucketKeys 
    952      */ 
    953     protected function getBucketKeysArray() 
    954     { 
    955         $bucketKeys = array(); 
    956          
    957         foreach($this->parsedXml->Contents AS $key) 
    958         { 
    959             $bucketKeys[] = array(    'Key'                         =>     (string)$key->Key, 
    960                                                             'LastModified'        =>    (string)$key->LastModified, 
    961                                                             'ETag'                        =>    (string)$key->Etag, 
    962                                                             'Size'                        =>    (string)$key->Size, 
    963                                                             'Owner'                        =>    array('ID' => (string)$key->Owner->ID, 'DisplayName' => (string)$key->Owner->DisplayName), 
    964                                                             'StorageClass'        =>    (string)$key->StorageClass); 
    965         } 
    966          
    967         return $bucketKeys; 
    968     } 
    969   
    970     /** 
    971      * Get Bucket ACL String 
    972      * 
    973      * Since no method existed to simple return the string ACL that was passed when setting, I had to hack up this logic to determine what it is based on the xml 
    974      * 
    975      * @return string  
    976      */ 
    977     protected function getBucketACLString() 
    978     { 
    979         $string = ''; 
    980         foreach($this->parsedXml->AccessControlList->Grant AS $perm) 
    981         { 
    982             if( $perm->Grantee->URI ) 
    983             { 
    984                 $string .= (string)str_replace('http://acs.amazonaws.com/groups/global/', '', $perm->Grantee->URI); 
    985                 $string .= (string)$perm->Permission; 
    986             } 
    987   
    988         } 
    989          
    990         if( !strstr($string, 'AuthenticatedUsersREAD') AND !strstr($string, 'AllUsersREAD') AND !strstr($string, 'AllUsersWRITE') ) 
    991         { 
    992             return 'private'; 
    993         } 
    994         else if( strstr($string, 'AllUsersREAD') AND strstr($string, 'AllUsersWRITE') ) 
    995         { 
    996             return 'public-read-write'; 
    997         } 
    998         else if( strstr($string, 'AllUsersREAD') AND !strstr($string, 'AllUsersWRITE') ) 
    999         { 
    1000             return 'public-read'; 
    1001         } 
    1002         else if( !strstr($string, 'AllUsersREAD') AND strstr($string, 'AllUsersWRITE') ) 
    1003         { 
    1004             return 'public-write'; 
    1005         } 
    1006         else if( strstr($string, 'AuthenticatedUsersREAD') ) 
    1007         { 
    1008             return 'authenticated-read'; 
    1009         }         
    1010     } 
    1011      
    1012     /* 
    1013      * Same as getBucketACLString() but it is for a BucketObject instead of a Bucket 
    1014      * 
    1015      * @return string 
    1016      */ 
    1017     protected function getBucketObjectACLString() 
    1018     { 
    1019         return $this->getBucketACLString(); 
    1020     } 
     1004    } 
     1005 
     1006    if (!strstr($string, 'AuthenticatedUsersREAD') AND !strstr($string, 'AllUsersREAD') AND !strstr($string, 'AllUsersWRITE')) 
     1007    { 
     1008      return 'private'; 
     1009    } 
     1010    elseif (strstr($string, 'AllUsersREAD') AND strstr($string, 'AllUsersWRITE')) 
     1011    { 
     1012      return 'public-read-write'; 
     1013    } 
     1014    elseif (strstr($string, 'AllUsersREAD') AND !strstr($string, 'AllUsersWRITE')) 
     1015    { 
     1016      return 'public-read'; 
     1017    } 
     1018    elseif (!strstr($string, 'AllUsersREAD') AND strstr($string, 'AllUsersWRITE')) 
     1019    { 
     1020      return 'public-write'; 
     1021    } 
     1022    elseif (strstr($string, 'AuthenticatedUsersREAD')) 
     1023    { 
     1024      return 'authenticated-read'; 
     1025    }         
     1026  } 
     1027 
     1028  /* 
     1029   * Same as getBucketACLString() but it is for a BucketObject instead of a Bucket 
     1030   * 
     1031   * @return string 
     1032   */ 
     1033  protected function getBucketObjectACLString() 
     1034  { 
     1035    return $this->getBucketACLString(); 
     1036  } 
    10211037} 
    1022   
     1038 
    10231039/** 
    10241040 * Symfony Amazon S3 Object Stream Class 
     
    10331049class sfAmazonS3ObjectStream 
    10341050{ 
    1035  /** 
    1036  * data  
    1037  *  
    1038  * @var mixed 
    1039  * @access public 
    1040  */ 
    1041  public $data; 
     1051  /** 
     1052  * data  
     1053  *  
     1054  * @var mixed 
     1055  * @access public 
     1056  */ 
     1057  public $data; 
    10421058 
    10431059  /** 
  • plugins/sfAmazonS3FSPlugin/lib/sfAmazonS3.class.php

    r4123 r5439  
    1313 * 
    1414 *  
    15  * @package    sfAmazonS3 
    16  * @version      SVN: $Id: sfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jtodd $ 
    17  * @author       Jonathan R. Todd <jtodd@adventexdesign.com> 
     15 * @package     sfAmazonS3 
     16 * @version    SVN: $Id: sfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jtodd $ 
     17 * @author      Jonathan R. Todd <jtodd@adventexdesign.com> 
    1818 */ 
    1919class sfAmazonS3 extends BasesfAmazonS3  
    2020{ 
    2121   
    22 }  
     22} 
  • plugins/sfAmazonS3FSPlugin/lib/sfAmazonS3File.class.php

    r4585 r5439  
    2424 *  
    2525 *  
    26  * @package    sfAmazonS3File 
    27  * @version      SVN: $Id: BasesfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jtodd $ 
    28  * @author       Jonathan R. Todd <jtodd@adventexdesign.com> 
     26 * @package     sfAmazonS3File 
     27 * @version    SVN: $Id: BasesfAmazonS3.class.php 3285 2007-02-28 20:01:09Z jtodd $ 
     28 * @author      Jonathan R. Todd <jtodd@adventexdesign.com> 
    2929 */ 
    3030class sfAmazonS3File 
    3131{ 
    3232  /** 
    33  * Local path to file 
    34  *  
    35  * @var string 
    36  * @access private 
    37  */ 
    38  private $filename; 
    39    
    40  /** 
    41  * File mime type 
    42  *  
    43  * @var string 
    44  * @access private 
    45  */ 
    46  private $file_type; 
    47    
    48  /** 
    49  * File size 
    50  *  
    51  * @var string 
    52  * @access private 
    53  */ 
    54  private $file_size; 
    55    
    56  /** 
    57  * Amazon access key 
    58  *  
    59  * @var string 
    60  * @access private 
    61  */ 
    62  private $accessKeyId = ''; 
    63    
    64   /** 
    65  * Amazon secret key 
    66  *  
    67  * @var string 
    68  * @access private 
    69  */ 
     33  * Local path to file 
     34  *  
     35  * @var string 
     36  * @access private 
     37  */ 
     38  private $filename; 
     39 
     40  /** 
     41  * File mime type 
     42  *  
     43  * @var string 
     44  * @access private 
     45  */ 
     46  private $file_type; 
     47 
     48  /** 
     49  * File size 
     50  *  
     51  * @var string 
     52  * @access private 
     53  */ 
     54  private $file_size; 
     55 
     56  /** 
     57  * Amazon access key 
     58  *  
     59  * @var string 
     60  * @access private 
     61  */ 
     62  private $accessKeyId = ''; 
     63 
     64  /** 
     65  * Amazon secret key 
     66  *  
     67  * @var string 
     68  * @access private 
     69  */ 
    7070  private $secretKey = ''; 
    71    
    72   /** 
    73  * Default Amazon S3 bucket 
    74  *  
    75  * @var string 
    76  * @access private 
    77  */ 
     71 
     72  /** 
     73  * Default Amazon S3 bucket 
     74  *  
     75  * @var string 
     76  * @access private 
     77  */ 
    7878  private $bucket = ''; 
    79    
    80   /** 
    81  * Default Amazon S3 ACL (permissions) 
    82  *  
    83  * @var string 
    84  * @access private 
    85  */ 
     79 
     80  /** 
     81  * Default Amazon S3 ACL (permissions) 
     82  *  
     83  * @var string 
     84  * @access private 
     85  */ 
    8686  private $ACL = 'private'; //private, public-read, public-read-write, authenticated-users-read 
    87    
     87 
    8888  function __construct($filename = null, $bucket=null, $accessKeyId = null, $secretKey  = null) 
    8989  { 
    9090    // If params passed then setup class, otherwise throw exception 
    91     if($filename) 
     91    if ($filename) 
     92    { 
    9293      $this->setFilename($filename); 
     94    } 
    9395    else 
     96    { 
    9497      throw new Exception('You must instantiate sfAmazonS3File with a filename.'); 
    95      
    96     if($bucket) 
     98    } 
     99 
     100    if ($bucket) 
     101    { 
    97102      $this->bucket = $bucket; 
     103    } 
    98104    else 
     105    { 
    99106      $this->bucket = sfConfig::get('app_amazon_s3_fs_default_bucket'); 
    100        
    101     if($accessKeyId && $secretKey) 
     107    } 
     108 
     109    if ($accessKeyId && $secretKey) 
    102110    { 
    103111      $this->accessKeyId = $accessKeyId; 
    104112      $this->secretKey = $secretKey; 
    105113    } 
    106     elseif(!$accessKeyId && !$secretKey) 
     114    elseif (!$accessKeyId && !$secretKey) 
    107115    { 
    108116      $this->accessKeyId = sfConfig::get('app_amazon_s3_fs_aws_access_key_id'); 
    109117      $this->secretKey = sfConfig::get('app_amazon_s3_fs_secret_access_key'); 
    110118    } 
    111      
     119 
    112120    // If the file is not cached but is on S3 then go get it 
    113     if(!$this->fileExists()) 
    114     { 
    115       if($this->s3ObjectExists($this->getKey())) 
     121    if (!$this->fileExists()) 
     122    { 
     123      if ($this->s3ObjectExists($this->getKey())) 
     124      { 
    116125        $this->s3GetFile(); 
     126      } 
    117127      // else 
    118128      //         throw new sfException('The file: \''.$filename.'\' doesn\'t exist in S3'); 
    119129    } 
    120130  } 
    121    
     131 
    122132  /** 
    123133   * Instantiates and returns sfAmazonS3File object 
     
    126136  { 
    127137    static $sfAmazonS3File; 
    128      
    129     if( !isset($sfAmazonS3File)
     138 
     139    if (!isset($sfAmazonS3File)
    130140    { 
    131141      // Get instance 
    132       $sfAmazonS3File = new sfAmazonS3File($filename,$bucket,sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key'));  
     142      $sfAmazonS3File = new sfAmazonS3File($filename,$bucket,sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key'));   
    133143    } 
    134144 
    135145    return $sfAmazonS3File; 
    136146  } 
    137    
     147 
    138148  /** 
    139149   * Instantiates and returns sfAmazonS3File object 
     
    142152  { 
    143153    // Get instance 
    144     $sfAmazonS3File = new sfAmazonS3File($filename,$bucket,sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key'));  
     154    $sfAmazonS3File = new sfAmazonS3File($filename,$bucket,sfConfig::get('app_amazon_s3_fs_aws_access_key_id'), sfConfig::get('app_amazon_s3_fs_secret_access_key'));   
    145155 
    146156    return $sfAmazonS3File; 
    147157  } 
    148    
     158 
    149159  // 
    150160  // Public Functions 
    151161  // 
    152        
     162 
    153163  /** 
    154164   * Add a file from the request param (put request) 
     
    161171    $request = sfContext::getInstance()->getRequest(); 
    162172 
    163     if($request->hasFile($param)) 
     173    if ($request->hasFile($param)) 
    164174    { 
    165175      $this->file_size = $request->getFileSize($param); 
     
    170180    } 
    171181    else 
     182    { 
    172183      throw new Exception('Could not add file from request param: '.$param); 
    173      
     184    } 
     185 
    174186    // Put file in s3 
    175187    $this->s3AddFile(); 
    176188  } 
    177    
     189 
    178190  /** 
    179191   * Add a file from the local file system 
     
    185197    throw new Exception('This function has not been written yet'); 
    186198  } 
    187    
     199 
    188200  /** 
    189201   * Delete file and return false if it doesn't exist 
     
    191203  public function delete() 
    192204  { 
    193     if($this->exists()) 
    194     { 
    195       if(!unlink($this->getPath())) 
     205    if ($this->exists()) 
     206    { 
     207      if (!unlink($this->getPath())) 
     208      { 
    196209        throw new Exception('Was unable to delete file: '.$this->getPath()); 
    197        
     210      } 
     211 
    198212      $this->s3DeleteObject($this->getKey()); 
    199        
    200213      return true; 
    201214    } 
     215 
    202216    return false; 
    203217  } 
    204    
     218 
    205219  /** 
    206220   * Does file exist in the system 
     
    210224    return $this->fileExists(); // TODO: Check if file exists in S3 
    211225  } 
    212    
     226 
    213227  /** 
    214228   * Get the absolute local path to the file 
     
    218232    return sfConfig::get('sf_amazon_s3_fs_dir').$this->getFilename(); 
    219233  } 
    220    
     234 
    221235  /** 
    222236   * Get file mime type 
     
    226240    return $this->file_type; 
    227241  } 
    228      
     242 
    229243  /** 
    230244   * Get URL to file 
     
    234248    return sfConfig::get('sf_amazon_s3_fs_web_path').$this->getFilename(); 
    235249  } 
    236    
     250 
    237251  /** 
    238252   * Set the filename for this file 
     
    240254  public function setFilename($f) 
    241255  { 
    242     if(substr($f,0,1) != '/') 
     256    if (substr($f,0,1) != '/') 
     257    { 
    243258      $this->filename = '/'.$f; 
     259    } 
    244260    else 
     261    { 
    245262      $this->filename = $f; 
    246   } 
    247    
     263    } 
     264  } 
     265 
    248266  /** 
    249267   * Get the filename for this file 
     
    253271    return $this->filename; 
    254272  } 
    255    
     273 
    256274  // 
    257275  // Private Functions 
    258276  // 
    259    
     277 
    260278  /** 
    261279   * Recursively makes dir on local machine if it doesn't already exist 
     
    264282  { 
    265283    // File exists with same name 
    266     if(file_exists($dir) && !is_dir($dir)) 
     284    if (file_exists($dir) && !is_dir($dir)) 
     285    { 
    267286      throw new Exception("Was unable to create dir: $dir \nA file exists with the same name"); 
    268      
     287    } 
    269288    // Dir already exists 
    270     elseif(file_exists($dir) && is_dir($dir)) 
     289    elseif (file_exists($dir) && is_dir($dir)) 
     290    { 
    271291      return true; 
     292    } 
    272293 
    273294    // Make dir recursively 
    274     if(!(mkdir($dir, $perms, true))) 
     295    if (!(mkdir($dir, $perms, true))) 
     296    { 
    275297      throw new Exception('Was unable to create dir: '.dirname($this->getPath())); 
    276      
     298    } 
     299 
    277300    return true; 
    278301  } 
    279    
     302 
    280303  /** 
    281304   * Does local file exists 
     
    303326    return $fileName; 
    304327  } 
    305    
     328 
    306329  /** 
    307330   * Get path to use on Amazon s3 
     
    311334    return $this->getURL(); 
    312335  } 
    313    
     336 
    314337  /** 
    315338   * Get Amazon key for file 
     
    319342    return sfConfig::get('sf_amazon_s3_fs_folder').$this->getFilename(); 
    320343  } 
    321    
     344 
    322345  /** 
    323346   * Add this file to s3 
     
    329352    $sfAmazonS3->putObjectInBucket($this->bucket, $this->getKey(), $this->getFilePathS3(), $this->getPath(),$this->getType(), $this->ACL); 
    330353  } 
    331    
     354 
    332355  /** 
    333356   * Create Bucket if it doesn't exists 
     
    337360  private function s3CreateBucket($bucket) 
    338361  { 
    339     if(!$this->s3BucketExists($bucket)) 
     362    if (!$this->s3BucketExists($bucket)) 
    340363    { 
    341364      $sfAmazonS3 = new sfAmazonS3($this->accessKeyId, $this->secretKey); 
     
    343366    } 
    344367  } 
    345    
     368 
    346369  /** 
    347370   * Does a given bucket exists? 
     
    355378    return in_array($bucket, $sfAmazonS3->listBuckets()); 
    356379  } 
    357    
     380 
    358381  /** 
    359382   * Get file from s3, put it on local disk 
     
    364387    $file_data = $sfAmazonS3->getBucketObjectAsString($this->bucket, $this->getKey()); 
    365388    $file_meta = $sfAmazonS3->getBucketObjectMetaData($this->bucket, $this->getKey()); 
    366      
     389 
    367390    $filename = $this->getPath(); 
    368      
     391 
    369392    $this->fileMakeDir(dirname($this->getPath()),0777); 
    370      
     393 
    371394    if (!$handle = fopen($filename, 'w')) 
     395    { 
    372396      throw new Exception("Cannot open file ($filename)"); 
     397    } 
    373398 
    374399    // Write $somecontent to our opened file. 
     
    377402      throw new Exception("Cannot write to file ($filename)"); 
    378403    } 
     404 
    379405    fclose($handle); 
    380  
    381   } 
    382    
     406  } 
     407 
    383408  /** 
    384409   * Delete s3 object 
     
    392417    return $sfAmazonS3->deleteBucketObject($this->bucket, $key); 
    393418  } 
    394    
     419 
    395420  /** 
    396421   * Does object exist 
     
    404429    // TODO: There is probably a better way to check existance then to loop through all files 
    405430    $objects = $sfAmazonS3->listBucketKeys($this->bucket,false,false,false,1000); 
    406     foreach($objects as $object) 
    407       if($object['Key'] == $key) 
     431 
     432    foreach ($objects as $object) 
     433    { 
     434      if ($object['Key'] == $key) 
     435      { 
    408436        return true; 
     437      } 
     438    } 
     439 
    409440    return false; 
    410441  } 
    411442} 
    412 ?> 
  • plugins/sfFeed2Plugin/lib/sfAtom1Feed.class.php

    r5334 r5439  
    2525  protected function initContext() 
    2626  { 
    27   if(!$this->context) 
    28  
    29     $this->context = sfContext::getInstance(); 
    30  
     27    if(!$this->context) 
     28   
     29      $this->context = sfContext::getInstance(); 
     30   
    3131  } 
    3232 
  • plugins/sfFeed2Plugin/lib/sfRssFeed.class.php

    r3796 r5439  
    2626  protected function initContext() 
    2727  { 
    28   if(!$this->context)  
    29  
    30     $this->context = sfContext::getInstance(); 
    31  
     28    if(!$this->context)  
     29   
     30      $this->context = sfContext::getInstance(); 
     31   
    3232  } 
    3333 
  • plugins/sfPHPUnitPlugin/data/tasks/sfPakePHPUnit.php

    r5418 r5439  
    1818function run_phpunit_unit($task, $args) 
    1919{ 
    20   _init_phpunit(); 
    21    
    22   if (isset($args[0])) 
    23   { 
    24     foreach ($args as $path) 
    25     { 
    26       $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'unit'.DIRECTORY_SEPARATOR.dirname($path)); 
    27       foreach ($files as $file) 
    28       { 
    29         $initialiser = new sfPHPUnitInitialiser(); 
    30          
    31         try 
    32         { 
    33           $initialiser->init($file); 
    34         } 
    35         catch (Exception $e) 
    36         { 
    37           continue; 
    38         } 
    39          
    40         $initialiser->run(new sfPHPUnitTestPrinterTapColour()); 
    41       } 
    42     } 
    43   } 
    44   else 
    45   { 
    46     $h = new sfPHPUnitHarness(); 
    47     $h->base_dir = sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'unit'; 
    48      
    49     $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
    50     $h->register($finder->in($h->base_dir)); 
    51      
    52     $h->run(); 
    53   } 
    54  
     20  _init_phpunit(); 
     21 
     22  if (isset($args[0])) 
     23  { 
     24    foreach ($args as $path) 
     25    { 
     26      $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'unit'.DIRECTORY_SEPARATOR.dirname($path)); 
     27      foreach ($files as $file) 
     28      { 
     29        $initialiser = new sfPHPUnitInitialiser(); 
     30 
     31        try 
     32        { 
     33          $initialiser->init($file); 
     34        } 
     35        catch (Exception $e) 
     36        { 
     37          continue; 
     38        } 
     39 
     40        $initialiser->run(new sfPHPUnitTestPrinterTapColour()); 
     41      } 
     42    } 
     43  } 
     44  else 
     45  { 
     46    $h = new sfPHPUnitHarness(); 
     47    $h->base_dir = sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'unit'; 
     48 
     49    $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
     50    $h->register($finder->in($h->base_dir)); 
     51 
     52    $h->run(); 
     53  } 
    5554} 
    5655 
    5756function run_phpunit_functional($task, $args) 
    5857{ 
    59  _init_phpunit(); 
    60    
    61  $selenium_process = _init_selenium(); 
    62    
    63  if (isset($args[0])) 
    64 
    65    foreach ($args as $path) 
    66    
    67      $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'functional'.DIRECTORY_SEPARATOR.dirname($path)); 
    68      foreach ($files as $file) 
    69      
    70        $initialiser = new sfPHPUnitInitialiser(); 
    71          
    72        try 
    73        
    74          $initialiser->init($file); 
    75        
    76        catch (Exception $e) 
    77        
    78          continue; 
    79        
    80          
    81        $initialiser->run(new sfPHPUnitTestPrinterTapColour()); 
    82      
    83    
    84 
    85  else 
    86 
    87    $h = new sfPHPUnitHarness(); 
    88    $h->base_dir = sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional'; 
    89      
    90    $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
    91    $h->register($finder->in($h->base_dir)); 
    92      
    93    $h->run(); 
    94 
    95    
    96  _terminate_selenium($selenium_process); 
     58  _init_phpunit(); 
     59 
     60  $selenium_process = _init_selenium(); 
     61 
     62  if (isset($args[0])) 
     63 
     64    foreach ($args as $path) 
     65   
     66      $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path).'Test.php')->in(sfConfig::get('sf_test_dir').DIRECTORY_SEPARATOR.'functional'.DIRECTORY_SEPARATOR.dirname($path)); 
     67      foreach ($files as $file) 
     68     
     69        $initialiser = new sfPHPUnitInitialiser(); 
     70 
     71        try 
     72       
     73          $initialiser->init($file); 
     74       
     75        catch (Exception $e) 
     76       
     77          continue; 
     78       
     79 
     80        $initialiser->run(new sfPHPUnitTestPrinterTapColour()); 
     81     
     82   
     83 
     84  else 
     85 
     86    $h = new sfPHPUnitHarness(); 
     87    $h->base_dir = sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional'; 
     88 
     89    $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
     90    $h->register($finder->in($h->base_dir)); 
     91 
     92    $h->run(); 
     93 
     94 
     95  _terminate_selenium($selenium_process); 
    9796} 
    9897 
    9998function _init_phpunit() 
    10099{ 
    101  $phpUnitPath = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . '/lib/PHPUnit'); 
    102  set_include_path($phpUnitPath . PATH_SEPARATOR . get_include_path()); 
     100  $phpUnitPath = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . '/lib/PHPUnit'); 
     101  set_include_path($phpUnitPath . PATH_SEPARATOR . get_include_path()); 
    103102} 
    104103 
    105104function _init_selenium() 
    106105{ 
    107  _init_symfony(); 
    108    
    109  $host = sfConfig::get('sf_selenium_host'); 
    110  $port = sfConfig::get('sf_selenium_port'); 
    111    
    112  // probe for selenium running externally 
    113  pake_echo_comment( 
    114    sprintf( 
    115      'checking for selenium on %s:%s', 
    116      $host, 
    117      $port 
    118    
    119  ); 
    120    
    121  $success = _probe_selenium($host, $port, 1); 
    122    
    123  if ($success) 
    124 
    125    pake_echo_comment('selenium found! proceeding with tests..'); 
    126    return false; 
    127 
    128    
    129  pake_echo_comment('could not find selenium. will look for selenium .jars in /lib/selenium'); 
    130    
    131  // try and find selenium .jar, use it! 
    132  // look in /lib/selenium 
    133  $seleniumPath = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'selenium'; 
    134  $jar = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*selenium*server*.jar')->in($seleniumPath); 
    135    
    136  if (0 === count($jar)) 
    137 
    138    throw new Exception('could not find selenium-server.jar'); 
    139 
    140    
    141  $jar = $jar[0]; 
    142    
    143  pake_echo_comment('found ' . basename($jar) . '! starting now...'); 
    144    
    145  $resource = _start_selenium($jar); 
    146    
    147  if (false === $resource) 
    148 
    149    throw new Exception('could not launch selenium'); 
    150 
    151    
    152  $success = _probe_selenium($host, $port, 5, 1); 
    153    
    154  if (false === $success) 
    155 
    156    _terminate_selenium($resource); 
    157    throw new Exception('selenium doesn\'t seem to be responding'); 
    158 
    159    
    160  pake_echo_comment('selenium started'); 
    161    
    162  return $resource; 
     106  _init_symfony(); 
     107 
     108  $host = sfConfig::get('sf_selenium_host'); 
     109  $port = sfConfig::get('sf_selenium_port'); 
     110 
     111  // probe for selenium running externally 
     112  pake_echo_comment( 
     113    sprintf( 
     114      'checking for selenium on %s:%s', 
     115      $host, 
     116      $port 
     117   
     118  ); 
     119 
     120  $success = _probe_selenium($host, $port, 1); 
     121 
     122  if ($success) 
     123 
     124    pake_echo_comment('selenium found! proceeding with tests..'); 
     125    return false; 
     126 
     127 
     128  pake_echo_comment('could not find selenium. will look for selenium .jars in /lib/selenium'); 
     129 
     130  // try and find selenium .jar, use it! 
     131  // look in /lib/selenium 
     132  $seleniumPath = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'selenium'; 
     133  $jar = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*selenium*server*.jar')->in($seleniumPath); 
     134 
     135  if (0 === count($jar)) 
     136 
     137    throw new Exception('could not find selenium-server.jar'); 
     138 
     139 
     140  $jar = $jar[0]; 
     141 
     142  pake_echo_comment('found ' . basename($jar) . '! starting now...'); 
     143 
     144  $resource = _start_selenium($jar); 
     145 
     146  if (false === $resource) 
     147 
     148    throw new Exception('could not launch selenium'); 
     149 
     150 
     151  $success = _probe_selenium($host, $port, 5, 1); 
     152 
     153  if (false === $success) 
     154 
     155    _terminate_selenium($resource); 
     156    throw new Exception('selenium doesn\'t seem to be responding'); 
     157 
     158 
     159  pake_echo_comment('selenium started'); 
     160 
     161  return $resource; 
    163162} 
    164163 
    165164function _terminate_selenium($selenium_process) 
    166165{ 
    167  pake_echo_comment('selenium terminating'); 
    168  proc_terminate($selenium_process); 
     166  pake_echo_comment('selenium terminating'); 
     167  proc_terminate($selenium_process); 
    169168} 
    170169 
    171170function _start_selenium($jar_path) 
    172171{ 
    173  $cmd = "java -jar $jar_path"; 
    174  $cmd = escapeshellcmd($cmd); 
    175    
    176  $descriptorspec = array( 
    177    0 => array('pipe', 'r'), 
    178    1 => array('pipe', 'w'), 
    179    2 => array('pipe', 'r') 
    180  ); 
    181  
    182  $pipes = array(); 
    183  $resource = proc_open($cmd, $descriptorspec, $pipes); 
    184    
    185  return $resource; 
     172  $cmd = "java -jar $jar_path"; 
     173  $cmd = escapeshellcmd($cmd); 
     174 
     175  $descriptorspec = array( 
     176    0 => array('pipe', 'r'), 
     177    1 => array('pipe', 'w'), 
     178    2 => array('pipe', 'r') 
     179  ); 
     180 
     181  $pipes = array(); 
     182  $resource = proc_open($cmd, $descriptorspec, $pipes); 
     183 
     184  return $resource; 
    186185} 
    187186 
    188187function _probe_selenium($host, $port, $attempts = 5, $timeout = 1) 
    189188{ 
    190   while (true) 
    191   { 
    192     $r = @fsockopen($host, $port); 
    193      
    194     if (false !== $r) 
    195     { 
    196       return true; 
    197     } 
    198     else 
    199     { 
    200        
    201       if (--$attempts <= 0) 
    202       { 
    203         return false; 
    204       } 
    205        
    206       pake_echo_comment('.'); 
    207       sleep($timeout); 
    208     } 
    209   } 
    210    
    211   return false; 
     189  while (true) 
     190  { 
     191    $r = @fsockopen($host, $port); 
     192 
     193    if (false !== $r) 
     194    { 
     195      return true; 
     196    } 
     197    else 
     198    { 
     199      if (--$attempts <= 0) 
     200      { 
     201        return false; 
     202      } 
     203 
     204      pake_echo_comment('.'); 
     205      sleep($timeout); 
     206    } 
     207  } 
     208 
     209  return false; 
    212210} 
    213211 
    214212function _init_symfony() 
    215213{ 
    216  define('SF_ROOT_DIR',    realpath(dirname(__file__).'/../../../..')); 
    217  define('SF_APP',         'frontend'); 
    218  define('SF_ENVIRONMENT', 'dev'); 
    219  define('SF_DEBUG',       true); 
    220    
    221  require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');  
     214  define('SF_ROOT_DIR',    realpath(dirname(__file__).'/../../../..')); 
     215  define('SF_APP',         'frontend'); 
     216  define('SF_ENVIRONMENT', 'dev'); 
     217  define('SF_DEBUG',       true); 
     218 
     219  require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');  
    222220} 
    223221 
    224222function run_phpunit_all($task, $args) 
    225223{ 
    226  _init_phpunit(); 
    227    
    228  $h = new sfPHPUnitHarness(); 
    229  $h->base_dir = sfConfig::get('sf_test_dir'); 
    230    
    231  $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
    232  $h->register($finder->in($h->base_dir)); 
    233    
    234  $h->run(); 
    235 } 
     224  _init_phpunit(); 
     225 
     226  $h = new sfPHPUnitHarness(); 
     227  $h->base_dir = sfConfig::get('sf_test_dir'); 
     228 
     229  $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php'); 
     230  $h->register($finder->in($h->base_dir)); 
     231 
     232  $h->run(); 
     233} 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitHarness.php

    r5418 r5439  
    44class sfPHPUnitHarness extends sfPHPUnitRegistration 
    55{ 
    6  public $stats = array(); 
    7  public $output = null; 
    8    
    9  public function __construct() 
    10 
    11    $this->output = new sfPHPUnitOutputColour(); 
    12 
     6  public $stats = array(); 
     7  public $output = null; 
     8   
     9  public function __construct() 
     10 
     11    $this->output = new sfPHPUnitOutputColour(); 
     12 
    1313 
    14  private function process_test_output($lines) 
    15 
    16    foreach (explode("\n", $lines) as $text) 
    17    
    18      if (false !== strpos($text, 'not ok ')) 
    19      
    20        ++$this->current_test; 
    21        $test_number = (int) substr($text, 7); 
    22        $this->stats[$this->current_file]['failed'][] = $test_number; 
     14  private function process_test_output($lines) 
     15 
     16    foreach (explode("\n", $lines) as $text) 
     17   
     18      if (false !== strpos($text, 'not ok ')) 
     19     
     20        ++$this->current_test; 
     21        $test_number = (int) substr($text, 7); 
     22        $this->stats[$this->current_file]['failed'][] = $test_number; 
    2323 
    24        ++$this->stats[$this->current_file]['nb_tests']; 
    25        ++$this->stats['_nb_tests']; 
    26      
    27      else if (false !== strpos($text, 'ok ')) 
    28      
    29        ++$this->stats[$this->current_file]['nb_tests']; 
    30        ++$this->stats['_nb_tests']; 
    31      
    32      else if (preg_match('/^1\.\.(\d+)/', $text, $match)) 
    33      
    34        $this->stats[$this->current_file]['plan'] = $match[1]; 
    35      
    36    
     24        ++$this->stats[$this->current_file]['nb_tests']; 
     25        ++$this->stats['_nb_tests']; 
     26     
     27      else if (false !== strpos($text, 'ok ')) 
     28     
     29        ++$this->stats[$this->current_file]['nb_tests']; 
     30        ++$this->stats['_nb_tests']; 
     31     
     32      else if (preg_match('/^1\.\.(\d+)/', $text, $match)) 
     33     
     34        $this->stats[$this->current_file]['plan'] = $match[1]; 
     35     
     36   
    3737 
    38    return; 
    39 
    40    
    41  public function run() 
    42 
    43    if (!count($this->files)) 
    44    
    45      throw new Exception('You must register some test files before running them!'); 
    46    
    47      
    48    // sort the files to be able to predict the order 
    49    sort($this->files); 
    50      
    51    $this->stats = array( 
    52      '_failed_files' => array(), 
    53      '_failed_tests' => 0, 
    54      '_nb_tests'     => 0, 
    55    ); 
    56      
    57    foreach ($this->files as $file) 
    58    
    59      $initialiser = new sfPHPUnitInitialiser(); 
    60        
    61      try 
    62      
    63        $initialiser->init($file); 
    64      
    65      catch (Exception $e) 
    66      
    67        continue; 
    68      
    69        
    70      $this->stats[$file] = array( 
    71        'plan'    => null, 
    72        'nb_tests'  => 0, 
    73        'failed'  => array(), 
    74        'passed'  => array(), 
    75      ); 
    76        
    77      $this->current_file = $file; 
    78      $this->current_test = 0; 
    79      $relative_file = basename($file); 
    80        
    81      ob_start(array($this, 'process_test_output')); 
    82      $initialiser->run(new sfPHPUnitTestPrinterTap());   /* @var $result PHPUnit_Framework_TestResult */ 
    83          ob_end_clean(); 
     38    return; 
     39 
     40   
     41  public function run() 
     42 
     43    if (!count($this->files)) 
     44   
     45      throw new Exception('You must register some test files before running them!'); 
     46   
     47     
     48    // sort the files to be able to predict the order 
     49    sort($this->files); 
     50     
     51    $this->stats = array( 
     52      '_failed_files' => array(), 
     53      '_failed_tests' => 0, 
     54      '_nb_tests'     => 0, 
     55    ); 
     56     
     57    foreach ($this->files as $file) 
     58   
     59      $initialiser = new sfPHPUnitInitialiser(); 
     60       
     61      try 
     62     
     63        $initialiser->init($file); 
     64     
     65      catch (Exception $e) 
     66     
     67        continue; 
     68     
     69       
     70      $this->stats[$file] = array( 
     71        'plan'    => null, 
     72        'nb_tests'  => 0, 
     73        'failed'  => array(), 
     74        'passed'  => array(), 
     75      ); 
     76       
     77      $this->current_file = $file; 
     78      $this->current_test = 0; 
     79      $relative_file = basename($file); 
     80       
     81      ob_start(array($this, 'process_test_output')); 
     82      $initialiser->run(new sfPHPUnitTestPrinterTap());    /* @var $result PHPUnit_Framework_TestResult */ 
     83          ob_end_clean(); 
    8484 
    85      $this->stats[$file]['status_code'] = 0; 
    86      $this->stats[$file]['status'] = $this->stats[$file]['failed'] ? 'not ok' : 'ok'; 
     85      $this->stats[$file]['status_code'] = 0; 
     86      $this->stats[$file]['status'] = $this->stats[$file]['failed'] ? 'not ok' : 'ok'; 
    8787 
    88      $this->output->echoln( 
    89        sprintf( 
    90          '%s%s%s', 
    91          substr( 
    92            $relative_file, 
    93            -min(67, strlen($relative_file)) 
    94          ), 
    95          str_repeat( 
    96            '.', 
    97            70 - min(67, strlen($relative_file)) 
    98          ), 
    99          $this->stats[$file]['status'] 
    100        
    101      ); 
     88      $this->output->echoln( 
     89        sprintf( 
     90          '%s%s%s', 
     91          substr( 
     92            $relative_file, 
     93            -min(67, strlen($relative_file)) 
     94          ), 
     95          str_repeat( 
     96            '.', 
     97            70 - min(67, strlen($relative_file)) 
     98          ), 
     99          $this->stats[$file]['status'] 
     100       
     101      ); 
    102102 
    103      if (($nb = count($this->stats[$file]['failed']))) 
    104      
    105        if ($nb) 
    106        
    107          $this->output->echoln(sprintf("    Failed tests: %s", implode(', ', $this->stats[$file]['failed']))); 
    108        
    109          
    110        $this->stats['_failed_files'][] = $file; 
    111        $this->stats['_failed_tests']  += $nb; 
    112      
    113    
     103      if (($nb = count($this->stats[$file]['failed']))) 
     104     
     105        if ($nb) 
     106       
     107          $this->output->echoln(sprintf("    Failed tests: %s", implode(', ', $this->stats[$file]['failed']))); 
     108       
     109         
     110        $this->stats['_failed_files'][] = $file; 
     111        $this->stats['_failed_tests']  += $nb; 
     112     
     113   
    114114 
    115    if (count($this->stats['_failed_files'])) 
    116    
    117      $format = "%-30s  %4s  %5s  %5s  %s"; 
    118      $this->output->echoln(sprintf($format, 'Failed Test', 'Stat', 'Total', 'Fail', 'List of Failed')); 
    119      $this->output->echoln("------------------------------------------------------------------"); 
    120      foreach ($this->stats as $file => $file_stat) 
    121      
    122        if (!in_array($file, $this->stats['_failed_files'])) 
    123        
    124          continue; 
    125        
     115    if (count($this->stats['_failed_files'])) 
     116   
     117      $format = "%-30s  %4s  %5s  %5s  %s"; 
     118      $this->output->echoln(sprintf($format, 'Failed Test', 'Stat', 'Total', 'Fail', 'List of Failed')); 
     119      $this->output->echoln("------------------------------------------------------------------"); 
     120      foreach ($this->stats as $file => $file_stat) 
     121     
     122        if (!in_array($file, $this->stats['_failed_files'])) 
     123       
     124          continue; 
     125       
    126126 
    127        $relative_file = $this->get_relative_file($file); 
    128        $this->output->echoln(sprintf($format, substr($relative_file, -min(30, strlen($relative_file))), $file_stat['status_code'], count($file_stat['failed']) + count($file_stat['passed']), count($file_stat['failed']), implode(' ', $file_stat['failed']))); 
    129      
     127        $relative_file = $this->get_relative_file($file); 
     128        $this->output->echoln(sprintf($format, substr($relative_file, -min(30, strlen($relative_file))), $file_stat['status_code'], count($file_stat['failed']) + count($file_stat['passed']), count($file_stat['failed']), implode(' ', $file_stat['failed']))); 
     129     
    130130 
    131      $this->output->red_bar( 
    132        sprintf( 
    133          'Failed %d/%d test scripts, %.2f%% okay. %d/%d subtests failed, %.2f%% okay.', 
    134          $nb_failed_files = count($this->stats['_failed_files']), 
    135          $nb_files = count($this->files), 
    136          ($nb_files - $nb_failed_files) * 100 / $nb_files, 
    137          $nb_failed_tests = $this->stats['_failed_tests'], 
    138          $nb_tests = $this->stats['_nb_tests'], 
    139          $nb_tests > 0 ? ($nb_tests - $nb_failed_tests) * 100 / $nb_tests : 0 
    140        
    141      ); 
    142    
    143    else 
    144    
    145      $this->output->green_bar(' All tests successful.'); 
    146      $this->output->green_bar(sprintf(' Files=%d, Tests=%d', count($this->files), $this->stats['_nb_tests'])); 
    147    
     131      $this->output->red_bar( 
     132        sprintf( 
     133          'Failed %d/%d test scripts, %.2f%% okay. %d/%d subtests failed, %.2f%% okay.', 
     134          $nb_failed_files = count($this->stats['_failed_files']), 
     135          $nb_files = count($this->files), 
     136          ($nb_files - $nb_failed_files) * 100 / $nb_files, 
     137          $nb_failed_tests = $this->stats['_failed_tests'], 
     138          $nb_tests = $this->stats['_nb_tests'], 
     139          $nb_tests > 0 ? ($nb_tests - $nb_failed_tests) * 100 / $nb_tests : 0 
     140       
     141      ); 
     142   
     143    else 
     144   
     145      $this->output->green_bar(' All tests successful.'); 
     146      $this->output->green_bar(sprintf(' Files=%d, Tests=%d', count($this->files), $this->stats['_nb_tests'])); 
     147   
    148148 
    149    return $this->stats['_failed_tests'] ? false : true; 
    150 
     149    return $this->stats['_failed_tests'] ? false : true; 
     150 
    151151} 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitInitialiser.php

    r5418 r5439  
    22class sfPHPUnitInitialiser 
    33{ 
    4  private $class = ''; 
    5  private $file = ''; 
    6  private $initialised = false; 
    7    
    8  public function init($file) 
    9 
    10    $relative_file = str_replace('.php', '', basename($file)); 
    11    $this->class = basename($relative_file); 
    12      
    13    // require, so phpunit doesn't have to (fail at) find it 
    14    ob_start(); 
    15    require_once($file); 
    16    ob_end_clean(); 
    17      
    18    if (!class_exists($this->class)) 
    19    
    20      throw new Exception('Undefined class: ' . $this->class); 
    21    
    22      
    23    $this->file = $file; 
    24    $this->initialised = true; 
    25 
    26    
    27  public function run($printer = null) 
    28 
    29    if (!$this->initialised) 
    30    
    31      throw new Exception('Test not initialised before running'); 
    32    
    33      
    34    $arguments = array( 
    35      'test' => $this->class, 
    36      'testFile' => $this->file, 
    37      'printer' => $printer 
    38    ); 
    39      
    40    $runner = new sfPHPUnitTestRunner(); 
    41      
    42    $suite = $runner->getTest( 
    43      $arguments['test'], 
    44      $arguments['testFile'] 
    45    ); 
    46      
     4  private $class = ''; 
     5  private $file = ''; 
     6  private $initialised = false; 
     7   
     8  public function init($file) 
     9 
     10    $relative_file = str_replace('.php', '', basename($file)); 
     11    $this->class = basename($relative_file); 
     12     
     13    // require, so phpunit doesn't have to (fail at) find it 
     14    ob_start(); 
     15    require_once($file); 
     16    ob_end_clean(); 
     17     
     18    if (!class_exists($this->class)) 
     19   
     20      throw new Exception('Undefined class: ' . $this->class); 
     21   
     22     
     23    $this->file = $file; 
     24    $this->initialised = true; 
     25 
     26   
     27  public function run($printer = null) 
     28 
     29    if (!$this->initialised) 
     30   
     31      throw new Exception('Test not initialised before running'); 
     32   
     33     
     34    $arguments = array( 
     35      'test' => $this->class, 
     36      'testFile' => $this->file, 
     37      'printer' => $printer 
     38    ); 
     39     
     40    $runner = new sfPHPUnitTestRunner(); 
     41     
     42    $suite = $runner->getTest( 
     43      $arguments['test'], 
     44      $arguments['testFile'] 
     45    ); 
     46     
    4747        if ($suite->testAt(0) instanceof PHPUnit_Framework_Warning && 
    4848            strpos($suite->testAt(0)->getMessage(), 'No tests found in class') !== FALSE) 
     
    7676         
    7777        return $result; 
    78 
    79    
    80  public function getClass() 
    81 
    82    return $this->class; 
    83 
     78 
     79   
     80  public function getClass() 
     81 
     82    return $this->class; 
     83 
    8484} 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitOutputColour.php

    r5418 r5439  
    33class sfPHPUnitOutputColour 
    44{ 
    5  public $coloriser = null; 
     5  public $coloriser = null; 
    66 
    7  public function __construct() 
    8 
    9    $this->coloriser = new pakeColor(); 
    10 
    11    
    12    
     7  public function __construct() 
     8 
     9    $this->coloriser = new pakeColor(); 
     10 
     11   
     12   
    1313 
    1414  function diag() 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitRegistration.php

    r5418 r5439  
    33class sfPHPUnitRegistration 
    44{ 
    5  public $files = array(); 
    6  public $extension = '.php'; 
    7  public $base_dir = ''; 
    8    
    9  public function register($files_or_directories) 
    10 
    11    foreach ((array) $files_or_directories as $f_or_d) 
    12    
    13      if (is_file($f_or_d)) 
    14      
    15        $this->files[] = realpath($f_or_d); 
    16      
    17      elseif (is_dir($f_or_d)) 
    18      
    19        $this->register_dir($f_or_d); 
    20      
    21      else 
    22      
    23        throw new Exception(sprintf('The file or directory "%s" does not exist.', $f_or_d)); 
    24      
    25    
    26 
    27    
    28  public function register_dir($directory) 
    29 
    30    if (!is_dir($directory)) 
    31    
    32      throw new Exception(sprintf('The directory "%s" does not exist.', $directory)); 
    33    
     5  public $files = array(); 
     6  public $extension = '.php'; 
     7  public $base_dir = ''; 
     8   
     9  public function register($files_or_directories) 
     10 
     11    foreach ((array) $files_or_directories as $f_or_d) 
     12   
     13      if (is_file($f_or_d)) 
     14     
     15        $this->files[] = realpath($f_or_d); 
     16     
     17      elseif (is_dir($f_or_d)) 
     18     
     19        $this->register_dir($f_or_d); 
     20     
     21      else 
     22     
     23        throw new Exception(sprintf('The file or directory "%s" does not exist.', $f_or_d)); 
     24     
     25   
     26 
     27   
     28  public function register_dir($directory) 
     29 
     30    if (!is_dir($directory)) 
     31   
     32      throw new Exception(sprintf('The directory "%s" does not exist.', $directory)); 
     33   
    3434 
    35    $files = array(); 
     35    $files = array(); 
    3636 
    37    $current_dir = opendir($directory); 
    38    while ($entry = readdir($current_dir)) 
    39    
    40      if ($entry == '.' || $entry == '..') continue; 
     37    $current_dir = opendir($directory); 
     38    while ($entry = readdir($current_dir)) 
     39   
     40      if ($entry == '.' || $entry == '..') continue; 
    4141 
    42      if (is_dir($entry)) 
    43      
    44        $this->register_dir($entry); 
    45      
    46      elseif (preg_match('#'.$this->extension.'$#', $entry)) 
    47      
    48        $files[] = realpath($directory.DIRECTORY_SEPARATOR.$entry); 
    49      
    50    
     42      if (is_dir($entry)) 
     43     
     44        $this->register_dir($entry); 
     45     
     46      elseif (preg_match('#'.$this->extension.'$#', $entry)) 
     47     
     48        $files[] = realpath($directory.DIRECTORY_SEPARATOR.$entry); 
     49     
     50   
    5151 
    52    $this->files = array_merge($this->files, $files); 
    53 
     52    $this->files = array_merge($this->files, $files); 
     53 
    5454 
    55  protected function get_relative_file($file) 
    56 
    57    return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(array(realpath($this->base_dir).DIRECTORY_SEPARATOR, $this->extension), '', $file)); 
    58 
     55  protected function get_relative_file($file) 
     56 
     57    return str_replace(DIRECTORY_SEPARATOR, '/', str_replace(array(realpath($this->base_dir).DIRECTORY_SEPARATOR, $this->extension), '', $file)); 
     58 
    5959} 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitTestPrinterTap.php

    r5420 r5439  
    66class sfPHPUnitTestPrinterTap extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener 
    77{ 
    8     /** 
    9      * @var    integer 
    10      * @access protected 
    11      */ 
    12     protected $testNumber = 0; 
    13  
    14     /** 
    15      * @var    boolean 
    16      * @access protected 
    17      */ 
    18     protected $testSuccessful = TRUE; 
    19      
    20     protected $failCount = 0; 
    21  
    22     /** 
    23      * An error occurred. 
    24      * 
    25      * @param  PHPUnit_Framework_Test $test 
    26      * @param  Exception              $e 
    27      * @param  float                  $time 
    28      * @access public 
    29      */ 
    30     public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) 
    31     { 
    32         $this->writeNotOk($test, 'Error'); 
     8  /** 
     9   * @var    integer 
     10   * @access protected 
     11   */ 
     12  protected $testNumber = 0; 
     13 
     14  /** 
     15   * @var    boolean 
     16   * @access protected 
     17   */ 
     18  protected $testSuccessful = TRUE; 
     19   
     20  protected $failCount = 0; 
     21 
     22  /** 
     23   * An error occurred. 
     24   * 
     25   * @param  PHPUnit_Framework_Test $test 
     26   * @param  Exception              $e 
     27   * @param  float                  $time 
     28   * @access public 
     29   */ 
     30  public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) 
     31  { 
     32      $this->writeNotOk($test, 'Error'); 
     33       
     34      $this->failCount++; 
     35  } 
     36 
     37  /** 
     38   * A failure occurred. 
     39   * 
     40   * @param  PHPUnit_Framework_Test                 $test 
     41   * @param  PHPUnit_Framework_AssertionFailedError $e 
     42   * @param  float                                  $time 
     43   * @access public 
     44   */ 
     45  public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) 
     46  { 
     47    $this->writeNotOk($test, 'Failure'); 
     48     
     49    $location = $e->getLocation(); 
     50     
     51    $this->writeComment( 
     52      sprintf( 
     53        '#     Failed test (%s at line %d)', 
    3354         
    34         $this->failCount++; 
    35     } 
    36  
    37     /** 
    38      * A failure occurred. 
    39      * 
    40      * @param  PHPUnit_Framework_Test                 $test 
    41      * @param  PHPUnit_Framework_AssertionFailedError $e 
    42      * @param  float                                  $time 
    43      * @access public 
    44      */ 
    45     public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) 
    46     { 
    47         $this->writeNotOk($test, 'Failure'); 
    48          
    49         $location = $e->getLocation(); 
    50          
    51         $this->writeComment( 
    52           sprintf( 
    53             '#     Failed test (%s at line %d)', 
    54              
    55             $location['file'], 
    56             $location['line'] 
    57           ) 
    58         ); 
    59          
    60         if ($e->toString()) 
    61         { 
    62           $this->writeComment( 
    63             sprintf( 
    64               '#       %s', 
    65                
    66               $e->toString() 
    67             ) 
    68           ); 
    69         } 
    70          
    71         $this->failCount++; 
    72     } 
    73  
    74     /** 
    75      * Incomplete test. 
    76      * 
    77      * @param  PHPUnit_Framework_Test $test 
    78      * @param  Exception              $e 
    79      * @param  float                  $time 
    80      * @access public 
    81      */ 
    82     public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
    83     { 
    84         $this->writeOkWithPrefix($test, 'TODO'); 
    85  
    86         $this->testSuccessful = false; 
    87     } 
    88  
    89     /** 
    90      * Skipped test. 
    91      * 
    92      * @param  PHPUnit_Framework_Test $test 
    93      * @param  Exception              $e 
    94      * @param  float                  $time 
    95      * @access public 
    96      * @since  Method available since Release 3.0.0 
    97      */ 
    98     public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
    99     { 
    100         $this->writeOkWithPrefix($test, 'SKIP'); 
    101  
    102         $this->testSuccessful = false; 
    103     } 
    104  
    105     /** 
    106      * A testsuite started. 
    107      * 
    108      * @param  PHPUnit_Framework_TestSuite $suite 
    109      * @access public 
    110      */ 
    111     public function startTestSuite(PHPUnit_Framework_TestSuite $suite) 
    112     { 
    113         if ($this->testNumber == 0) { 
    114             $this->writeln( 
    115               sprintf( 
    116                 "1..%d", 
    117  
    118                 count($suite) 
    119               ) 
    120             ); 
    121         } 
    122  
    123         $this->writeComment( 
     55        $location['file'], 
     56        $location['line'] 
     57      ) 
     58    ); 
     59     
     60    if ($e->toString()) 
     61    { 
     62      $this->writeComment( 
     63        sprintf( 
     64          '#       %s', 
     65           
     66          $e->toString() 
     67        ) 
     68      ); 
     69    } 
     70     
     71    $this->failCount++; 
     72  } 
     73 
     74  /** 
     75   * Incomplete test. 
     76   * 
     77   * @param  PHPUnit_Framework_Test $test 
     78   * @param  Exception              $e 
     79   * @param  float                  $time 
     80   * @access public 
     81   */ 
     82  public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
     83  { 
     84    $this->writeOkWithPrefix($test, 'TODO'); 
     85    $this->testSuccessful = false; 
     86  } 
     87 
     88  /** 
     89   * Skipped test. 
     90   * 
     91   * @param  PHPUnit_Framework_Test $test 
     92   * @param  Exception              $e 
     93   * @param  float                  $time 
     94   * @access public 
     95   * @since  Method available since Release 3.0.0 
     96   */ 
     97  public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) 
     98  { 
     99    $this->writeOkWithPrefix($test, 'SKIP'); 
     100    $this->testSuccessful = false; 
     101  } 
     102 
     103  /** 
     104   * A testsuite started. 
     105   * 
     106   * @param  PHPUnit_Framework_TestSuite $suite 
     107   * @access public 
     108   */ 
     109  public function startTestSuite(PHPUnit_Framework_TestSuite $suite) 
     110  { 
     111    if ($this->testNumber == 0) 
     112    { 
     113        $this->writeln( 
    124114          sprintf( 
    125             "# TestSuite%s started.", 
    126  
    127             $suite->getName() ? sprintf(" \"%s\"", $suite->getName()) : '' 
     115            "1..%d", 
     116 
     117            count($suite) 
    128118          ) 
    129119        ); 
    130120    } 
    131121 
    132     /** 
    133      * A testsuite ended. 
    134      * 
    135      * @param  PHPUnit_Framework_TestSuite $suite 
    136      * @access public 
    137      */ 
    138     public function endTestSuite(PHPUnit_Framework_TestSuite $suite) 
    139     { 
     122    $this->writeComment( 
     123      sprintf( 
     124        "# TestSuite%s started.", 
     125 
     126        $suite->getName() ? sprintf(" \"%s\"", $suite->getName()) : '' 
     127      ) 
     128    ); 
     129  } 
     130 
     131  /** 
     132   * A testsuite ended. 
     133   * 
     134   * @param  PHPUnit_Framework_TestSuite $suite 
     135   * @access public 
     136   */ 
     137  public function endTestSuite(PHPUnit_Framework_TestSuite $suite) 
     138  { 
    140139/*        $this->writeComment( 
    141140          sprintf( 
     
    145144          ) 
    146145        );*/ 
     146       
     147    if (0 === $this->failCount) 
     148    { 
     149      $this->writeSuccessBar(" Looks like everything went fine."); 
     150    } 
     151    else 
     152    { 
     153      $this->writeErrorBar( 
     154        sprintf( 
     155          ' Looks like you failed %d test%s of %d.', 
     156           
     157          $this->failCount, 
     158          1 !== $this->failCount ? 's' : '', 
     159          $suite->testCount() 
     160        ) 
     161      ); 
     162    } 
     163  } 
     164 
     165  /** 
     166   * A test started. 
     167   * 
     168   * @param  PHPUnit_Framework_Test $test 
     169   * @access public 
     170   */ 
     171  public function startTest(PHPUnit_Framework_Test $test) 
     172  { 
     173    $this->testNumber++; 
     174    $this->testSuccessful = TRUE; 
     175  } 
     176 
     177  /** 
     178   * A test ended. 
     179   * 
     180   * @param  PHPUnit_Framework_Test $test 
     181   * @param  float                  $time 
     182   * @access public 
     183   */ 
     184  public function endTest(PHPUnit_Framework_Test $test, $time) 
     185  { 
     186    if ($this->testSuccessful) 
     187    { 
     188      $this->writeOk($test); 
     189    } 
     190  } 
     191 
     192  /** 
     193   * @param  PHPUnit_Framework_Test $test 
     194   * @param  string                  $prefix 
     195   * @param  string                  $directive 
     196   * @access protected 
     197   */ 
     198  protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
     199  { 
     200    $line = sprintf( 
     201        "%s - %s%s%s", 
    147202         
    148         if (0 === $this->failCount) 
    149         { 
    150           $this->writeSuccessBar(" Looks like everything went fine."); 
    151         } 
    152         else 
    153         { 
    154           $this->writeErrorBar( 
    155             sprintf( 
    156               ' Looks like you failed %d test%s of %d.', 
    157                
    158               $this->failCount, 
    159               1 !== $this->failCount ? 's' : '', 
    160               $suite->testCount() 
    161             ) 
    162           ); 
    163         } 
    164     } 
    165  
    166     /** 
    167      * A test started. 
    168      * 
    169      * @param  PHPUnit_Framework_Test $test 
    170      * @access public 
    171      */ 
    172     public function startTest(PHPUnit_Framework_Test $test) 
    173     { 
    174         $this->testNumber++; 
    175         $this->testSuccessful = TRUE; 
    176     } 
    177  
    178     /** 
    179      * A test ended. 
    180      * 
    181      * @param  PHPUnit_Framework_Test $test 
    182      * @param  float                  $time 
    183      * @access public 
    184      */ 
    185     public function endTest(PHPUnit_Framework_Test $test, $time) 
    186     { 
    187       if ($this->testSuccessful) 
    188       { 
    189         $this->writeOk($test); 
    190       } 
    191     } 
    192  
    193     /** 
    194      * @param  PHPUnit_Framework_Test $test 
    195      * @param  string                  $prefix 
    196      * @param  string                  $directive 
    197      * @access protected 
    198      */ 
    199     protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
    200     { 
    201         $line = sprintf( 
    202             "%s - %s%s%s", 
    203              
    204       sprintf('%s %d', 'not ok', $this->testNumber), 
    205             $prefix != '' ? $prefix . ': ' : '', 
    206             PHPUnit_Util_Test::describe($test), 
    207             $directive != '' ? ' # ' . $directive : '' 
    208         ); 
    209          
    210         $this->writeln($line); 
    211          
    212         $this->testSuccessful = FALSE; 
    213     } 
    214      
    215     protected function writeOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
    216     { 
    217         if ($this->testSuccessful === TRUE) { 
    218             $this->writeln( 
    219               sprintf( 
    220                 "%s - %s", 
    221  
    222         sprintf('%s %d', 'ok', $this->testNumber), 
     203    sprintf('%s %d', 'not ok', $this->testNumber), 
     204        $prefix != '' ? $prefix . ': ' : '', 
     205        PHPUnit_Util_Test::describe($test), 
     206        $directive != '' ? ' # ' . $directive : '' 
     207    ); 
     208     
     209    $this->writeln($line); 
     210    $this->testSuccessful = FALSE; 
     211  } 
     212   
     213  protected function writeOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
     214  { 
     215    if ($this->testSuccessful === TRUE) 
     216    { 
     217      $this->writeln( 
     218        sprintf( 
     219          "%s - %s", 
     220 
     221      sprintf('%s %d', 'ok', $this->testNumber), 
     222              PHPUnit_Util_Test::describe($test) 
     223        ) 
     224      ); 
     225    } 
     226  } 
     227   
     228  protected function writeComment($line) 
     229  { 
     230    $this->writeln( 
     231    $line 
     232    ); 
     233  } 
     234   
     235  protected function writeErrorBar($line) 
     236  { 
     237    $this->writeln( 
     238      $line 
     239    ); 
     240  } 
     241   
     242  protected function writeSuccessBar($line) 
     243  { 
     244    $this->writeln( 
     245      $line 
     246    ); 
     247  } 
     248     
     249  protected function writeOkWithPrefix(PHPUnit_Framework_Test $test, $prefix) 
     250  { 
     251    $this->writeln( 
     252      sprintf( 
     253        "%s # %s %s", 
     254 
     255        sprintf('%s %d', 'ok', $this->testNumber), 
     256        $prefix, 
    223257                PHPUnit_Util_Test::describe($test) 
    224258              ) 
    225259            ); 
    226         } 
    227     } 
    228      
    229     protected function writeComment($line) 
    230     { 
    231       $this->writeln( 
    232       $line 
    233       ); 
    234     } 
    235      
    236     protected function writeErrorBar($line) 
    237     { 
    238       $this->writeln( 
    239         $line 
    240       ); 
    241     } 
    242      
    243     protected function writeSuccessBar($line) 
    244     { 
    245       $this->writeln( 
    246         $line 
    247       ); 
    248     } 
    249      
    250   protected function writeOkWithPrefix(PHPUnit_Framework_Test $test, $prefix) 
    251   { 
    252     $this->writeln( 
    253       sprintf( 
    254         "%s # %s %s", 
    255  
    256         sprintf('%s %d', 'ok', $this->testNumber), 
    257         $prefix, 
    258                 PHPUnit_Util_Test::describe($test) 
    259               ) 
    260             ); 
    261   } 
    262      
    263     public function writeln($buffer) 
    264     { 
    265       $this->write($buffer . "\n"); 
    266     } 
    267      
    268     public function echoln($buffer) 
    269     { 
    270       $this->writeln($buffer); 
    271     } 
    272      
    273     /** 
    274      * @param  string $buffer 
    275      * @access public 
    276      */ 
    277     public function write($buffer) 
    278     { 
    279         parent::write($buffer); 
    280     } 
     260  } 
     261 
     262  public function writeln($buffer) 
     263  { 
     264    $this->write($buffer . "\n"); 
     265  } 
     266 
     267  public function echoln($buffer) 
     268  { 
     269    $this->writeln($buffer); 
     270  } 
     271 
     272  /** 
     273   * @param  string $buffer 
     274   * @access public 
     275   */ 
     276  public function write($buffer) 
     277  { 
     278    parent::write($buffer); 
     279  } 
    281280} 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitTestPrinterTapColour.php

    r5418 r5439  
    99class sfPHPUnitTestPrinterTapColour extends sfPHPUnitTestPrinterTap 
    1010{ 
    11  protected $coloriser = null; 
     11  protected $coloriser = null; 
    1212     
    1313    public function __construct() 
    1414    { 
    15     $this->coloriser = new pakeColor(); 
     15      $this->coloriser = new pakeColor(); 
    1616    } 
    1717 
     
    2424    protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
    2525    { 
    26         $line = sprintf( 
    27             "%s - %s%s%s", 
    28              
    29      $this->coloriser->colorize(sprintf('%s %d', 'not ok', $this->testNumber), 'ERROR'), 
    30             $prefix != '' ? $prefix . ': ' : '', 
    31             PHPUnit_Util_Test::describe($test), 
    32             $directive != '' ? ' # ' . $directive : '' 
    33         ); 
    34          
    35         $this->writeln($line); 
    36          
    37         $this->testSuccessful = FALSE; 
     26      $line = sprintf( 
     27          "%s - %s%s%s", 
     28           
     29          $this->coloriser->colorize(sprintf('%s %d', 'not ok', $this->testNumber), 'ERROR'), 
     30          $prefix != '' ? $prefix . ': ' : '', 
     31          PHPUnit_Util_Test::describe($test), 
     32          $directive != '' ? ' # ' . $directive : '' 
     33      ); 
     34       
     35      $this->writeln($line); 
     36       
     37      $this->testSuccessful = FALSE; 
    3838    } 
    3939     
    4040    protected function writeOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') 
    4141    { 
    42         if ($this->testSuccessful === TRUE) { 
    43             $this->writeln( 
    44               sprintf( 
    45                 "%s - %s", 
     42      if ($this->testSuccessful === TRUE) 
     43      { 
     44        $this->writeln( 
     45          sprintf( 
     46            "%s - %s", 
    4647 
    47        $this->coloriser->colorize(sprintf('%s %d', 'ok', $this->testNumber), 'INFO'), 
    48                 PHPUnit_Util_Test::describe($test) 
    49              
    50             ); 
    51        
     48            $this->coloriser->colorize(sprintf('%s %d', 'ok', $this->testNumber), 'INFO'), 
     49            PHPUnit_Util_Test::describe($test) 
     50         
     51        ); 
     52     
    5253    } 
    5354     
    5455    protected function writeComment($line) 
    5556    { 
    56     $this->writeln( 
    57      $this->coloriser->colorize($line, 'COMMENT') 
    58     ); 
     57      $this->writeln( 
     58      $this->coloriser->colorize($line, 'COMMENT') 
     59      ); 
    5960    } 
    6061     
    6162    protected function writeErrorBar($line) 
    6263    { 
    63     $this->writeln( 
    64        $this->coloriser->colorize($line.str_repeat(' ', 71 - min(71, strlen($line))), 'RED_BAR') 
    65     ); 
     64      $this->writeln( 
     65        $this->coloriser->colorize($line.str_repeat(' ', 71 - min(71, strlen($line))), 'RED_BAR') 
     66      ); 
    6667    } 
    6768     
    6869    protected function writeSuccessBar($line) 
    6970    { 
    70     $this->writeln( 
    71        $this->coloriser->colorize($line.str_repeat(' ', 71 - min(71, strlen($line))), 'GREEN_BAR') 
    72     ); 
     71      $this->writeln( 
     72        $this->coloriser->colorize($line.str_repeat(' ', 71 - min(71, strlen($line))), 'GREEN_BAR') 
     73      ); 
    7374    } 
    7475     
    75  protected function writeOkWithPrefix(PHPUnit_Framework_Test $test, $prefix) 
    76 
    77    $this->writeln( 
    78      sprintf( 
    79        "%s # %s %s", 
     76  protected function writeOkWithPrefix(PHPUnit_Framework_Test $test, $prefix) 
     77 
     78    $this->writeln( 
     79      sprintf( 
     80        "%s # %s %s", 
    8081 
    81        $this->coloriser->colorize(sprintf('%s %d', 'ok', $this->testNumber), 'INFO'), 
    82        $prefix, 
     82        $this->coloriser->colorize(sprintf('%s %d', 'ok', $this->testNumber), 'INFO'), 
     83        $prefix, 
    8384                PHPUnit_Util_Test::describe($test) 
    8485              ) 
    8586            ); 
    86 
     87 
    8788} 
    8889 
  • plugins/sfPHPUnitPlugin/lib/sfPHPUnitTestRunner.php

    r5421 r5439  
    99class sfPHPUnitTestRunner extends PHPUnit_Runner_BaseTestRunner 
    1010{ 
    11     const SUCCESS_EXIT   = 0; 
    12     const FAILURE_EXIT   = 1; 
    13     const EXCEPTION_EXIT = 2; 
     11  const SUCCESS_EXIT   = 0; 
     12  const FAILURE_EXIT   = 1; 
     13  const EXCEPTION_EXIT = 2; 
    1414     
    15  private $printer = null; 
    16    
    17    
    18    
    19     public static function run($test, array $arguments = array()
     15  private $printer = null; 
     16 
     17  public static function run($test, array $arguments = array()) 
     18  { 
     19    if ($test instanceof ReflectionClass
    2020    { 
    21         if ($test instanceof ReflectionClass) 
    22         { 
    23             $test = new PHPUnit_Framework_TestSuite($test); 
    24         } 
    25  
    26         if ($test instanceof PHPUnit_Framework_Test) 
    27         { 
    28             $aTestRunner = new sfPHPUnitTestRunner(); 
    29  
    30             return $aTestRunner->doRun( 
    31               $test, 
    32               $arguments 
    33             ); 
    34         } 
    35         else 
    36         { 
    37             throw new InvalidArgumentException( 
    38               'No test case or test suite found.' 
    39             ); 
    40         } 
    41     } 
    42      
    43     public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) 
    44     { 
    45         $arguments['filter']             = isset($arguments['filter'])             ? $arguments['filter']             : FALSE; 
    46         $arguments['group']              = isset($arguments['group'])              ? $arguments['group']              : array(); 
    47         $arguments['stopOnFailure']      = isset($arguments['stopOnFailure'])      ? $arguments['stopOnFailure']      : FALSE; 
    48         $arguments['repeat']             = isset($arguments['repeat'])             ? $arguments['repeat']             : FALSE; 
    49         $arguments['reportCharset']      = isset($arguments['reportCharset'])      ? $arguments['reportCharset']      : 'ISO-8859-1'; 
    50         $arguments['testDatabasePrefix'] = isset($arguments['testDatabasePrefix']) ? $arguments['testDatabasePrefix'] : ''; 
    51         $arguments['verbose']            = isset($arguments['verbose'])            ? $arguments['verbose']            : FALSE; 
    52         $arguments['wait']               = isset($arguments['wait'])               ? $arguments['wait']               : FALSE; 
    53  
    54         if (is_integer($arguments['repeat'])) { 
    55             $suite = new PHPUnit_Extensions_RepeatedTest( 
    56               $suite, $arguments['repeat'], $arguments['filter'], $arguments['group'] 
    57             ); 
    58         } 
    59  
    60         $result = $this->createTestResult(); 
    61  
    62         if ($arguments['stopOnFailure']) { 
    63             $result->stopOnFailure(TRUE); 
    64         } 
    65  
    66         if ($this->printer === NULL) 
    67         { 
    68             if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) 
    69             { 
    70                 $this->printer = $arguments['printer']; 
    71             } 
    72         } 
    73  
    74         if ($this->printer instanceof PHPUnit_Framework_TestListener) 
    75         { 
    76           $result->addListener($this->printer); 
    77         } 
    78  
    79         $suite->run($result, $arguments['filter'], $arguments['group']); 
    80  
    81         $result->flushListeners(); 
    82  
    83         if ($this->printer instanceof sfPHPUnitTestPrinter) 
    84         { 
    85             $this->printer->printResult($result); 
    86         } 
    87  
    88         $this->pause($arguments['wait']); 
    89  
    90         return $result; 
     21      $test = new PHPUnit_Framework_TestSuite($test); 
    9122    } 
    9223 
     24    if ($test instanceof PHPUnit_Framework_Test) 
     25    { 
     26      $aTestRunner = new sfPHPUnitTestRunner(); 
     27 
     28      return $aTestRunner->doRun( 
     29        $test, 
     30        $arguments 
     31      ); 
     32    } 
     33    else 
     34    { 
     35      throw new InvalidArgumentException( 
     36        'No test case or test suite found.' 
     37      ); 
     38    } 
     39  } 
    9340     
    94      
    95     protected function pause($wait) 
     41  public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) 
     42  { 
     43    $arguments['filter']             = isset($arguments['filter'])             ? $arguments['filter']             : FALSE; 
     44    $arguments['group']              = isset($arguments['group'])              ? $arguments['group']              : array(); 
     45    $arguments['stopOnFailure']      = isset($arguments['stopOnFailure'])      ? $arguments['stopOnFailure']      : FALSE; 
     46    $arguments['repeat']             = isset($arguments['repeat'])             ? $arguments['repeat']             : FALSE; 
     47    $arguments['reportCharset']      = isset($arguments['reportCharset'])      ? $arguments['reportCharset']      : 'ISO-8859-1'; 
     48    $arguments['testDatabasePrefix'] = isset($arguments['testDatabasePrefix']) ? $arguments['testDatabasePrefix'] : ''; 
     49    $arguments['verbose']            = isset($arguments['verbose'])            ? $arguments['verbose']            : FALSE; 
     50    $arguments['wait']               = isset($arguments['wait'])               ? $arguments['wait']               : FALSE; 
     51 
     52    if (is_integer($arguments['repeat'])) 
    9653    { 
    97        return; 
    98     } 
    99      
    100     protected function createTestResult() 
    101     { 
    102         return new PHPUnit_Framework_TestResult(); 
    103     } 
    104      
    105     public function testStarted($testName) 
    106     { 
     54      $suite = new PHPUnit_Extensions_RepeatedTest( 
     55        $suite, $arguments['repeat'], $arguments['filter'], $arguments['group'] 
     56      ); 
    10757    } 
    10858 
    109     public function testEnded($testName) 
     59    $result = $this->createTestResult(); 
     60 
     61    if ($arguments['stopOnFailure']) 
    11062    { 
    111     } 
    112      
    113     public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) 
    114     { 
     63        $result->stopOnFailure(TRUE); 
    11564    } 
    11665 
    117     protected function runFailed($message
     66    if ($this->printer === NULL
    11867    { 
    119         //self::printVersionString(); 
    120         //self::write($message); 
    121         //exit(self::FAILURE_EXIT); 
     68      if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) 
     69      { 
     70        $this->printer = $arguments['printer']; 
     71      } 
    12272    } 
     73 
     74    if ($this->printer instanceof PHPUnit_Framework_TestListener) 
     75    { 
     76      $result->addListener($this->printer); 
     77    } 
     78 
     79    $suite->run($result, $arguments['filter'], $arguments['group']); 
     80 
     81    $result->flushListeners(); 
     82 
     83    if ($this->printer instanceof sfPHPUnitTestPrinter) 
     84    { 
     85      $this->printer->printResult($result); 
     86    } 
     87 
     88    $this->pause($arguments['wait']); 
     89 
     90    return $result; 
     91  } 
     92 
     93  protected function pause($wait) 
     94  { 
     95   return; 
     96  } 
     97   
     98  protected function createTestResult() 
     99  { 
     100    return new PHPUnit_Framework_TestResult(); 
     101  } 
     102   
     103  public function testStarted($testName) 
     104  { 
     105  } 
     106 
     107  public function testEnded($testName) 
     108  { 
     109  } 
     110   
     111  public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) 
     112  { 
     113  } 
     114 
     115  protected function runFailed($message) 
     116  { 
     117    //self::printVersionString(); 
     118    //self::write($message); 
     119    //exit(self::FAILURE_EXIT); 
     120  } 
    123121} 
  • plugins/sfPayloadFilterChain_TextTransformationPlugin/lib/transformer/pfcGeshiHighlightTransformer.class.php

    r4403 r5439  
    1717class pfcGeshiHighlightTransformer extends pfcAbstractTransformer 
    1818{ 
    19  
    2019  /**  
    2120   * Highlights code in-beetwen "pre" tags. 
     
    3837    if ($nb_matches > 0) 
    3938    { 
    40         $i = 0; 
    41         // delete first result of preg_match_all 
    42         unset($matches[0]); 
    43         for($i ; $i < ($nb_matches) ;$i++) 
     39      $i = 0; 
     40      // delete first result of preg_match_all 
     41      unset($matches[0]); 
     42 
     43      for($i ; $i < ($nb_matches) ;$i++) 
     44      { 
     45        // instanciate and configure GeSHi 
     46        $geshi = new GeSHi(trim($matches[5][$i]), $matches[1][$i]); 
     47 
     48        if ($this->getParameter('show_line_numbers', true)) 
    4449        { 
    45           // instanciate and configure GeSHi 
    46           $geshi = new GeSHi(trim($matches[5][$i]), $matches[1][$i]); 
     50          $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); 
     51        } 
    4752 
    48           if ($this->getParameter('show_line_numbers', true)) 
    49           { 
    50             $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); 
    51           } 
     53        if ($this->getParameter('highlight_lines_extra', true)) 
     54        { 
     55          $lines = $this->parseInterval($matches[3][$i]); 
     56          $geshi->highlight_lines_extra($lines); 
     57        } 
    5258 
    53           if ($this->getParameter('highlight_lines_extra', true)) 
    54           { 
    55             $lines = $this->parseInterval($matches[3][$i]); 
    56             $geshi->highlight_lines_extra($lines); 
    57           } 
     59        // Highligh text 
     60        $highlight_text = $geshi->parse_code(); 
    5861 
    59           // Highligh text 
    60           $highlight_text = $geshi->parse_code(); 
    61  
    62           // Replace code with its highlighted version  
    63           $text = str_replace($matches[5][$i], $highlight_text, $text); 
    64         } 
     62        // Replace code with its highlighted version  
     63        $text = str_replace($matches[5][$i], $highlight_text, $text); 
     64      } 
    6565    } 
    6666     
     
    8080    $highlight_lines = array(); 
    8181 
    82   foreach (explode(',', $lines_list) as $line) 
    83  
    84     if (preg_match('/\d+\-\d+/', $line)) 
    85     { 
    86       $lines = explode('-', $line); 
    87       $highlight_lines = array_merge($highlight_lines, range($lines[0], $lines[1])); 
    88     } 
    89     else 
    90     { 
    91       $highlight_lines[] = $line; 
    92     } 
    93  
     82    foreach (explode(',', $lines_list) as $line) 
     83   
     84      if (preg_match('/\d+\-\d+/', $line)) 
     85      { 
     86        $lines = explode('-', $line); 
     87        $highlight_lines = array_merge($highlight_lines, range($lines[0], $lines[1])); 
     88      } 
     89      else 
     90      { 
     91        $highlight_lines[] = $line; 
     92      } 
     93   
    9494 
    95   return array_unique($highlight_lines); 
     95    return array_unique($highlight_lines); 
    9696  } 
    9797} 
    98  
  • plugins/sfPayloadFilterChain_TextTransformationPlugin/lib/transformer/pfcMimeConversionTransformer.class.php

    r4444 r5439  
    1111class pfcMimeConversionTransformer extends pfcAbstractTransformer 
    1212{ 
    13  
    1413  /** 
    1514   * Transforms text. 
     
    5554    foreach($list as $l) 
    5655    { 
    57     $liste[$l] = $l; 
     56      $liste[$l] = $l; 
    5857    } 
    5958 
     
    6160  } 
    6261} 
    63 ?> 
  • plugins/sfPropelVersionableBehaviorPlugin/lib/sfPropelVersionableBehavior.class.php

    r3620 r5439  
    176176  public function postSave(BaseObject $resource) 
    177177  { 
    178  if (self::versionConditionMet($resource)) 
     178    if (self::versionConditionMet($resource)) 
    179179    { 
    180180      $version = new ResourceVersion(); 
  • plugins/sfSimpleBlogPlugin/modules/sfSimpleBlog/templates/layout.php

    r5012 r5439  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-200000126/DTD/xhtml1-transitional.dtd"> 
    22<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    3 <head> 
    4 <?php use_stylesheet('/sfSimpleBlogPlugin/css/layout.css') ?> 
    5 <?php echo include_http_metas() ?> 
    6 <?php echo include_metas() ?> 
    7 <?php echo include_title() ?> 
    8 <?php include_slot('auto_discovery_link_tag') ?> 
    9 <link rel="shortcut icon" href="/favicon.ico"> 
    10  
    11 </head> 
    12 <body> 
    13    
    14 <div id="sfSimpleBlog_container"> 
    15   <div id="header"> 
    16     <h1><?php echo link_to(sfConfig::get('app_sfSimpleBlog_title', 'How is life on earth?'), 'sfSimpleBlog/index') ?></h1> 
    17     <div id="tagline"><?php echo sfConfig::get('app_sfSimpleBlog_tagline', 'You\'d better start to live before it\'s too late') ?></div> 
    18   </div> 
    19   <div id="sidebar-a"> 
    20     <?php include_slot('sfSimpleBlog_sidebar') ?> 
    21   </div> 
    22   <div id="content" > 
    23     <?php echo $sf_data->getRaw('content') ?> 
    24   </div> 
    25   <div id="footer"></div> 
    26 </div> 
    27  
    28 </body> 
     3  <head> 
     4    <?php use_stylesheet('/sfSimpleBlogPlugin/css/layout.css') ?> 
     5    <?php echo include_http_metas() ?> 
     6    <?php echo include_metas() ?> 
     7    <?php echo include_title() ?> 
     8    <?php include_slot('auto_discovery_link_tag') ?> 
     9    <link rel="shortcut icon" href="/favicon.ico"> 
     10  </head> 
     11  <body> 
     12    <div id="sfSimpleBlog_container"> 
     13      <div id="header"> 
     14        <h1><?php echo link_to(sfConfig::get('app_sfSimpleBlog_title', 'How is life on earth?'), 'sfSimpleBlog/index') ?></h1> 
     15        <div id="tagline"><?php echo sfConfig::get('app_sfSimpleBlog_tagline', 'You\'d better start to live before it\'s too late') ?></div> 
     16      </div> 
     17      <div id="sidebar-a"> 
     18        <?php include_slot('sfSimpleBlog_sidebar') ?> 
     19      </div> 
     20      <div id="content" > 
     21        <?php echo $sf_data->getRaw('content') ?> 
     22      </div> 
     23      <div id="footer"></div> 
     24    </div> 
     25  </body> 
    2926</html> 
  • plugins/sfSimpleCMSPlugin/modules/sfSimpleCMS/templates/layout.php

    r4872 r5439  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-200000126/DTD/xhtml1-transitional.dtd"> 
    22<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    3 <head> 
    4  
    5 <?php echo include_http_metas() ?> 
    6 <?php echo include_metas() ?> 
    7 <?php echo include_title() ?> 
    8 <?php include_slot('auto_discovery_link_tag') ?> 
    9 <link rel="shortcut icon" href="/favicon.ico"> 
    10  
    11 </head> 
    12 <body> 
    13    
    14 <div id="cms"> 
    15  
    16   <div id="head"> 
    17     <div id="site_name"> 
    18       <?php if(!include_slot('sfSimpleCMS_home_link')): ?> 
    19         <?php echo link_to( 
    20           sfConfig::get('app_sfSimpleCMS_home_link', 'My Swell site'), 
    21           sfSimpleCMSTools::urlForPage(sfConfig::get('app_sfSimpleCMS_default_page', 'home')), 
    22           array('class' => 'cms_page_navigation')) ?>   
    23       <?php endif; ?> 
    24  
    25       <?php if(!include_slot('sfSimpleCMS_tagline')): ?> 
    26         <div id="site_tagline"> 
    27           <?php echo sfConfig::get('app_sfSimpleCMS_tagline', 'All there is to know about [you name it]') ?> 
     3  <head> 
     4    <?php echo include_http_metas() ?> 
     5    <?php echo include_metas() ?> 
     6    <?php echo include_title() ?> 
     7    <?php include_slot('auto_discovery_link_tag') ?> 
     8    <link rel="shortcut icon" href="/favicon.ico"> 
     9  </head> 
     10  <body> 
     11    <div id="cms"> 
     12      <div id="head"> 
     13        <div id="site_name"> 
     14          <?php if(!include_slot('sfSimpleCMS_home_link')): ?> 
     15            <?php echo link_to( 
     16              sfConfig::get('app_sfSimpleCMS_home_link', 'My Swell site'), 
     17              sfSimpleCMSTools::urlForPage(sfConfig::get('app_sfSimpleCMS_default_page', 'home')), 
     18              array('class' => 'cms_page_navigation')) ?>   
     19          <?php endif; ?> 
     20     
     21          <?php if(!include_slot('sfSimpleCMS_tagline')): ?> 
     22            <div id="site_tagline"> 
     23              <?php echo sfConfig::get('app_sfSimpleCMS_tagline', 'All there is to know about [you name it]') ?> 
     24            </div> 
     25          <?php endif; ?> 
    2826        </div> 
    29       <?php endif; ?> 
     27      </div> 
     28     
     29      <?php if(!include_slot('sfSimpleCMS_main_navigation')): ?> 
     30        <div id="mainNavigation"> 
     31          <?php include_component('sfSimpleCMS', 'mainNavigation', array('page' => $page, 'culture' => $culture)); ?> 
     32        </div> 
     33      <?php endif; ?>   
     34       
     35      <div id="content" class="<?php echo $page->getTemplate() ?>" > 
     36        <?php if(!include_slot('sfSimpleCMS_breadcrumb')): ?> 
     37          <?php include_component('sfSimpleCMS', 'breadcrumb', array('page' => $page, 'culture' => $culture)) ?> 
     38        <?php endif; ?> 
     39         
     40        <?php echo $sf_data->getRaw('sf_content') ?> 
     41      </div> 
    3042    </div> 
    31  
    32   </div> 
    33  
    34   <?php if(!include_slot('sfSimpleCMS_main_navigation')): ?> 
    35     <div id="mainNavigation"> 
    36       <?php include_component('sfSimpleCMS', 'mainNavigation', array('page' => $page, 'culture' => $culture)); ?> 
    37     </div> 
    38   <?php endif; ?>   
    39    
    40   <div id="content" class="<?php echo $page->getTemplate() ?>" > 
    41     <?php if(!include_slot('sfSimpleCMS_breadcrumb')): ?> 
    42       <?php include_component('sfSimpleCMS', 'breadcrumb', array('page' => $page, 'culture' => $culture)) ?> 
     43    <?php if(!include_slot('sfSimpleCMS_footer_message')): ?> 
     44      <div id="footer_message"> 
     45        <?php echo sfConfig::get('app_sfSimpleCMS_footer_message', 'Powered by <b>sfSimpleCMS</b> and '.link_to(image_tag('/sfSimpleCMSPlugin/images/symfony_button.gif', 'align=absmiddle'), 'http://www.symfony-project.com')) ?> 
     46      </div> 
    4347    <?php endif; ?> 
    44      
    45     <?php echo $sf_data->getRaw('sf_content') ?> 
    46   </div> 
    47    
    48 </div> 
    49  
    50 <?php if(!include_slot('sfSimpleCMS_footer_message')): ?> 
    51   <div id="footer_message"> 
    52     <?php echo sfConfig::get('app_sfSimpleCMS_footer_message', 'Powered by <b>sfSimpleCMS</b> and '.link_to(image_tag('/sfSimpleCMSPlugin/images/symfony_button.gif', 'align=absmiddle'), 'http://www.symfony-project.com')) ?> 
    53   </div> 
    54 <?php endif; ?> 
    55  
    56 </body> 
     48  </body> 
    5749</html> 
  • plugins/sfUJSPlugin/lib/helper/UJSHelper.php

    r4061 r5439  
    145145function UJS_change_attributes($selector, $html_options = array()) 
    146146{ 
    147  return UJS_attr($selector, $html_options); 
     147  return UJS_attr($selector, $html_options); 
    148148} 
    149149 
     
    183183function UJS_change_style($selector, $css_options = array()) 
    184184{ 
    185  return UJS_css($selector, $css_options); 
     185  return UJS_css($selector, $css_options); 
    186186} 
    187187 
     
    547547  if ($UJS = $response->getParameter('script', false, 'symfony/view/UJS')) 
    548548  { 
    549     $code = sprintf("jQuery(document).ready(function(){\n%s })", $UJS); 
    550     if($static) 
    551     { 
     549    $code = sprintf("jQuery(document).ready(function(){\n%s })", $UJS); 
     550 
     551    if($static) 
     552    { 
    552553      // JavaScript code is in another file 
    553554      use_helper('PJS'); 
  • plugins/sfUJSPlugin/modules/sfUJS/actions/actions.class.php

    r4059 r5439  
    44class sfUJSActions extends sfActions 
    55{ 
    6  public function executeScript() 
    7 
    8    $this->getResponse()->setContentType('application/x-javascript'); 
    9    $this->setLayout(false); 
    10    $key = substr($this->getRequestParameter('key'), 0, 32); 
    11    $script = $this->getUser()->getAttribute('UJS_'.$key, '', 'symfony/UJS'); 
    12    $this->getUser()->getAttributeHolder()->remove('UJS_'.$key, 'symfony/UJS'); 
    13      
    14    return $this->renderText($script); 
    15 
     6  public function executeScript() 
     7 
     8    $this->getResponse()->setContentType('application/x-javascript'); 
     9    $this->setLayout(false); 
     10    $key = substr($this->getRequestParameter('key'), 0, 32); 
     11    $script = $this->getUser()->getAttribute('UJS_'.$key, '', 'symfony/UJS'); 
     12    $this->getUser()->getAttributeHolder()->remove('UJS_'.$key, 'symfony/UJS'); 
     13     
     14    return $this->renderText($script); 
     15 
    1616} 
  • plugins/sfUJSPlugin/modules/sfUJSTest/actions/actions.class.php

    r4059 r5439  
    44class sfUJSTestActions extends sfActions 
    55{ 
    6  public function executeIndex() 
    7 
    8    $this->static = $this->getRequestParameter('static', 1); 
    9 
     6  public function executeIndex() 
     7 
     8    $this->static = $this->getRequestParameter('static', 1); 
     9 
    1010} 
  • plugins/sfUJSPlugin/modules/sfUJSTest/templates/indexSuccess.php

    r4062 r5439  
    6060  test("Basic unobtrusive scripting", function() { 
    6161    expect(2); 
    62    is($('#test_case1').text(), "success", "Scripts added by UJS() are executed" ); 
    63    is($('#test_case2').text(), "success", "Scripts added by UJS_block() are executed" ); 
    64  }); 
     62    is($('#test_case1').text(), "success", "Scripts added by UJS() are executed" ); 
     63    is($('#test_case2').text(), "success", "Scripts added by UJS_block() are executed" ); 
     64  }); 
    6565 
    6666  test("Changing DOM element attributes and style", function() { 
    6767    expect(11); 
    68    test3 = 'failure'; 
    69    $('#test_case3').click() 
    70    is(test3, "success", "UJS_add_behaviour() adds a behaviour to selected nodes" ); 
    71    is($('#test_case4').attr('name'), "baz", "UJS_change_attributes() adds new attributes" ); 
    72    is($('#test_case4').attr('class'), "foo", "UJS_change_attributes() changes existing attributes" ); 
    73    is_deeply([$('#test_case4').attr('width'), $('#test_case4').attr('height')], ["20", "30"], "UJS_change_attributes() can change more than one attribute at a time (string syntax, blank separator)" ); 
    74    is_deeply([$('#test_case5').attr('width'), $('#test_case5').attr('height')], ["20", "30"], "UJS_change_attributes() can change more than one attribute at a time (array syntax)" ); 
    75    is($('#test_case5').css('color'), "yellow", "UJS_change_attributes() can also change the style attribute" ); 
    76    is($('#test_case6').css('text-decoration'), "underline", "UJS_change_style() adds new style attributes" ); 
    77    is($('#test_case6').css('color'), "green", "UJS_change_style() changes existing style attributes" ); 
    78    is_deeply([$('#test_case6').css('text-align'), $('#test_case6').css('font-style')], ["right", "italic"], "UJS_change_style() can change more than one style attribute at a time (string syntax, blank separator)" ); 
    79    is_deeply([$('#test_case6').css('line-height'), $('#test_case6').css('letter-spacing')], ["2px", "2px"], "UJS_change_style() can change more than one style attribute at a time (string syntax, semicolon separator)" ); 
    80    is_deeply([$('#test_case6').css('font-weight'), $('#test_case6').css('font-size')], ["800", "19px"], "UJS_change_style() can change more than one style attribute at a time (array syntax)" ); 
     68    test3 = 'failure'; 
     69    $('#test_case3').click() 
     70    is(test3, "success", "UJS_add_behaviour() adds a behaviour to selected nodes" ); 
     71    is($('#test_case4').attr('name'), "baz", "UJS_change_attributes() adds new attributes" ); 
     72    is($('#test_case4').attr('class'), "foo", "UJS_change_attributes() changes existing attributes" ); 
     73    is_deeply([$('#test_case4').attr('width'), $('#test_case4').attr('height')], ["20", "30"], "UJS_change_attributes() can change more than one attribute at a time (string syntax, blank separator)" ); 
     74    is_deeply([$('#test_case5').attr('width'), $('#test_case5').attr('height')], ["20", "30"], "UJS_change_attributes() can change more than one attribute at a time (array syntax)" ); 
     75    is($('#test_case5').css('color'), "yellow", "UJS_change_attributes() can also change the style attribute" ); 
     76    is($('#test_case6').css('text-decoration'), "underline", "UJS_change_style() adds new style attributes" ); 
     77    is($('#test_case6').css('color'), "green", "UJS_change_style() changes existing style attributes" ); 
     78    is_deeply([$('#test_case6').css('text-align'), $('#test_case6').css('font-style')], ["right", "italic"], "UJS_change_style() can change more than one style attribute at a time (string syntax, blank separator)" ); 
     79    is_deeply([$('#test_case6').css('line-height'), $('#test_case6').css('letter-spacing')], ["2px", "2px"], "UJS_change_style() can change more than one style attribute at a time (string syntax, semicolon separator)" ); 
     80    is_deeply([$('#test_case6').css('font-weight'), $('#test_case6').css('font-size')], ["800", "19px"], "UJS_change_style() can change more than one style attribute at a time (array syntax)" ); 
    8181  }); 
    8282   
    8383  test("Placeholder, replacer and writer", function() { 
    8484    expect(11); 
    85    ok(String('<?php echo UJS_incremental_id() ?>').indexOf('UJS') === 0 , "UJS_incremental_id() returns a unique id starting with 'UJS'" ); 
    86    ok('<?php echo UJS_incremental_id() ?>' != '<?php echo UJS_incremental_id() ?>', "Each call to UJS_incremental_id() returns a new id" ); 
    87    ok($('#test_case7').is("span"), "UJS_placeholder() inserts a <span> node with the given id" ); 
    88    is($('#test_case7').attr('class'), "UJS_placeholder", "UJS_placeholder() inserts a placeholder with class 'UJS_placeholder'" ); 
    89    is($('#test_case7').css('display'), "none", "UJS_placeholder() inserts an invisible placeholder" ); 
    90    is($('#test_case8').html().toLowerCase(), "<b>success</b>", "UJS_replace() replaces existing elements matching selector with given HTML" ); 
    91    is_deeply($('#test_case8_inside'), [], "UJS_replace() removes existing elements matching selector " ); 
    92    is($('#test_case9').html().toLowerCase(), '<span class="foo" name="bar">success</span>', "UJS_replace() espaces single and double quotes in second argument properly" ); 
    93    is($('#test_case10').html(), "success", "UJS_write() writes into the document" ); 
    94    is($('#test_case11').html().toLowerCase(), "<b>success</b>", "UJS_write() writes HTML into the document" ); 
    95    is($('#test_case12').html().toLowerCase(), "<b>success</b>", "UJS_write_block() writes HTML into the document" ); 
    96  }); 
     85    ok(String('<?php echo UJS_incremental_id() ?>').indexOf('UJS') === 0 , "UJS_incremental_id() returns a unique id starting with 'UJS'" ); 
     86    ok('<?php echo UJS_incremental_id() ?>' != '<?php echo UJS_incremental_id() ?>', "Each call to UJS_incremental_id() returns a new id" ); 
     87    ok($('#test_case7').is("span"), "UJS_placeholder() inserts a <span> node with the given id" ); 
     88    is($('#test_case7').attr('class'), "UJS_placeholder", "UJS_placeholder() inserts a placeholder with class 'UJS_placeholder'" ); 
     89    is($('#test_case7').css('display'), "none", "UJS_placeholder() inserts an invisible placeholder" ); 
     90    is($('#test_case8').html().toLowerCase(), "<b>success</b>", "UJS_replace() replaces existing elements matching selector with given HTML" ); 
     91    is_deeply($('#test_case8_inside'), [], "UJS_replace() removes existing elements matching selector " ); 
     92    is($('#test_case9').html().toLowerCase(), '<span class="foo" name="bar">success</span>', "UJS_replace() espaces single and double quotes in second argument properly" ); 
     93    is($('#test_case10').html(), "success", "UJS_write() writes into the document" ); 
     94    is($('#test_case11').html().toLowerCase(), "<b>success</b>", "UJS_write() writes HTML into the document" ); 
     95    is($('#test_case12').html().toLowerCase(), "<b>success</b>", "UJS_write_block() writes HTML into the document" ); 
     96  }); 
    9797   
    9898  runTest(); 
  • plugins/sfYUIPlugin/lib/helper/YUIConnectionHelper.php

    r3577 r5439  
    207207 * @see link_to_function() 
    208208 */ 
    209  
    210   function yui_live_form_tag($submit_route, $options = array()) 
    211   { 
    212  
    213     sfYUI::addComponent('yahoo'); 
    214     sfYUI::addComponent('connection'); 
    215     $options = _parse_attributes($options); 
    216  
    217     $url = ''; 
    218     if (isset($options['url'])) 
    219     { 
    220       $url = url_for($options['url']); 
    221       unset($options['url']); 
    222     } 
    223     $update = ''; 
    224     if (isset($options['update'])) 
    225     { 
    226       $update = $options['update']; 
    227       unset($options['update']); 
    228     } 
    229      
    230     $func = 'new function(){var t=event.target||event.srcElement;var c=YAHOO.util.Connect;c.setForm(t.form);'; 
    231     $func .= 'c.initHeader(\'X-Requested-With\', \'XMLHttpRequest\');'; 
    232     $func .= 'c.asyncRequest("POST", "'.$url.'",{success:function(o){document.getElementById("'.$update.'").innerHTML=o.responseText;}});}'; 
    233     $options['onchange'] = $func; 
    234     return form_tag($submit_route, $options); 
    235   } 
    236    
    237   /** 
    238    * Returns a text input tag that makes an ajax request onchange that  
    239    *  updates a specified element 
    240    * 
    241    * Example usage: 
    242    *    
    243    *   <div id="results"></div> 
    244    *   <?php echo yui_live_input_tag('@form_submit', array( 
    245    *     'url' => '@live_form', 
    246    *     'update' => 'results' 
    247    *   )) ?> 
    248    * 
    249    *  @form_submit does the final submission 
    250    *  @live_form takes a dynamic submission and  
    251    * 
    252    * This is useful for live javascript validation. 
    253    * 
    254    * @param string $name 
    255    * @param string $default 
    256    * @param array $options 
    257    * @see input_tag 
    258    */ 
    259  
    260     function yui_live_input_tag($name, $default = null, $options = array()) 
    261     { 
    262  
    263       sfYUI::addComponent('yahoo'); 
    264       sfYUI::addComponent('connection'); 
    265       $options = _parse_attributes($options); 
    266  
    267       $url = ''; 
    268       if (isset($options['url'])) 
    269       { 
    270         $url = url_for($options['url']); 
    271         unset($options['url']); 
    272       } 
    273       $update = ''; 
    274       if (isset($options['update'])) 
    275       { 
    276         $update = $options['update']; 
    277         unset($options['update']); 
    278       } 
    279  
    280       $func = 'new function(){c=YAHOO.util.Connect;'; 
    281       $func .= 'c.initHeader(\'X-Requested-With\', \'XMLHttpRequest\');'; 
    282       $func .= 'c.asyncRequest("POST", "'.$url.'",{success:function(o){document.getElementById("'.$update.'").innerHTML=o.responseText;}},"value="+event.target.value);}'; 
    283       $options['onchange'] = $func; 
    284       return input_tag($name, $default, $options); 
    285     } 
     209function yui_live_form_tag($submit_route, $options = array()) 
     210
     211 
     212  sfYUI::addComponent('yahoo'); 
     213  sfYUI::addComponent('connection'); 
     214  $options = _parse_attributes($options); 
     215 
     216  $url = ''; 
     217  if (isset($options['url'])) 
     218  { 
     219    $url = url_for($options['url']); 
     220    unset($options['url']); 
     221  } 
     222  $update = ''; 
     223  if (isset($options['update'])) 
     224  { 
     225    $update = $options['update']; 
     226    unset($options['update']); 
     227  } 
     228   
     229  $func = 'new function(){var t=event.target||event.srcElement;var c=YAHOO.util.Connect;c.setForm(t.form);'; 
     230  $func .= 'c.initHeader(\'X-Requested-With\', \'XMLHttpRequest\');'; 
     231  $func .= 'c.asyncRequest("POST", "'.$url.'",{success:function(o){document.getElementById("'.$update.'").innerHTML=o.responseText;}});}'; 
     232  $options['onchange'] = $func; 
     233  return form_tag($submit_route, $options); 
     234
     235 
     236/** 
     237 * Returns a text input tag that makes an ajax request onchange that  
     238 *  updates a specified element 
     239 * 
     240 * Example usage: 
     241 *    
     242 *   <div id="results"></div> 
     243 *   <?php echo yui_live_input_tag('@form_submit', array( 
     244 *     'url' => '@live_form', 
     245 *     'update' => 'results' 
     246 *   )) ?> 
     247 * 
     248 *  @form_submit does the final submission 
     249 *  @live_form takes a dynamic submission and  
     250 * 
     251 * This is useful for live javascript validation. 
     252 * 
     253 * @param string $name 
     254 * @param string $default 
     255 * @param array $options 
     256 * @see input_tag 
     257 */ 
     258function yui_live_input_tag($name, $default = null, $options = array()) 
     259
     260 
     261  sfYUI::addComponent('yahoo'); 
     262  sfYUI::addComponent('connection'); 
     263  $options = _parse_attributes($options); 
     264 
     265  $url = ''; 
     266  if (isset($options['url'])) 
     267  { 
     268    $url = url_for($options['url']); 
     269    unset($options['url']); 
     270  } 
     271  $update = ''; 
     272  if (isset($options['update'])) 
     273  { 
     274    $update = $options['update']; 
     275    unset($options['update']); 
     276  } 
     277 
     278  $func = 'new function(){c=YAHOO.util.Connect;'; 
     279  $func .= 'c.initHeader(\'X-Requested-With\', \'XMLHttpRequest\');'; 
     280  $func .= 'c.asyncRequest("POST", "'.$url.'",{success:function(o){document.getElementById("'.$update.'").innerHTML=o.responseText;}},"value="+event.target.value);}'; 
     281  $options['onchange'] = $func; 
     282  return input_tag($name, $default, $options); 
     283
  • plugins/sfYUIPlugin/lib/helper/YUITabviewHelper.php

    r3473 r5439  
    6767 
    6868  $js = "var " . $element . "_tabView = new YAHOO.widget.TabView('" . $element . "', { "; 
    69    
    70   if(isset($options['orientation'])){ 
    71     $js .= $orientation = "orientation: " . "'".$options['orientation']."'"; 
    72   } 
    73    
    74   $js .= " });"; 
     69   
     70  if(isset($options['orientation'])) 
     71  { 
     72    $js .= $orientation = "orientation: " . "'".$options['orientation']."'"; 
     73  } 
     74   
     75  $js .= " });"; 
    7576 
    7677  echo javascript_tag($js) . "\n" . $content; 
     
    157158    { 
    158159      $tab_attributes[] = "dataSrc: '" . $tab['dataSrc'] . "'"; 
     160 
    159161      if (isset($tab['cacheData'])) 
    160162      {