Skip to content

Commit

Permalink
Dev Updated Yii to 1.1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Feb 26, 2016
1 parent bc72d46 commit 2fdb409
Show file tree
Hide file tree
Showing 143 changed files with 35,284 additions and 35,080 deletions.
5 changes: 3 additions & 2 deletions framework/YiiBase.php
Expand Up @@ -80,7 +80,7 @@ class YiiBase
*/
public static function getVersion()
{
return '1.1.16';
return '1.1.17';
}

/**
Expand Down Expand Up @@ -434,7 +434,7 @@ public static function autoload($className,$classMapOnly=false)
else // class name with namespace in PHP 5.3
{
$namespace=str_replace('\\','.',ltrim($className,'\\'));
if(($path=self::getPathOfAlias($namespace))!==false)
if(($path=self::getPathOfAlias($namespace))!==false && is_file($path.'.php'))
include($path.'.php');
else
return false;
Expand Down Expand Up @@ -652,6 +652,7 @@ public static function registerAutoloader($callback, $append=false)
'CApplicationComponent' => '/base/CApplicationComponent.php',
'CBehavior' => '/base/CBehavior.php',
'CComponent' => '/base/CComponent.php',
'CDbStatePersister' => '/base/CDbStatePersister.php',
'CErrorEvent' => '/base/CErrorEvent.php',
'CErrorHandler' => '/base/CErrorHandler.php',
'CException' => '/base/CException.php',
Expand Down
10 changes: 10 additions & 0 deletions framework/base/CApplication.php
Expand Up @@ -73,6 +73,7 @@
* @property CPhpMessageSource $coreMessages The core message translations.
* @property CMessageSource $messages The application message translations.
* @property CHttpRequest $request The request component.
* @property CFormatter $format The formatter component.
* @property CUrlManager $urlManager The URL manager component.
* @property CController $controller The currently active controller. Null is returned in this base class.
* @property string $baseUrl The relative URL for the application.
Expand Down Expand Up @@ -530,6 +531,15 @@ public function getUrlManager()
return $this->getComponent('urlManager');
}

/**
* Returns the formatter component.
* @return CFormatter the formatter component
*/
public function getFormat()
{
return $this->getComponent('format');
}

/**
* @return CController the currently active controller. Null is returned in this base class.
* @since 1.1.8
Expand Down
24 changes: 15 additions & 9 deletions framework/base/CErrorHandler.php
Expand Up @@ -556,7 +556,7 @@ protected function getHttpHeader($httpCode, $replacement='')
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
118 => 'Connection timed out',
118 => 'Connection Timed Out',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
Expand All @@ -573,7 +573,7 @@ protected function getHttpHeader($httpCode, $replacement='')
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
310 => 'Too many Redirect',
310 => 'Too Many Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
Expand All @@ -582,32 +582,38 @@ protected function getHttpHeader($httpCode, $replacement='')
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested range unsatisfiable',
417 => 'Expectation failed',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I’m a teapot',
422 => 'Unprocessable entity',
423 => 'Locked',
424 => 'Method failure',
425 => 'Unordered Collection',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
449 => 'Retry With',
450 => 'Blocked by Windows Parental Controls',
451 => 'Unavailable For Legal Reasons',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway ou Proxy Error',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Time-out',
505 => 'HTTP Version not supported',
507 => 'Insufficient storage',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
507 => 'Insufficient Storage',
509 => 'Bandwidth Limit Exceeded',
510 => 'Not Extended',
511 => 'Network Authentication Required',
);
if(isset($httpCodes[$httpCode]))
return $httpCodes[$httpCode];
Expand Down
17 changes: 11 additions & 6 deletions framework/base/CSecurityManager.php
Expand Up @@ -59,6 +59,7 @@ class CSecurityManager extends CApplicationComponent

/**
* @var boolean if encryption key should be validated
* @deprecated
*/
public $validateEncryptionKey=true;

Expand Down Expand Up @@ -95,6 +96,7 @@ class CSecurityManager extends CApplicationComponent
private $_encryptionKey;
private $_mbstring;


public function init()
{
parent::init();
Expand Down Expand Up @@ -527,18 +529,20 @@ protected function validateEncryptionKey($key)
{
if(is_string($key))
{
$supportedKeyLengths=mcrypt_module_get_supported_key_sizes($this->cryptAlgorithm);
$cryptAlgorithm = is_array($this->cryptAlgorithm) ? $this->cryptAlgorithm[0] : $this->cryptAlgorithm;

$supportedKeyLengths=mcrypt_module_get_supported_key_sizes($cryptAlgorithm);

if($supportedKeyLengths)
{
if(!in_array($this->strlen($key),$supportedKeyLengths)) {
throw new CException(Yii::t('yii','Encryption key length can be {keyLengths}',array('{keyLengths}'=>implode(',',$supportedKeyLengths).'.')));
throw new CException(Yii::t('yii','Encryption key length can be {keyLengths}.',array('{keyLengths}'=>implode(',',$supportedKeyLengths))));
}
}
elseif(isset(self::$encryptionKeyMinimumLengths[$this->cryptAlgorithm]))
elseif(isset(self::$encryptionKeyMinimumLengths[$cryptAlgorithm]))
{
$minLength=self::$encryptionKeyMinimumLengths[$this->cryptAlgorithm];
$maxLength=mcrypt_module_get_algo_key_size($this->cryptAlgorithm);
$minLength=self::$encryptionKeyMinimumLengths[$cryptAlgorithm];
$maxLength=mcrypt_module_get_algo_key_size($cryptAlgorithm);
if($this->strlen($key)<$minLength || $this->strlen($key)>$maxLength)
throw new CException(Yii::t('yii','Encryption key length must be between {minLength} and {maxLength}.',array('{minLength}'=>$minLength,'{maxLength}'=>$maxLength)));
}
Expand Down Expand Up @@ -566,6 +570,7 @@ public function legacyDecrypt($data,$key=null,$cipher='des')
$key=Yii::app()->getGlobalState(self::STATE_ENCRYPTION_KEY);
if(!$key)
throw new CException(Yii::t('yii','No encryption key specified.'));
$key = md5($key);
}

if(extension_loaded('mcrypt'))
Expand All @@ -581,7 +586,7 @@ public function legacyDecrypt($data,$key=null,$cipher='des')
else
throw new CException(Yii::t('yii','CSecurityManager requires PHP mcrypt extension to be loaded in order to use data encryption feature.'));

$derivedKey=$this->substr(md5($key),0,mcrypt_enc_get_key_size($module));
$derivedKey=$this->substr($key,0,mcrypt_enc_get_key_size($module));
$ivSize=mcrypt_enc_get_iv_size($module);
$iv=$this->substr($data,0,$ivSize);
mcrypt_generic_init($module,$derivedKey,$iv);
Expand Down
41 changes: 33 additions & 8 deletions framework/base/CStatePersister.php
Expand Up @@ -33,7 +33,6 @@
*
* CStatePersister is a core application component used to store global application state.
* It may be accessed via {@link CApplication::getStatePersister()}.
* page state persistent method based on cache.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.base
Expand Down Expand Up @@ -82,20 +81,46 @@ public function load()
$cacheKey='Yii.CStatePersister.'.$stateFile;
if(($value=$cache->get($cacheKey))!==false)
return unserialize($value);
elseif(($content=@file_get_contents($stateFile))!==false)
else
{
$cache->set($cacheKey,$content,0,new CFileCacheDependency($stateFile));
return unserialize($content);
if(($content=$this->getContent($stateFile))!==false)
{
$unserialized_content=unserialize($content);
// If it can't be unserialized, don't cache it:
if ($unserialized_content!==false || $content=="")
$cache->set($cacheKey,$content,0,new CFileCacheDependency($stateFile));
return $unserialized_content;
}
else
return null;
}
else
return null;
}
elseif(($content=@file_get_contents($stateFile))!==false)
elseif(($content=$this->getContent($stateFile))!==false)
return unserialize($content);
else
return null;
}


/**
* Loads content from file using a shared lock to avoid data corruption when reading
* the file while it is being written by save()
*
* @return string file contents
* @since 1.1.17
*/
protected function getContent($filename)
{
$file=@fopen($filename,"r");
if($file && flock($file,LOCK_SH))
{
$contents=@file_get_contents($filename);
flock($file,LOCK_UN);
fclose($file);
return $contents;
}
return false;
}

/**
* Saves application state in persistent storage.
* @param mixed $state state data (must be serializable).
Expand Down
31 changes: 20 additions & 11 deletions framework/caching/CApcCache.php
Expand Up @@ -22,6 +22,16 @@
*/
class CApcCache extends CCache
{
/**
* @var boolean whether to use apcu or apc as the underlying caching extension.
* If true {@link http://pecl.php.net/package/apcu apcu} will be used.
* If false {@link http://pecl.php.net/package/apc apc}. will be used.
* Defaults to false.
* @since 1.1.17
*/
public $useApcu=false;


/**
* Initializes this application component.
* This method is required by the {@link IApplicationComponent} interface.
Expand All @@ -31,8 +41,10 @@ class CApcCache extends CCache
public function init()
{
parent::init();
if(!extension_loaded('apc'))
throw new CException(Yii::t('yii','CApcCache requires PHP apc extension to be loaded.'));
$extension=$this->useApcu ? 'apcu' : 'apc';
if(!extension_loaded($extension))
throw new CException(Yii::t('yii',"CApcCache requires PHP {extension} extension to be loaded.",
array('{extension}'=>$extension)));
}

/**
Expand All @@ -43,7 +55,7 @@ public function init()
*/
protected function getValue($key)
{
return apc_fetch($key);
return $this->useApcu ? apcu_fetch($key) : apc_fetch($key);
}

/**
Expand All @@ -53,7 +65,7 @@ protected function getValue($key)
*/
protected function getValues($keys)
{
return apc_fetch($keys);
return $this->useApcu ? apcu_fetch($keys) : apc_fetch($keys);
}

/**
Expand All @@ -67,7 +79,7 @@ protected function getValues($keys)
*/
protected function setValue($key,$value,$expire)
{
return apc_store($key,$value,$expire);
return $this->useApcu ? apcu_store($key,$value,$expire) : apc_store($key,$value,$expire);
}

/**
Expand All @@ -81,7 +93,7 @@ protected function setValue($key,$value,$expire)
*/
protected function addValue($key,$value,$expire)
{
return apc_add($key,$value,$expire);
return $this->useApcu ? apcu_add($key,$value,$expire) : apc_add($key,$value,$expire);
}

/**
Expand All @@ -92,7 +104,7 @@ protected function addValue($key,$value,$expire)
*/
protected function deleteValue($key)
{
return apc_delete($key);
return $this->useApcu ? apcu_delete($key) : apc_delete($key);
}

/**
Expand All @@ -103,9 +115,6 @@ protected function deleteValue($key)
*/
protected function flushValues()
{
if(extension_loaded('apcu'))
return apc_clear_cache();

return apc_clear_cache('user');
return $this->useApcu ? apcu_clear_cache() : apc_clear_cache('user');
}
}
2 changes: 1 addition & 1 deletion framework/caching/CMemCache.php
Expand Up @@ -114,7 +114,7 @@ public function getMemCache()
$extension=$this->useMemcached ? 'memcached' : 'memcache';
if(!extension_loaded($extension))
throw new CException(Yii::t('yii',"CMemCache requires PHP {extension} extension to be loaded.",
array('{extension}'=>$extension)));
array('{extension}'=>$extension)));
return $this->_cache=$this->useMemcached ? new Memcached : new Memcache;
}
}
Expand Down
24 changes: 21 additions & 3 deletions framework/caching/CRedisCache.php
Expand Up @@ -30,6 +30,7 @@
* 'hostname'=>'localhost',
* 'port'=>6379,
* 'database'=>0,
* 'options'=>STREAM_CLIENT_CONNECT,
* ),
* ),
* )
Expand Down Expand Up @@ -59,6 +60,11 @@ class CRedisCache extends CCache
* @var int the redis database to use. This is an integer value starting from 0. Defaults to 0.
*/
public $database=0;
/**
* @var int the options to pass to the flags parameter of stream_socket_client when connecting to the redis server. Defaults to STREAM_CLIENT_CONNECT.
* @see http://php.net/manual/en/function.stream-socket-client.php
*/
public $options=STREAM_CLIENT_CONNECT;
/**
* @var float timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
*/
Expand All @@ -79,7 +85,8 @@ protected function connect()
$this->hostname.':'.$this->port,
$errorNumber,
$errorDescription,
$this->timeout ? $this->timeout : ini_get("default_socket_timeout")
$this->timeout ? $this->timeout : ini_get("default_socket_timeout"),
$this->options
);
if ($this->_socket)
{
Expand Down Expand Up @@ -118,7 +125,7 @@ public function executeCommand($name,$params=array())
array_unshift($params,$name);
$command='*'.count($params)."\r\n";
foreach($params as $arg)
$command.='$'.strlen($arg)."\r\n".$arg."\r\n";
$command.='$'.$this->byteLength($arg)."\r\n".$arg."\r\n";

fwrite($this->_socket,$command);

Expand Down Expand Up @@ -155,7 +162,7 @@ private function parseResponse()
if(($block=fread($this->_socket,$length))===false)
throw new CException('Failed reading data from redis connection socket.');
$data.=$block;
$length-=(function_exists('mb_strlen') ? mb_strlen($block,'8bit') : strlen($block));
$length-=$this->byteLength($block);
}
return substr($data,0,-2);
case '*': // Multi-bulk replies
Expand All @@ -169,6 +176,17 @@ private function parseResponse()
}
}

/**
* Counting amount of bytes in a string.
*
* @param string $str
* @return int
*/
private function byteLength($str)
{
return function_exists('mb_strlen') ? mb_strlen($str, '8bit') : strlen($str);
}

/**
* Retrieves a value from cache with a specified key.
* This is the implementation of the method declared in the parent class.
Expand Down

0 comments on commit 2fdb409

Please sign in to comment.