Merge branch 'MDL-52207-master' of git://github.com/cameron1729/moodle
This commit is contained in:
+2
-2
@@ -68,7 +68,7 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
* Return user data for the provided token, compare with user_agent string.
|
||||
*
|
||||
* @param string $token The unique ID provided by remotehost.
|
||||
* @param string $UA User Agent string.
|
||||
* @param string $useragent User Agent string.
|
||||
* @return array $userdata Array of user info for remote host
|
||||
*/
|
||||
function user_authorise($token, $useragent) {
|
||||
@@ -1031,7 +1031,7 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
*
|
||||
* @see process_new_icon()
|
||||
* @uses mnet_remote_client callable via MNet XML-RPC
|
||||
* @param int $userid The id of the user
|
||||
* @param int $username The id of the user
|
||||
* @return false|array false if user not found, empty array if no picture exists, array with data otherwise
|
||||
*/
|
||||
function fetch_user_image($username) {
|
||||
|
||||
@@ -217,8 +217,6 @@ require_once($CFG->dirroot.'/cache/lib.php');
|
||||
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
|
||||
//the problem is that we need specific version of quickforms and hacked excel files :-(
|
||||
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
|
||||
//point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
|
||||
ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
|
||||
|
||||
// Register our classloader, in theory somebody might want to replace it to load other hacked core classes.
|
||||
// Required because the database checks below lead to session interaction which is going to lead us to requiring autoloaded classes.
|
||||
|
||||
@@ -572,9 +572,6 @@ if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
|
||||
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
|
||||
//the problem is that we need specific version of quickforms and hacked excel files :-(
|
||||
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
|
||||
//point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
|
||||
//please note zend library is supposed to be used only from web service protocol classes, it may be removed in future
|
||||
ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
|
||||
|
||||
// Register our classloader, in theory somebody might want to replace it to load other hacked core classes.
|
||||
if (defined('COMPONENT_CLASSLOADER')) {
|
||||
|
||||
@@ -196,13 +196,6 @@
|
||||
<version>1.11.4</version>
|
||||
<licenseversion></licenseversion>
|
||||
</library>
|
||||
<library>
|
||||
<location>zend</location>
|
||||
<name>Zend Framework</name>
|
||||
<license>BSD</license>
|
||||
<version>1.12.16</version>
|
||||
<licenseversion></licenseversion>
|
||||
</library>
|
||||
<library>
|
||||
<location>html2text.php</location>
|
||||
<name>HTML2Text</name>
|
||||
|
||||
@@ -84,6 +84,7 @@ information provided here is intended especially for developers.
|
||||
* \repository::antivir_scan_file() has been deprecated, \core\antivirus\manager::scan_file() that
|
||||
applies antivirus plugins is replacing its functionality.
|
||||
* Added core_text::str_max_bytes() which safely truncates multi-byte strings to a maximum number of bytes.
|
||||
* Zend Framework has been removed completely.
|
||||
|
||||
=== 3.0 ===
|
||||
|
||||
|
||||
+70
-35
@@ -1831,7 +1831,6 @@ function upgrade_plugin_mnet_functions($component) {
|
||||
}
|
||||
|
||||
// reflect all the services we're publishing and save them
|
||||
require_once($CFG->dirroot . '/lib/zend/Zend/Server/Reflection.php');
|
||||
static $cachedclasses = array(); // to store reflection information in
|
||||
foreach ($publishes as $service => $data) {
|
||||
$f = $data['filename'];
|
||||
@@ -1864,8 +1863,8 @@ function upgrade_plugin_mnet_functions($component) {
|
||||
$key = $dataobject->filename . '|' . $dataobject->classname;
|
||||
if (!array_key_exists($key, $cachedclasses)) { // look to see if we've already got a reflection object
|
||||
try {
|
||||
$cachedclasses[$key] = Zend_Server_Reflection::reflectClass($dataobject->classname);
|
||||
} catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful
|
||||
$cachedclasses[$key] = new ReflectionClass($dataobject->classname);
|
||||
} catch (ReflectionException $e) { // catch these and rethrow them to something more helpful
|
||||
throw new moodle_exception('installreflectionclasserror', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname, 'error' => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
@@ -1873,27 +1872,20 @@ function upgrade_plugin_mnet_functions($component) {
|
||||
if (!$r->hasMethod($dataobject->functionname)) {
|
||||
throw new moodle_exception('installnosuchmethod', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname));
|
||||
}
|
||||
// stupid workaround for zend not having a getMethod($name) function
|
||||
$ms = $r->getMethods();
|
||||
foreach ($ms as $m) {
|
||||
if ($m->getName() == $dataobject->functionname) {
|
||||
$functionreflect = $m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$functionreflect = $r->getMethod($dataobject->functionname);
|
||||
$dataobject->static = (int)$functionreflect->isStatic();
|
||||
} else {
|
||||
if (!function_exists($dataobject->functionname)) {
|
||||
throw new moodle_exception('installnosuchfunction', 'mnet', '', (object)array('method' => $dataobject->functionname, 'file' => $dataobject->filename));
|
||||
}
|
||||
try {
|
||||
$functionreflect = Zend_Server_Reflection::reflectFunction($dataobject->functionname);
|
||||
} catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful
|
||||
$functionreflect = new ReflectionFunction($dataobject->functionname);
|
||||
} catch (ReflectionException $e) { // catch these and rethrow them to something more helpful
|
||||
throw new moodle_exception('installreflectionfunctionerror', 'mnet', '', (object)array('method' => $dataobject->functionname, '' => $dataobject->filename, 'error' => $e->getMessage()));
|
||||
}
|
||||
}
|
||||
$dataobject->profile = serialize(admin_mnet_method_profile($functionreflect));
|
||||
$dataobject->help = $functionreflect->getDescription();
|
||||
$dataobject->help = admin_mnet_method_get_help($functionreflect);
|
||||
|
||||
if ($record_exists = $DB->get_record('mnet_rpc', array('xmlrpcpath'=>$dataobject->xmlrpcpath))) {
|
||||
$dataobject->id = $record_exists->id;
|
||||
@@ -1971,31 +1963,74 @@ function upgrade_plugin_mnet_functions($component) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some sort of Zend Reflection function/method object, return a profile array, ready to be serialized and stored
|
||||
* Given some sort of reflection function/method object, return a profile array, ready to be serialized and stored
|
||||
*
|
||||
* @param Zend_Server_Reflection_Function_Abstract $function can be any subclass of this object type
|
||||
* @param ReflectionFunctionAbstract $function reflection function/method object from which to extract information
|
||||
*
|
||||
* @return array
|
||||
* @return array associative array with function/method information
|
||||
*/
|
||||
function admin_mnet_method_profile(Zend_Server_Reflection_Function_Abstract $function) {
|
||||
$protos = $function->getPrototypes();
|
||||
$proto = array_pop($protos);
|
||||
$ret = $proto->getReturnValue();
|
||||
$profile = array(
|
||||
'parameters' => array(),
|
||||
'return' => array(
|
||||
'type' => $ret->getType(),
|
||||
'description' => $ret->getDescription(),
|
||||
),
|
||||
function admin_mnet_method_profile(ReflectionFunctionAbstract $function) {
|
||||
$commentlines = admin_mnet_method_get_docblock($function);
|
||||
$getkey = function($key) use ($commentlines) {
|
||||
return array_values(array_filter($commentlines, function($line) use ($key) {
|
||||
return $line[0] == $key;
|
||||
}));
|
||||
};
|
||||
$returnline = $getkey('@return');
|
||||
return array (
|
||||
'parameters' => array_map(function($line) {
|
||||
return array(
|
||||
'name' => trim($line[2], " \t\n\r\0\x0B$"),
|
||||
'type' => $line[1],
|
||||
'description' => $line[3]
|
||||
);
|
||||
}, $getkey('@param')),
|
||||
|
||||
'return' => array(
|
||||
'type' => !empty($returnline[0][1]) ? $returnline[0][1] : 'void',
|
||||
'description' => !empty($returnline[0][2]) ? $returnline[0][2] : ''
|
||||
)
|
||||
);
|
||||
foreach ($proto->getParameters() as $p) {
|
||||
$profile['parameters'][] = array(
|
||||
'name' => $p->getName(),
|
||||
'type' => $p->getType(),
|
||||
'description' => $p->getDescription(),
|
||||
);
|
||||
}
|
||||
return $profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some sort of reflection function/method object, return an array of docblock lines, where each line is an array of
|
||||
* keywords/descriptions
|
||||
*
|
||||
* @param ReflectionFunctionAbstract $function reflection function/method object from which to extract information
|
||||
*
|
||||
* @return array docblock converted in to an array
|
||||
*/
|
||||
function admin_mnet_method_get_docblock(ReflectionFunctionAbstract $function) {
|
||||
return array_map(function($line) {
|
||||
$text = trim($line, " \t\n\r\0\x0B*/");
|
||||
if (strpos($text, '@param') === 0) {
|
||||
return preg_split('/\s+/', $text, 4);
|
||||
}
|
||||
|
||||
if (strpos($text, '@return') === 0) {
|
||||
return preg_split('/\s+/', $text, 3);
|
||||
}
|
||||
|
||||
return array($text);
|
||||
}, explode("\n", $function->getDocComment()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some sort of reflection function/method object, return just the help text
|
||||
*
|
||||
* @param ReflectionFunctionAbstract $function reflection function/method object from which to extract information
|
||||
*
|
||||
* @return string docblock help text
|
||||
*/
|
||||
function admin_mnet_method_get_help(ReflectionFunctionAbstract $function) {
|
||||
$helplines = array_map(function($line) {
|
||||
return implode(' ', $line);
|
||||
}, array_values(array_filter(admin_mnet_method_get_docblock($function), function($line) {
|
||||
return strpos($line[0], '@') !== 0 && !empty($line[0]);
|
||||
})));
|
||||
|
||||
return implode("\n", $helplines);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl
|
||||
*/
|
||||
require_once 'Zend/Acl.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Resource_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Resource/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Assert_Interface
|
||||
{
|
||||
/**
|
||||
* Returns true if and only if the assertion conditions are met
|
||||
*
|
||||
* This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
|
||||
* $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
|
||||
* privileges, respectively.
|
||||
*
|
||||
* @param Zend_Acl $acl
|
||||
* @param Zend_Acl_Role_Interface $role
|
||||
* @param Zend_Acl_Resource_Interface $resource
|
||||
* @param string $privilege
|
||||
* @return boolean
|
||||
*/
|
||||
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null,
|
||||
$privilege = null);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Exception extends Zend_Exception
|
||||
{}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Resource_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Resource/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Resource implements Zend_Acl_Resource_Interface
|
||||
{
|
||||
/**
|
||||
* Unique id of Resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_resourceId;
|
||||
|
||||
/**
|
||||
* Sets the Resource identifier
|
||||
*
|
||||
* @param string $resourceId
|
||||
*/
|
||||
public function __construct($resourceId)
|
||||
{
|
||||
$this->_resourceId = (string) $resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceId()
|
||||
{
|
||||
return $this->_resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
|
||||
* Proxies to getResourceId()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getResourceId();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Resource_Interface
|
||||
{
|
||||
/**
|
||||
* Returns the string identifier of the Resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceId();
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role implements Zend_Acl_Role_Interface
|
||||
{
|
||||
/**
|
||||
* Unique id of Role
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_roleId;
|
||||
|
||||
/**
|
||||
* Sets the Role identifier
|
||||
*
|
||||
* @param string $roleId
|
||||
*/
|
||||
public function __construct($roleId)
|
||||
{
|
||||
$this->_roleId = (string) $roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleId()
|
||||
{
|
||||
return $this->_roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
|
||||
* Proxies to getRoleId()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getRoleId();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Role_Interface
|
||||
{
|
||||
/**
|
||||
* Returns the string identifier of the Role
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleId();
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role_Registry
|
||||
{
|
||||
/**
|
||||
* Internal Role registry data storage
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_roles = array();
|
||||
|
||||
/**
|
||||
* Adds a Role having an identifier unique to the registry
|
||||
*
|
||||
* The $parents parameter may be a reference to, or the string identifier for,
|
||||
* a Role existing in the registry, or $parents may be passed as an array of
|
||||
* these - mixing string identifiers and objects is ok - to indicate the Roles
|
||||
* from which the newly added Role will directly inherit.
|
||||
*
|
||||
* In order to resolve potential ambiguities with conflicting rules inherited
|
||||
* from different parents, the most recently added parent takes precedence over
|
||||
* parents that were previously added. In other words, the first parent added
|
||||
* will have the least priority, and the last parent added will have the
|
||||
* highest priority.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface $role
|
||||
* @param Zend_Acl_Role_Interface|string|array $parents
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function add(Zend_Acl_Role_Interface $role, $parents = null)
|
||||
{
|
||||
$roleId = $role->getRoleId();
|
||||
|
||||
if ($this->has($roleId)) {
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
throw new Zend_Acl_Role_Registry_Exception("Role id '$roleId' already exists in the registry");
|
||||
}
|
||||
|
||||
$roleParents = array();
|
||||
|
||||
if (null !== $parents) {
|
||||
if (!is_array($parents)) {
|
||||
$parents = array($parents);
|
||||
}
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
foreach ($parents as $parent) {
|
||||
try {
|
||||
if ($parent instanceof Zend_Acl_Role_Interface) {
|
||||
$roleParentId = $parent->getRoleId();
|
||||
} else {
|
||||
$roleParentId = $parent;
|
||||
}
|
||||
$roleParent = $this->get($roleParentId);
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
|
||||
}
|
||||
$roleParents[$roleParentId] = $roleParent;
|
||||
$this->_roles[$roleParentId]['children'][$roleId] = $role;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_roles[$roleId] = array(
|
||||
'instance' => $role,
|
||||
'parents' => $roleParents,
|
||||
'children' => array()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identified Role
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Interface
|
||||
*/
|
||||
public function get($role)
|
||||
{
|
||||
if ($role instanceof Zend_Acl_Role_Interface) {
|
||||
$roleId = $role->getRoleId();
|
||||
} else {
|
||||
$roleId = (string) $role;
|
||||
}
|
||||
|
||||
if (!$this->has($role)) {
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
throw new Zend_Acl_Role_Registry_Exception("Role '$roleId' not found");
|
||||
}
|
||||
|
||||
return $this->_roles[$roleId]['instance'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if the Role exists in the registry
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($role)
|
||||
{
|
||||
if ($role instanceof Zend_Acl_Role_Interface) {
|
||||
$roleId = $role->getRoleId();
|
||||
} else {
|
||||
$roleId = (string) $role;
|
||||
}
|
||||
|
||||
return isset($this->_roles[$roleId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of an existing Role's parents
|
||||
*
|
||||
* The array keys are the identifiers of the parent Roles, and the values are
|
||||
* the parent Role instances. The parent Roles are ordered in this array by
|
||||
* ascending priority. The highest priority parent Role, last in the array,
|
||||
* corresponds with the parent Role most recently added.
|
||||
*
|
||||
* If the Role does not have any parents, then an empty array is returned.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @uses Zend_Acl_Role_Registry::get()
|
||||
* @return array
|
||||
*/
|
||||
public function getParents($role)
|
||||
{
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
|
||||
return $this->_roles[$roleId]['parents'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if $role inherits from $inherit
|
||||
*
|
||||
* Both parameters may be either a Role or a Role identifier. If
|
||||
* $onlyParents is true, then $role must inherit directly from
|
||||
* $inherit in order to return true. By default, this method looks
|
||||
* through the entire inheritance DAG to determine whether $role
|
||||
* inherits from $inherit through its ancestor Roles.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @param Zend_Acl_Role_Interface|string $inherit
|
||||
* @param boolean $onlyParents
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return boolean
|
||||
*/
|
||||
public function inherits($role, $inherit, $onlyParents = false)
|
||||
{
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
try {
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
$inheritId = $this->get($inherit)->getRoleId();
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$inherits = isset($this->_roles[$roleId]['parents'][$inheritId]);
|
||||
|
||||
if ($inherits || $onlyParents) {
|
||||
return $inherits;
|
||||
}
|
||||
|
||||
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
|
||||
if ($this->inherits($parentId, $inheritId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the Role from the registry
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function remove($role)
|
||||
{
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
try {
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
|
||||
unset($this->_roles[$childId]['parents'][$roleId]);
|
||||
}
|
||||
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
|
||||
unset($this->_roles[$parentId]['children'][$roleId]);
|
||||
}
|
||||
|
||||
unset($this->_roles[$roleId]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all Roles from the registry
|
||||
*
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function removeAll()
|
||||
{
|
||||
$this->_roles = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->_roles;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role_Registry_Exception extends Zend_Acl_Exception
|
||||
{}
|
||||
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Auth_Abstract */
|
||||
require_once 'Zend/Amf/Auth/Abstract.php';
|
||||
|
||||
/** @see Zend_Acl */
|
||||
require_once 'Zend/Acl.php';
|
||||
|
||||
/** @see Zend_Auth_Result */
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
/** @see Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/**
|
||||
* This class implements authentication against XML file with roles for Flex Builder.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* ACL for authorization
|
||||
*
|
||||
* @var Zend_Acl
|
||||
*/
|
||||
protected $_acl;
|
||||
|
||||
/**
|
||||
* Username/password array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_users = array();
|
||||
|
||||
/**
|
||||
* Create auth adapter
|
||||
*
|
||||
* @param string $rolefile File containing XML with users and roles
|
||||
*/
|
||||
public function __construct($rolefile)
|
||||
{
|
||||
$this->_acl = new Zend_Acl();
|
||||
$xml = Zend_Xml_Security::scanFile($rolefile);
|
||||
/*
|
||||
Roles file format:
|
||||
<roles>
|
||||
<role id=”admin”>
|
||||
<user name=”user1” password=”pwd”/>
|
||||
</role>
|
||||
<role id=”hr”>
|
||||
<user name=”user2” password=”pwd2”/>
|
||||
</role>
|
||||
</roles>
|
||||
*/
|
||||
foreach($xml->role as $role) {
|
||||
$this->_acl->addRole(new Zend_Acl_Role((string)$role["id"]));
|
||||
foreach($role->user as $user) {
|
||||
$this->_users[(string)$user["name"]] = array("password" => (string)$user["password"],
|
||||
"role" => (string)$role["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ACL with roles from XML file
|
||||
*
|
||||
* @return Zend_Acl
|
||||
*/
|
||||
public function getAcl()
|
||||
{
|
||||
return $this->_acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform authentication
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
* @see Zend_Auth_Adapter_Interface#authenticate()
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
if (empty($this->_username) ||
|
||||
empty($this->_password)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Username/password should be set');
|
||||
}
|
||||
|
||||
if(!isset($this->_users[$this->_username])) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
|
||||
null,
|
||||
array('Username not found')
|
||||
);
|
||||
}
|
||||
|
||||
$user = $this->_users[$this->_username];
|
||||
if($user["password"] != $this->_password) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
null,
|
||||
array('Authentication failed')
|
||||
);
|
||||
}
|
||||
|
||||
$id = new stdClass();
|
||||
$id->role = $user["role"];
|
||||
$id->name = $this->_username;
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id);
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements authentication against XML file with roles for Flex Builder.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_DbInspector
|
||||
{
|
||||
|
||||
/**
|
||||
* Connect to the database
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return Zend_Db_Adapter_Abstract
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
protected function _connect($dbType, $dbDescription)
|
||||
{
|
||||
if(is_object($dbDescription)) {
|
||||
$dbDescription = get_object_vars($dbDescription);
|
||||
}
|
||||
return Zend_Db::factory($dbType, $dbDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe database object.
|
||||
*
|
||||
* Usage example:
|
||||
* $inspector->describeTable('Pdo_Mysql',
|
||||
* array(
|
||||
* 'host' => '127.0.0.1',
|
||||
* 'username' => 'webuser',
|
||||
* 'password' => 'xxxxxxxx',
|
||||
* 'dbname' => 'test'
|
||||
* ),
|
||||
* 'mytable'
|
||||
* );
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @param string $tableName Table name
|
||||
* @return array Table description
|
||||
* @see Zend_Db::describeTable()
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
public function describeTable($dbType, $dbDescription, $tableName)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
return $db->describeTable($tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test database connection
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return bool
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
public function connect($dbType, $dbDescription)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
$db->listTables();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of database tables
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return array List of the tables
|
||||
*/
|
||||
public function getTables($dbType, $dbDescription)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
return $db->listTables();
|
||||
}
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/** @see Zend_Reflection_Class */
|
||||
require_once 'Zend/Reflection/Class.php';
|
||||
|
||||
/** @see Zend_Server_Reflection */
|
||||
require_once 'Zend/Server/Reflection.php';
|
||||
|
||||
/**
|
||||
* This class implements a service for generating AMF service descriptions as XML.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_Introspector
|
||||
{
|
||||
/**
|
||||
* Options used:
|
||||
* - server: instance of Zend_Amf_Server to use
|
||||
* - directories: directories where class files may be looked up
|
||||
*
|
||||
* @var array Introspector options
|
||||
*/
|
||||
protected $_options;
|
||||
|
||||
/**
|
||||
* @var DOMElement DOM element to store types
|
||||
*/
|
||||
protected $_types;
|
||||
|
||||
/**
|
||||
* @var array Map of the known types
|
||||
*/
|
||||
protected $_typesMap = array();
|
||||
|
||||
/**
|
||||
* @var DOMDocument XML document to store data
|
||||
*/
|
||||
protected $_xml;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_xml = new DOMDocument('1.0', 'utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create XML definition on an AMF service class
|
||||
*
|
||||
* @param string $serviceClass Service class name
|
||||
* @param array $options invocation options
|
||||
* @return string XML with service class introspection
|
||||
*/
|
||||
public function introspect($serviceClass, $options = array())
|
||||
{
|
||||
$this->_options = $options;
|
||||
|
||||
if (strpbrk($serviceClass, '\\/<>')) {
|
||||
return $this->_returnError('Invalid service name');
|
||||
}
|
||||
|
||||
// Transform com.foo.Bar into com_foo_Bar
|
||||
$serviceClass = str_replace('.' , '_', $serviceClass);
|
||||
|
||||
// Introspect!
|
||||
if (!class_exists($serviceClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($serviceClass, $this->_getServicePath());
|
||||
}
|
||||
|
||||
$serv = $this->_xml->createElement('service-description');
|
||||
$serv->setAttribute('xmlns', 'http://ns.adobe.com/flex/service-description/2008');
|
||||
|
||||
$this->_types = $this->_xml->createElement('types');
|
||||
$this->_ops = $this->_xml->createElement('operations');
|
||||
|
||||
$r = Zend_Server_Reflection::reflectClass($serviceClass);
|
||||
$this->_addService($r, $this->_ops);
|
||||
|
||||
$serv->appendChild($this->_types);
|
||||
$serv->appendChild($this->_ops);
|
||||
$this->_xml->appendChild($serv);
|
||||
|
||||
return $this->_xml->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication handler
|
||||
*
|
||||
* @param Zend_Acl $acl
|
||||
* @return unknown_type
|
||||
*/
|
||||
public function initAcl(Zend_Acl $acl)
|
||||
{
|
||||
return false; // we do not need auth for this class
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate map of public class attributes
|
||||
*
|
||||
* @param string $typename type name
|
||||
* @param DOMElement $typexml target XML element
|
||||
* @return void
|
||||
*/
|
||||
protected function _addClassAttributes($typename, DOMElement $typexml)
|
||||
{
|
||||
// Do not try to autoload here because _phpTypeToAS should
|
||||
// have already attempted to load this class
|
||||
if (!class_exists($typename, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rc = new Zend_Reflection_Class($typename);
|
||||
foreach ($rc->getProperties() as $prop) {
|
||||
if (!$prop->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$propxml = $this->_xml->createElement('property');
|
||||
$propxml->setAttribute('name', $prop->getName());
|
||||
|
||||
$type = $this->_registerType($this->_getPropertyType($prop));
|
||||
$propxml->setAttribute('type', $type);
|
||||
|
||||
$typexml->appendChild($propxml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build XML service description from reflection class
|
||||
*
|
||||
* @param Zend_Server_Reflection_Class $refclass
|
||||
* @param DOMElement $target target XML element
|
||||
* @return void
|
||||
*/
|
||||
protected function _addService(Zend_Server_Reflection_Class $refclass, DOMElement $target)
|
||||
{
|
||||
foreach ($refclass->getMethods() as $method) {
|
||||
if (!$method->isPublic()
|
||||
|| $method->isConstructor()
|
||||
|| ('__' == substr($method->name, 0, 2))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($method->getPrototypes() as $proto) {
|
||||
$op = $this->_xml->createElement('operation');
|
||||
$op->setAttribute('name', $method->getName());
|
||||
|
||||
$rettype = $this->_registerType($proto->getReturnType());
|
||||
$op->setAttribute('returnType', $rettype);
|
||||
|
||||
foreach ($proto->getParameters() as $param) {
|
||||
$arg = $this->_xml->createElement('argument');
|
||||
$arg->setAttribute('name', $param->getName());
|
||||
|
||||
$type = $param->getType();
|
||||
if ($type == 'mixed' && ($pclass = $param->getClass())) {
|
||||
$type = $pclass->getName();
|
||||
}
|
||||
|
||||
$ptype = $this->_registerType($type);
|
||||
$arg->setAttribute('type', $ptype);
|
||||
|
||||
if($param->isDefaultValueAvailable()) {
|
||||
$arg->setAttribute('defaultvalue', $param->getDefaultValue());
|
||||
}
|
||||
|
||||
$op->appendChild($arg);
|
||||
}
|
||||
|
||||
$target->appendChild($op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract type of the property from DocBlock
|
||||
*
|
||||
* @param Zend_Reflection_Property $prop reflection property object
|
||||
* @return string Property type
|
||||
*/
|
||||
protected function _getPropertyType(Zend_Reflection_Property $prop)
|
||||
{
|
||||
$docBlock = $prop->getDocComment();
|
||||
|
||||
if (!$docBlock) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
if (!$docBlock->hasTag('var')) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
$tag = $docBlock->getTag('var');
|
||||
return trim($tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of service directories
|
||||
*
|
||||
* @return array Service class directories
|
||||
*/
|
||||
protected function _getServicePath()
|
||||
{
|
||||
if (isset($this->_options['server'])) {
|
||||
return $this->_options['server']->getDirectory();
|
||||
}
|
||||
|
||||
if (isset($this->_options['directories'])) {
|
||||
return $this->_options['directories'];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map from PHP type name to AS type name
|
||||
*
|
||||
* @param string $typename PHP type name
|
||||
* @return string AS type name
|
||||
*/
|
||||
protected function _phpTypeToAS($typename)
|
||||
{
|
||||
if (class_exists($typename)) {
|
||||
$vars = get_class_vars($typename);
|
||||
|
||||
if (isset($vars['_explicitType'])) {
|
||||
return $vars['_explicitType'];
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== ($asname = Zend_Amf_Parse_TypeLoader::getMappedClassName($typename))) {
|
||||
return $asname;
|
||||
}
|
||||
|
||||
return $typename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new type on the system
|
||||
*
|
||||
* @param string $typename type name
|
||||
* @return string New type name
|
||||
*/
|
||||
protected function _registerType($typename)
|
||||
{
|
||||
// Known type - return its AS name
|
||||
if (isset($this->_typesMap[$typename])) {
|
||||
return $this->_typesMap[$typename];
|
||||
}
|
||||
|
||||
// Standard types
|
||||
if (in_array($typename, array('void', 'null', 'mixed', 'unknown_type'))) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
// Arrays
|
||||
if ('array' == $typename) {
|
||||
return 'Unknown[]';
|
||||
}
|
||||
|
||||
if (in_array($typename, array('int', 'integer', 'bool', 'boolean', 'float', 'string', 'object', 'Unknown', 'stdClass'))) {
|
||||
return $typename;
|
||||
}
|
||||
|
||||
// Resolve and store AS name
|
||||
$asTypeName = $this->_phpTypeToAS($typename);
|
||||
$this->_typesMap[$typename] = $asTypeName;
|
||||
|
||||
// Create element for the name
|
||||
$typeEl = $this->_xml->createElement('type');
|
||||
$typeEl->setAttribute('name', $asTypeName);
|
||||
$this->_addClassAttributes($typename, $typeEl);
|
||||
$this->_types->appendChild($typeEl);
|
||||
|
||||
return $asTypeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return error with error message
|
||||
*
|
||||
* @param string $msg Error message
|
||||
* @return string
|
||||
*/
|
||||
protected function _returnError($msg)
|
||||
{
|
||||
return 'ERROR: $msg';
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Auth_Adapter_Interface */
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
/**
|
||||
* Base abstract class for AMF authentication implementation
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Auth_Abstract implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
protected $_username;
|
||||
protected $_password;
|
||||
|
||||
public function setCredentials($username, $password) {
|
||||
$this->_username = $username;
|
||||
$this->_password = $password;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* The following constants are used throughout serialization and
|
||||
* deserialization to detect the AMF marker and encoding types.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
final class Zend_Amf_Constants
|
||||
{
|
||||
const AMF0_NUMBER = 0x00;
|
||||
const AMF0_BOOLEAN = 0x01;
|
||||
const AMF0_STRING = 0x02;
|
||||
const AMF0_OBJECT = 0x03;
|
||||
const AMF0_MOVIECLIP = 0x04;
|
||||
const AMF0_NULL = 0x05;
|
||||
const AMF0_UNDEFINED = 0x06;
|
||||
const AMF0_REFERENCE = 0x07;
|
||||
const AMF0_MIXEDARRAY = 0x08;
|
||||
const AMF0_OBJECTTERM = 0x09;
|
||||
const AMF0_ARRAY = 0x0a;
|
||||
const AMF0_DATE = 0x0b;
|
||||
const AMF0_LONGSTRING = 0x0c;
|
||||
const AMF0_UNSUPPORTED = 0x0e;
|
||||
const AMF0_XML = 0x0f;
|
||||
const AMF0_TYPEDOBJECT = 0x10;
|
||||
const AMF0_AMF3 = 0x11;
|
||||
const AMF0_OBJECT_ENCODING = 0x00;
|
||||
|
||||
const AMF3_UNDEFINED = 0x00;
|
||||
const AMF3_NULL = 0x01;
|
||||
const AMF3_BOOLEAN_FALSE = 0x02;
|
||||
const AMF3_BOOLEAN_TRUE = 0x03;
|
||||
const AMF3_INTEGER = 0x04;
|
||||
const AMF3_NUMBER = 0x05;
|
||||
const AMF3_STRING = 0x06;
|
||||
const AMF3_XML = 0x07;
|
||||
const AMF3_DATE = 0x08;
|
||||
const AMF3_ARRAY = 0x09;
|
||||
const AMF3_OBJECT = 0x0A;
|
||||
const AMF3_XMLSTRING = 0x0B;
|
||||
const AMF3_BYTEARRAY = 0x0C;
|
||||
const AMF3_OBJECT_ENCODING = 0x03;
|
||||
|
||||
// Object encodings for AMF3 object types
|
||||
const ET_PROPLIST = 0x00;
|
||||
const ET_EXTERNAL = 0x01;
|
||||
const ET_DYNAMIC = 0x02;
|
||||
const ET_PROXY = 0x03;
|
||||
|
||||
const FMS_OBJECT_ENCODING = 0x01;
|
||||
|
||||
/**
|
||||
* Special content length value that indicates "unknown" content length
|
||||
* per AMF Specification
|
||||
*/
|
||||
const UNKNOWN_CONTENT_LENGTH = -1;
|
||||
const URL_APPEND_HEADER = 'AppendToGatewayUrl';
|
||||
const RESULT_METHOD = '/onResult';
|
||||
const STATUS_METHOD = '/onStatus';
|
||||
const CREDENTIALS_HEADER = 'Credentials';
|
||||
const PERSISTENT_HEADER = 'RequestPersistentHeader';
|
||||
const DESCRIBE_HEADER = 'DescribeService';
|
||||
|
||||
const GUEST_ROLE = 'anonymous';
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Deserializer.php';
|
||||
|
||||
/**
|
||||
* Read an AMF0 input stream and convert it into PHP data types
|
||||
*
|
||||
* @todo Implement Typed Object Class Mapping
|
||||
* @todo Class could be implemented as Factory Class with each data type it's own class
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf0_Deserializer extends Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* An array of objects used for recursively deserializing an object.
|
||||
* @var array
|
||||
*/
|
||||
protected $_reference = array();
|
||||
|
||||
/**
|
||||
* If AMF3 serialization occurs, update to AMF0 0x03
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_objectEncoding = Zend_Amf_Constants::AMF0_OBJECT_ENCODING;
|
||||
|
||||
/**
|
||||
* Read AMF markers and dispatch for deserialization
|
||||
*
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. Markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param integer $typeMarker
|
||||
* @return mixed whatever the data type is of the marker in php
|
||||
* @throws Zend_Amf_Exception for invalid type
|
||||
*/
|
||||
public function readTypeMarker($typeMarker = null)
|
||||
{
|
||||
if ($typeMarker === null) {
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
}
|
||||
|
||||
switch($typeMarker) {
|
||||
// number
|
||||
case Zend_Amf_Constants::AMF0_NUMBER:
|
||||
return $this->_stream->readDouble();
|
||||
|
||||
// boolean
|
||||
case Zend_Amf_Constants::AMF0_BOOLEAN:
|
||||
return (boolean) $this->_stream->readByte();
|
||||
|
||||
// string
|
||||
case Zend_Amf_Constants::AMF0_STRING:
|
||||
return $this->_stream->readUTF();
|
||||
|
||||
// object
|
||||
case Zend_Amf_Constants::AMF0_OBJECT:
|
||||
return $this->readObject();
|
||||
|
||||
// null
|
||||
case Zend_Amf_Constants::AMF0_NULL:
|
||||
return null;
|
||||
|
||||
// undefined
|
||||
case Zend_Amf_Constants::AMF0_UNDEFINED:
|
||||
return null;
|
||||
|
||||
// Circular references are returned here
|
||||
case Zend_Amf_Constants::AMF0_REFERENCE:
|
||||
return $this->readReference();
|
||||
|
||||
// mixed array with numeric and string keys
|
||||
case Zend_Amf_Constants::AMF0_MIXEDARRAY:
|
||||
return $this->readMixedArray();
|
||||
|
||||
// array
|
||||
case Zend_Amf_Constants::AMF0_ARRAY:
|
||||
return $this->readArray();
|
||||
|
||||
// date
|
||||
case Zend_Amf_Constants::AMF0_DATE:
|
||||
return $this->readDate();
|
||||
|
||||
// longString strlen(string) > 2^16
|
||||
case Zend_Amf_Constants::AMF0_LONGSTRING:
|
||||
return $this->_stream->readLongUTF();
|
||||
|
||||
//internal AS object, not supported
|
||||
case Zend_Amf_Constants::AMF0_UNSUPPORTED:
|
||||
return null;
|
||||
|
||||
// XML
|
||||
case Zend_Amf_Constants::AMF0_XML:
|
||||
return $this->readXmlString();
|
||||
|
||||
// typed object ie Custom Class
|
||||
case Zend_Amf_Constants::AMF0_TYPEDOBJECT:
|
||||
return $this->readTypedObject();
|
||||
|
||||
//AMF3-specific
|
||||
case Zend_Amf_Constants::AMF0_AMF3:
|
||||
return $this->readAmf3TypeMarker();
|
||||
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported marker type: ' . $typeMarker);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read AMF objects and convert to PHP objects
|
||||
*
|
||||
* Read the name value pair objects form the php message and convert them to
|
||||
* a php object class.
|
||||
*
|
||||
* Called when the marker type is 3.
|
||||
*
|
||||
* @param array|null $object
|
||||
* @return object
|
||||
*/
|
||||
public function readObject($object = null)
|
||||
{
|
||||
if ($object === null) {
|
||||
$object = array();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$key = $this->_stream->readUTF();
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
if ($typeMarker != Zend_Amf_Constants::AMF0_OBJECTTERM ){
|
||||
//Recursivly call readTypeMarker to get the types of properties in the object
|
||||
$object[$key] = $this->readTypeMarker($typeMarker);
|
||||
} else {
|
||||
//encountered AMF object terminator
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_reference[] = $object;
|
||||
return (object) $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read reference objects
|
||||
*
|
||||
* Used to gain access to the private array of reference objects.
|
||||
* Called when marker type is 7.
|
||||
*
|
||||
* @return object
|
||||
* @throws Zend_Amf_Exception for invalid reference keys
|
||||
*/
|
||||
public function readReference()
|
||||
{
|
||||
$key = $this->_stream->readInt();
|
||||
if (!array_key_exists($key, $this->_reference)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid reference key: '. $key);
|
||||
}
|
||||
return $this->_reference[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an array with numeric and string indexes.
|
||||
*
|
||||
* Called when marker type is 8
|
||||
*
|
||||
* @todo As of Flash Player 9 there is not support for mixed typed arrays
|
||||
* so we handle this as an object. With the introduction of vectors
|
||||
* in Flash Player 10 this may need to be reconsidered.
|
||||
* @return array
|
||||
*/
|
||||
public function readMixedArray()
|
||||
{
|
||||
$length = $this->_stream->readLong();
|
||||
return $this->readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts numerically indexed actiosncript arrays into php arrays.
|
||||
*
|
||||
* Called when marker type is 10
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function readArray()
|
||||
{
|
||||
$length = $this->_stream->readLong();
|
||||
$array = array();
|
||||
while ($length--) {
|
||||
$array[] = $this->readTypeMarker();
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert AS Date to Zend_Date
|
||||
*
|
||||
* @return Zend_Date
|
||||
*/
|
||||
public function readDate()
|
||||
{
|
||||
// get the unix time stamp. Not sure why ActionScript does not use
|
||||
// milliseconds
|
||||
$timestamp = floor($this->_stream->readDouble() / 1000);
|
||||
|
||||
// The timezone offset is never returned to the server; it is always 0,
|
||||
// so read and ignore.
|
||||
$offset = $this->_stream->readInt();
|
||||
|
||||
require_once 'Zend/Date.php';
|
||||
$date = new Zend_Date($timestamp);
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert XML to SimpleXml
|
||||
* If user wants DomDocument they can use dom_import_simplexml
|
||||
*
|
||||
* @return SimpleXml Object
|
||||
*/
|
||||
public function readXmlString()
|
||||
{
|
||||
$string = $this->_stream->readLongUTF();
|
||||
return Zend_Xml_Security::scan($string); //simplexml_load_string($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Class that is to be mapped to a server class.
|
||||
*
|
||||
* Commonly used for Value Objects on the server
|
||||
*
|
||||
* @todo implement Typed Class mapping
|
||||
* @return object|array
|
||||
* @throws Zend_Amf_Exception if unable to load type
|
||||
*/
|
||||
public function readTypedObject()
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
// get the remote class name
|
||||
$className = $this->_stream->readUTF();
|
||||
$loader = Zend_Amf_Parse_TypeLoader::loadType($className);
|
||||
$returnObject = new $loader();
|
||||
$properties = get_object_vars($this->readObject());
|
||||
foreach($properties as $key=>$value) {
|
||||
if($key) {
|
||||
$returnObject->$key = $value;
|
||||
}
|
||||
}
|
||||
if($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
|
||||
$returnObject = get_object_vars($returnObject);
|
||||
}
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* AMF3 data type encountered load AMF3 Deserializer to handle
|
||||
* type markers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readAmf3TypeMarker()
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
|
||||
$deserializer = new Zend_Amf_Parse_Amf3_Deserializer($this->_stream);
|
||||
$this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
return $deserializer->readTypeMarker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object encoding to check if an AMF3 object
|
||||
* is going to be return.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectEncoding()
|
||||
{
|
||||
return $this->_objectEncoding;
|
||||
}
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Serializer.php';
|
||||
|
||||
/**
|
||||
* Serializer PHP misc types back to there corresponding AMF0 Type Marker.
|
||||
*
|
||||
* @uses Zend_Amf_Parse_Serializer
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* @var string Name of the class to be returned
|
||||
*/
|
||||
protected $_className = '';
|
||||
|
||||
/**
|
||||
* An array of reference objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* Determine type and serialize accordingly
|
||||
*
|
||||
* Checks to see if the type was declared and then either
|
||||
* auto negotiates the type or relies on the user defined markerType to
|
||||
* serialize the data into amf
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $markerType
|
||||
* @param mixed $dataByVal
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
* @throws Zend_Amf_Exception for unrecognized types or data
|
||||
*/
|
||||
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $data) && ($dataByVal !== false)) {
|
||||
$data = &$dataByVal;
|
||||
}
|
||||
if (null !== $markerType) {
|
||||
//try to reference the given object
|
||||
if (!$this->writeObjectReference($data, $markerType)) {
|
||||
// Write the Type Marker to denote the following action script data type
|
||||
$this->_stream->writeByte($markerType);
|
||||
switch($markerType) {
|
||||
case Zend_Amf_Constants::AMF0_NUMBER:
|
||||
$this->_stream->writeDouble($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_BOOLEAN:
|
||||
$this->_stream->writeByte($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_STRING:
|
||||
$this->_stream->writeUTF($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_OBJECT:
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_NULL:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_REFERENCE:
|
||||
$this->_stream->writeInt($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_MIXEDARRAY:
|
||||
// Write length of numeric keys as zero.
|
||||
$this->_stream->writeLong(0);
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_ARRAY:
|
||||
$this->writeArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_DATE:
|
||||
$this->writeDate($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_LONGSTRING:
|
||||
$this->_stream->writeLongUTF($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_TYPEDOBJECT:
|
||||
$this->writeTypedObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_AMF3:
|
||||
$this->writeAmf3TypeMarker($data);
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception("Unknown Type Marker: " . $markerType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_resource($data)) {
|
||||
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
|
||||
}
|
||||
switch (true) {
|
||||
case (is_int($data) || is_float($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_NUMBER;
|
||||
break;
|
||||
case (is_bool($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
|
||||
break;
|
||||
case (is_string($data) && (($this->_mbStringFunctionsOverloaded ? mb_strlen($data, '8bit') : strlen($data)) > 65536)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
|
||||
break;
|
||||
case (is_string($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_STRING;
|
||||
break;
|
||||
case (is_object($data)):
|
||||
if (($data instanceof DateTime) || ($data instanceof Zend_Date)) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_DATE;
|
||||
} else {
|
||||
|
||||
if($className = $this->getClassName($data)){
|
||||
//Object is a Typed object set classname
|
||||
$markerType = Zend_Amf_Constants::AMF0_TYPEDOBJECT;
|
||||
$this->_className = $className;
|
||||
} else {
|
||||
// Object is a generic classname
|
||||
$markerType = Zend_Amf_Constants::AMF0_OBJECT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case (null === $data):
|
||||
$markerType = Zend_Amf_Constants::AMF0_NULL;
|
||||
break;
|
||||
case (is_array($data)):
|
||||
// check if it is an associative array
|
||||
$i = 0;
|
||||
foreach (array_keys($data) as $key) {
|
||||
// check if it contains non-integer keys
|
||||
if (!is_numeric($key) || intval($key) != $key) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_OBJECT;
|
||||
break;
|
||||
// check if it is a sparse indexed array
|
||||
} else if ($key != $i) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_MIXEDARRAY;
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// Dealing with a standard numeric array
|
||||
if(!$markerType){
|
||||
$markerType = Zend_Amf_Constants::AMF0_ARRAY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
|
||||
}
|
||||
|
||||
$this->writeTypeMarker($data, $markerType);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given object is in the reference table, write the reference if it exists,
|
||||
* otherwise add the object to the reference table
|
||||
*
|
||||
* @param mixed $object object reference to check for reference
|
||||
* @param string $markerType AMF type of the object to write
|
||||
* @param mixed $objectByVal object to check for reference
|
||||
* @return Boolean true, if the reference was written, false otherwise
|
||||
*/
|
||||
protected function writeObjectReference(&$object, $markerType, $objectByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $object) && ($objectByVal !== false)) {
|
||||
$object = &$objectByVal;
|
||||
}
|
||||
|
||||
if ($markerType == Zend_Amf_Constants::AMF0_OBJECT
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_ARRAY
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_TYPEDOBJECT
|
||||
) {
|
||||
$ref = array_search($object, $this->_referenceObjects, true);
|
||||
//handle object reference
|
||||
if($ref !== false){
|
||||
$this->writeTypeMarker($ref,Zend_Amf_Constants::AMF0_REFERENCE);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->_referenceObjects[] = $object;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PHP array with string or mixed keys.
|
||||
*
|
||||
* @param object $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeObject($object)
|
||||
{
|
||||
// Loop each element and write the name of the property.
|
||||
foreach ($object as $key => &$value) {
|
||||
// skip variables starting with an _ private transient
|
||||
if( $key[0] == "_") continue;
|
||||
$this->_stream->writeUTF($key);
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
|
||||
// Write the end object flag
|
||||
$this->_stream->writeInt(0);
|
||||
$this->_stream->writeByte(Zend_Amf_Constants::AMF0_OBJECTTERM);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a standard numeric array to the output stream. If a mixed array
|
||||
* is encountered call writeTypeMarker with mixed array.
|
||||
*
|
||||
* @param array $array
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeArray(&$array)
|
||||
{
|
||||
$length = count($array);
|
||||
if (!$length < 0) {
|
||||
// write the length of the array
|
||||
$this->_stream->writeLong(0);
|
||||
} else {
|
||||
// Write the length of the numeric array
|
||||
$this->_stream->writeLong($length);
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
$value = isset($array[$i]) ? $array[$i] : null;
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the DateTime into an AMF Date
|
||||
*
|
||||
* @param DateTime|Zend_Date $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeDate($data)
|
||||
{
|
||||
if ($data instanceof DateTime) {
|
||||
$dateString = $data->format('U');
|
||||
} elseif ($data instanceof Zend_Date) {
|
||||
$dateString = $data->toString('U');
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid date specified; must be a DateTime or Zend_Date object');
|
||||
}
|
||||
$dateString *= 1000;
|
||||
|
||||
// Make the conversion and remove milliseconds.
|
||||
$this->_stream->writeDouble($dateString);
|
||||
|
||||
// Flash does not respect timezone but requires it.
|
||||
$this->_stream->writeInt(0);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a class mapped object to the output stream.
|
||||
*
|
||||
* @param object $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeTypedObject($data)
|
||||
{
|
||||
$this->_stream->writeUTF($this->_className);
|
||||
$this->writeObject($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encountered and AMF3 Type Marker use AMF3 serializer. Once AMF3 is
|
||||
* encountered it will not return to AMf0.
|
||||
*
|
||||
* @param string $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeAmf3TypeMarker(&$data)
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/Amf3/Serializer.php';
|
||||
$serializer = new Zend_Amf_Parse_Amf3_Serializer($this->_stream);
|
||||
$serializer->writeTypeMarker($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if the class name is a class mapped name and return the
|
||||
* respective classname if it is.
|
||||
*
|
||||
* @param object $object
|
||||
* @return false|string $className
|
||||
*/
|
||||
protected function getClassName($object)
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
//Check to see if the object is a typed object and we need to change
|
||||
$className = '';
|
||||
switch (true) {
|
||||
// the return class mapped name back to actionscript class name.
|
||||
case Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
|
||||
$className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object));
|
||||
break;
|
||||
// Check to see if the user has defined an explicit Action Script type.
|
||||
case isset($object->_explicitType):
|
||||
$className = $object->_explicitType;
|
||||
break;
|
||||
// Check if user has defined a method for accessing the Action Script type
|
||||
case method_exists($object, 'getASClassName'):
|
||||
$className = $object->getASClassName();
|
||||
break;
|
||||
// No return class name is set make it a generic object
|
||||
case ($object instanceof stdClass):
|
||||
$className = '';
|
||||
break;
|
||||
// By default, use object's class name
|
||||
default:
|
||||
$className = get_class($object);
|
||||
break;
|
||||
}
|
||||
if(!$className == '') {
|
||||
return $className;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,425 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Parse_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Deserializer.php';
|
||||
|
||||
/** Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/** Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/**
|
||||
* Read an AMF3 input stream and convert it into PHP data types.
|
||||
*
|
||||
* @todo readObject to handle Typed Objects
|
||||
* @todo readXMLStrimg to be implemented.
|
||||
* @todo Class could be implemented as Factory Class with each data type it's own class.
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf3_Deserializer extends Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* Total number of objects in the referenceObject array
|
||||
* @var int
|
||||
*/
|
||||
protected $_objectCount;
|
||||
|
||||
/**
|
||||
* An array of reference objects per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* An array of reference strings per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceStrings = array();
|
||||
|
||||
/**
|
||||
* An array of reference class definitions per body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceDefinitions = array();
|
||||
|
||||
/**
|
||||
* Read AMF markers and dispatch for deserialization
|
||||
*
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param integer $typeMarker
|
||||
* @return mixed Whatever the corresponding PHP data type is
|
||||
* @throws Zend_Amf_Exception for unidentified marker type
|
||||
*/
|
||||
public function readTypeMarker($typeMarker = null)
|
||||
{
|
||||
if(null === $typeMarker) {
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
}
|
||||
|
||||
switch($typeMarker) {
|
||||
case Zend_Amf_Constants::AMF3_UNDEFINED:
|
||||
return null;
|
||||
case Zend_Amf_Constants::AMF3_NULL:
|
||||
return null;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE:
|
||||
return false;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE:
|
||||
return true;
|
||||
case Zend_Amf_Constants::AMF3_INTEGER:
|
||||
return $this->readInteger();
|
||||
case Zend_Amf_Constants::AMF3_NUMBER:
|
||||
return $this->_stream->readDouble();
|
||||
case Zend_Amf_Constants::AMF3_STRING:
|
||||
return $this->readString();
|
||||
case Zend_Amf_Constants::AMF3_DATE:
|
||||
return $this->readDate();
|
||||
case Zend_Amf_Constants::AMF3_ARRAY:
|
||||
return $this->readArray();
|
||||
case Zend_Amf_Constants::AMF3_OBJECT:
|
||||
return $this->readObject();
|
||||
case Zend_Amf_Constants::AMF3_XML:
|
||||
case Zend_Amf_Constants::AMF3_XMLSTRING:
|
||||
return $this->readXmlString();
|
||||
case Zend_Amf_Constants::AMF3_BYTEARRAY:
|
||||
return $this->readString();
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported type marker: ' . $typeMarker);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize an integer
|
||||
*
|
||||
* AMF 3 represents smaller integers with fewer bytes using the most
|
||||
* significant bit of each byte. The worst case uses 32-bits
|
||||
* to represent a 29-bit number, which is what we would have
|
||||
* done with no compression.
|
||||
* - 0x00000000 - 0x0000007F : 0xxxxxxx
|
||||
* - 0x00000080 - 0x00003FFF : 1xxxxxxx 0xxxxxxx
|
||||
* - 0x00004000 - 0x001FFFFF : 1xxxxxxx 1xxxxxxx 0xxxxxxx
|
||||
* - 0x00200000 - 0x3FFFFFFF : 1xxxxxxx 1xxxxxxx 1xxxxxxx xxxxxxxx
|
||||
* - 0x40000000 - 0xFFFFFFFF : throw range exception
|
||||
*
|
||||
* 0x04 -> integer type code, followed by up to 4 bytes of data.
|
||||
*
|
||||
* Parsing integers on OSFlash for the AMF3 integer data format:
|
||||
* @link http://osflash.org/amf3/parsing_integers
|
||||
* @return int|float
|
||||
*/
|
||||
public function readInteger()
|
||||
{
|
||||
$count = 1;
|
||||
$intReference = $this->_stream->readByte();
|
||||
$result = 0;
|
||||
while ((($intReference & 0x80) != 0) && $count < 4) {
|
||||
$result <<= 7;
|
||||
$result |= ($intReference & 0x7f);
|
||||
$intReference = $this->_stream->readByte();
|
||||
$count++;
|
||||
}
|
||||
if ($count < 4) {
|
||||
$result <<= 7;
|
||||
$result |= $intReference;
|
||||
} else {
|
||||
// Use all 8 bits from the 4th byte
|
||||
$result <<= 8;
|
||||
$result |= $intReference;
|
||||
|
||||
// Check if the integer should be negative
|
||||
if (($result & 0x10000000) != 0) {
|
||||
//and extend the sign bit
|
||||
$result |= ~0xFFFFFFF;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize a string
|
||||
*
|
||||
* Strings can be sent as a reference to a previously
|
||||
* occurring String by using an index to the implicit string reference table.
|
||||
* Strings are encoding using UTF-8 - however the header may either
|
||||
* describe a string literal or a string reference.
|
||||
*
|
||||
* - string = 0x06 string-data
|
||||
* - string-data = integer-data [ modified-utf-8 ]
|
||||
* - modified-utf-8 = *OCTET
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function readString()
|
||||
{
|
||||
$stringReference = $this->readInteger();
|
||||
|
||||
//Check if this is a reference string
|
||||
if (($stringReference & 0x01) == 0) {
|
||||
// reference string
|
||||
$stringReference = $stringReference >> 1;
|
||||
if ($stringReference >= count($this->_referenceStrings)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Undefined string reference: ' . $stringReference);
|
||||
}
|
||||
// reference string found
|
||||
return $this->_referenceStrings[$stringReference];
|
||||
}
|
||||
|
||||
$length = $stringReference >> 1;
|
||||
if ($length) {
|
||||
$string = $this->_stream->readBytes($length);
|
||||
$this->_referenceStrings[] = $string;
|
||||
} else {
|
||||
$string = "";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize a date
|
||||
*
|
||||
* Data is the number of milliseconds elapsed since the epoch
|
||||
* of midnight, 1st Jan 1970 in the UTC time zone.
|
||||
* Local time zone information is not sent to flash.
|
||||
*
|
||||
* - date = 0x08 integer-data [ number-data ]
|
||||
*
|
||||
* @return Zend_Date
|
||||
*/
|
||||
public function readDate()
|
||||
{
|
||||
$dateReference = $this->readInteger();
|
||||
if (($dateReference & 0x01) == 0) {
|
||||
$dateReference = $dateReference >> 1;
|
||||
if ($dateReference>=count($this->_referenceObjects)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Undefined date reference: ' . $dateReference);
|
||||
}
|
||||
return $this->_referenceObjects[$dateReference];
|
||||
}
|
||||
|
||||
$timestamp = floor($this->_stream->readDouble() / 1000);
|
||||
|
||||
require_once 'Zend/Date.php';
|
||||
$dateTime = new Zend_Date($timestamp);
|
||||
$this->_referenceObjects[] = $dateTime;
|
||||
return $dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read amf array to PHP array
|
||||
*
|
||||
* - array = 0x09 integer-data ( [ 1OCTET *amf3-data ] | [OCTET *amf3-data 1] | [ OCTET *amf-data ] )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function readArray()
|
||||
{
|
||||
$arrayReference = $this->readInteger();
|
||||
if (($arrayReference & 0x01)==0){
|
||||
$arrayReference = $arrayReference >> 1;
|
||||
if ($arrayReference>=count($this->_referenceObjects)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknow array reference: ' . $arrayReference);
|
||||
}
|
||||
return $this->_referenceObjects[$arrayReference];
|
||||
}
|
||||
|
||||
// Create a holder for the array in the reference list
|
||||
$data = array();
|
||||
$this->_referenceObjects[] =& $data;
|
||||
$key = $this->readString();
|
||||
|
||||
// Iterating for string based keys.
|
||||
while ($key != '') {
|
||||
$data[$key] = $this->readTypeMarker();
|
||||
$key = $this->readString();
|
||||
}
|
||||
|
||||
$arrayReference = $arrayReference >>1;
|
||||
|
||||
//We have a dense array
|
||||
for ($i=0; $i < $arrayReference; $i++) {
|
||||
$data[] = $this->readTypeMarker();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an object from the AMF stream and convert it into a PHP object
|
||||
*
|
||||
* @todo Rather than using an array of traitsInfo create Zend_Amf_Value_TraitsInfo
|
||||
* @return object|array
|
||||
*/
|
||||
public function readObject()
|
||||
{
|
||||
$traitsInfo = $this->readInteger();
|
||||
$storedObject = ($traitsInfo & 0x01)==0;
|
||||
$traitsInfo = $traitsInfo >> 1;
|
||||
|
||||
// Check if the Object is in the stored Objects reference table
|
||||
if ($storedObject) {
|
||||
$ref = $traitsInfo;
|
||||
if (!isset($this->_referenceObjects[$ref])) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Object reference: ' . $ref);
|
||||
}
|
||||
$returnObject = $this->_referenceObjects[$ref];
|
||||
} else {
|
||||
// Check if the Object is in the stored Definitions reference table
|
||||
$storedClass = ($traitsInfo & 0x01) == 0;
|
||||
$traitsInfo = $traitsInfo >> 1;
|
||||
if ($storedClass) {
|
||||
$ref = $traitsInfo;
|
||||
if (!isset($this->_referenceDefinitions[$ref])) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknows Definition reference: '. $ref);
|
||||
}
|
||||
// Populate the reference attributes
|
||||
$className = $this->_referenceDefinitions[$ref]['className'];
|
||||
$encoding = $this->_referenceDefinitions[$ref]['encoding'];
|
||||
$propertyNames = $this->_referenceDefinitions[$ref]['propertyNames'];
|
||||
} else {
|
||||
// The class was not in the reference tables. Start reading rawdata to build traits.
|
||||
// Create a traits table. Zend_Amf_Value_TraitsInfo would be ideal
|
||||
$className = $this->readString();
|
||||
$encoding = $traitsInfo & 0x03;
|
||||
$propertyNames = array();
|
||||
$traitsInfo = $traitsInfo >> 2;
|
||||
}
|
||||
|
||||
// We now have the object traits defined in variables. Time to go to work:
|
||||
if (!$className) {
|
||||
// No class name generic object
|
||||
$returnObject = new stdClass();
|
||||
} else {
|
||||
// Defined object
|
||||
// Typed object lookup against registered classname maps
|
||||
if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
|
||||
$returnObject = new $loader();
|
||||
} else {
|
||||
//user defined typed object
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Typed object not found: '. $className . ' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Add the Object to the reference table
|
||||
$this->_referenceObjects[] = $returnObject;
|
||||
|
||||
$properties = array(); // clear value
|
||||
// Check encoding types for additional processing.
|
||||
switch ($encoding) {
|
||||
case (Zend_Amf_Constants::ET_EXTERNAL):
|
||||
// Externalizable object such as {ArrayCollection} and {ObjectProxy}
|
||||
if (!$storedClass) {
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
$returnObject->externalizedData = $this->readTypeMarker();
|
||||
break;
|
||||
case (Zend_Amf_Constants::ET_DYNAMIC):
|
||||
// used for Name-value encoding
|
||||
if (!$storedClass) {
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
// not a reference object read name value properties from byte stream
|
||||
do {
|
||||
$property = $this->readString();
|
||||
if ($property != "") {
|
||||
$propertyNames[] = $property;
|
||||
$properties[$property] = $this->readTypeMarker();
|
||||
}
|
||||
} while ($property !="");
|
||||
break;
|
||||
default:
|
||||
// basic property list object.
|
||||
if (!$storedClass) {
|
||||
$count = $traitsInfo; // Number of properties in the list
|
||||
for($i=0; $i< $count; $i++) {
|
||||
$propertyNames[] = $this->readString();
|
||||
}
|
||||
// Add a reference to the class.
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
foreach ($propertyNames as $property) {
|
||||
$properties[$property] = $this->readTypeMarker();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Add properties back to the return object.
|
||||
if (!is_array($properties)) $properties = array();
|
||||
foreach($properties as $key=>$value) {
|
||||
if($key) {
|
||||
$returnObject->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
|
||||
if (isset($returnObject->externalizedData)) {
|
||||
$returnObject = $returnObject->externalizedData;
|
||||
} else {
|
||||
$returnObject = get_object_vars($returnObject);
|
||||
}
|
||||
}
|
||||
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert XML to SimpleXml
|
||||
* If user wants DomDocument they can use dom_import_simplexml
|
||||
*
|
||||
* @return SimpleXml Object
|
||||
*/
|
||||
public function readXmlString()
|
||||
{
|
||||
$xmlReference = $this->readInteger();
|
||||
$length = $xmlReference >> 1;
|
||||
$string = $this->_stream->readBytes($length);
|
||||
return Zend_Xml_Security::scan($string);
|
||||
}
|
||||
}
|
||||
@@ -1,534 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
|
||||
/** Zend_Amf_Parse_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Serializer.php';
|
||||
|
||||
/** Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/**
|
||||
* Detect PHP object type and convert it to a corresponding AMF3 object type
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* A constant empty string
|
||||
* @var string
|
||||
*/
|
||||
protected $_strEmpty = '';
|
||||
|
||||
/**
|
||||
* An array of reference objects per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* An array of reference strings per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceStrings = array();
|
||||
|
||||
/**
|
||||
* An array of reference class definitions, indexed by classname
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceDefinitions = array();
|
||||
|
||||
/**
|
||||
* Serialize PHP types to AMF3 and write to stream
|
||||
*
|
||||
* Checks to see if the type was declared and then either
|
||||
* auto negotiates the type or use the user defined markerType to
|
||||
* serialize the data from php back to AMF3
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $markerType
|
||||
* @param mixed $dataByVal
|
||||
* @return void
|
||||
*/
|
||||
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $data) && ($dataByVal !== false)) {
|
||||
$data = &$dataByVal;
|
||||
}
|
||||
if (null !== $markerType) {
|
||||
// Write the Type Marker to denote the following action script data type
|
||||
$this->_stream->writeByte($markerType);
|
||||
|
||||
switch ($markerType) {
|
||||
case Zend_Amf_Constants::AMF3_NULL:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_INTEGER:
|
||||
$this->writeInteger($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_NUMBER:
|
||||
$this->_stream->writeDouble($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_STRING:
|
||||
$this->writeString($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_DATE:
|
||||
$this->writeDate($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_ARRAY:
|
||||
$this->writeArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_OBJECT:
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BYTEARRAY:
|
||||
$this->writeByteArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_XMLSTRING;
|
||||
$this->writeXml($data);
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Type Marker: ' . $markerType);
|
||||
}
|
||||
} else {
|
||||
// Detect Type Marker
|
||||
if (is_resource($data)) {
|
||||
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
|
||||
}
|
||||
switch (true) {
|
||||
case (null === $data):
|
||||
$markerType = Zend_Amf_Constants::AMF3_NULL;
|
||||
break;
|
||||
case (is_bool($data)):
|
||||
if ($data){
|
||||
$markerType = Zend_Amf_Constants::AMF3_BOOLEAN_TRUE;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_BOOLEAN_FALSE;
|
||||
}
|
||||
break;
|
||||
case (is_int($data)):
|
||||
if (($data > 0xFFFFFFF) || ($data < -268435456)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_NUMBER;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_INTEGER;
|
||||
}
|
||||
break;
|
||||
case (is_float($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_NUMBER;
|
||||
break;
|
||||
case (is_string($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_STRING;
|
||||
break;
|
||||
case (is_array($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_ARRAY;
|
||||
break;
|
||||
case (is_object($data)):
|
||||
// Handle object types.
|
||||
if (($data instanceof DateTime) || ($data instanceof Zend_Date)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_DATE;
|
||||
} else if ($data instanceof Zend_Amf_Value_ByteArray) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_BYTEARRAY;
|
||||
} else if (($data instanceof DOMDocument) || ($data instanceof SimpleXMLElement)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_XMLSTRING;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_OBJECT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
|
||||
}
|
||||
$this->writeTypeMarker($data, $markerType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an AMF3 integer
|
||||
*
|
||||
* @param int|float $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeInteger($int)
|
||||
{
|
||||
if (($int & 0xffffff80) == 0) {
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (($int & 0xffffc000) == 0 ) {
|
||||
$this->_stream->writeByte(($int >> 7 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (($int & 0xffe00000) == 0) {
|
||||
$this->_stream->writeByte(($int >> 14 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 7 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->_stream->writeByte(($int >> 22 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 15 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 8 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0xff);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send string to output stream, without trying to reference it.
|
||||
* The string is prepended with strlen($string) << 1 | 0x01
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
protected function writeBinaryString(&$string){
|
||||
$ref = ($this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string)) << 1 | 0x01;
|
||||
$this->writeInteger($ref);
|
||||
$this->_stream->writeBytes($string);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send string to output stream
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeString(&$string)
|
||||
{
|
||||
$len = $this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string);
|
||||
if(!$len){
|
||||
$this->writeInteger(0x01);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$ref = array_key_exists($string, $this->_referenceStrings)
|
||||
? $this->_referenceStrings[$string]
|
||||
: false;
|
||||
if ($ref === false){
|
||||
$this->_referenceStrings[$string] = count($this->_referenceStrings);
|
||||
$this->writeBinaryString($string);
|
||||
} else {
|
||||
$ref <<= 1;
|
||||
$this->writeInteger($ref);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ByteArray to output stream
|
||||
*
|
||||
* @param string|Zend_Amf_Value_ByteArray $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeByteArray(&$data)
|
||||
{
|
||||
if ($this->writeObjectReference($data)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
//nothing to do
|
||||
} else if ($data instanceof Zend_Amf_Value_ByteArray) {
|
||||
$data = $data->getData();
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid ByteArray specified; must be a string or Zend_Amf_Value_ByteArray');
|
||||
}
|
||||
|
||||
$this->writeBinaryString($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send xml to output stream
|
||||
*
|
||||
* @param DOMDocument|SimpleXMLElement $xml
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeXml($xml)
|
||||
{
|
||||
if ($this->writeObjectReference($xml)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if(is_string($xml)) {
|
||||
//nothing to do
|
||||
} else if ($xml instanceof DOMDocument) {
|
||||
$xml = $xml->saveXml();
|
||||
} else if ($xml instanceof SimpleXMLElement) {
|
||||
$xml = $xml->asXML();
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid xml specified; must be a DOMDocument or SimpleXMLElement');
|
||||
}
|
||||
|
||||
$this->writeBinaryString($xml);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert DateTime/Zend_Date to AMF date
|
||||
*
|
||||
* @param DateTime|Zend_Date $date
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeDate($date)
|
||||
{
|
||||
if ($this->writeObjectReference($date)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($date instanceof DateTime) {
|
||||
$dateString = $date->format('U') * 1000;
|
||||
} elseif ($date instanceof Zend_Date) {
|
||||
$dateString = $date->toString('U') * 1000;
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid date specified; must be a string DateTime or Zend_Date object');
|
||||
}
|
||||
|
||||
$this->writeInteger(0x01);
|
||||
// write time to stream minus milliseconds
|
||||
$this->_stream->writeDouble($dateString);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PHP array back to the amf output stream
|
||||
*
|
||||
* @param array $array
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeArray(&$array)
|
||||
{
|
||||
// arrays aren't reference here but still counted
|
||||
$this->_referenceObjects[] = $array;
|
||||
|
||||
// have to seperate mixed from numberic keys.
|
||||
$numeric = array();
|
||||
$string = array();
|
||||
foreach ($array as $key => &$value) {
|
||||
if (is_int($key)) {
|
||||
$numeric[] = $value;
|
||||
} else {
|
||||
$string[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// write the preamble id of the array
|
||||
$length = count($numeric);
|
||||
$id = ($length << 1) | 0x01;
|
||||
$this->writeInteger($id);
|
||||
|
||||
//Write the mixed type array to the output stream
|
||||
foreach($string as $key => &$value) {
|
||||
$this->writeString($key)
|
||||
->writeTypeMarker($value);
|
||||
}
|
||||
$this->writeString($this->_strEmpty);
|
||||
|
||||
// Write the numeric array to ouput stream
|
||||
foreach($numeric as &$value) {
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given object is in the reference table, write the reference if it exists,
|
||||
* otherwise add the object to the reference table
|
||||
*
|
||||
* @param mixed $object object reference to check for reference
|
||||
* @param mixed $objectByVal object to check for reference
|
||||
* @return Boolean true, if the reference was written, false otherwise
|
||||
*/
|
||||
protected function writeObjectReference(&$object, $objectByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $object) && ($objectByVal !== false)) {
|
||||
$object = &$objectByVal;
|
||||
}
|
||||
|
||||
$hash = spl_object_hash($object);
|
||||
$ref = array_key_exists($hash, $this->_referenceObjects)
|
||||
? $this->_referenceObjects[$hash]
|
||||
: false;
|
||||
|
||||
// quickly handle object references
|
||||
if ($ref !== false){
|
||||
$ref <<= 1;
|
||||
$this->writeInteger($ref);
|
||||
return true;
|
||||
}
|
||||
$this->_referenceObjects[$hash] = count($this->_referenceObjects);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object to ouput stream
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeObject($object)
|
||||
{
|
||||
if($this->writeObjectReference($object)){
|
||||
return $this;
|
||||
}
|
||||
|
||||
$className = '';
|
||||
|
||||
//Check to see if the object is a typed object and we need to change
|
||||
switch (true) {
|
||||
// the return class mapped name back to actionscript class name.
|
||||
case ($className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object))):
|
||||
break;
|
||||
|
||||
// Check to see if the user has defined an explicit Action Script type.
|
||||
case isset($object->_explicitType):
|
||||
$className = $object->_explicitType;
|
||||
break;
|
||||
|
||||
// Check if user has defined a method for accessing the Action Script type
|
||||
case method_exists($object, 'getASClassName'):
|
||||
$className = $object->getASClassName();
|
||||
break;
|
||||
|
||||
// No return class name is set make it a generic object
|
||||
case ($object instanceof stdClass):
|
||||
$className = '';
|
||||
break;
|
||||
|
||||
// By default, use object's class name
|
||||
default:
|
||||
$className = get_class($object);
|
||||
break;
|
||||
}
|
||||
|
||||
$writeTraits = true;
|
||||
|
||||
//check to see, if we have a corresponding definition
|
||||
if(array_key_exists($className, $this->_referenceDefinitions)){
|
||||
$traitsInfo = $this->_referenceDefinitions[$className]['id'];
|
||||
$encoding = $this->_referenceDefinitions[$className]['encoding'];
|
||||
$propertyNames = $this->_referenceDefinitions[$className]['propertyNames'];
|
||||
|
||||
$traitsInfo = ($traitsInfo << 2) | 0x01;
|
||||
|
||||
$writeTraits = false;
|
||||
} else {
|
||||
$propertyNames = array();
|
||||
|
||||
if($className == ''){
|
||||
//if there is no className, we interpret the class as dynamic without any sealed members
|
||||
$encoding = Zend_Amf_Constants::ET_DYNAMIC;
|
||||
} else {
|
||||
$encoding = Zend_Amf_Constants::ET_PROPLIST;
|
||||
|
||||
foreach($object as $key => $value) {
|
||||
if( $key[0] != "_") {
|
||||
$propertyNames[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_referenceDefinitions[$className] = array(
|
||||
'id' => count($this->_referenceDefinitions),
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
|
||||
$traitsInfo = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
$traitsInfo |= $encoding << 2;
|
||||
$traitsInfo |= (count($propertyNames) << 4);
|
||||
}
|
||||
|
||||
$this->writeInteger($traitsInfo);
|
||||
|
||||
if($writeTraits){
|
||||
$this->writeString($className);
|
||||
foreach ($propertyNames as $value) {
|
||||
$this->writeString($value);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch($encoding) {
|
||||
case Zend_Amf_Constants::ET_PROPLIST:
|
||||
//Write the sealed values to the output stream.
|
||||
foreach ($propertyNames as $key) {
|
||||
$this->writeTypeMarker($object->$key);
|
||||
}
|
||||
break;
|
||||
case Zend_Amf_Constants::ET_DYNAMIC:
|
||||
//Write the sealed values to the output stream.
|
||||
foreach ($propertyNames as $key) {
|
||||
$this->writeTypeMarker($object->$key);
|
||||
}
|
||||
|
||||
//Write remaining properties
|
||||
foreach($object as $key => $value){
|
||||
if(!in_array($key,$propertyNames) && $key[0] != "_"){
|
||||
$this->writeString($key);
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
}
|
||||
|
||||
//Write an empty string to end the dynamic part
|
||||
$this->writeString($this->_strEmpty);
|
||||
break;
|
||||
case Zend_Amf_Constants::ET_EXTERNAL:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('External Object Encoding not implemented');
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract cass that all deserializer must implement.
|
||||
*
|
||||
* Logic for deserialization of the AMF envelop is based on resources supplied
|
||||
* by Adobe Blaze DS. For and example of deserialization please review the BlazeDS
|
||||
* source tree.
|
||||
*
|
||||
* @see http://opensource.adobe.com/svn/opensource/blazeds/trunk/modules/core/src/java/flex/messaging/io/amf/
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* The raw string that represents the AMF request.
|
||||
*
|
||||
* @var Zend_Amf_Parse_InputStream
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Amf_Parse_InputStream $stream
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Amf_Parse_InputStream $stream)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. Markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param int $typeMarker
|
||||
* @return mixed Whatever the data type is of the marker in php
|
||||
*/
|
||||
public abstract function readTypeMarker($markerType = null);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Util_BinaryStream */
|
||||
require_once 'Zend/Amf/Util/BinaryStream.php';
|
||||
|
||||
/**
|
||||
* InputStream is used to iterate at a binary level through the AMF request.
|
||||
*
|
||||
* InputStream extends BinaryStream as eventually BinaryStream could be placed
|
||||
* outside of Zend_Amf in order to allow other packages to use the class.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_InputStream extends Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Util_BinaryStream */
|
||||
require_once 'Zend/Amf/Util/BinaryStream.php';
|
||||
|
||||
/**
|
||||
* Iterate at a binary level through the AMF response
|
||||
*
|
||||
* OutputStream extends BinaryStream as eventually BinaryStream could be placed
|
||||
* outside of Zend_Amf in order to allow other packages to use the class.
|
||||
*
|
||||
* @uses Zend_Amf_Util_BinaryStream
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_OutputStream extends Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('');
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_MysqlResult
|
||||
{
|
||||
/**
|
||||
* @var array List of Mysql types with PHP counterparts
|
||||
*
|
||||
* Key => Value is Mysql type (exact string) => PHP type
|
||||
*/
|
||||
static public $fieldTypes = array(
|
||||
"int" => "int",
|
||||
"timestamp" => "int",
|
||||
"year" => "int",
|
||||
"real" => "float",
|
||||
);
|
||||
/**
|
||||
* Parse resource into array
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
$result = array();
|
||||
$fieldcnt = mysql_num_fields($resource);
|
||||
$fields_transform = array();
|
||||
for($i=0;$i<$fieldcnt;$i++) {
|
||||
$type = mysql_field_type($resource, $i);
|
||||
if(isset(self::$fieldTypes[$type])) {
|
||||
$fields_transform[mysql_field_name($resource, $i)] = self::$fieldTypes[$type];
|
||||
}
|
||||
}
|
||||
|
||||
while($row = mysql_fetch_object($resource)) {
|
||||
foreach($fields_transform as $fieldname => $fieldtype) {
|
||||
settype($row->$fieldname, $fieldtype);
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_MysqliResult
|
||||
{
|
||||
|
||||
/**
|
||||
* mapping taken from http://forums.mysql.com/read.php?52,255868,255895#msg-255895
|
||||
*/
|
||||
static public $mysqli_type = array(
|
||||
0 => "MYSQLI_TYPE_DECIMAL",
|
||||
1 => "MYSQLI_TYPE_TINYINT",
|
||||
2 => "MYSQLI_TYPE_SMALLINT",
|
||||
3 => "MYSQLI_TYPE_INTEGER",
|
||||
4 => "MYSQLI_TYPE_FLOAT",
|
||||
5 => "MYSQLI_TYPE_DOUBLE",
|
||||
7 => "MYSQLI_TYPE_TIMESTAMP",
|
||||
8 => "MYSQLI_TYPE_BIGINT",
|
||||
9 => "MYSQLI_TYPE_MEDIUMINT",
|
||||
10 => "MYSQLI_TYPE_DATE",
|
||||
11 => "MYSQLI_TYPE_TIME",
|
||||
12 => "MYSQLI_TYPE_DATETIME",
|
||||
13 => "MYSQLI_TYPE_YEAR",
|
||||
14 => "MYSQLI_TYPE_DATE",
|
||||
16 => "MYSQLI_TYPE_BIT",
|
||||
246 => "MYSQLI_TYPE_DECIMAL",
|
||||
247 => "MYSQLI_TYPE_ENUM",
|
||||
248 => "MYSQLI_TYPE_SET",
|
||||
249 => "MYSQLI_TYPE_TINYBLOB",
|
||||
250 => "MYSQLI_TYPE_MEDIUMBLOB",
|
||||
251 => "MYSQLI_TYPE_LONGBLOB",
|
||||
252 => "MYSQLI_TYPE_BLOB",
|
||||
253 => "MYSQLI_TYPE_VARCHAR",
|
||||
254 => "MYSQLI_TYPE_CHAR",
|
||||
255 => "MYSQLI_TYPE_GEOMETRY",
|
||||
);
|
||||
|
||||
// Build an associative array for a type look up
|
||||
static $mysqli_to_php = array(
|
||||
"MYSQLI_TYPE_DECIMAL" => 'float',
|
||||
"MYSQLI_TYPE_NEWDECIMAL" => 'float',
|
||||
"MYSQLI_TYPE_BIT" => 'integer',
|
||||
"MYSQLI_TYPE_TINYINT" => 'integer',
|
||||
"MYSQLI_TYPE_SMALLINT" => 'integer',
|
||||
"MYSQLI_TYPE_MEDIUMINT" => 'integer',
|
||||
"MYSQLI_TYPE_BIGINT" => 'integer',
|
||||
"MYSQLI_TYPE_INTEGER" => 'integer',
|
||||
"MYSQLI_TYPE_FLOAT" => 'float',
|
||||
"MYSQLI_TYPE_DOUBLE" => 'float',
|
||||
"MYSQLI_TYPE_NULL" => 'null',
|
||||
"MYSQLI_TYPE_TIMESTAMP" => 'string',
|
||||
"MYSQLI_TYPE_INT24" => 'integer',
|
||||
"MYSQLI_TYPE_DATE" => 'string',
|
||||
"MYSQLI_TYPE_TIME" => 'string',
|
||||
"MYSQLI_TYPE_DATETIME" => 'string',
|
||||
"MYSQLI_TYPE_YEAR" => 'string',
|
||||
"MYSQLI_TYPE_NEWDATE" => 'string',
|
||||
"MYSQLI_TYPE_ENUM" => 'string',
|
||||
"MYSQLI_TYPE_SET" => 'string',
|
||||
"MYSQLI_TYPE_TINYBLOB" => 'object',
|
||||
"MYSQLI_TYPE_MEDIUMBLOB" => 'object',
|
||||
"MYSQLI_TYPE_LONGBLOB" => 'object',
|
||||
"MYSQLI_TYPE_BLOB" => 'object',
|
||||
"MYSQLI_TYPE_CHAR" => 'string',
|
||||
"MYSQLI_TYPE_VARCHAR" => 'string',
|
||||
"MYSQLI_TYPE_GEOMETRY" => 'object',
|
||||
"MYSQLI_TYPE_BIT" => 'integer',
|
||||
);
|
||||
|
||||
/**
|
||||
* Parse resource into array
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
|
||||
$result = array();
|
||||
$fieldcnt = mysqli_num_fields($resource);
|
||||
|
||||
|
||||
$fields_transform = array();
|
||||
|
||||
for($i=0;$i<$fieldcnt;$i++) {
|
||||
$finfo = mysqli_fetch_field_direct($resource, $i);
|
||||
|
||||
if(isset(self::$mysqli_type[$finfo->type])) {
|
||||
$fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
|
||||
}
|
||||
}
|
||||
|
||||
while($row = mysqli_fetch_assoc($resource)) {
|
||||
foreach($fields_transform as $fieldname => $fieldtype) {
|
||||
settype($row[$fieldname], $fieldtype);
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert stream resource to string by just reading it
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_Stream
|
||||
{
|
||||
/**
|
||||
* Parse resource into string
|
||||
*
|
||||
* @param resource $resource Stream resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
return stream_get_contents($resource);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base abstract class for all AMF serializers.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* Reference to the current output stream being constructed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* str* functions overloaded using mbstring.func_overload
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $mbStringFunctionsOverloaded;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Amf_Parse_OutputStream $stream
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Amf_Parse_OutputStream $stream)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the PHP object type and convert it into an AMF object type
|
||||
*
|
||||
* @param mixed $content
|
||||
* @param int $markerType
|
||||
* @param mixed $contentByVal
|
||||
* @return void
|
||||
*/
|
||||
public abstract function writeTypeMarker(&$content, $markerType = null, $contentByVal = false);
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AcknowledgeMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AsyncMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_CommandMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/CommandMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_ErrorMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_RemotingMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
|
||||
|
||||
/**
|
||||
* Loads a local class and executes the instantiation of that class.
|
||||
*
|
||||
* @todo PHP 5.3 can drastically change this class w/ namespace and the new call_user_func w/ namespace
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
final class Zend_Amf_Parse_TypeLoader
|
||||
{
|
||||
/**
|
||||
* @var string callback class
|
||||
*/
|
||||
public static $callbackClass;
|
||||
|
||||
/**
|
||||
* @var array AMF class map
|
||||
*/
|
||||
public static $classMap = array (
|
||||
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
|
||||
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
|
||||
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
|
||||
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Default class map
|
||||
*/
|
||||
protected static $_defaultClassMap = array(
|
||||
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
|
||||
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
|
||||
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
|
||||
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var Zend_Loader_PluginLoader_Interface
|
||||
*/
|
||||
protected static $_resourceLoader = null;
|
||||
|
||||
|
||||
/**
|
||||
* Load the mapped class type into a callback.
|
||||
*
|
||||
* @param string $className
|
||||
* @return object|false
|
||||
*/
|
||||
public static function loadType($className)
|
||||
{
|
||||
$class = self::getMappedClassName($className);
|
||||
if(!$class) {
|
||||
$class = str_replace('.', '_', $className);
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
return "stdClass";
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the supplied call name to its mapped class name
|
||||
*
|
||||
* @param string $className
|
||||
* @return string
|
||||
*/
|
||||
public static function getMappedClassName($className)
|
||||
{
|
||||
$mappedName = array_search($className, self::$classMap);
|
||||
|
||||
if ($mappedName) {
|
||||
return $mappedName;
|
||||
}
|
||||
|
||||
$mappedName = array_search($className, array_flip(self::$classMap));
|
||||
|
||||
if ($mappedName) {
|
||||
return $mappedName;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map PHP class names to ActionScript class names
|
||||
*
|
||||
* Allows users to map the class names of there action script classes
|
||||
* to the equivelent php class name. Used in deserialization to load a class
|
||||
* and serialiation to set the class name of the returned object.
|
||||
*
|
||||
* @param string $asClassName
|
||||
* @param string $phpClassName
|
||||
* @return void
|
||||
*/
|
||||
public static function setMapping($asClassName, $phpClassName)
|
||||
{
|
||||
self::$classMap[$asClassName] = $phpClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset type map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetMap()
|
||||
{
|
||||
self::$classMap = self::$_defaultClassMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set loader for resource type handlers
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface $loader
|
||||
*/
|
||||
public static function setResourceLoader(Zend_Loader_PluginLoader_Interface $loader)
|
||||
{
|
||||
self::$_resourceLoader = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add directory to the list of places where to look for resource handlers
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $dir
|
||||
*/
|
||||
public static function addResourceDirectory($prefix, $dir)
|
||||
{
|
||||
if(self::$_resourceLoader) {
|
||||
self::$_resourceLoader->addPrefixPath($prefix, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin class that handles this resource
|
||||
*
|
||||
* @param resource $resource Resource type
|
||||
* @return string Class name
|
||||
*/
|
||||
public static function getResourceParser($resource)
|
||||
{
|
||||
if(self::$_resourceLoader) {
|
||||
$type = preg_replace("/[^A-Za-z0-9_]/", " ", get_resource_type($resource));
|
||||
$type = str_replace(" ","", ucwords($type));
|
||||
return self::$_resourceLoader->load($type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert resource to a serializable object
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return mixed
|
||||
*/
|
||||
public static function handleResource($resource)
|
||||
{
|
||||
if(!self::$_resourceLoader) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to handle resources - resource plugin loader not set');
|
||||
}
|
||||
try {
|
||||
while(is_resource($resource)) {
|
||||
$resclass = self::getResourceParser($resource);
|
||||
if(!$resclass) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource));
|
||||
}
|
||||
$parser = new $resclass();
|
||||
if(is_callable(array($parser, 'parse'))) {
|
||||
$resource = $parser->parse($resource);
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception("Could not call parse() method on class $resclass");
|
||||
}
|
||||
}
|
||||
return $resource;
|
||||
} catch(Zend_Amf_Exception $e) {
|
||||
throw new Zend_Amf_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
} catch(Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Parse_InputStream */
|
||||
require_once 'Zend/Amf/Parse/InputStream.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Amf0_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Amf0/Deserializer.php';
|
||||
|
||||
/** @see Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Value_MessageHeader */
|
||||
require_once 'Zend/Amf/Value/MessageHeader.php';
|
||||
|
||||
/** @see Zend_Amf_Value_MessageBody */
|
||||
require_once 'Zend/Amf/Value/MessageBody.php';
|
||||
|
||||
/**
|
||||
* Handle the incoming AMF request by deserializing the data to php object
|
||||
* types and storing the data for Zend_Amf_Server to handle for processing.
|
||||
*
|
||||
* @todo Currently not checking if the object needs to be Type Mapped to a server object.
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Request
|
||||
{
|
||||
/**
|
||||
* @var int AMF client type (AMF0, AMF3)
|
||||
*/
|
||||
protected $_clientType = 0; // default AMF0
|
||||
|
||||
/**
|
||||
* @var array Message bodies
|
||||
*/
|
||||
protected $_bodies = array();
|
||||
|
||||
/**
|
||||
* @var array Message headers
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* @var int Message encoding to use for objects in response
|
||||
*/
|
||||
protected $_objectEncoding = 0;
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_InputStream
|
||||
*/
|
||||
protected $_inputStream;
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_AMF0_Deserializer
|
||||
*/
|
||||
protected $_deserializer;
|
||||
|
||||
/**
|
||||
* Time of the request
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_time;
|
||||
|
||||
/**
|
||||
* Prepare the AMF InputStream for parsing.
|
||||
*
|
||||
* @param string $request
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function initialize($request)
|
||||
{
|
||||
$this->_inputStream = new Zend_Amf_Parse_InputStream($request);
|
||||
$this->_deserializer = new Zend_Amf_Parse_Amf0_Deserializer($this->_inputStream);
|
||||
$this->readMessage($this->_inputStream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the raw AMF input stream and converts it into valid PHP objects
|
||||
*
|
||||
* @param Zend_Amf_Parse_InputStream
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function readMessage(Zend_Amf_Parse_InputStream $stream)
|
||||
{
|
||||
$clientVersion = $stream->readUnsignedShort();
|
||||
if (($clientVersion != Zend_Amf_Constants::AMF0_OBJECT_ENCODING)
|
||||
&& ($clientVersion != Zend_Amf_Constants::AMF3_OBJECT_ENCODING)
|
||||
&& ($clientVersion != Zend_Amf_Constants::FMS_OBJECT_ENCODING)
|
||||
) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Player Version ' . $clientVersion);
|
||||
}
|
||||
|
||||
$this->_bodies = array();
|
||||
$this->_headers = array();
|
||||
$headerCount = $stream->readInt();
|
||||
|
||||
// Iterate through the AMF envelope header
|
||||
while ($headerCount--) {
|
||||
$this->_headers[] = $this->readHeader();
|
||||
}
|
||||
|
||||
// Iterate through the AMF envelope body
|
||||
$bodyCount = $stream->readInt();
|
||||
while ($bodyCount--) {
|
||||
$this->_bodies[] = $this->readBody();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a message header from the input stream.
|
||||
*
|
||||
* A message header is structured as:
|
||||
* - NAME String
|
||||
* - MUST UNDERSTAND Boolean
|
||||
* - LENGTH Int
|
||||
* - DATA Object
|
||||
*
|
||||
* @return Zend_Amf_Value_MessageHeader
|
||||
*/
|
||||
public function readHeader()
|
||||
{
|
||||
$name = $this->_inputStream->readUTF();
|
||||
$mustRead = (bool)$this->_inputStream->readByte();
|
||||
$length = $this->_inputStream->readLong();
|
||||
|
||||
try {
|
||||
$data = $this->_deserializer->readTypeMarker();
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to parse ' . $name . ' header data: ' . $e->getMessage() . ' '. $e->getLine(), 0, $e);
|
||||
}
|
||||
|
||||
$header = new Zend_Amf_Value_MessageHeader($name, $mustRead, $data, $length);
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a message body from the input stream
|
||||
*
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function readBody()
|
||||
{
|
||||
$targetURI = $this->_inputStream->readUTF();
|
||||
$responseURI = $this->_inputStream->readUTF();
|
||||
$length = $this->_inputStream->readLong();
|
||||
|
||||
try {
|
||||
$data = $this->_deserializer->readTypeMarker();
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to parse ' . $targetURI . ' body data ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
// Check for AMF3 objectEncoding
|
||||
if ($this->_deserializer->getObjectEncoding() == Zend_Amf_Constants::AMF3_OBJECT_ENCODING) {
|
||||
/*
|
||||
* When and AMF3 message is sent to the server it is nested inside
|
||||
* an AMF0 array called Content. The following code gets the object
|
||||
* out of the content array and sets it as the message data.
|
||||
*/
|
||||
if(is_array($data) && $data[0] instanceof Zend_Amf_Value_Messaging_AbstractMessage){
|
||||
$data = $data[0];
|
||||
}
|
||||
|
||||
// set the encoding so we return our message in AMF3
|
||||
$this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
}
|
||||
|
||||
$body = new Zend_Amf_Value_MessageBody($targetURI, $responseURI, $data);
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the body objects that were found in the amf request.
|
||||
*
|
||||
* @return array {target, response, length, content}
|
||||
*/
|
||||
public function getAmfBodies()
|
||||
{
|
||||
return $this->_bodies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to private array of message bodies.
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageBody $message
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function addAmfBody(Zend_Amf_Value_MessageBody $message)
|
||||
{
|
||||
$this->_bodies[] = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of headers that were found in the amf request.
|
||||
*
|
||||
* @return array {operation, mustUnderstand, length, param}
|
||||
*/
|
||||
public function getAmfHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the either 0 or 3 for respect AMF version
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectEncoding()
|
||||
{
|
||||
return $this->_objectEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object response encoding
|
||||
*
|
||||
* @param mixed $int
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function setObjectEncoding($int)
|
||||
{
|
||||
$this->_objectEncoding = $int;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Request */
|
||||
require_once 'Zend/Amf/Request.php';
|
||||
|
||||
/**
|
||||
* AMF Request object -- Request via HTTP
|
||||
*
|
||||
* Extends {@link Zend_Amf_Request} to accept a request via HTTP. Request is
|
||||
* built at construction time using a raw POST; if no data is available, the
|
||||
* request is declared a fault.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Request_Http extends Zend_Amf_Request
|
||||
{
|
||||
/**
|
||||
* Raw AMF request
|
||||
* @var string
|
||||
*/
|
||||
protected $_rawRequest;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Attempts to read from php://input to get raw POST request; if an error
|
||||
* occurs in doing so, or if the AMF body is invalid, the request is declared a
|
||||
* fault.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// php://input allows you to read raw POST data. It is a less memory
|
||||
// intensive alternative to $HTTP_RAW_POST_DATA and does not need any
|
||||
// special php.ini directives
|
||||
$amfRequest = file_get_contents('php://input');
|
||||
|
||||
// Check to make sure that we have data on the input stream.
|
||||
if ($amfRequest != '') {
|
||||
$this->_rawRequest = $amfRequest;
|
||||
$this->initialize($amfRequest);
|
||||
} else {
|
||||
echo '<p>Zend Amf Endpoint</p>' ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve raw AMF Request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawRequest()
|
||||
{
|
||||
return $this->_rawRequest;
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_OutputStream */
|
||||
require_once 'Zend/Amf/Parse/OutputStream.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Amf0_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Amf0/Serializer.php';
|
||||
|
||||
/**
|
||||
* Handles converting the PHP object ready for response back into AMF
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Response
|
||||
{
|
||||
/**
|
||||
* @var int Object encoding for response
|
||||
*/
|
||||
protected $_objectEncoding = 0;
|
||||
|
||||
/**
|
||||
* Array of Zend_Amf_Value_MessageBody objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_bodies = array();
|
||||
|
||||
/**
|
||||
* Array of Zend_Amf_Value_MessageHeader objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_OutputStream
|
||||
*/
|
||||
protected $_outputStream;
|
||||
|
||||
/**
|
||||
* Instantiate new output stream and start serialization
|
||||
*
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function finalize()
|
||||
{
|
||||
$this->_outputStream = new Zend_Amf_Parse_OutputStream();
|
||||
$this->writeMessage($this->_outputStream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the PHP data types back into Actionscript and
|
||||
* create and AMF stream.
|
||||
*
|
||||
* @param Zend_Amf_Parse_OutputStream $stream
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function writeMessage(Zend_Amf_Parse_OutputStream $stream)
|
||||
{
|
||||
$objectEncoding = $this->_objectEncoding;
|
||||
|
||||
//Write encoding to start of stream. Preamble byte is written of two byte Unsigned Short
|
||||
$stream->writeByte(0x00);
|
||||
$stream->writeByte($objectEncoding);
|
||||
|
||||
// Loop through the AMF Headers that need to be returned.
|
||||
$headerCount = count($this->_headers);
|
||||
$stream->writeInt($headerCount);
|
||||
foreach ($this->getAmfHeaders() as $header) {
|
||||
$serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
|
||||
$stream->writeUTF($header->name);
|
||||
$stream->writeByte($header->mustRead);
|
||||
$stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
|
||||
if (is_object($header->data)) {
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about
|
||||
// "Only variables should be passed by reference"
|
||||
$placeholder = null;
|
||||
$serializer->writeTypeMarker($placeholder, null, $header->data);
|
||||
} else {
|
||||
$serializer->writeTypeMarker($header->data);
|
||||
}
|
||||
}
|
||||
|
||||
// loop through the AMF bodies that need to be returned.
|
||||
$bodyCount = count($this->_bodies);
|
||||
$stream->writeInt($bodyCount);
|
||||
foreach ($this->_bodies as $body) {
|
||||
$serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
|
||||
$stream->writeUTF($body->getTargetURI());
|
||||
$stream->writeUTF($body->getResponseURI());
|
||||
$stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
|
||||
$bodyData = $body->getData();
|
||||
$markerType = ($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) ? null : Zend_Amf_Constants::AMF0_AMF3;
|
||||
if (is_object($bodyData)) {
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about
|
||||
// "Only variables should be passed by reference"
|
||||
$placeholder = null;
|
||||
$serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
|
||||
} else {
|
||||
$serializer->writeTypeMarker($bodyData, $markerType);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the output stream content
|
||||
*
|
||||
* @return string The contents of the output stream
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_outputStream->getStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the output stream content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an AMF body to be sent to the Flash Player
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageBody $body
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function addAmfBody(Zend_Amf_Value_MessageBody $body)
|
||||
{
|
||||
$this->_bodies[] = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of AMF bodies to be serialized
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAmfBodies()
|
||||
{
|
||||
return $this->_bodies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an AMF Header to be sent back to the flash player
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageHeader $header
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function addAmfHeader(Zend_Amf_Value_MessageHeader $header)
|
||||
{
|
||||
$this->_headers[] = $header;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve attached AMF message headers
|
||||
*
|
||||
* @return array Array of Zend_Amf_Value_MessageHeader objects
|
||||
*/
|
||||
public function getAmfHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AMF encoding that will be used for serialization
|
||||
*
|
||||
* @param int $encoding
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function setObjectEncoding($encoding)
|
||||
{
|
||||
$this->_objectEncoding = $encoding;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Response */
|
||||
require_once 'Zend/Amf/Response.php';
|
||||
|
||||
/**
|
||||
* Creates the proper http headers and send the serialized AMF stream to standard out.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Response_Http extends Zend_Amf_Response
|
||||
{
|
||||
/**
|
||||
* Create the application response header for AMF and sends the serialized AMF string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
if (!headers_sent()) {
|
||||
if ($this->isIeOverSsl()) {
|
||||
header('Cache-Control: cache, must-revalidate');
|
||||
header('Pragma: public');
|
||||
} else {
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
|
||||
header('Content-Type: application/x-amf');
|
||||
}
|
||||
return parent::getResponse();
|
||||
}
|
||||
|
||||
protected function isIeOverSsl()
|
||||
{
|
||||
$ssl = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : false;
|
||||
if (!$ssl || ($ssl == 'off')) {
|
||||
// IIS reports "off", whereas other browsers simply don't populate
|
||||
return false;
|
||||
}
|
||||
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
if (!preg_match('/; MSIE \d+\.\d+;/', $ua)) {
|
||||
// Not MicroSoft Internet Explorer
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Server
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Exception */
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Amf_Server_Exception
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Server
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Server_Exception extends Zend_Amf_Exception
|
||||
{
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Util
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class to walk through a data stream byte by byte with conventional names
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Util
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
/**
|
||||
* @var string Byte stream
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* @var int Length of stream
|
||||
*/
|
||||
protected $_streamLength;
|
||||
|
||||
/**
|
||||
* @var bool BigEndian encoding?
|
||||
*/
|
||||
protected $_bigEndian;
|
||||
|
||||
/**
|
||||
* @var int Current position in stream
|
||||
*/
|
||||
protected $_needle;
|
||||
|
||||
/**
|
||||
* @var bool str* functions overloaded using mbstring.func_overload?
|
||||
*/
|
||||
protected $_mbStringFunctionsOverloaded;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Create a reference to a byte stream that is going to be parsed or created
|
||||
* by the methods in the class. Detect if the class should use big or
|
||||
* little Endian encoding.
|
||||
*
|
||||
* @param string $stream use '' if creating a new stream or pass a string if reading.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($stream)
|
||||
{
|
||||
if (!is_string($stream)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Inputdata is not of type String');
|
||||
}
|
||||
|
||||
$this->_stream = $stream;
|
||||
$this->_needle = 0;
|
||||
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
|
||||
$this->_streamLength = $this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream);
|
||||
$this->_bigEndian = (pack('l', 1) === "\x00\x00\x00\x01");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->_stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the number of bytes in a row for the length supplied.
|
||||
*
|
||||
* @todo Should check that there are enough bytes left in the stream we are about to read.
|
||||
* @param int $length
|
||||
* @return string
|
||||
* @throws Zend_Amf_Exception for buffer underrun
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
if (($length + $this->_needle) > $this->_streamLength) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
|
||||
}
|
||||
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, $length, '8bit') : substr($this->_stream, $this->_needle, $length);
|
||||
$this->_needle+= $length;
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write any length of bytes to the stream
|
||||
*
|
||||
* Usually a string.
|
||||
*
|
||||
* @param string $bytes
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeBytes($bytes)
|
||||
{
|
||||
$this->_stream.= $bytes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed byte
|
||||
*
|
||||
* @return int Value is in the range of -128 to 127.
|
||||
* @throws Zend_Amf_Exception
|
||||
*/
|
||||
public function readByte()
|
||||
{
|
||||
if (($this->_needle + 1) > $this->_streamLength) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception(
|
||||
'Buffer underrun at needle position: '
|
||||
. $this->_needle
|
||||
. ' while requesting length: '
|
||||
. $this->_streamLength
|
||||
);
|
||||
}
|
||||
|
||||
return ord($this->_stream{$this->_needle++});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the passed string into a signed byte on the stream.
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeByte($stream)
|
||||
{
|
||||
$this->_stream.= pack('c', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed 32-bit integer from the data stream.
|
||||
*
|
||||
* @return int Value is in the range of -2147483648 to 2147483647
|
||||
*/
|
||||
public function readInt()
|
||||
{
|
||||
return ($this->readByte() << 8) + $this->readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an the integer to the output stream as a 32 bit signed integer
|
||||
*
|
||||
* @param int $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeInt($stream)
|
||||
{
|
||||
$this->_stream.= pack('n', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a UTF-8 string from the data stream
|
||||
*
|
||||
* @return string A UTF-8 string produced by the byte representation of characters
|
||||
*/
|
||||
public function readUtf()
|
||||
{
|
||||
$length = $this->readInt();
|
||||
return $this->readBytes($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wite a UTF-8 string to the outputstream
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeUtf($stream)
|
||||
{
|
||||
$this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
|
||||
$this->_stream.= $stream;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a long UTF string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readLongUtf()
|
||||
{
|
||||
$length = $this->readLong();
|
||||
return $this->readBytes($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a long UTF string to the buffer
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeLongUtf($stream)
|
||||
{
|
||||
$this->writeLong($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
|
||||
$this->_stream.= $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a long numeric value
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function readLong()
|
||||
{
|
||||
return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write long numeric value to output stream
|
||||
*
|
||||
* @param int|string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeLong($stream)
|
||||
{
|
||||
$this->_stream.= pack('N', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 16 bit unsigned short.
|
||||
*
|
||||
* @todo This could use the unpack() w/ S,n, or v
|
||||
* @return double
|
||||
*/
|
||||
public function readUnsignedShort()
|
||||
{
|
||||
$byte1 = $this->readByte();
|
||||
$byte2 = $this->readByte();
|
||||
return (($byte1 << 8) | $byte2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an IEEE 754 double-precision floating point number from the data stream.
|
||||
*
|
||||
* @return double Floating point number
|
||||
*/
|
||||
public function readDouble()
|
||||
{
|
||||
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, 8, '8bit') : substr($this->_stream, $this->_needle, 8);
|
||||
$this->_needle+= 8;
|
||||
|
||||
if (!$this->_bigEndian) {
|
||||
$bytes = strrev($bytes);
|
||||
}
|
||||
|
||||
$double = unpack('dflt', $bytes);
|
||||
return $double['flt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an IEEE 754 double-precision floating point number from the data stream.
|
||||
*
|
||||
* @param string|double $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeDouble($stream)
|
||||
{
|
||||
$stream = pack('d', $stream);
|
||||
if (!$this->_bigEndian) {
|
||||
$stream = strrev($stream);
|
||||
}
|
||||
$this->_stream.= $stream;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrapper class to store an AMF3 flash.utils.ByteArray
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_ByteArray
|
||||
{
|
||||
/**
|
||||
* @var string ByteString Data
|
||||
*/
|
||||
protected $_data = '';
|
||||
|
||||
/**
|
||||
* Create a ByteArray
|
||||
*
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* An AMF Message contains information about the actual individual
|
||||
* transaction that is to be performed. It specifies the remote
|
||||
* operation that is to be performed; a local (client) operation
|
||||
* to be invoked upon success; and, the data to be used in the
|
||||
* operation.
|
||||
* <p/>
|
||||
* This Message structure defines how a local client would
|
||||
* invoke a method/operation on a remote server. Additionally,
|
||||
* the response from the Server is structured identically.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_MessageBody
|
||||
{
|
||||
/**
|
||||
* A string describing which operation, function, or method
|
||||
* is to be remotley invoked.
|
||||
* @var string
|
||||
*/
|
||||
protected $_targetUri = "";
|
||||
|
||||
/**
|
||||
* Universal Resource Identifier that uniquely targets the originator's
|
||||
* Object that should receive the server's response. The server will
|
||||
* use this path specification to target the "OnResult()" or "onStatus()"
|
||||
* handlers within the client. For Flash, it specifies an ActionScript
|
||||
* Object path only. The NetResponse object pointed to by the Response Uri
|
||||
* contains the connection state information. Passing/specifying this
|
||||
* provides a convenient mechanism for the client/server to share access
|
||||
* to an object that is managing the state of the shared connection.
|
||||
*
|
||||
* Since the server will use this field in the event of an error,
|
||||
* this field is required even if a successful server request would
|
||||
* not be expected to return a value to the client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_responseUri = "";
|
||||
|
||||
/**
|
||||
* Contains the actual data associated with the operation. It contains
|
||||
* the client's parameter data that is passed to the server's operation/method.
|
||||
* When serializing a root level data type or a parameter list array, no
|
||||
* name field is included. That is, the data is anonomously represented
|
||||
* as "Type Marker"/"Value" pairs. When serializing member data, the data is
|
||||
* represented as a series of "Name"/"Type"/"Value" combinations.
|
||||
*
|
||||
* For server generated responses, it may contain any ActionScript
|
||||
* data/objects that the server was expected to provide.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $targetUri
|
||||
* @param string $responseUri
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($targetUri, $responseUri, $data)
|
||||
{
|
||||
$this->setTargetUri($targetUri);
|
||||
$this->setResponseUri($responseUri);
|
||||
$this->setData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve target Uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetUri()
|
||||
{
|
||||
return $this->_targetUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set target Uri
|
||||
*
|
||||
* @param string $targetUri
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setTargetUri($targetUri)
|
||||
{
|
||||
if (null === $targetUri) {
|
||||
$targetUri = '';
|
||||
}
|
||||
$this->_targetUri = (string) $targetUri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target Uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseUri()
|
||||
{
|
||||
return $this->_responseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response Uri
|
||||
*
|
||||
* @param string $responseUri
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setResponseUri($responseUri)
|
||||
{
|
||||
if (null === $responseUri) {
|
||||
$responseUri = '';
|
||||
}
|
||||
$this->_responseUri = $responseUri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve response data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response data
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set reply method
|
||||
*
|
||||
* @param string $methodName
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setReplyMethod($methodName)
|
||||
{
|
||||
if (!preg_match('#^[/?]#', $methodName)) {
|
||||
$this->_targetUri = rtrim($this->_targetUri, '/') . '/';
|
||||
}
|
||||
$this->_targetUri = $this->_targetUri . $methodName;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message Headers provide context for the processing of the
|
||||
* the AMF Packet and all subsequent Messages.
|
||||
*
|
||||
* Multiple Message Headers may be included within an AMF Packet.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_MessageHeader
|
||||
{
|
||||
/**
|
||||
* Name of the header
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Flag if the data has to be parsed on return
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $mustRead;
|
||||
|
||||
/**
|
||||
* Length of the data field
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* Data sent with the header name
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Used to create and store AMF Header data.
|
||||
*
|
||||
* @param String $name
|
||||
* @param Boolean $mustRead
|
||||
* @param misc $content
|
||||
* @param integer $length
|
||||
*/
|
||||
public function __construct($name, $mustRead, $data, $length=null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->mustRead = (bool) $mustRead;
|
||||
$this->data = $data;
|
||||
if (null !== $length) {
|
||||
$this->length = (int) $length;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the default Implementation of Message, which provides
|
||||
* a convenient base for behavior and association of common endpoints
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
/**
|
||||
* @var string Client identifier
|
||||
*/
|
||||
public $clientId;
|
||||
|
||||
/**
|
||||
* @var string Destination
|
||||
*/
|
||||
public $destination;
|
||||
|
||||
/**
|
||||
* @var string Message identifier
|
||||
*/
|
||||
public $messageId;
|
||||
|
||||
/**
|
||||
* @var int Message timestamp
|
||||
*/
|
||||
public $timestamp;
|
||||
|
||||
/**
|
||||
* @var int Message TTL
|
||||
*/
|
||||
public $timeToLive;
|
||||
|
||||
/**
|
||||
* @var object Message headers
|
||||
*/
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* @var string Message body
|
||||
*/
|
||||
public $body;
|
||||
|
||||
/**
|
||||
* generate a unique id
|
||||
*
|
||||
* Format is: ########-####-####-####-############
|
||||
* Where # is an uppercase letter or number
|
||||
* example: 6D9DC7EC-A273-83A9-ABE3-00005FD752D6
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateId()
|
||||
{
|
||||
return sprintf(
|
||||
'%08X-%04X-%04X-%02X%02X-%012X',
|
||||
mt_rand(),
|
||||
mt_rand(0, 65535),
|
||||
bindec(substr_replace(
|
||||
sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
|
||||
),
|
||||
bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)),
|
||||
mt_rand(0, 255),
|
||||
mt_rand()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AsyncMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
|
||||
/**
|
||||
* This is the type of message returned by the MessageBroker
|
||||
* to endpoints after the broker has routed an endpoint's message
|
||||
* to a service.
|
||||
*
|
||||
* flex.messaging.messages.AcknowledgeMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AcknowledgeMessage extends Zend_Amf_Value_Messaging_AsyncMessage
|
||||
{
|
||||
/**
|
||||
* Create a new Acknowledge Message
|
||||
*
|
||||
* @param unknown_type $message
|
||||
*/
|
||||
public function __construct($message)
|
||||
{
|
||||
$this->clientId = $this->generateId();
|
||||
$this->destination = null;
|
||||
$this->messageId = $this->generateId();
|
||||
$this->timestamp = time().'00';
|
||||
$this->timeToLive = 0;
|
||||
$this->headers = new STDClass();
|
||||
$this->body = null;
|
||||
|
||||
// correleate the two messages
|
||||
if ($message && isset($message->messageId)) {
|
||||
$this->correlationId = $message->messageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Type encapsulating Flex ArrayCollection
|
||||
*
|
||||
* Corresponds to flex.messaging.io.ArrayCollection
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_ArrayCollection extends ArrayObject
|
||||
{
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AbstractMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
|
||||
|
||||
/**
|
||||
* This type of message contains information necessary to perform
|
||||
* point-to-point or publish-subscribe messaging.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AsyncMessage extends Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
/**
|
||||
* The message id to be responded to.
|
||||
* @var String
|
||||
*/
|
||||
public $correlationId;
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AsyncMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
|
||||
/**
|
||||
* A message that represents an infrastructure command passed between
|
||||
* client and server. Subscribe/unsubscribe operations result in
|
||||
* CommandMessage transmissions, as do polling operations.
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.CommandMessage
|
||||
*
|
||||
* Note: THESE VALUES MUST BE THE SAME ON CLIENT AND SERVER
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_CommandMessage extends Zend_Amf_Value_Messaging_AsyncMessage
|
||||
{
|
||||
/**
|
||||
* This operation is used to subscribe to a remote destination.
|
||||
*/
|
||||
const SUBSCRIBE_OPERATION = 0;
|
||||
|
||||
/**
|
||||
* This operation is used to unsubscribe from a remote destination.
|
||||
*/
|
||||
const UNSUSBSCRIBE_OPERATION = 1;
|
||||
|
||||
/**
|
||||
* This operation is used to poll a remote destination for pending,
|
||||
* undelivered messages.
|
||||
*/
|
||||
const POLL_OPERATION = 2;
|
||||
|
||||
/**
|
||||
* This operation is used by a remote destination to sync missed or cached messages
|
||||
* back to a client as a result of a client issued poll command.
|
||||
*/
|
||||
const CLIENT_SYNC_OPERATION = 4;
|
||||
|
||||
/**
|
||||
* This operation is used to test connectivity over the current channel to
|
||||
* the remote endpoint.
|
||||
*/
|
||||
const CLIENT_PING_OPERATION = 5;
|
||||
|
||||
/**
|
||||
* This operation is used to request a list of failover endpoint URIs
|
||||
* for the remote destination based on cluster membership.
|
||||
*/
|
||||
const CLUSTER_REQUEST_OPERATION = 7;
|
||||
|
||||
/**
|
||||
* This operation is used to send credentials to the endpoint so that
|
||||
* the user can be logged in over the current channel.
|
||||
* The credentials need to be Base64 encoded and stored in the <code>body</code>
|
||||
* of the message.
|
||||
*/
|
||||
const LOGIN_OPERATION = 8;
|
||||
|
||||
/**
|
||||
* This operation is used to log the user out of the current channel, and
|
||||
* will invalidate the server session if the channel is HTTP based.
|
||||
*/
|
||||
const LOGOUT_OPERATION = 9;
|
||||
|
||||
/**
|
||||
* This operation is used to indicate that the client's subscription to a
|
||||
* remote destination has been invalidated.
|
||||
*/
|
||||
const SESSION_INVALIDATE_OPERATION = 10;
|
||||
|
||||
/**
|
||||
* This operation is used by the MultiTopicConsumer to subscribe/unsubscribe
|
||||
* from multiple subtopics/selectors in the same message.
|
||||
*/
|
||||
const MULTI_SUBSCRIBE_OPERATION = 11;
|
||||
|
||||
/**
|
||||
* This operation is used to indicate that a channel has disconnected
|
||||
*/
|
||||
const DISCONNECT_OPERATION = 12;
|
||||
|
||||
/**
|
||||
* This is the default operation for new CommandMessage instances.
|
||||
*/
|
||||
const UNKNOWN_OPERATION = 10000;
|
||||
|
||||
/**
|
||||
* The operation to execute for messages of this type
|
||||
* @var int
|
||||
*/
|
||||
public $operation = self::UNKNOWN_OPERATION;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Value_Messaging_AcknowledgeMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
|
||||
|
||||
/**
|
||||
* Creates the error message to report to flex the issue with the call
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.ErrorMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_ErrorMessage extends Zend_Amf_Value_Messaging_AcknowledgeMessage
|
||||
{
|
||||
/**
|
||||
* Additional data with error
|
||||
* @var object
|
||||
*/
|
||||
public $extendedData = null;
|
||||
|
||||
/**
|
||||
* Error code number
|
||||
* @var string
|
||||
*/
|
||||
public $faultCode;
|
||||
|
||||
/**
|
||||
* Description as to the cause of the error
|
||||
* @var string
|
||||
*/
|
||||
public $faultDetail;
|
||||
|
||||
/**
|
||||
* Short description of error
|
||||
* @var string
|
||||
*/
|
||||
public $faultString = '';
|
||||
|
||||
/**
|
||||
* root cause of error
|
||||
* @var object
|
||||
*/
|
||||
public $rootCause = null;
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AbstractMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
|
||||
|
||||
/**
|
||||
* This type of message contains information needed to perform
|
||||
* a Remoting invocation.
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.RemotingMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_RemotingMessage extends Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the service to be called including package name
|
||||
* @var String
|
||||
*/
|
||||
public $source;
|
||||
|
||||
/**
|
||||
* The name of the method to be called
|
||||
* @var string
|
||||
*/
|
||||
public $operation;
|
||||
|
||||
/**
|
||||
* The arguments to call the mathod with
|
||||
* @var array
|
||||
*/
|
||||
public $parameters;
|
||||
|
||||
/**
|
||||
* Create a new Remoting Message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->clientId = $this->generateId();
|
||||
$this->destination = null;
|
||||
$this->messageId = $this->generateId();
|
||||
$this->timestamp = time().'00';
|
||||
$this->timeToLive = 0;
|
||||
$this->headers = new stdClass();
|
||||
$this->body = null;
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Amf_Value_TraitsInfo
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_TraitsInfo
|
||||
{
|
||||
/**
|
||||
* @var string Class name
|
||||
*/
|
||||
protected $_className;
|
||||
|
||||
/**
|
||||
* @var bool Whether or not this is a dynamic class
|
||||
*/
|
||||
protected $_dynamic;
|
||||
|
||||
/**
|
||||
* @var bool Whether or not the class is externalizable
|
||||
*/
|
||||
protected $_externalizable;
|
||||
|
||||
/**
|
||||
* @var array Class properties
|
||||
*/
|
||||
protected $_properties;
|
||||
|
||||
/**
|
||||
* Used to keep track of all class traits of an AMF3 object
|
||||
*
|
||||
* @param string $className
|
||||
* @param boolean $dynamic
|
||||
* @param boolean $externalizable
|
||||
* @param boolean $properties
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($className, $dynamic=false, $externalizable=false, $properties=null)
|
||||
{
|
||||
$this->_className = $className;
|
||||
$this->_dynamic = $dynamic;
|
||||
$this->_externalizable = $externalizable;
|
||||
$this->_properties = $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the class is a dynamic class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDynamic()
|
||||
{
|
||||
return $this->_dynamic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if class is externalizable
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExternalizable()
|
||||
{
|
||||
return $this->_externalizable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of properties in the class
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function length()
|
||||
{
|
||||
return count($this->_properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->_className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an additional property
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Amf_Value_TraitsInfo
|
||||
*/
|
||||
public function addProperty($name)
|
||||
{
|
||||
$this->_properties[] = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all properties of the class.
|
||||
*
|
||||
* @param array $props
|
||||
* @return Zend_Amf_Value_TraitsInfo
|
||||
*/
|
||||
public function addAllProperties(array $props)
|
||||
{
|
||||
$this->_properties = $props;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property at a given index
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty($index)
|
||||
{
|
||||
return $this->_properties[(int) $index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all properties of the class.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllProperties()
|
||||
{
|
||||
return $this->_properties;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth
|
||||
{
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* @var Zend_Auth
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Persistent storage handler
|
||||
*
|
||||
* @var Zend_Auth_Storage_Interface
|
||||
*/
|
||||
protected $_storage = null;
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "new" unavailable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "clone" unavailable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __clone()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Returns an instance of Zend_Auth
|
||||
*
|
||||
* Singleton pattern implementation
|
||||
*
|
||||
* @return Zend_Auth Provides a fluent interface
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === self::$_instance) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistent storage handler
|
||||
*
|
||||
* Session storage is used by default unless a different storage adapter has been set.
|
||||
*
|
||||
* @return Zend_Auth_Storage_Interface
|
||||
*/
|
||||
public function getStorage()
|
||||
{
|
||||
if (null === $this->_storage) {
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Session
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Session.php';
|
||||
$this->setStorage(new Zend_Auth_Storage_Session());
|
||||
}
|
||||
|
||||
return $this->_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the persistent storage handler
|
||||
*
|
||||
* @param Zend_Auth_Storage_Interface $storage
|
||||
* @return Zend_Auth Provides a fluent interface
|
||||
*/
|
||||
public function setStorage(Zend_Auth_Storage_Interface $storage)
|
||||
{
|
||||
$this->_storage = $storage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates against the supplied adapter
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Interface $adapter
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate(Zend_Auth_Adapter_Interface $adapter)
|
||||
{
|
||||
$result = $adapter->authenticate();
|
||||
|
||||
/**
|
||||
* ZF-7546 - prevent multiple succesive calls from storing inconsistent results
|
||||
* Ensure storage has clean state
|
||||
*/
|
||||
if ($this->hasIdentity()) {
|
||||
$this->clearIdentity();
|
||||
}
|
||||
|
||||
if ($result->isValid()) {
|
||||
$this->getStorage()->write($result->getIdentity());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if an identity is available from storage
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasIdentity()
|
||||
{
|
||||
return !$this->getStorage()->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity from storage or null if no identity is available
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getIdentity()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
|
||||
if ($storage->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $storage->read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the identity from persistent storage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearIdentity()
|
||||
{
|
||||
$this->getStorage()->clear();
|
||||
}
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Filename against which authentication queries are performed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_filename;
|
||||
|
||||
/**
|
||||
* Digest authentication realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_realm;
|
||||
|
||||
/**
|
||||
* Digest authentication user
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_username;
|
||||
|
||||
/**
|
||||
* Password for the user of the realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_password;
|
||||
|
||||
/**
|
||||
* Sets adapter options
|
||||
*
|
||||
* @param mixed $filename
|
||||
* @param mixed $realm
|
||||
* @param mixed $username
|
||||
* @param mixed $password
|
||||
*/
|
||||
public function __construct($filename = null, $realm = null, $username = null, $password = null)
|
||||
{
|
||||
$options = array('filename', 'realm', 'username', 'password');
|
||||
foreach ($options as $option) {
|
||||
if (null !== $$option) {
|
||||
$methodName = 'set' . ucfirst($option);
|
||||
$this->$methodName($$option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename option value
|
||||
*
|
||||
* @param mixed $filename
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->_filename = (string) $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the realm option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->_realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the realm option value
|
||||
*
|
||||
* @param mixed $realm
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->_realm = (string) $realm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username option value
|
||||
*
|
||||
* @param mixed $username
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->_username = (string) $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password option value
|
||||
*
|
||||
* @param mixed $password
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->_password = (string) $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Adapter_Interface
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$optionsRequired = array('filename', 'realm', 'username', 'password');
|
||||
foreach ($optionsRequired as $optionRequired) {
|
||||
if (null === $this->{"_$optionRequired"}) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception("Option '$optionRequired' must be set before authentication");
|
||||
}
|
||||
}
|
||||
|
||||
if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception("Cannot open '$this->_filename' for reading");
|
||||
}
|
||||
|
||||
$id = "$this->_username:$this->_realm";
|
||||
$idLength = strlen($id);
|
||||
|
||||
$result = array(
|
||||
'code' => Zend_Auth_Result::FAILURE,
|
||||
'identity' => array(
|
||||
'realm' => $this->_realm,
|
||||
'username' => $this->_username,
|
||||
),
|
||||
'messages' => array()
|
||||
);
|
||||
|
||||
while ($line = trim(fgets($fileHandle))) {
|
||||
if (substr($line, 0, $idLength) === $id) {
|
||||
if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) {
|
||||
$result['code'] = Zend_Auth_Result::SUCCESS;
|
||||
} else {
|
||||
$result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
|
||||
$result['messages'][] = 'Password incorrect';
|
||||
}
|
||||
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
|
||||
}
|
||||
}
|
||||
|
||||
$result['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
|
||||
$result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found";
|
||||
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Securely compare two strings for equality while avoided C level memcmp()
|
||||
* optimisations capable of leaking timing information useful to an attacker
|
||||
* attempting to iteratively guess the unknown string (e.g. password) being
|
||||
* compared against.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return bool
|
||||
*/
|
||||
protected function _secureStringCompare($a, $b)
|
||||
{
|
||||
if (strlen($a) !== strlen($b)) {
|
||||
return false;
|
||||
}
|
||||
$result = 0;
|
||||
for ($i = 0; $i < strlen($a); $i++) {
|
||||
$result |= ord($a[$i]) ^ ord($b[$i]);
|
||||
}
|
||||
return $result == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
@@ -1,868 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Authentication Adapter
|
||||
*
|
||||
* Implements a pretty good chunk of RFC 2617.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @todo Support auth-int
|
||||
* @todo Track nonces, nonce-count, opaque for replay protection and stale support
|
||||
* @todo Support Authentication-Info header
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Reference to the HTTP Request object
|
||||
*
|
||||
* @var Zend_Controller_Request_Http
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* Reference to the HTTP Response object
|
||||
*
|
||||
* @var Zend_Controller_Response_Http
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* Object that looks up user credentials for the Basic scheme
|
||||
*
|
||||
* @var Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
protected $_basicResolver;
|
||||
|
||||
/**
|
||||
* Object that looks up user credentials for the Digest scheme
|
||||
*
|
||||
* @var Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
protected $_digestResolver;
|
||||
|
||||
/**
|
||||
* List of authentication schemes supported by this class
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedSchemes = array('basic', 'digest');
|
||||
|
||||
/**
|
||||
* List of schemes this class will accept from the client
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_acceptSchemes;
|
||||
|
||||
/**
|
||||
* Space-delimited list of protected domains for Digest Auth
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_domains;
|
||||
|
||||
/**
|
||||
* The protection realm to use
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_realm;
|
||||
|
||||
/**
|
||||
* Nonce timeout period
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_nonceTimeout;
|
||||
|
||||
/**
|
||||
* Whether to send the opaque value in the header. True by default
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useOpaque;
|
||||
|
||||
/**
|
||||
* List of the supported digest algorithms. I want to support both MD5 and
|
||||
* MD5-sess, but MD5-sess won't make it into the first version.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedAlgos = array('MD5');
|
||||
|
||||
/**
|
||||
* The actual algorithm to use. Defaults to MD5
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_algo;
|
||||
|
||||
/**
|
||||
* List of supported qop options. My intetion is to support both 'auth' and
|
||||
* 'auth-int', but 'auth-int' won't make it into the first version.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedQops = array('auth');
|
||||
|
||||
/**
|
||||
* Whether or not to do Proxy Authentication instead of origin server
|
||||
* authentication (send 407's instead of 401's). Off by default.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_imaProxy;
|
||||
|
||||
/**
|
||||
* Flag indicating the client is IE and didn't bother to return the opaque string
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_ieNoOpaque;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config Configuration settings:
|
||||
* 'accept_schemes' => 'basic'|'digest'|'basic digest'
|
||||
* 'realm' => <string>
|
||||
* 'digest_domains' => <string> Space-delimited list of URIs
|
||||
* 'nonce_timeout' => <int>
|
||||
* 'use_opaque' => <bool> Whether to send the opaque value in the header
|
||||
* 'alogrithm' => <string> See $_supportedAlgos. Default: MD5
|
||||
* 'proxy_auth' => <bool> Whether to do authentication as a Proxy
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
if (!extension_loaded('hash')) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception(__CLASS__ . ' requires the \'hash\' extension');
|
||||
}
|
||||
|
||||
$this->_request = null;
|
||||
$this->_response = null;
|
||||
$this->_ieNoOpaque = false;
|
||||
|
||||
|
||||
if (empty($config['accept_schemes'])) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'accept_schemes\' is required');
|
||||
}
|
||||
|
||||
$schemes = explode(' ', $config['accept_schemes']);
|
||||
$this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes);
|
||||
if (empty($this->_acceptSchemes)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('No supported schemes given in \'accept_schemes\'. Valid values: '
|
||||
. implode(', ', $this->_supportedSchemes));
|
||||
}
|
||||
|
||||
// Double-quotes are used to delimit the realm string in the HTTP header,
|
||||
// and colons are field delimiters in the password file.
|
||||
if (empty($config['realm']) ||
|
||||
!ctype_print($config['realm']) ||
|
||||
strpos($config['realm'], ':') !== false ||
|
||||
strpos($config['realm'], '"') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'realm\' is required, and must contain only printable '
|
||||
. 'characters, excluding quotation marks and colons');
|
||||
} else {
|
||||
$this->_realm = $config['realm'];
|
||||
}
|
||||
|
||||
if (in_array('digest', $this->_acceptSchemes)) {
|
||||
if (empty($config['digest_domains']) ||
|
||||
!ctype_print($config['digest_domains']) ||
|
||||
strpos($config['digest_domains'], '"') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'digest_domains\' is required, and must contain '
|
||||
. 'only printable characters, excluding quotation marks');
|
||||
} else {
|
||||
$this->_domains = $config['digest_domains'];
|
||||
}
|
||||
|
||||
if (empty($config['nonce_timeout']) ||
|
||||
!is_numeric($config['nonce_timeout'])) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'nonce_timeout\' is required, and must be an '
|
||||
. 'integer');
|
||||
} else {
|
||||
$this->_nonceTimeout = (int) $config['nonce_timeout'];
|
||||
}
|
||||
|
||||
// We use the opaque value unless explicitly told not to
|
||||
if (isset($config['use_opaque']) && false == (bool) $config['use_opaque']) {
|
||||
$this->_useOpaque = false;
|
||||
} else {
|
||||
$this->_useOpaque = true;
|
||||
}
|
||||
|
||||
if (isset($config['algorithm']) && in_array($config['algorithm'], $this->_supportedAlgos)) {
|
||||
$this->_algo = $config['algorithm'];
|
||||
} else {
|
||||
$this->_algo = 'MD5';
|
||||
}
|
||||
}
|
||||
|
||||
// Don't be a proxy unless explicitly told to do so
|
||||
if (isset($config['proxy_auth']) && true == (bool) $config['proxy_auth']) {
|
||||
$this->_imaProxy = true; // I'm a Proxy
|
||||
} else {
|
||||
$this->_imaProxy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the _basicResolver property
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setBasicResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
|
||||
{
|
||||
$this->_basicResolver = $resolver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _basicResolver property
|
||||
*
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
public function getBasicResolver()
|
||||
{
|
||||
return $this->_basicResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the _digestResolver property
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setDigestResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
|
||||
{
|
||||
$this->_digestResolver = $resolver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _digestResolver property
|
||||
*
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
public function getDigestResolver()
|
||||
{
|
||||
return $this->_digestResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Request object
|
||||
*
|
||||
* @param Zend_Controller_Request_Http $request
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Http $request)
|
||||
{
|
||||
$this->_request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Http
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Response object
|
||||
*
|
||||
* @param Zend_Controller_Response_Http $response
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Http $response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Http
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
if (empty($this->_request) ||
|
||||
empty($this->_response)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling '
|
||||
. 'authenticate()');
|
||||
}
|
||||
|
||||
if ($this->_imaProxy) {
|
||||
$getHeader = 'Proxy-Authorization';
|
||||
} else {
|
||||
$getHeader = 'Authorization';
|
||||
}
|
||||
|
||||
$authHeader = $this->_request->getHeader($getHeader);
|
||||
if (!$authHeader) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
list($clientScheme) = explode(' ', $authHeader);
|
||||
$clientScheme = strtolower($clientScheme);
|
||||
|
||||
// The server can issue multiple challenges, but the client should
|
||||
// answer with only the selected auth scheme.
|
||||
if (!in_array($clientScheme, $this->_supportedSchemes)) {
|
||||
$this->_response->setHttpResponseCode(400);
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
|
||||
array(),
|
||||
array('Client requested an incorrect or unsupported authentication scheme')
|
||||
);
|
||||
}
|
||||
|
||||
// client sent a scheme that is not the one required
|
||||
if (!in_array($clientScheme, $this->_acceptSchemes)) {
|
||||
// challenge again the client
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
switch ($clientScheme) {
|
||||
case 'basic':
|
||||
$result = $this->_basicAuth($authHeader);
|
||||
break;
|
||||
case 'digest':
|
||||
$result = $this->_digestAuth($authHeader);
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Unsupported authentication scheme');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Challenge Client
|
||||
*
|
||||
* Sets a 401 or 407 Unauthorized response code, and creates the
|
||||
* appropriate Authenticate header(s) to prompt for credentials.
|
||||
*
|
||||
* @return Zend_Auth_Result Always returns a non-identity Auth result
|
||||
*/
|
||||
protected function _challengeClient()
|
||||
{
|
||||
if ($this->_imaProxy) {
|
||||
$statusCode = 407;
|
||||
$headerName = 'Proxy-Authenticate';
|
||||
} else {
|
||||
$statusCode = 401;
|
||||
$headerName = 'WWW-Authenticate';
|
||||
}
|
||||
|
||||
$this->_response->setHttpResponseCode($statusCode);
|
||||
|
||||
// Send a challenge in each acceptable authentication scheme
|
||||
if (in_array('basic', $this->_acceptSchemes)) {
|
||||
$this->_response->setHeader($headerName, $this->_basicHeader());
|
||||
}
|
||||
if (in_array('digest', $this->_acceptSchemes)) {
|
||||
$this->_response->setHeader($headerName, $this->_digestHeader());
|
||||
}
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
array(),
|
||||
array('Invalid or absent credentials; challenging client')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Header
|
||||
*
|
||||
* Generates a Proxy- or WWW-Authenticate header value in the Basic
|
||||
* authentication scheme.
|
||||
*
|
||||
* @return string Authenticate header value
|
||||
*/
|
||||
protected function _basicHeader()
|
||||
{
|
||||
return 'Basic realm="' . $this->_realm . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Digest Header
|
||||
*
|
||||
* Generates a Proxy- or WWW-Authenticate header value in the Digest
|
||||
* authentication scheme.
|
||||
*
|
||||
* @return string Authenticate header value
|
||||
*/
|
||||
protected function _digestHeader()
|
||||
{
|
||||
$wwwauth = 'Digest realm="' . $this->_realm . '", '
|
||||
. 'domain="' . $this->_domains . '", '
|
||||
. 'nonce="' . $this->_calcNonce() . '", '
|
||||
. ($this->_useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '')
|
||||
. 'algorithm="' . $this->_algo . '", '
|
||||
. 'qop="' . implode(',', $this->_supportedQops) . '"';
|
||||
|
||||
return $wwwauth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Authentication
|
||||
*
|
||||
* @param string $header Client's Authorization header
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
protected function _basicAuth($header)
|
||||
{
|
||||
if (empty($header)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
|
||||
}
|
||||
if (empty($this->_basicResolver)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('A basicResolver object must be set before doing Basic '
|
||||
. 'authentication');
|
||||
}
|
||||
|
||||
// Decode the Authorization header
|
||||
$auth = substr($header, strlen('Basic '));
|
||||
$auth = base64_decode($auth);
|
||||
if (!$auth) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Unable to base64_decode Authorization header value');
|
||||
}
|
||||
|
||||
// See ZF-1253. Validate the credentials the same way the digest
|
||||
// implementation does. If invalid credentials are detected,
|
||||
// re-challenge the client.
|
||||
if (!ctype_print($auth)) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
// Fix for ZF-1515: Now re-challenges on empty username or password
|
||||
$creds = array_filter(explode(':', $auth));
|
||||
if (count($creds) != 2) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
$password = $this->_basicResolver->resolve($creds[0], $this->_realm);
|
||||
if ($password && $this->_secureStringCompare($password, $creds[1])) {
|
||||
$identity = array('username'=>$creds[0], 'realm'=>$this->_realm);
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} else {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Digest Authentication
|
||||
*
|
||||
* @param string $header Client's Authorization header
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result Valid auth result only on successful auth
|
||||
*/
|
||||
protected function _digestAuth($header)
|
||||
{
|
||||
if (empty($header)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
|
||||
}
|
||||
if (empty($this->_digestResolver)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('A digestResolver object must be set before doing Digest authentication');
|
||||
}
|
||||
|
||||
$data = $this->_parseDigestAuth($header);
|
||||
if ($data === false) {
|
||||
$this->_response->setHttpResponseCode(400);
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
|
||||
array(),
|
||||
array('Invalid Authorization header format')
|
||||
);
|
||||
}
|
||||
|
||||
// See ZF-1052. This code was a bit too unforgiving of invalid
|
||||
// usernames. Now, if the username is bad, we re-challenge the client.
|
||||
if ('::invalid::' == $data['username']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// Verify that the client sent back the same nonce
|
||||
if ($this->_calcNonce() != $data['nonce']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
// The opaque value is also required to match, but of course IE doesn't
|
||||
// play ball.
|
||||
if (!$this->_ieNoOpaque && $this->_calcOpaque() != $data['opaque']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// Look up the user's password hash. If not found, deny access.
|
||||
// This makes no assumptions about how the password hash was
|
||||
// constructed beyond that it must have been built in such a way as
|
||||
// to be recreatable with the current settings of this object.
|
||||
$ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']);
|
||||
if ($ha1 === false) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// If MD5-sess is used, a1 value is made of the user's password
|
||||
// hash with the server and client nonce appended, separated by
|
||||
// colons.
|
||||
if ($this->_algo == 'MD5-sess') {
|
||||
$ha1 = hash('md5', $ha1 . ':' . $data['nonce'] . ':' . $data['cnonce']);
|
||||
}
|
||||
|
||||
// Calculate h(a2). The value of this hash depends on the qop
|
||||
// option selected by the client and the supported hash functions
|
||||
switch ($data['qop']) {
|
||||
case 'auth':
|
||||
$a2 = $this->_request->getMethod() . ':' . $data['uri'];
|
||||
break;
|
||||
case 'auth-int':
|
||||
// Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body),
|
||||
// but this isn't supported yet, so fall through to default case
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Client requested an unsupported qop option');
|
||||
}
|
||||
// Using hash() should make parameterizing the hash algorithm
|
||||
// easier
|
||||
$ha2 = hash('md5', $a2);
|
||||
|
||||
|
||||
// Calculate the server's version of the request-digest. This must
|
||||
// match $data['response']. See RFC 2617, section 3.2.2.1
|
||||
$message = $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $ha2;
|
||||
$digest = hash('md5', $ha1 . ':' . $message);
|
||||
|
||||
// If our digest matches the client's let them in, otherwise return
|
||||
// a 401 code and exit to prevent access to the protected resource.
|
||||
if ($this->_secureStringCompare($digest, $data['response'])) {
|
||||
$identity = array('username'=>$data['username'], 'realm'=>$data['realm']);
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} else {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Nonce
|
||||
*
|
||||
* @return string The nonce value
|
||||
*/
|
||||
protected function _calcNonce()
|
||||
{
|
||||
// Once subtle consequence of this timeout calculation is that it
|
||||
// actually divides all of time into _nonceTimeout-sized sections, such
|
||||
// that the value of timeout is the point in time of the next
|
||||
// approaching "boundary" of a section. This allows the server to
|
||||
// consistently generate the same timeout (and hence the same nonce
|
||||
// value) across requests, but only as long as one of those
|
||||
// "boundaries" is not crossed between requests. If that happens, the
|
||||
// nonce will change on its own, and effectively log the user out. This
|
||||
// would be surprising if the user just logged in.
|
||||
$timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout;
|
||||
|
||||
$nonce = hash('md5', $timeout . ':' . $this->_request->getServer('HTTP_USER_AGENT') . ':' . __CLASS__);
|
||||
return $nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Opaque
|
||||
*
|
||||
* The opaque string can be anything; the client must return it exactly as
|
||||
* it was sent. It may be useful to store data in this string in some
|
||||
* applications. Ideally, a new value for this would be generated each time
|
||||
* a WWW-Authenticate header is sent (in order to reduce predictability),
|
||||
* but we would have to be able to create the same exact value across at
|
||||
* least two separate requests from the same client.
|
||||
*
|
||||
* @return string The opaque value
|
||||
*/
|
||||
protected function _calcOpaque()
|
||||
{
|
||||
return hash('md5', 'Opaque Data:' . __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Digest Authorization header
|
||||
*
|
||||
* @param string $header Client's Authorization: HTTP header
|
||||
* @return array|false Data elements from header, or false if any part of
|
||||
* the header is invalid
|
||||
*/
|
||||
protected function _parseDigestAuth($header)
|
||||
{
|
||||
$temp = null;
|
||||
$data = array();
|
||||
|
||||
// See ZF-1052. Detect invalid usernames instead of just returning a
|
||||
// 400 code.
|
||||
$ret = preg_match('/username="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])
|
||||
|| !ctype_print($temp[1])
|
||||
|| strpos($temp[1], ':') !== false) {
|
||||
$data['username'] = '::invalid::';
|
||||
} else {
|
||||
$data['username'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/realm="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_print($temp[1]) || strpos($temp[1], ':') !== false) {
|
||||
return false;
|
||||
} else {
|
||||
$data['realm'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/nonce="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['nonce'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/uri="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
// Section 3.2.2.5 in RFC 2617 says the authenticating server must
|
||||
// verify that the URI field in the Authorization header is for the
|
||||
// same resource requested in the Request Line.
|
||||
$rUri = @parse_url($this->_request->getRequestUri());
|
||||
$cUri = @parse_url($temp[1]);
|
||||
if (false === $rUri || false === $cUri) {
|
||||
return false;
|
||||
} else {
|
||||
// Make sure the path portion of both URIs is the same
|
||||
if ($rUri['path'] != $cUri['path']) {
|
||||
return false;
|
||||
}
|
||||
// Section 3.2.2.5 seems to suggest that the value of the URI
|
||||
// Authorization field should be made into an absolute URI if the
|
||||
// Request URI is absolute, but it's vague, and that's a bunch of
|
||||
// code I don't want to write right now.
|
||||
$data['uri'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/response="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (32 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['response'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// The spec says this should default to MD5 if omitted. OK, so how does
|
||||
// that square with the algo we send out in the WWW-Authenticate header,
|
||||
// if it can easily be overridden by the client?
|
||||
$ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp);
|
||||
if ($ret && !empty($temp[1])
|
||||
&& in_array($temp[1], $this->_supportedAlgos)) {
|
||||
$data['algorithm'] = $temp[1];
|
||||
} else {
|
||||
$data['algorithm'] = 'MD5'; // = $this->_algo; ?
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// Not optional in this implementation
|
||||
$ret = preg_match('/cnonce="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_print($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['cnonce'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// If the server sent an opaque value, the client must send it back
|
||||
if ($this->_useOpaque) {
|
||||
$ret = preg_match('/opaque="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
|
||||
// Big surprise: IE isn't RFC 2617-compliant.
|
||||
if (false !== strpos($this->_request->getHeader('User-Agent'), 'MSIE')) {
|
||||
$temp[1] = '';
|
||||
$this->_ieNoOpaque = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// This implementation only sends MD5 hex strings in the opaque value
|
||||
if (!$this->_ieNoOpaque &&
|
||||
(32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) {
|
||||
return false;
|
||||
} else {
|
||||
$data['opaque'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
}
|
||||
|
||||
// Not optional in this implementation, but must be one of the supported
|
||||
// qop types
|
||||
$ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($temp[1], $this->_supportedQops)) {
|
||||
return false;
|
||||
} else {
|
||||
$data['qop'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// Not optional in this implementation. The spec says this value
|
||||
// shouldn't be a quoted string, but apparently some implementations
|
||||
// quote it anyway. See ZF-1544.
|
||||
$ret = preg_match('/nc="?([0-9A-Fa-f]{8})"?/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (8 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['nc'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Securely compare two strings for equality while avoided C level memcmp()
|
||||
* optimisations capable of leaking timing information useful to an attacker
|
||||
* attempting to iteratively guess the unknown string (e.g. password) being
|
||||
* compared against.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return bool
|
||||
*/
|
||||
protected function _secureStringCompare($a, $b)
|
||||
{
|
||||
if (strlen($a) !== strlen($b)) {
|
||||
return false;
|
||||
}
|
||||
$result = 0;
|
||||
for ($i = 0; $i < strlen($a); $i++) {
|
||||
$result |= ord($a[$i]) ^ ord($b[$i]);
|
||||
}
|
||||
return $result == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Auth Resolver Exception
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http_Resolver_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
@@ -1,166 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Authentication File Resolver
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http_Resolver_File implements Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
{
|
||||
/**
|
||||
* Path to credentials file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_file;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $path Complete filename where the credentials are stored
|
||||
*/
|
||||
public function __construct($path = '')
|
||||
{
|
||||
if (!empty($path)) {
|
||||
$this->setFile($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path to the credentials file
|
||||
*
|
||||
* @param string $path
|
||||
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_File Provides a fluent interface
|
||||
*/
|
||||
public function setFile($path)
|
||||
{
|
||||
if (empty($path) || !is_readable($path)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Path not readable: ' . $path);
|
||||
}
|
||||
$this->_file = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the credentials file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
return $this->_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve credentials
|
||||
*
|
||||
* Only the first matching username/realm combination in the file is
|
||||
* returned. If the file contains credentials for Digest authentication,
|
||||
* the returned string is the password hash, or h(a1) from RFC 2617. The
|
||||
* returned string is the plain-text password for Basic authentication.
|
||||
*
|
||||
* The expected format of the file is:
|
||||
* username:realm:sharedSecret
|
||||
*
|
||||
* That is, each line consists of the user's username, the applicable
|
||||
* authentication realm, and the password or hash, each delimited by
|
||||
* colons.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $realm Authentication Realm
|
||||
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
* @return string|false User's shared secret, if the user is found in the
|
||||
* realm, false otherwise.
|
||||
*/
|
||||
public function resolve($username, $realm)
|
||||
{
|
||||
if (empty($username)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username is required');
|
||||
} else if (!ctype_print($username) || strpos($username, ':') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username must consist only of printable characters, '
|
||||
. 'excluding the colon');
|
||||
}
|
||||
if (empty($realm)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm is required');
|
||||
} else if (!ctype_print($realm) || strpos($realm, ':') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm must consist only of printable characters, '
|
||||
. 'excluding the colon.');
|
||||
}
|
||||
|
||||
// Open file, read through looking for matching credentials
|
||||
$fp = @fopen($this->_file, 'r');
|
||||
if (!$fp) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Unable to open password file: ' . $this->_file);
|
||||
}
|
||||
|
||||
// No real validation is done on the contents of the password file. The
|
||||
// assumption is that we trust the administrators to keep it secure.
|
||||
while (($line = fgetcsv($fp, 512, ':')) !== false) {
|
||||
if ($line[0] == $username && $line[1] == $realm) {
|
||||
$password = $line[2];
|
||||
fclose($fp);
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Auth HTTP Resolver Interface
|
||||
*
|
||||
* Defines an interace to resolve a username/realm combination into a shared
|
||||
* secret usable by HTTP Authentication.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
{
|
||||
/**
|
||||
* Resolve username/realm to password/hash/etc.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $realm Authentication Realm
|
||||
* @return string|false User's shared secret, if the user is found in the
|
||||
* realm, false otherwise.
|
||||
*/
|
||||
public function resolve($username, $realm);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Result
|
||||
*/
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Performs an authentication attempt
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Exception extends Zend_Exception
|
||||
{}
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Result
|
||||
{
|
||||
/**
|
||||
* General Failure
|
||||
*/
|
||||
const FAILURE = 0;
|
||||
|
||||
/**
|
||||
* Failure due to identity not being found.
|
||||
*/
|
||||
const FAILURE_IDENTITY_NOT_FOUND = -1;
|
||||
|
||||
/**
|
||||
* Failure due to identity being ambiguous.
|
||||
*/
|
||||
const FAILURE_IDENTITY_AMBIGUOUS = -2;
|
||||
|
||||
/**
|
||||
* Failure due to invalid credential being supplied.
|
||||
*/
|
||||
const FAILURE_CREDENTIAL_INVALID = -3;
|
||||
|
||||
/**
|
||||
* Failure due to uncategorized reasons.
|
||||
*/
|
||||
const FAILURE_UNCATEGORIZED = -4;
|
||||
|
||||
/**
|
||||
* Authentication success.
|
||||
*/
|
||||
const SUCCESS = 1;
|
||||
|
||||
/**
|
||||
* Authentication result code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_code;
|
||||
|
||||
/**
|
||||
* The identity used in the authentication attempt
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_identity;
|
||||
|
||||
/**
|
||||
* An array of string reasons why the authentication attempt was unsuccessful
|
||||
*
|
||||
* If authentication was successful, this should be an empty array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messages;
|
||||
|
||||
/**
|
||||
* Sets the result code, identity, and failure messages
|
||||
*
|
||||
* @param int $code
|
||||
* @param mixed $identity
|
||||
* @param array $messages
|
||||
*/
|
||||
public function __construct($code, $identity, array $messages = array())
|
||||
{
|
||||
$code = (int) $code;
|
||||
|
||||
if ($code < self::FAILURE_UNCATEGORIZED) {
|
||||
$code = self::FAILURE;
|
||||
} elseif ($code > self::SUCCESS ) {
|
||||
$code = 1;
|
||||
}
|
||||
|
||||
$this->_code = $code;
|
||||
$this->_identity = $identity;
|
||||
$this->_messages = $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the result represents a successful authentication attempt
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
return ($this->_code > 0) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCode() - Get the result code for this authentication attempt
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity used in the authentication attempt
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIdentity()
|
||||
{
|
||||
return $this->_identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of string reasons why the authentication attempt was unsuccessful
|
||||
*
|
||||
* If authentication was successful, this method returns an empty array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->_messages;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Returns true if and only if storage is empty
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty();
|
||||
|
||||
/**
|
||||
* Returns the contents of storage
|
||||
*
|
||||
* Behavior is undefined when storage is empty.
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
|
||||
* @return mixed
|
||||
*/
|
||||
public function read();
|
||||
|
||||
/**
|
||||
* Writes $contents to storage
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents);
|
||||
|
||||
/**
|
||||
* Clears contents from storage
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* Non-Persistent Auth Storage
|
||||
*
|
||||
* Since HTTP Authentication happens again on each request, this will always be
|
||||
* re-populated. So there's no need to use sessions, this simple value class
|
||||
* will hold the data for rest of the current request.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_NonPersistent implements Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Holds the actual auth data
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* Returns true if and only if storage is empty
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of storage
|
||||
* Behavior is undefined when storage is empty.
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
|
||||
* @return mixed
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes $contents to storage
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents)
|
||||
{
|
||||
$this->_data = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears contents from storage
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->_data = null;
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Session
|
||||
*/
|
||||
require_once 'Zend/Session.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Default session namespace
|
||||
*/
|
||||
const NAMESPACE_DEFAULT = 'Zend_Auth';
|
||||
|
||||
/**
|
||||
* Default session object member name
|
||||
*/
|
||||
const MEMBER_DEFAULT = 'storage';
|
||||
|
||||
/**
|
||||
* Object to proxy $_SESSION storage
|
||||
*
|
||||
* @var Zend_Session_Namespace
|
||||
*/
|
||||
protected $_session;
|
||||
|
||||
/**
|
||||
* Session namespace
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_namespace;
|
||||
|
||||
/**
|
||||
* Session object member
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_member;
|
||||
|
||||
/**
|
||||
* Sets session storage options and initializes session namespace object
|
||||
*
|
||||
* @param mixed $namespace
|
||||
* @param mixed $member
|
||||
*/
|
||||
public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
|
||||
{
|
||||
$this->_namespace = $namespace;
|
||||
$this->_member = $member;
|
||||
$this->_session = new Zend_Session_Namespace($this->_namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session namespace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the session object member
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMember()
|
||||
{
|
||||
return $this->_member;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return !isset($this->_session->{$this->_member});
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return $this->_session->{$this->_member};
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents)
|
||||
{
|
||||
$this->_session->{$this->_member} = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
unset($this->_session->{$this->_member});
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Cache
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard frontends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Standard backends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform',
|
||||
'Xcache', 'TwoLevels', 'WinCache', 'ZendServer_Disk', 'ZendServer_ShMem');
|
||||
|
||||
/**
|
||||
* Standard backends which implement the ExtendedInterface
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite', 'WinCache');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'WinCache', 'TwoLevels');
|
||||
|
||||
/**
|
||||
* Consts for clean() method
|
||||
*/
|
||||
const CLEANING_MODE_ALL = 'all';
|
||||
const CLEANING_MODE_OLD = 'old';
|
||||
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
|
||||
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
|
||||
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*
|
||||
* @param mixed $frontend frontend name (string) or Zend_Cache_Frontend_ object
|
||||
* @param mixed $backend backend name (string) or Zend_Cache_Backend_ object
|
||||
* @param array $frontendOptions associative array of options for the corresponding frontend constructor
|
||||
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
|
||||
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
|
||||
* @param boolean $autoload if true, there will no require_once for backend and frontend (useful only for custom backends/frontends)
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (is_string($backend)) {
|
||||
$backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
|
||||
} else {
|
||||
if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
|
||||
$backendObject = $backend;
|
||||
} else {
|
||||
self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
|
||||
}
|
||||
}
|
||||
if (is_string($frontend)) {
|
||||
$frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
|
||||
} else {
|
||||
if (is_object($frontend)) {
|
||||
$frontendObject = $frontend;
|
||||
} else {
|
||||
self::throwException('frontend must be a frontend name (string) or an object');
|
||||
}
|
||||
}
|
||||
$frontendObject->setBackend($backendObject);
|
||||
return $frontendObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend Constructor
|
||||
*
|
||||
* @param string $backend
|
||||
* @param array $backendOptions
|
||||
* @param boolean $customBackendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Backend
|
||||
*/
|
||||
public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customBackendNaming) {
|
||||
$backend = self::_normalizeName($backend);
|
||||
}
|
||||
if (in_array($backend, Zend_Cache::$standardBackends)) {
|
||||
// we use a standard backend
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
// security controls are explicit
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom backend
|
||||
if (!preg_match('~^[\w\\\\]+$~D', $backend)) {
|
||||
Zend_Cache::throwException("Invalid backend name [$backend]");
|
||||
}
|
||||
if (!$customBackendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
} else {
|
||||
$backendClass = $backend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
return new $backendClass($backendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend Constructor
|
||||
*
|
||||
* @param string $frontend
|
||||
* @param array $frontendOptions
|
||||
* @param boolean $customFrontendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customFrontendNaming) {
|
||||
$frontend = self::_normalizeName($frontend);
|
||||
}
|
||||
if (in_array($frontend, self::$standardFrontends)) {
|
||||
// we use a standard frontend
|
||||
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
|
||||
$frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
|
||||
// security controls are explicit
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom frontend
|
||||
if (!preg_match('~^[\w\\\\]+$~D', $frontend)) {
|
||||
Zend_Cache::throwException("Invalid frontend name [$frontend]");
|
||||
}
|
||||
if (!$customFrontendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$frontendClass = 'Zend_Cache_Frontend_' . $frontend;
|
||||
} else {
|
||||
$frontendClass = $frontend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
return new $frontendClass($frontendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception
|
||||
*
|
||||
* Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic
|
||||
* @param string $msg Message for the exception
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public static function throwException($msg, Exception $e = null)
|
||||
{
|
||||
// For perfs reasons, we use this dynamic inclusion
|
||||
require_once 'Zend/Cache/Exception.php';
|
||||
throw new Zend_Cache_Exception($msg, 0, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize frontend and backend names to allow multiple words TitleCased
|
||||
*
|
||||
* @param string $name Name to normalize
|
||||
* @return string
|
||||
*/
|
||||
protected static function _normalizeName($name)
|
||||
{
|
||||
$name = ucfirst(strtolower($name));
|
||||
$name = str_replace(array('-', '_', '.'), ' ', $name);
|
||||
$name = ucwords($name);
|
||||
$name = str_replace(' ', '', $name);
|
||||
if (stripos($name, 'ZendServer') === 0) {
|
||||
$name = 'ZendServer_' . substr($name, strlen('ZendServer'));
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the $filename is readable, or FALSE otherwise.
|
||||
* This function uses the PHP include_path, where PHP's is_readable()
|
||||
* does not.
|
||||
*
|
||||
* Note : this method comes from Zend_Loader (see #ZF-2891 for details)
|
||||
*
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
private static function _isReadable($filename)
|
||||
{
|
||||
if (!$fh = @fopen($filename, 'r', true)) {
|
||||
return false;
|
||||
}
|
||||
@fclose($fh);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend
|
||||
{
|
||||
/**
|
||||
* Frontend or Core directives
|
||||
*
|
||||
* =====> (int) lifetime :
|
||||
* - Cache lifetime (in seconds)
|
||||
* - If null, the cache is valid forever
|
||||
*
|
||||
* =====> (int) logging :
|
||||
* - if set to true, a logging is activated throw Zend_Log
|
||||
*
|
||||
* @var array directives
|
||||
*/
|
||||
protected $_directives = array(
|
||||
'lifetime' => 3600,
|
||||
'logging' => false,
|
||||
'logger' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
|
||||
while (list($name, $value) = each($directives)) {
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_directives)) {
|
||||
$this->_directives[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->_loggerSanity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an option
|
||||
*
|
||||
* @param string $name Optional, the options name to return
|
||||
* @throws Zend_Cache_Exceptions
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
return $this->_options[$name];
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $this->_directives)) {
|
||||
return $this->_directives[$name];
|
||||
}
|
||||
|
||||
Zend_Cache::throwException("Incorrect option name : {$name}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the life time
|
||||
*
|
||||
* if $specificLifetime is not false, the given specific life time is used
|
||||
* else, the global lifetime is used
|
||||
*
|
||||
* @param int $specificLifetime
|
||||
* @return int Cache life time
|
||||
*/
|
||||
public function getLifetime($specificLifetime)
|
||||
{
|
||||
if ($specificLifetime === false) {
|
||||
return $this->_directives['lifetime'];
|
||||
}
|
||||
return $specificLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine system TMP directory and detect if we have read access
|
||||
*
|
||||
* inspired from Zend_File_Transfer_Adapter_Abstract
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Cache_Exception if unable to determine directory
|
||||
*/
|
||||
public function getTmpDir()
|
||||
{
|
||||
$tmpdir = array();
|
||||
foreach (array($_ENV, $_SERVER) as $tab) {
|
||||
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
||||
if (isset($tab[$key]) && is_string($tab[$key])) {
|
||||
if (($key == 'windir') or ($key == 'SystemRoot')) {
|
||||
$dir = realpath($tab[$key] . '\\temp');
|
||||
} else {
|
||||
$dir = realpath($tab[$key]);
|
||||
}
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$upload = ini_get('upload_tmp_dir');
|
||||
if ($upload) {
|
||||
$dir = realpath($upload);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if (function_exists('sys_get_temp_dir')) {
|
||||
$dir = sys_get_temp_dir();
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
// Attemp to detect by creating a temporary file
|
||||
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
|
||||
if ($tempFile) {
|
||||
$dir = realpath(dirname($tempFile));
|
||||
unlink($tempFile);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if ($this->_isGoodTmpDir('/tmp')) {
|
||||
return '/tmp';
|
||||
}
|
||||
if ($this->_isGoodTmpDir('\\temp')) {
|
||||
return '\\temp';
|
||||
}
|
||||
Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the given temporary directory is readable and writable
|
||||
*
|
||||
* @param string $dir temporary directory
|
||||
* @return boolean true if the directory is ok
|
||||
*/
|
||||
protected function _isGoodTmpDir($dir)
|
||||
{
|
||||
if (is_readable($dir)) {
|
||||
if (is_writable($dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if we enable logging that the Zend_Log class
|
||||
* is available.
|
||||
* Create a default log object if none is set.
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _loggerSanity()
|
||||
{
|
||||
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_directives['logger'])) {
|
||||
if ($this->_directives['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
}
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
|
||||
// Create a default logger to the standard output stream
|
||||
require_once 'Zend/Log.php';
|
||||
require_once 'Zend/Log/Writer/Stream.php';
|
||||
require_once 'Zend/Log/Filter/Priority.php';
|
||||
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||
$logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN, '<='));
|
||||
$this->_directives['logger'] = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN (4) priority.
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $priority
|
||||
* @return void
|
||||
*/
|
||||
protected function _log($message, $priority = 4)
|
||||
{
|
||||
if (!$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->_directives['logger'])) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set.');
|
||||
}
|
||||
$logger = $this->_directives['logger'];
|
||||
if (!$logger instanceof Zend_Log) {
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
$logger->log($message, $priority);
|
||||
}
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the Apc backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return apc_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return apc_clear_cache('user');
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = apc_sma_info(true);
|
||||
$memSize = $mem['num_seg'] * $mem['seg_size'];
|
||||
$memAvailable= $mem['avail_mem'];
|
||||
$memUsed = $memSize - $memAvailable;
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get apc memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$ids = array();
|
||||
$iterator = new APCIterator('user', null, APC_ITER_KEY);
|
||||
foreach ($iterator as $item) {
|
||||
$ids[] = $item['key'];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_BlackHole
|
||||
extends Zend_Cache_Backend
|
||||
implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => remove too old cache entries ($tags is not used)
|
||||
* 'matchingTag' => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param tags array $tags array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => true,
|
||||
'priority' => true,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds();
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags();
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage();
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id);
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime);
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities();
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives assoc of directives
|
||||
*/
|
||||
public function setDirectives($directives);
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false);
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id);
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false);
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id);
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array());
|
||||
|
||||
}
|
||||
@@ -1,484 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Server Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* =====> (array) client :
|
||||
* an array of memcached client options ; the memcached client is described by an associative array :
|
||||
* @see http://php.net/manual/memcached.constants.php
|
||||
* - The option name can be the name of the constant without the prefix 'OPT_'
|
||||
* or the integer value of this option constant
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
)),
|
||||
'client' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcached object
|
||||
*
|
||||
* @var mixed memcached object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcached')) {
|
||||
Zend_Cache::throwException('The memcached extension must be loaded for using this backend !');
|
||||
}
|
||||
|
||||
// override default client options
|
||||
$this->_options['client'] = array(
|
||||
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
|
||||
Memcached::OPT_HASH => Memcached::HASH_MD5,
|
||||
Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
|
||||
);
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value = $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcached;
|
||||
|
||||
// setup memcached client options
|
||||
foreach ($this->_options['client'] as $name => $value) {
|
||||
$optId = null;
|
||||
if (is_int($name)) {
|
||||
$optId = $name;
|
||||
} else {
|
||||
$optConst = 'Memcached::OPT_' . strtoupper($name);
|
||||
if (defined($optConst)) {
|
||||
$optId = constant($optConst);
|
||||
} else {
|
||||
$this->_log("Unknown memcached client option '{$name}' ({$optConst})");
|
||||
}
|
||||
}
|
||||
if (null !== $optId) {
|
||||
if (!$this->_memcache->setOption($optId, $value)) {
|
||||
$this->_log("Setting memcached client option '{$optId}' failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setup memcached servers
|
||||
$servers = array();
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
|
||||
$servers[] = array($server['host'], $server['port'], $server['weight']);
|
||||
}
|
||||
$this->_memcache->addServers($servers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1])) {
|
||||
return (int)$tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getStats();
|
||||
if ($mems === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
$eachUsed = $mem['bytes'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,509 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_PERSISTENT = true;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
const DEFAULT_TIMEOUT = 1;
|
||||
const DEFAULT_RETRY_INTERVAL = 15;
|
||||
const DEFAULT_STATUS = true;
|
||||
const DEFAULT_FAILURE_CALLBACK = null;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'persistent' => (bool) : use or not persistent connections to this memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* 'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
|
||||
* before changing the default value of 1 second - you can lose all the
|
||||
* advantages of caching if your connection is too slow.
|
||||
* 'retry_interval' => (int) : controls how often a failed server will be retried, the default value
|
||||
* is 15 seconds. Setting this parameter to -1 disables automatic retry.
|
||||
* 'status' => (bool) : controls if the server should be flagged as online.
|
||||
* 'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
|
||||
* encountering an error. The callback is run before failover
|
||||
* is attempted. The function takes two parameters, the hostname
|
||||
* and port of the failed server.
|
||||
*
|
||||
* =====> (boolean) compression :
|
||||
* true if you want to use on-the-fly compression
|
||||
*
|
||||
* =====> (boolean) compatibility :
|
||||
* true if you use old memcache server or extension
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'persistent' => self::DEFAULT_PERSISTENT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
'timeout' => self::DEFAULT_TIMEOUT,
|
||||
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
|
||||
'status' => self::DEFAULT_STATUS,
|
||||
'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
|
||||
)),
|
||||
'compression' => false,
|
||||
'compatibility' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcache object
|
||||
*
|
||||
* @var mixed memcache object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcache')) {
|
||||
Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value= $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcache;
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('persistent', $server)) {
|
||||
$server['persistent'] = self::DEFAULT_PERSISTENT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
if (!array_key_exists('timeout', $server)) {
|
||||
$server['timeout'] = self::DEFAULT_TIMEOUT;
|
||||
}
|
||||
if (!array_key_exists('retry_interval', $server)) {
|
||||
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
|
||||
}
|
||||
if (!array_key_exists('status', $server)) {
|
||||
$server['status'] = self::DEFAULT_STATUS;
|
||||
}
|
||||
if (!array_key_exists('failure_callback', $server)) {
|
||||
$server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
|
||||
}
|
||||
if ($this->_options['compatibility']) {
|
||||
// No status for compatibility mode (#ZF-5887)
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval']);
|
||||
} else {
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval'],
|
||||
$server['status'], $server['failure_callback']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp) && isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getExtendedStats();
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
|
||||
/**
|
||||
* Couchbase 1.x uses 'mem_used' instead of 'bytes'
|
||||
* @see https://www.couchbase.com/issues/browse/MB-3466
|
||||
*/
|
||||
$eachUsed = isset($mem['bytes']) ? $mem['bytes'] : $mem['mem_used'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,678 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) cache_db_complete_path :
|
||||
* - the complete path (filename included) of the SQLITE database
|
||||
*
|
||||
* ====> (int) automatic_vacuum_factor :
|
||||
* - Disable / Tune the automatic vacuum process
|
||||
* - The automatic vacuum process defragment the database file (and make it smaller)
|
||||
* when a clean() or delete() is called
|
||||
* 0 => no automatic vacuum
|
||||
* 1 => systematic vacuum (when delete() or clean() methods are called)
|
||||
* x (integer) > 1 => automatic vacuum randomly 1 times on x clean() or delete()
|
||||
*
|
||||
* @var array Available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'cache_db_complete_path' => null,
|
||||
'automatic_vacuum_factor' => 10
|
||||
);
|
||||
|
||||
/**
|
||||
* DB ressource
|
||||
*
|
||||
* @var mixed $_db
|
||||
*/
|
||||
private $_db = null;
|
||||
|
||||
/**
|
||||
* Boolean to store if the structure has benn checked or not
|
||||
*
|
||||
* @var boolean $_structureChecked
|
||||
*/
|
||||
private $_structureChecked = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
if ($this->_options['cache_db_complete_path'] === null) {
|
||||
Zend_Cache::throwException('cache_db_complete_path option has to set');
|
||||
}
|
||||
if (!extension_loaded('sqlite')) {
|
||||
Zend_Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
|
||||
}
|
||||
$this->_getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@sqlite_close($this->_getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false Cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$sql = "SELECT content FROM cache WHERE id='$id'";
|
||||
if (!$doNotTestCacheValidity) {
|
||||
$sql = $sql . " AND (expire=0 OR expire>" . time() . ')';
|
||||
}
|
||||
$result = $this->_query($sql);
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if ($row) {
|
||||
return $row['content'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$sql = "SELECT lastModified FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||
$result = $this->_query($sql);
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if ($row) {
|
||||
return ((int) $row['lastModified']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$data = @sqlite_escape_string($data);
|
||||
$mktime = time();
|
||||
if ($lifetime === null) {
|
||||
$expire = 0;
|
||||
} else {
|
||||
$expire = $mktime + $lifetime;
|
||||
}
|
||||
$this->_query("DELETE FROM cache WHERE id='$id'");
|
||||
$sql = "INSERT INTO cache (id, content, lastModified, expire) VALUES ('$id', '$data', $mktime, $expire)";
|
||||
$res = $this->_query($sql);
|
||||
if (!$res) {
|
||||
$this->_log("Zend_Cache_Backend_Sqlite::save() : impossible to store the cache id=$id");
|
||||
return false;
|
||||
}
|
||||
$res = true;
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_registerTag($id, $tag) && $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT COUNT(*) AS nbr FROM cache WHERE id='$id'");
|
||||
$result1 = @sqlite_fetch_single($res);
|
||||
$result2 = $this->_query("DELETE FROM cache WHERE id='$id'");
|
||||
$result3 = $this->_query("DELETE FROM tag WHERE id='$id'");
|
||||
$this->_automaticVacuum();
|
||||
return ($result1 && $result2 && $result3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$return = $this->_clean($mode, $tags);
|
||||
$this->_automaticVacuum();
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT id FROM cache WHERE (expire=0 OR expire>" . time() . ")");
|
||||
$result = array();
|
||||
while ($id = @sqlite_fetch_single($res)) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_checkAndBuildStructure();
|
||||
$res = $this->_query("SELECT DISTINCT(name) AS name FROM tag");
|
||||
$result = array();
|
||||
while ($id = @sqlite_fetch_single($res)) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$first = true;
|
||||
$ids = array();
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$ids2 = array();
|
||||
foreach ($rows as $row) {
|
||||
$ids2[] = $row['id'];
|
||||
}
|
||||
if ($first) {
|
||||
$ids = $ids2;
|
||||
$first = false;
|
||||
} else {
|
||||
$ids = array_intersect($ids, $ids2);
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
foreach ($ids as $id) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$res = $this->_query("SELECT id FROM cache");
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$result = array();
|
||||
foreach ($rows as $row) {
|
||||
$id = $row['id'];
|
||||
$matching = false;
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$nbr = (int) @sqlite_fetch_single($res);
|
||||
if ($nbr > 0) {
|
||||
$matching = true;
|
||||
}
|
||||
}
|
||||
if (!$matching) {
|
||||
$result[] = $id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$first = true;
|
||||
$ids = array();
|
||||
foreach ($tags as $tag) {
|
||||
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||
if (!$res) {
|
||||
return array();
|
||||
}
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
$ids2 = array();
|
||||
foreach ($rows as $row) {
|
||||
$ids2[] = $row['id'];
|
||||
}
|
||||
if ($first) {
|
||||
$ids = $ids2;
|
||||
$first = false;
|
||||
} else {
|
||||
$ids = array_merge($ids, $ids2);
|
||||
}
|
||||
}
|
||||
$result = array();
|
||||
foreach ($ids as $id) {
|
||||
$result[] = $id;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$dir = dirname($this->_options['cache_db_complete_path']);
|
||||
$free = disk_free_space($dir);
|
||||
$total = disk_total_space($dir);
|
||||
if ($total == 0) {
|
||||
Zend_Cache::throwException('can\'t get disk_total_space');
|
||||
} else {
|
||||
if ($free >= $total) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($total - $free) / $total));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tags = array();
|
||||
$res = $this->_query("SELECT name FROM tag WHERE id='$id'");
|
||||
if ($res) {
|
||||
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||
foreach ($rows as $row) {
|
||||
$tags[] = $row['name'];
|
||||
}
|
||||
}
|
||||
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||
$res = $this->_query("SELECT lastModified,expire FROM cache WHERE id='$id'");
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
$row = @sqlite_fetch_array($res, SQLITE_ASSOC);
|
||||
return array(
|
||||
'tags' => $tags,
|
||||
'mtime' => $row['lastModified'],
|
||||
'expire' => $row['expire']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$sql = "SELECT expire FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||
$res = $this->_query($sql);
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
$expire = @sqlite_fetch_single($res);
|
||||
$newExpire = $expire + $extraLifetime;
|
||||
$res = $this->_query("UPDATE cache SET lastModified=" . time() . ", expire=$newExpire WHERE id='$id'");
|
||||
if ($res) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => true,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
$time = time() - 1;
|
||||
$this->_query("UPDATE cache SET lastModified=$time, expire=$time WHERE id='$id'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the connection resource
|
||||
*
|
||||
* If we are not connected, the connection is made
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return resource Connection resource
|
||||
*/
|
||||
private function _getConnection()
|
||||
{
|
||||
if (is_resource($this->_db)) {
|
||||
return $this->_db;
|
||||
} else {
|
||||
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
|
||||
if (!(is_resource($this->_db))) {
|
||||
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
|
||||
}
|
||||
return $this->_db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an SQL query silently
|
||||
*
|
||||
* @param string $query SQL query
|
||||
* @return mixed|false query results
|
||||
*/
|
||||
private function _query($query)
|
||||
{
|
||||
$db = $this->_getConnection();
|
||||
if (is_resource($db)) {
|
||||
$res = @sqlite_query($db, $query);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
} else {
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with the automatic vacuum process
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _automaticVacuum()
|
||||
{
|
||||
if ($this->_options['automatic_vacuum_factor'] > 0) {
|
||||
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
|
||||
if ($rand == 1) {
|
||||
$this->_query('VACUUM');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a cache id with the given tag
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param string $tag Tag
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
private function _registerTag($id, $tag) {
|
||||
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
|
||||
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
|
||||
if (!$res) {
|
||||
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the database structure
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
private function _buildStructure()
|
||||
{
|
||||
$this->_query('DROP INDEX tag_id_index');
|
||||
$this->_query('DROP INDEX tag_name_index');
|
||||
$this->_query('DROP INDEX cache_id_expire_index');
|
||||
$this->_query('DROP TABLE version');
|
||||
$this->_query('DROP TABLE cache');
|
||||
$this->_query('DROP TABLE tag');
|
||||
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
|
||||
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
|
||||
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
|
||||
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
|
||||
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
|
||||
$this->_query('INSERT INTO version (num) VALUES (1)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database structure is ok (with the good version)
|
||||
*
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _checkStructureVersion()
|
||||
{
|
||||
$result = $this->_query("SELECT num FROM version");
|
||||
if (!$result) return false;
|
||||
$row = @sqlite_fetch_array($result);
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
if (((int) $row['num']) != 1) {
|
||||
// old cache structure
|
||||
$this->_log('Zend_Cache_Backend_Sqlite::_checkStructureVersion() : old cache structure version detected => the cache is going to be dropped');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
private function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$res1 = $this->_query('DELETE FROM cache');
|
||||
$res2 = $this->_query('DELETE FROM tag');
|
||||
return $res1 && $res2;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$mktime = time();
|
||||
$res1 = $this->_query("DELETE FROM tag WHERE id IN (SELECT id FROM cache WHERE expire>0 AND expire<=$mktime)");
|
||||
$res2 = $this->_query("DELETE FROM cache WHERE expire>0 AND expire<=$mktime");
|
||||
return $res1 && $res2;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$ids = $this->getIdsMatchingTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$ids = $this->getIdsNotMatchingTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$ids = $this->getIdsMatchingAnyTags($tags);
|
||||
$result = true;
|
||||
foreach ($ids as $id) {
|
||||
$result = $this->remove($id) && $result;
|
||||
}
|
||||
return $result;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database structure is ok (with the good version), if no : build it
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _checkAndBuildStructure()
|
||||
{
|
||||
if (!($this->_structureChecked)) {
|
||||
if (!$this->_checkStructureVersion()) {
|
||||
$this->_buildStructure();
|
||||
if (!$this->_checkStructureVersion()) {
|
||||
Zend_Cache::throwException("Impossible to build cache structure in " . $this->_options['cache_db_complete_path']);
|
||||
}
|
||||
}
|
||||
$this->_structureChecked = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,579 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Static
|
||||
extends Zend_Cache_Backend
|
||||
implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
const INNER_CACHE_NAME = 'zend_cache_backend_static_tagcache';
|
||||
|
||||
/**
|
||||
* Static backend options
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'public_dir' => null,
|
||||
'sub_dir' => 'html',
|
||||
'file_extension' => '.html',
|
||||
'index_filename' => 'index',
|
||||
'file_locking' => true,
|
||||
'cache_file_perm' => 0600,
|
||||
'cache_directory_perm' => 0700,
|
||||
'debug_header' => false,
|
||||
'tag_cache' => null,
|
||||
'disable_caching' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Cache for handling tags
|
||||
* @var Zend_Cache_Core
|
||||
*/
|
||||
protected $_tagCache = null;
|
||||
|
||||
/**
|
||||
* Tagged items
|
||||
* @var array
|
||||
*/
|
||||
protected $_tagged = null;
|
||||
|
||||
/**
|
||||
* Interceptor child method to handle the case where an Inner
|
||||
* Cache object is being set since it's not supported by the
|
||||
* standard backend interface
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Cache_Backend_Static
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($name == 'tag_cache') {
|
||||
$this->setInnerCache($value);
|
||||
} else {
|
||||
// See #ZF-12047 and #GH-91
|
||||
if ($name == 'cache_file_umask') {
|
||||
trigger_error(
|
||||
"'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead",
|
||||
E_USER_NOTICE
|
||||
);
|
||||
|
||||
$name = 'cache_file_perm';
|
||||
}
|
||||
if ($name == 'cache_directory_umask') {
|
||||
trigger_error(
|
||||
"'cache_directory_umask' is deprecated -> please use 'cache_directory_perm' instead",
|
||||
E_USER_NOTICE
|
||||
);
|
||||
|
||||
$name = 'cache_directory_perm';
|
||||
}
|
||||
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve any option via interception of the parent's statically held
|
||||
* options including the local option for a tag cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
|
||||
if ($name == 'tag_cache') {
|
||||
return $this->getInnerCache();
|
||||
}
|
||||
|
||||
return parent::getOption($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
if (($id = (string)$id) === '') {
|
||||
$id = $this->_detectId();
|
||||
} else {
|
||||
$id = $this->_decodeId($id);
|
||||
}
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
if ($doNotTestCacheValidity) {
|
||||
$this->_log("Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend");
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension'];
|
||||
if (file_exists($file)) {
|
||||
$content = file_get_contents($file);
|
||||
return $content;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return bool
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$id = $this->_decodeId($id);
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return false;
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
|
||||
// Switch extension if needed
|
||||
if (isset($this->_tagged[$id])) {
|
||||
$extension = $this->_tagged[$id]['extension'];
|
||||
} else {
|
||||
$extension = $this->_options['file_extension'];
|
||||
}
|
||||
$file = $pathName . '/' . $fileName . $extension;
|
||||
if (file_exists($file)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
if ($this->_options['disable_caching']) {
|
||||
return true;
|
||||
}
|
||||
$extension = null;
|
||||
if ($this->_isSerialized($data)) {
|
||||
$data = unserialize($data);
|
||||
$extension = '.' . ltrim($data[1], '.');
|
||||
$data = $data[0];
|
||||
}
|
||||
|
||||
clearstatcache();
|
||||
if (($id = (string)$id) === '') {
|
||||
$id = $this->_detectId();
|
||||
} else {
|
||||
$id = $this->_decodeId($id);
|
||||
}
|
||||
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
|
||||
$pathName = realpath($this->_options['public_dir']) . dirname($id);
|
||||
$this->_createDirectoriesFor($pathName);
|
||||
|
||||
if ($id === null || strlen($id) == 0) {
|
||||
$dataUnserialized = unserialize($data);
|
||||
$data = $dataUnserialized['data'];
|
||||
}
|
||||
$ext = $this->_options['file_extension'];
|
||||
if ($extension) $ext = $extension;
|
||||
$file = rtrim($pathName, '/') . '/' . $fileName . $ext;
|
||||
if ($this->_options['file_locking']) {
|
||||
$result = file_put_contents($file, $data, LOCK_EX);
|
||||
} else {
|
||||
$result = file_put_contents($file, $data);
|
||||
}
|
||||
@chmod($file, $this->_octdec($this->_options['cache_file_perm']));
|
||||
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif ($this->_tagged === null) {
|
||||
$this->_tagged = array();
|
||||
}
|
||||
if (!isset($this->_tagged[$id])) {
|
||||
$this->_tagged[$id] = array();
|
||||
}
|
||||
if (!isset($this->_tagged[$id]['tags'])) {
|
||||
$this->_tagged[$id]['tags'] = array();
|
||||
}
|
||||
$this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id]['tags'], $tags));
|
||||
$this->_tagged[$id]['extension'] = $ext;
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively create the directories needed to write the static file
|
||||
*/
|
||||
protected function _createDirectoriesFor($path)
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
$oldUmask = umask(0);
|
||||
if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_perm']), true)) {
|
||||
$lastErr = error_get_last();
|
||||
umask($oldUmask);
|
||||
Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");
|
||||
}
|
||||
umask($oldUmask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect serialization of data (cannot predict since this is the only way
|
||||
* to obey the interface yet pass in another parameter).
|
||||
*
|
||||
* In future, ZF 2.0, check if we can just avoid the interface restraints.
|
||||
*
|
||||
* This format is the only valid one possible for the class, so it's simple
|
||||
* to just run a regular expression for the starting serialized format.
|
||||
*/
|
||||
protected function _isSerialized($data)
|
||||
{
|
||||
return preg_match("/a:2:\{i:0;s:\d+:\"/", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
$fileName = basename($id);
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return false;
|
||||
}
|
||||
if (isset($this->_tagged[$id])) {
|
||||
$extension = $this->_tagged[$id]['extension'];
|
||||
} else {
|
||||
$extension = $this->_options['file_extension'];
|
||||
}
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = realpath($pathName) . '/' . $fileName . $extension;
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record recursively for the given directory matching a
|
||||
* REQUEST_URI based relative path (deletes the actual file matching this
|
||||
* in addition to the matching directory)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function removeRecursively($id)
|
||||
{
|
||||
if (!$this->_verifyPath($id)) {
|
||||
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||
}
|
||||
$fileName = basename($id);
|
||||
if ($fileName === '') {
|
||||
$fileName = $this->_options['index_filename'];
|
||||
}
|
||||
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||
$file = $pathName . '/' . $fileName . $this->_options['file_extension'];
|
||||
$directory = $pathName . '/' . $fileName;
|
||||
if (file_exists($directory)) {
|
||||
if (!is_writable($directory)) {
|
||||
return false;
|
||||
}
|
||||
if (is_dir($directory)) {
|
||||
foreach (new DirectoryIterator($directory) as $file) {
|
||||
if (true === $file->isFile()) {
|
||||
if (false === unlink($file->getPathName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rmdir($directory);
|
||||
}
|
||||
if (file_exists($file)) {
|
||||
if (!is_writable($file)) {
|
||||
return false;
|
||||
}
|
||||
return unlink($file);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean true if no problem
|
||||
* @throws Zend_Exception
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$result = false;
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
if (empty($tags)) {
|
||||
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||
}
|
||||
if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||
$this->_tagged = $tagged;
|
||||
} elseif (!$this->_tagged) {
|
||||
return true;
|
||||
}
|
||||
foreach ($tags as $tag) {
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
if (isset($this->_tagged[$url]['tags']) && in_array($tag, $this->_tagged[$url]['tags'])) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
if ($this->_tagged === null) {
|
||||
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||
$this->_tagged = $tagged;
|
||||
}
|
||||
if ($this->_tagged === null || empty($this->_tagged)) {
|
||||
return true;
|
||||
}
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
if (empty($tags)) {
|
||||
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||
}
|
||||
if ($this->_tagged === null) {
|
||||
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||
$this->_tagged = $tagged;
|
||||
}
|
||||
if ($this->_tagged === null || empty($this->_tagged)) {
|
||||
return true;
|
||||
}
|
||||
$urls = array_keys($this->_tagged);
|
||||
foreach ($urls as $url) {
|
||||
$difference = array_diff($tags, $this->_tagged[$url]['tags']);
|
||||
if (count($tags) == count($difference)) {
|
||||
$this->remove($url);
|
||||
unset($this->_tagged[$url]);
|
||||
}
|
||||
}
|
||||
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||
$result = true;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an Inner Cache, used here primarily to store Tags associated
|
||||
* with caches created by this backend. Note: If Tags are lost, the cache
|
||||
* should be completely cleaned as the mapping of tags to caches will
|
||||
* have been irrevocably lost.
|
||||
*
|
||||
* @param Zend_Cache_Core
|
||||
* @return void
|
||||
*/
|
||||
public function setInnerCache(Zend_Cache_Core $cache)
|
||||
{
|
||||
$this->_tagCache = $cache;
|
||||
$this->_options['tag_cache'] = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Inner Cache if set
|
||||
*
|
||||
* @return Zend_Cache_Core
|
||||
*/
|
||||
public function getInnerCache()
|
||||
{
|
||||
if ($this->_tagCache === null) {
|
||||
Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()');
|
||||
}
|
||||
return $this->_tagCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify path exists and is non-empty
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
protected function _verifyPath($path)
|
||||
{
|
||||
$path = realpath($path);
|
||||
$base = realpath($this->_options['public_dir']);
|
||||
return strncmp($path, $base, strlen($base)) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the page to save from the request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _detectId()
|
||||
{
|
||||
return $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||
*
|
||||
* Throw an exception if a problem is found
|
||||
*
|
||||
* @param string $string Cache id or tag
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
* @deprecated Not usable until perhaps ZF 2.0
|
||||
*/
|
||||
protected static function _validateIdOrTag($string)
|
||||
{
|
||||
if (!is_string($string)) {
|
||||
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||
}
|
||||
|
||||
// Internal only checked in Frontend - not here!
|
||||
if (substr($string, 0, 9) == 'internal-') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation assumes no query string, fragments or scheme included - only the path
|
||||
if (!preg_match(
|
||||
'/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/',
|
||||
$string
|
||||
)
|
||||
) {
|
||||
Zend_Cache::throwException("Invalid id or tag '$string' : must be a valid URL path");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect an octal string and return its octal value for file permission ops
|
||||
* otherwise return the non-string (assumed octal or decimal int already)
|
||||
*
|
||||
* @param string $val The potential octal in need of conversion
|
||||
* @return int
|
||||
*/
|
||||
protected function _octdec($val)
|
||||
{
|
||||
if (is_string($val) && decoct(octdec($val)) == $val) {
|
||||
return octdec($val);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a request URI from the provided ID
|
||||
*
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
protected function _decodeId($id)
|
||||
{
|
||||
return pack('H*', $id);
|
||||
}
|
||||
}
|
||||
@@ -1,416 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Frontend or Core directives
|
||||
*
|
||||
* @var array directives
|
||||
*/
|
||||
protected $_directives = array();
|
||||
|
||||
/**
|
||||
* Array to log actions
|
||||
*
|
||||
* @var array $_log
|
||||
*/
|
||||
private $_log = array();
|
||||
|
||||
/**
|
||||
* Current index for log array
|
||||
*
|
||||
* @var int $_index
|
||||
*/
|
||||
private $_index = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$this->_addLog('construct', array($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives assoc of directives
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
$this->_addLog('setDirectives', array($directives));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* if $id == 'serialized', the method will return a serialized array
|
||||
* ('foo' else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string Cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$this->_addLog('get', array($id, $doNotTestCacheValidity));
|
||||
|
||||
if ( $id == 'false'
|
||||
|| $id == 'd8523b3ee441006261eeffa5c3d3a0a7'
|
||||
|| $id == 'e83249ea22178277d5befc2c5e2e9ace'
|
||||
|| $id == '40f649b94977c0a6e76902e2a0b43587'
|
||||
|| $id == '88161989b73a4cbfd0b701c446115a99'
|
||||
|| $id == '205fc79cba24f0f0018eb92c7c8b3ba4'
|
||||
|| $id == '170720e35f38150b811f68a937fb042d')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($id=='serialized') {
|
||||
return serialize(array('foo'));
|
||||
}
|
||||
if ($id=='serialized2') {
|
||||
return serialize(array('headers' => array(), 'data' => 'foo'));
|
||||
}
|
||||
if ( $id == '71769f39054f75894288e397df04e445' || $id == '615d222619fb20b527168340cebd0578'
|
||||
|| $id == '8a02d218a5165c467e7a5747cc6bd4b6' || $id == '648aca1366211d17cbf48e65dc570bee'
|
||||
|| $id == '4a923ef02d7f997ca14d56dfeae25ea7') {
|
||||
return serialize(array('foo', 'bar'));
|
||||
}
|
||||
if ( $id == 'f53c7d912cc523d9a65834c8286eceb9') {
|
||||
return serialize(array('foobar'));
|
||||
}
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (123456 else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$this->_addLog('test', array($id));
|
||||
if ($id=='false') {
|
||||
return false;
|
||||
}
|
||||
if (($id=='3c439c922209e2cb0b54d6deffccd75a')) {
|
||||
return false;
|
||||
}
|
||||
return 123456;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$this->_addLog('save', array($data, $id, $tags));
|
||||
if (substr($id,-5)=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* For this test backend only, if $id == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$this->_addLog('remove', array($id));
|
||||
if (substr($id,-5)=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* For this test backend only, if $mode == 'false', then the method will return false
|
||||
* (true else)
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
$this->_addLog('clean', array($mode, $tags));
|
||||
if ($mode=='false') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last log
|
||||
*
|
||||
* @return string The last log
|
||||
*/
|
||||
public function getLastLog()
|
||||
{
|
||||
return $this->_log[$this->_index - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log index
|
||||
*
|
||||
* @return int Log index
|
||||
*/
|
||||
public function getLogIndex()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete log array
|
||||
*
|
||||
* @return array Complete log array
|
||||
*/
|
||||
public function getAllLogs()
|
||||
{
|
||||
return $this->_log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return array(
|
||||
'prefix_id1', 'prefix_id2'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return array(
|
||||
'tag1', 'tag2'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag1', 'tag2')) {
|
||||
return array('prefix_id1', 'prefix_id2');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag3', 'tag4')) {
|
||||
return array('prefix_id3', 'prefix_id4');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
if ($tags == array('tag5', 'tag6')) {
|
||||
return array('prefix_id5', 'prefix_id6');
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => false,
|
||||
'priority' => true,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the log array
|
||||
*
|
||||
* @param string $methodName MethodName
|
||||
* @param array $args Arguments
|
||||
* @return void
|
||||
*/
|
||||
private function _addLog($methodName, $args)
|
||||
{
|
||||
$this->_log[$this->_index] = array(
|
||||
'methodName' => $methodName,
|
||||
'args' => $args
|
||||
);
|
||||
$this->_index = $this->_index + 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,548 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) slow_backend :
|
||||
* - Slow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Should provide a big storage
|
||||
*
|
||||
* =====> (string) fast_backend :
|
||||
* - Flow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Must be much faster than slow_backend
|
||||
*
|
||||
* =====> (array) slow_backend_options :
|
||||
* - Slow backend options (see corresponding backend)
|
||||
*
|
||||
* =====> (array) fast_backend_options :
|
||||
* - Fast backend options (see corresponding backend)
|
||||
*
|
||||
* =====> (int) stats_update_factor :
|
||||
* - Disable / Tune the computation of the fast backend filling percentage
|
||||
* - When saving a record into cache :
|
||||
* 1 => systematic computation of the fast backend filling percentage
|
||||
* x (integer) > 1 => computation of the fast backend filling percentage randomly 1 times on x cache write
|
||||
*
|
||||
* =====> (boolean) slow_backend_custom_naming :
|
||||
* =====> (boolean) fast_backend_custom_naming :
|
||||
* =====> (boolean) slow_backend_autoload :
|
||||
* =====> (boolean) fast_backend_autoload :
|
||||
* - See Zend_Cache::factory() method
|
||||
*
|
||||
* =====> (boolean) auto_fill_fast_cache
|
||||
* - If true, automatically fill the fast cache when a cache record was not found in fast cache, but did
|
||||
* exist in slow cache. This can be usefull when a non-persistent cache like APC or Memcached got
|
||||
* purged for whatever reason.
|
||||
*
|
||||
* =====> (boolean) auto_refresh_fast_cache
|
||||
* - If true, auto refresh the fast cache when a cache record is hit
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'slow_backend' => 'File',
|
||||
'fast_backend' => 'Apc',
|
||||
'slow_backend_options' => array(),
|
||||
'fast_backend_options' => array(),
|
||||
'stats_update_factor' => 10,
|
||||
'slow_backend_custom_naming' => false,
|
||||
'fast_backend_custom_naming' => false,
|
||||
'slow_backend_autoload' => false,
|
||||
'fast_backend_autoload' => false,
|
||||
'auto_fill_fast_cache' => true,
|
||||
'auto_refresh_fast_cache' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Slow Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
protected $_slowBackend;
|
||||
|
||||
/**
|
||||
* Fast Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend_ExtendedInterface
|
||||
*/
|
||||
protected $_fastBackend;
|
||||
|
||||
/**
|
||||
* Cache for the fast backend filling percentage
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_fastBackendFillingPercentage = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
if ($this->_options['slow_backend'] === null) {
|
||||
Zend_Cache::throwException('slow_backend option has to set');
|
||||
} elseif ($this->_options['slow_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||
$this->_slowBackend = $this->_options['slow_backend'];
|
||||
} else {
|
||||
$this->_slowBackend = Zend_Cache::_makeBackend(
|
||||
$this->_options['slow_backend'],
|
||||
$this->_options['slow_backend_options'],
|
||||
$this->_options['slow_backend_custom_naming'],
|
||||
$this->_options['slow_backend_autoload']
|
||||
);
|
||||
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
|
||||
Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_options['fast_backend'] === null) {
|
||||
Zend_Cache::throwException('fast_backend option has to set');
|
||||
} elseif ($this->_options['fast_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||
$this->_fastBackend = $this->_options['fast_backend'];
|
||||
} else {
|
||||
$this->_fastBackend = Zend_Cache::_makeBackend(
|
||||
$this->_options['fast_backend'],
|
||||
$this->_options['fast_backend_options'],
|
||||
$this->_options['fast_backend_custom_naming'],
|
||||
$this->_options['fast_backend_autoload']
|
||||
);
|
||||
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
|
||||
Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_slowBackend->setDirectives($this->_directives);
|
||||
$this->_fastBackend->setDirectives($this->_directives);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$fastTest = $this->_fastBackend->test($id);
|
||||
if ($fastTest) {
|
||||
return $fastTest;
|
||||
} else {
|
||||
return $this->_slowBackend->test($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||
{
|
||||
$usage = $this->_getFastFillingPercentage('saving');
|
||||
$boolFast = true;
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$preparedData = $this->_prepareData($data, $lifetime, $priority);
|
||||
if (($priority > 0) && (10 * $priority >= $usage)) {
|
||||
$fastLifetime = $this->_getFastLifetime($lifetime, $priority);
|
||||
$boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
|
||||
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||
} else {
|
||||
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||
if ($boolSlow === true) {
|
||||
$boolFast = $this->_fastBackend->remove($id);
|
||||
if (!$boolFast && !$this->_fastBackend->test($id)) {
|
||||
// some backends return false on remove() even if the key never existed. (and it won't if fast is full)
|
||||
// all we care about is that the key doesn't exist now
|
||||
$boolFast = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ($boolFast && $boolSlow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$resultFast = $this->_fastBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($resultFast === false) {
|
||||
$resultSlow = $this->_slowBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($resultSlow === false) {
|
||||
// there is no cache at all for this id
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$array = $resultFast !== false ? unserialize($resultFast) : unserialize($resultSlow);
|
||||
|
||||
//In case no cache entry was found in the FastCache and auto-filling is enabled, copy data to FastCache
|
||||
if ($resultFast === false && $this->_options['auto_fill_fast_cache']) {
|
||||
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||
$this->_fastBackend->save($preparedData, $id, array(), $array['lifetime']);
|
||||
}
|
||||
// maybe, we have to refresh the fast cache ?
|
||||
elseif ($this->_options['auto_refresh_fast_cache']) {
|
||||
if ($array['priority'] == 10) {
|
||||
// no need to refresh the fast cache with priority = 10
|
||||
return $array['data'];
|
||||
}
|
||||
$newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
|
||||
// we have the time to refresh the fast cache
|
||||
$usage = $this->_getFastFillingPercentage('loading');
|
||||
if (($array['priority'] > 0) && (10 * $array['priority'] >= $usage)) {
|
||||
// we can refresh the fast cache
|
||||
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||
$this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
|
||||
}
|
||||
}
|
||||
return $array['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$boolFast = $this->_fastBackend->remove($id);
|
||||
$boolSlow = $this->_slowBackend->remove($id);
|
||||
return $boolFast && $boolSlow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$boolFast = $this->_fastBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||
$boolSlow = $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||
return $boolFast && $boolSlow;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
return $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$ids = $this->_slowBackend->getIdsMatchingTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$ids = $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$ids = $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||
$res = true;
|
||||
foreach ($ids as $id) {
|
||||
$bool = $this->remove($id);
|
||||
$res = $res && $bool;
|
||||
}
|
||||
return $res;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this->_slowBackend->getIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->_slowBackend->getTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsMatchingTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
return $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return $this->_slowBackend->getFillingPercentage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return $this->_slowBackend->getMetadatas($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return $this->_slowBackend->touch($id, $extraLifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
$slowBackendCapabilities = $this->_slowBackend->getCapabilities();
|
||||
return array(
|
||||
'automatic_cleaning' => $slowBackendCapabilities['automatic_cleaning'],
|
||||
'tags' => $slowBackendCapabilities['tags'],
|
||||
'expired_read' => $slowBackendCapabilities['expired_read'],
|
||||
'priority' => $slowBackendCapabilities['priority'],
|
||||
'infinite_lifetime' => $slowBackendCapabilities['infinite_lifetime'],
|
||||
'get_list' => $slowBackendCapabilities['get_list']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a serialized array to store datas and metadatas informations
|
||||
*
|
||||
* @param string $data data to store
|
||||
* @param int $lifetime original lifetime
|
||||
* @param int $priority priority
|
||||
* @return string serialize array to store into cache
|
||||
*/
|
||||
private function _prepareData($data, $lifetime, $priority)
|
||||
{
|
||||
$lt = $lifetime;
|
||||
if ($lt === null) {
|
||||
$lt = 9999999999;
|
||||
}
|
||||
return serialize(array(
|
||||
'data' => $data,
|
||||
'lifetime' => $lifetime,
|
||||
'expire' => time() + $lt,
|
||||
'priority' => $priority
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and return the lifetime for the fast backend
|
||||
*
|
||||
* @param int $lifetime original lifetime
|
||||
* @param int $priority priority
|
||||
* @param int $maxLifetime maximum lifetime
|
||||
* @return int lifetime for the fast backend
|
||||
*/
|
||||
private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
|
||||
{
|
||||
if ($lifetime <= 0) {
|
||||
// if no lifetime, we have an infinite lifetime
|
||||
// we need to use arbitrary lifetimes
|
||||
$fastLifetime = (int) (2592000 / (11 - $priority));
|
||||
} else {
|
||||
// prevent computed infinite lifetime (0) by ceil
|
||||
$fastLifetime = (int) ceil($lifetime / (11 - $priority));
|
||||
}
|
||||
|
||||
if ($maxLifetime >= 0 && $fastLifetime > $maxLifetime) {
|
||||
return $maxLifetime;
|
||||
}
|
||||
|
||||
return $fastLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
$this->_fastBackend->remove($id);
|
||||
$this->_slowBackend->___expire($id);
|
||||
}
|
||||
|
||||
private function _getFastFillingPercentage($mode)
|
||||
{
|
||||
|
||||
if ($mode == 'saving') {
|
||||
// mode saving
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
} else {
|
||||
$rand = rand(1, $this->_options['stats_update_factor']);
|
||||
if ($rand == 1) {
|
||||
// we force a refresh
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// mode loading
|
||||
// we compute the percentage only if it's not available in cache
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
}
|
||||
}
|
||||
return $this->_fastBackendFillingPercentage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_WinCache extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::clean() : tags are unsupported by the WinCache backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::save() : tags are unsupported by the WinCache backend';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('wincache')) {
|
||||
Zend_Cache::throwException('The wincache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the WinCache backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = wincache_ucache_set($id, array($data, time(), $lifetime), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return wincache_ucache_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return wincache_ucache_clear();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_WinCache::clean() : CLEANING_MODE_OLD is unsupported by the WinCache backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = wincache_ucache_meminfo();
|
||||
$memSize = $mem['memory_total'];
|
||||
$memUsed = $memSize - $mem['memory_free'];
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get WinCache memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$res = array();
|
||||
$array = wincache_ucache_info();
|
||||
$records = $array['ucache_entries'];
|
||||
foreach ($records as $record) {
|
||||
$res[] = $record['key_name'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = wincache_ucache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
return wincache_ucache_set($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) user :
|
||||
* xcache.admin.user (necessary for the clean() method)
|
||||
*
|
||||
* =====> (string) password :
|
||||
* xcache.admin.pass (clear, not MD5) (necessary for the clean() method)
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'user' => null,
|
||||
'password' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('xcache')) {
|
||||
Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
if ($doNotTestCacheValidity) {
|
||||
$this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend");
|
||||
}
|
||||
$tmp = xcache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
if (xcache_isset($id)) {
|
||||
$tmp = xcache_get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = xcache_set($id, array($data, time()), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return xcache_unset($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
// Necessary because xcache_clear_cache() need basic authentification
|
||||
$backup = array();
|
||||
if (isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
$backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
|
||||
}
|
||||
if (isset($_SERVER['PHP_AUTH_PW'])) {
|
||||
$backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
|
||||
}
|
||||
if ($this->_options['user']) {
|
||||
$_SERVER['PHP_AUTH_USER'] = $this->_options['user'];
|
||||
}
|
||||
if ($this->_options['password']) {
|
||||
$_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
|
||||
}
|
||||
|
||||
$cnt = xcache_count(XC_TYPE_VAR);
|
||||
for ($i=0; $i < $cnt; $i++) {
|
||||
xcache_clear_cache(XC_TYPE_VAR, $i);
|
||||
}
|
||||
|
||||
if (isset($backup['PHP_AUTH_USER'])) {
|
||||
$_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
|
||||
$_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* Impementation of Zend Cache Backend using the Zend Platform (Output Content Caching)
|
||||
*
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* internal ZP prefix
|
||||
*/
|
||||
const TAGS_PREFIX = "internal_ZPtag:";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Validate that the Zend Platform is loaded and licensed
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('accelerator_license_info')) {
|
||||
Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
|
||||
}
|
||||
if (!function_exists('accelerator_get_configuration')) {
|
||||
$licenseInfo = accelerator_license_info();
|
||||
Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: '.$licenseInfo['failure_reason']);
|
||||
}
|
||||
$accConf = accelerator_get_configuration();
|
||||
if (@!$accConf['output_cache_licensed']) {
|
||||
Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
|
||||
}
|
||||
if (@!$accConf['output_cache_enabled']) {
|
||||
Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
|
||||
}
|
||||
if (!is_writable($accConf['output_cache_dir'])) {
|
||||
Zend_Cache::throwException('The cache copies directory \''. ini_get('zend_accelerator.output_cache_dir') .'\' must be writable !');
|
||||
}
|
||||
parent:: __construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string Cached data (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
// doNotTestCacheValidity implemented by giving zero lifetime to the cache
|
||||
if ($doNotTestCacheValidity) {
|
||||
$lifetime = 0;
|
||||
} else {
|
||||
$lifetime = $this->_directives['lifetime'];
|
||||
}
|
||||
$res = output_cache_get($id, $lifetime);
|
||||
if($res) {
|
||||
return $res[0];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$result = output_cache_get($id, $this->_directives['lifetime']);
|
||||
if ($result) {
|
||||
return $result[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Data to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
if (!($specificLifetime === false)) {
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend");
|
||||
}
|
||||
|
||||
$lifetime = $this->_directives['lifetime'];
|
||||
$result1 = output_cache_put($id, array($data, time()));
|
||||
$result2 = (count($tags) == 0);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$tagid = self::TAGS_PREFIX.$tag;
|
||||
$old_tags = output_cache_get($tagid, $lifetime);
|
||||
if ($old_tags === false) {
|
||||
$old_tags = array();
|
||||
}
|
||||
$old_tags[$id] = $id;
|
||||
output_cache_remove_key($tagid);
|
||||
$result2 = output_cache_put($tagid, $old_tags);
|
||||
}
|
||||
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return output_cache_remove_key($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* This mode is not supported in this backend
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$cache_dir = ini_get('zend_accelerator.output_cache_dir');
|
||||
if (!$cache_dir) {
|
||||
return false;
|
||||
}
|
||||
$cache_dir .= '/.php_cache_api/';
|
||||
return $this->_clean($cache_dir, $mode);
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
$idlist = null;
|
||||
foreach ($tags as $tag) {
|
||||
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||
if ($idlist) {
|
||||
$idlist = array_intersect_assoc($idlist, $next_idlist);
|
||||
} else {
|
||||
$idlist = $next_idlist;
|
||||
}
|
||||
if (count($idlist) == 0) {
|
||||
// if ID list is already empty - we may skip checking other IDs
|
||||
$idlist = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($idlist) {
|
||||
foreach ($idlist as $id) {
|
||||
output_cache_remove_key($id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend");
|
||||
return false;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$idlist = null;
|
||||
foreach ($tags as $tag) {
|
||||
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||
if ($idlist) {
|
||||
$idlist = array_merge_recursive($idlist, $next_idlist);
|
||||
} else {
|
||||
$idlist = $next_idlist;
|
||||
}
|
||||
if (count($idlist) == 0) {
|
||||
// if ID list is already empty - we may skip checking other IDs
|
||||
$idlist = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($idlist) {
|
||||
foreach ($idlist as $id) {
|
||||
output_cache_remove_key($id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a directory and recursivly go over it's subdirectories
|
||||
*
|
||||
* Remove all the cached files that need to be cleaned (according to mode and files mtime)
|
||||
*
|
||||
* @param string $dir Path of directory ot clean
|
||||
* @param string $mode The same parameter as in Zend_Cache_Backend_ZendPlatform::clean()
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _clean($dir, $mode)
|
||||
{
|
||||
$d = @dir($dir);
|
||||
if (!$d) {
|
||||
return false;
|
||||
}
|
||||
$result = true;
|
||||
while (false !== ($file = $d->read())) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
$file = $d->path . $file;
|
||||
if (is_dir($file)) {
|
||||
$result = ($this->_clean($file .'/', $mode)) && ($result);
|
||||
} else {
|
||||
if ($mode == Zend_Cache::CLEANING_MODE_ALL) {
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
} else if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
|
||||
// Files older than lifetime get deleted from cache
|
||||
if ($this->_directives['lifetime'] !== null) {
|
||||
if ((time() - @filemtime($file)) > $this->_directives['lifetime']) {
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$d->close();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file
|
||||
*
|
||||
* If we can't remove the file (because of locks or any problem), we will touch
|
||||
* the file to invalidate it
|
||||
*
|
||||
* @param string $file Complete file path
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
private function _remove($file)
|
||||
{
|
||||
if (!@unlink($file)) {
|
||||
# If we can't remove the file (because of locks or any problem), we will touch
|
||||
# the file to invalidate it
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
|
||||
if ($this->_directives['lifetime'] === null) {
|
||||
return false;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
return @touch($file, time() - 2*abs($this->_directives['lifetime']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend */
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) namespace :
|
||||
* Namespace to be used for chaching operations
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'namespace' => 'zendframework'
|
||||
);
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _store($data, $id, $timeToLive);
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _fetch($id);
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
*/
|
||||
abstract protected function _unset($id);
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
abstract protected function _clear();
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_fetch($id);
|
||||
if ($tmp !== null) {
|
||||
return $tmp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_fetch('internal-metadatas---' . $id);
|
||||
if ($tmp !== false) {
|
||||
if (!is_array($tmp) || !isset($tmp['mtime'])) {
|
||||
Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' );
|
||||
}
|
||||
return $tmp['mtime'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute & return the expire time
|
||||
*
|
||||
* @return int expire time (unix timestamp)
|
||||
*/
|
||||
private function _expireTime($lifetime)
|
||||
{
|
||||
if ($lifetime === null) {
|
||||
return 9999999999;
|
||||
}
|
||||
return time() + $lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$metadatas = array(
|
||||
'mtime' => time(),
|
||||
'expire' => $this->_expireTime($lifetime),
|
||||
);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends');
|
||||
}
|
||||
|
||||
return $this->_store($data, $id, $lifetime) &&
|
||||
$this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$result1 = $this->_unset($id);
|
||||
$result2 = $this->_unset('internal-metadatas---' . $id);
|
||||
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$this->_clear();
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends.");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_clear();
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.');
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_disk_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_disk_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_shm_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @param mixed $data Object to store
|
||||
* @param string $id Cache id
|
||||
* @param int $timeToLive Time to live in seconds
|
||||
* @return bool
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_shm_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
||||
@@ -1,765 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Core
|
||||
{
|
||||
/**
|
||||
* Messages
|
||||
*/
|
||||
const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend';
|
||||
const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available';
|
||||
|
||||
/**
|
||||
* Backend Object
|
||||
*
|
||||
* @var Zend_Cache_Backend_Interface $_backend
|
||||
*/
|
||||
protected $_backend = null;
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* ====> (boolean) write_control :
|
||||
* - Enable / disable write control (the cache is read just after writing to detect corrupt entries)
|
||||
* - Enable write control will lightly slow the cache writing but not the cache reading
|
||||
* Write control can detect some corrupt cache files but maybe it's not a perfect control
|
||||
*
|
||||
* ====> (boolean) caching :
|
||||
* - Enable / disable caching
|
||||
* (can be very useful for the debug of cached scripts)
|
||||
*
|
||||
* =====> (string) cache_id_prefix :
|
||||
* - prefix for cache ids (namespace)
|
||||
*
|
||||
* ====> (boolean) automatic_serialization :
|
||||
* - Enable / disable automatic serialization
|
||||
* - It can be used to save directly datas which aren't strings (but it's slower)
|
||||
*
|
||||
* ====> (int) automatic_cleaning_factor :
|
||||
* - Disable / Tune the automatic cleaning process
|
||||
* - The automatic cleaning process destroy too old (for the given life time)
|
||||
* cache files when a new cache file is written :
|
||||
* 0 => no automatic cache cleaning
|
||||
* 1 => systematic cache cleaning
|
||||
* x (integer) > 1 => automatic cleaning randomly 1 times on x cache write
|
||||
*
|
||||
* ====> (int) lifetime :
|
||||
* - Cache lifetime (in seconds)
|
||||
* - If null, the cache is valid forever.
|
||||
*
|
||||
* ====> (boolean) logging :
|
||||
* - If set to true, logging is activated (but the system is slower)
|
||||
*
|
||||
* ====> (boolean) ignore_user_abort
|
||||
* - If set to true, the core will set the ignore_user_abort PHP flag inside the
|
||||
* save() method to avoid cache corruptions in some cases (default false)
|
||||
*
|
||||
* @var array $_options available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'write_control' => true,
|
||||
'caching' => true,
|
||||
'cache_id_prefix' => null,
|
||||
'automatic_serialization' => false,
|
||||
'automatic_cleaning_factor' => 10,
|
||||
'lifetime' => 3600,
|
||||
'logging' => false,
|
||||
'logger' => null,
|
||||
'ignore_user_abort' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of options which have to be transfered to backend
|
||||
*
|
||||
* @var array $_directivesList
|
||||
*/
|
||||
protected static $_directivesList = array('lifetime', 'logging', 'logger');
|
||||
|
||||
/**
|
||||
* Not used for the core, just a sort a hint to get a common setOption() method (for the core and for frontends)
|
||||
*
|
||||
* @var array $_specificOptions
|
||||
*/
|
||||
protected $_specificOptions = array();
|
||||
|
||||
/**
|
||||
* Last used cache id
|
||||
*
|
||||
* @var string $_lastId
|
||||
*/
|
||||
private $_lastId = null;
|
||||
|
||||
/**
|
||||
* True if the backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
*
|
||||
* @var boolean $_extendedBackend
|
||||
*/
|
||||
protected $_extendedBackend = false;
|
||||
|
||||
/**
|
||||
* Array of capabilities of the backend (only if it implements Zend_Cache_Backend_ExtendedInterface)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_backendCapabilities = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options Associative array of options or Zend_Config instance
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
Zend_Cache::throwException("Options passed were not an array"
|
||||
. " or Zend_Config instance.");
|
||||
}
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
$this->_loggerSanity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options using an instance of type Zend_Config
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @return Zend_Cache_Core
|
||||
*/
|
||||
public function setConfig(Zend_Config $config)
|
||||
{
|
||||
$options = $config->toArray();
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the backend
|
||||
*
|
||||
* @param Zend_Cache_Backend $backendObject
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setBackend(Zend_Cache_Backend $backendObject)
|
||||
{
|
||||
$this->_backend= $backendObject;
|
||||
// some options (listed in $_directivesList) have to be given
|
||||
// to the backend too (even if they are not "backend specific")
|
||||
$directives = array();
|
||||
foreach (Zend_Cache_Core::$_directivesList as $directive) {
|
||||
$directives[$directive] = $this->_options[$directive];
|
||||
}
|
||||
$this->_backend->setDirectives($directives);
|
||||
if (in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_backend))) {
|
||||
$this->_extendedBackend = true;
|
||||
$this->_backendCapabilities = $this->_backend->getCapabilities();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the backend
|
||||
*
|
||||
* @return Zend_Cache_Backend backend object
|
||||
*/
|
||||
public function getBackend()
|
||||
{
|
||||
return $this->_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public frontend to set an option
|
||||
*
|
||||
* There is an additional validation (relatively to the protected _setOption method)
|
||||
*
|
||||
* @param string $name Name of the option
|
||||
* @param mixed $value Value of the option
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name!");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
// This is a Core option
|
||||
$this->_setOption($name, $value);
|
||||
return;
|
||||
}
|
||||
if (array_key_exists($name, $this->_specificOptions)) {
|
||||
// This a specic option of this frontend
|
||||
$this->_specificOptions[$name] = $value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Public frontend to get an option value
|
||||
*
|
||||
* @param string $name Name of the option
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return mixed option value
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
// This is a Core option
|
||||
return $this->_options[$name];
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $this->_specificOptions)) {
|
||||
// This a specic option of this frontend
|
||||
return $this->_specificOptions[$name];
|
||||
}
|
||||
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option
|
||||
*
|
||||
* @param string $name Name of the option
|
||||
* @param mixed $value Value of the option
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
private function _setOption($name, $value)
|
||||
{
|
||||
if (!is_string($name) || !array_key_exists($name, $this->_options)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
if ($name == 'lifetime' && empty($value)) {
|
||||
$value = null;
|
||||
}
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a new lifetime
|
||||
*
|
||||
* The new value is set for the core/frontend but for the backend too (directive)
|
||||
*
|
||||
* @param int $newLifetime New lifetime (in seconds)
|
||||
* @return void
|
||||
*/
|
||||
public function setLifetime($newLifetime)
|
||||
{
|
||||
$this->_options['lifetime'] = $newLifetime;
|
||||
$this->_backend->setDirectives(array(
|
||||
'lifetime' => $newLifetime
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
|
||||
* @return mixed|false Cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
|
||||
{
|
||||
if (!$this->_options['caching']) {
|
||||
return false;
|
||||
}
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
$this->_lastId = $id;
|
||||
$this->_validateIdOrTag($id);
|
||||
|
||||
$this->_log("Zend_Cache_Core: load item '{$id}'", 7);
|
||||
$data = $this->_backend->load($id, $doNotTestCacheValidity);
|
||||
if ($data===false) {
|
||||
// no cache available
|
||||
return false;
|
||||
}
|
||||
if ((!$doNotUnserialize) && $this->_options['automatic_serialization']) {
|
||||
// we need to unserialize before sending the result
|
||||
return unserialize($data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return int|false Last modified time of cache entry if it is available, false otherwise
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
if (!$this->_options['caching']) {
|
||||
return false;
|
||||
}
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
$this->_validateIdOrTag($id);
|
||||
$this->_lastId = $id;
|
||||
|
||||
$this->_log("Zend_Cache_Core: test item '{$id}'", 7);
|
||||
return $this->_backend->test($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some data in a cache
|
||||
*
|
||||
* @param mixed $data Data to put in cache (can be another type than string if automatic_serialization is on)
|
||||
* @param string $id Cache id (if not set, the last cache id will be used)
|
||||
* @param array $tags Cache tags
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||
{
|
||||
if (!$this->_options['caching']) {
|
||||
return true;
|
||||
}
|
||||
if ($id === null) {
|
||||
$id = $this->_lastId;
|
||||
} else {
|
||||
$id = $this->_id($id);
|
||||
}
|
||||
$this->_validateIdOrTag($id);
|
||||
$this->_validateTagsArray($tags);
|
||||
if ($this->_options['automatic_serialization']) {
|
||||
// we need to serialize datas before storing them
|
||||
$data = serialize($data);
|
||||
} else {
|
||||
if (!is_string($data)) {
|
||||
Zend_Cache::throwException("Datas must be string or set automatic_serialization = true");
|
||||
}
|
||||
}
|
||||
|
||||
// automatic cleaning
|
||||
if ($this->_options['automatic_cleaning_factor'] > 0) {
|
||||
$rand = rand(1, $this->_options['automatic_cleaning_factor']);
|
||||
if ($rand==1) {
|
||||
// new way || deprecated way
|
||||
if ($this->_extendedBackend || method_exists($this->_backend, 'isAutomaticCleaningAvailable')) {
|
||||
$this->_log("Zend_Cache_Core::save(): automatic cleaning running", 7);
|
||||
$this->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||
} else {
|
||||
$this->_log("Zend_Cache_Core::save(): automatic cleaning is not available/necessary with current backend", 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_log("Zend_Cache_Core: save item '{$id}'", 7);
|
||||
if ($this->_options['ignore_user_abort']) {
|
||||
$abort = ignore_user_abort(true);
|
||||
}
|
||||
if (($this->_extendedBackend) && ($this->_backendCapabilities['priority'])) {
|
||||
$result = $this->_backend->save($data, $id, $tags, $specificLifetime, $priority);
|
||||
} else {
|
||||
$result = $this->_backend->save($data, $id, $tags, $specificLifetime);
|
||||
}
|
||||
if ($this->_options['ignore_user_abort']) {
|
||||
ignore_user_abort($abort);
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
// maybe the cache is corrupted, so we remove it !
|
||||
$this->_log("Zend_Cache_Core::save(): failed to save item '{$id}' -> removing it", 4);
|
||||
$this->_backend->remove($id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->_options['write_control']) {
|
||||
$data2 = $this->_backend->load($id, true);
|
||||
if ($data!=$data2) {
|
||||
$this->_log("Zend_Cache_Core::save(): write control of item '{$id}' failed -> removing it", 4);
|
||||
$this->_backend->remove($id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache
|
||||
*
|
||||
* @param string $id Cache id to remove
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
if (!$this->_options['caching']) {
|
||||
return true;
|
||||
}
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
$this->_validateIdOrTag($id);
|
||||
|
||||
$this->_log("Zend_Cache_Core: remove item '{$id}'", 7);
|
||||
return $this->_backend->remove($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean cache entries
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => remove too old cache entries ($tags is not used)
|
||||
* 'matchingTag' => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode
|
||||
* @param array|string $tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if ok
|
||||
*/
|
||||
public function clean($mode = 'all', $tags = array())
|
||||
{
|
||||
if (!$this->_options['caching']) {
|
||||
return true;
|
||||
}
|
||||
if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL,
|
||||
Zend_Cache::CLEANING_MODE_OLD,
|
||||
Zend_Cache::CLEANING_MODE_MATCHING_TAG,
|
||||
Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
|
||||
Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
|
||||
Zend_Cache::throwException('Invalid cleaning mode');
|
||||
}
|
||||
$this->_validateTagsArray($tags);
|
||||
|
||||
return $this->_backend->clean($mode, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
if (!($this->_backendCapabilities['tags'])) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||
}
|
||||
|
||||
$ids = $this->_backend->getIdsMatchingTags($tags);
|
||||
|
||||
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||
$prefix = & $this->_options['cache_id_prefix'];
|
||||
$prefixLen = strlen($prefix);
|
||||
foreach ($ids as &$id) {
|
||||
if (strpos($id, $prefix) === 0) {
|
||||
$id = substr($id, $prefixLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
if (!($this->_backendCapabilities['tags'])) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||
}
|
||||
|
||||
$ids = $this->_backend->getIdsNotMatchingTags($tags);
|
||||
|
||||
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||
$prefix = & $this->_options['cache_id_prefix'];
|
||||
$prefixLen = strlen($prefix);
|
||||
foreach ($ids as &$id) {
|
||||
if (strpos($id, $prefix) === 0) {
|
||||
$id = substr($id, $prefixLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching any cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
if (!($this->_backendCapabilities['tags'])) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||
}
|
||||
|
||||
$ids = $this->_backend->getIdsMatchingAnyTags($tags);
|
||||
|
||||
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||
$prefix = & $this->_options['cache_id_prefix'];
|
||||
$prefixLen = strlen($prefix);
|
||||
foreach ($ids as &$id) {
|
||||
if (strpos($id, $prefix) === 0) {
|
||||
$id = substr($id, $prefixLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
|
||||
$ids = $this->_backend->getIds();
|
||||
|
||||
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||
$prefix = & $this->_options['cache_id_prefix'];
|
||||
$prefixLen = strlen($prefix);
|
||||
foreach ($ids as &$id) {
|
||||
if (strpos($id, $prefix) === 0) {
|
||||
$id = substr($id, $prefixLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
if (!($this->_backendCapabilities['tags'])) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||
}
|
||||
return $this->_backend->getTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
return $this->_backend->getFillingPercentage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array will include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
return $this->_backend->getMetadatas($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||
}
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
|
||||
$this->_log("Zend_Cache_Core: touch item '{$id}'", 7);
|
||||
return $this->_backend->touch($id, $extraLifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||
*
|
||||
* Throw an exception if a problem is found
|
||||
*
|
||||
* @param string $string Cache id or tag
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _validateIdOrTag($string)
|
||||
{
|
||||
if (!is_string($string)) {
|
||||
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||
}
|
||||
if (substr($string, 0, 9) == 'internal-') {
|
||||
Zend_Cache::throwException('"internal-*" ids or tags are reserved');
|
||||
}
|
||||
if (!preg_match('~^[a-zA-Z0-9_]+$~D', $string)) {
|
||||
Zend_Cache::throwException("Invalid id or tag '$string' : must use only [a-zA-Z0-9_]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a tags array (security, reliable filenames, reserved prefixes...)
|
||||
*
|
||||
* Throw an exception if a problem is found
|
||||
*
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _validateTagsArray($tags)
|
||||
{
|
||||
if (!is_array($tags)) {
|
||||
Zend_Cache::throwException('Invalid tags array : must be an array');
|
||||
}
|
||||
foreach($tags as $tag) {
|
||||
$this->_validateIdOrTag($tag);
|
||||
}
|
||||
reset($tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if we enable logging that the Zend_Log class
|
||||
* is available.
|
||||
* Create a default log object if none is set.
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _loggerSanity()
|
||||
{
|
||||
if (!isset($this->_options['logging']) || !$this->_options['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_options['logger']) && $this->_options['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a default logger to the standard output stream
|
||||
require_once 'Zend/Log.php';
|
||||
require_once 'Zend/Log/Writer/Stream.php';
|
||||
require_once 'Zend/Log/Filter/Priority.php';
|
||||
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||
$logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN, '<='));
|
||||
$this->_options['logger'] = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN (4) priority.
|
||||
*
|
||||
* @param string $message
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _log($message, $priority = 4)
|
||||
{
|
||||
if (!$this->_options['logging']) {
|
||||
return;
|
||||
}
|
||||
if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof Zend_Log)) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set');
|
||||
}
|
||||
$logger = $this->_options['logger'];
|
||||
$logger->log($message, $priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make and return a cache id
|
||||
*
|
||||
* Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return string Cache id (with or without prefix)
|
||||
*/
|
||||
protected function _id($id)
|
||||
{
|
||||
if (($id !== null) && isset($this->_options['cache_id_prefix'])) {
|
||||
return $this->_options['cache_id_prefix'] . $id; // return with prefix
|
||||
}
|
||||
return $id; // no prefix, just return the $id passed
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Exception extends Zend_Exception {}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_Capture extends Zend_Cache_Core
|
||||
{
|
||||
/**
|
||||
* Page identifiers
|
||||
* @var array
|
||||
*/
|
||||
protected $_idStack = array();
|
||||
|
||||
/**
|
||||
* Tags
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags = array();
|
||||
|
||||
protected $_extension = null;
|
||||
|
||||
/**
|
||||
* Start the cache
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
|
||||
*/
|
||||
public function start($id, array $tags, $extension = null)
|
||||
{
|
||||
$this->_tags = $tags;
|
||||
$this->_extension = $extension;
|
||||
ob_start(array($this, '_flush'));
|
||||
ob_implicit_flush(false);
|
||||
$this->_idStack[] = $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* callback for output buffering
|
||||
* (shouldn't really be called manually)
|
||||
*
|
||||
* @param string $data Buffered output
|
||||
* @return string Data to send to browser
|
||||
*/
|
||||
public function _flush($data)
|
||||
{
|
||||
$id = array_pop($this->_idStack);
|
||||
if ($id === null) {
|
||||
Zend_Cache::throwException('use of _flush() without a start()');
|
||||
}
|
||||
if ($this->_extension) {
|
||||
$this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
|
||||
} else {
|
||||
$this->save($data, $id, $this->_tags);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* ====> (mixed) cached_entity :
|
||||
* - if set to a class name, we will cache an abstract class and will use only static calls
|
||||
* - if set to an object, we will cache this object methods
|
||||
*
|
||||
* ====> (boolean) cache_by_default :
|
||||
* - if true, method calls will be cached by default
|
||||
*
|
||||
* ====> (array) cached_methods :
|
||||
* - an array of method names which will be cached (even if cache_by_default = false)
|
||||
*
|
||||
* ====> (array) non_cached_methods :
|
||||
* - an array of method names which won't be cached (even if cache_by_default = true)
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_specificOptions = array(
|
||||
'cached_entity' => null,
|
||||
'cache_by_default' => true,
|
||||
'cached_methods' => array(),
|
||||
'non_cached_methods' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Tags array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tags = array();
|
||||
|
||||
/**
|
||||
* SpecificLifetime value
|
||||
*
|
||||
* false => no specific life time
|
||||
*
|
||||
* @var bool|int
|
||||
*/
|
||||
protected $_specificLifetime = false;
|
||||
|
||||
/**
|
||||
* The cached object or the name of the cached abstract class
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_cachedEntity = null;
|
||||
|
||||
/**
|
||||
* The class name of the cached object or cached abstract class
|
||||
*
|
||||
* Used to differentiate between different classes with the same method calls.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_cachedEntityLabel = '';
|
||||
|
||||
/**
|
||||
* Priority (used by some particular backends)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_priority = 8;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
if ($this->_specificOptions['cached_entity'] === null) {
|
||||
Zend_Cache::throwException('cached_entity must be set !');
|
||||
}
|
||||
$this->setCachedEntity($this->_specificOptions['cached_entity']);
|
||||
$this->setOption('automatic_serialization', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a specific life time
|
||||
*
|
||||
* @param bool|int $specificLifetime
|
||||
* @return void
|
||||
*/
|
||||
public function setSpecificLifetime($specificLifetime = false)
|
||||
{
|
||||
$this->_specificLifetime = $specificLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the priority (used by some particular backends)
|
||||
*
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority)
|
||||
*/
|
||||
public function setPriority($priority)
|
||||
{
|
||||
$this->_priority = $priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public frontend to set an option
|
||||
*
|
||||
* Just a wrapper to get a specific behaviour for cached_entity
|
||||
*
|
||||
* @param string $name Name of the option
|
||||
* @param mixed $value Value of the option
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($name == 'cached_entity') {
|
||||
$this->setCachedEntity($value);
|
||||
} else {
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific method to set the cachedEntity
|
||||
*
|
||||
* if set to a class name, we will cache an abstract class and will use only static calls
|
||||
* if set to an object, we will cache this object methods
|
||||
*
|
||||
* @param mixed $cachedEntity
|
||||
*/
|
||||
public function setCachedEntity($cachedEntity)
|
||||
{
|
||||
if (!is_string($cachedEntity) && !is_object($cachedEntity)) {
|
||||
Zend_Cache::throwException(
|
||||
'cached_entity must be an object or a class name'
|
||||
);
|
||||
}
|
||||
|
||||
$this->_cachedEntity = $cachedEntity;
|
||||
$this->_specificOptions['cached_entity'] = $cachedEntity;
|
||||
|
||||
if (is_string($this->_cachedEntity)) {
|
||||
$this->_cachedEntityLabel = $this->_cachedEntity;
|
||||
} else {
|
||||
$ro = new ReflectionObject($this->_cachedEntity);
|
||||
$this->_cachedEntityLabel = $ro->getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache array
|
||||
*
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function setTagsArray($tags = array())
|
||||
{
|
||||
$this->_tags = $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method : call the specified method or get the result from cache
|
||||
*
|
||||
* @param string $name Method name
|
||||
* @param array $parameters Method parameters
|
||||
* @return mixed Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __call($name, $parameters)
|
||||
{
|
||||
$callback = array($this->_cachedEntity, $name);
|
||||
|
||||
if (!is_callable($callback, false)) {
|
||||
Zend_Cache::throwException('Invalid callback');
|
||||
}
|
||||
|
||||
$cacheBool1 = $this->_specificOptions['cache_by_default'];
|
||||
$cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']);
|
||||
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']);
|
||||
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
|
||||
|
||||
if (!$cache) {
|
||||
// We do not have not cache
|
||||
return call_user_func_array($callback, $parameters);
|
||||
}
|
||||
|
||||
$id = $this->makeId($name, $parameters);
|
||||
if (($rs = $this->load($id)) && (array_key_exists(0, $rs))
|
||||
&& (array_key_exists(1, $rs))
|
||||
) {
|
||||
// A cache is available
|
||||
$output = $rs[0];
|
||||
$return = $rs[1];
|
||||
} else {
|
||||
// A cache is not available (or not valid for this frontend)
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
|
||||
try {
|
||||
$return = call_user_func_array($callback, $parameters);
|
||||
$output = ob_get_clean();
|
||||
$data = array($output, $return);
|
||||
|
||||
$this->save(
|
||||
$data, $id, $this->_tags, $this->_specificLifetime,
|
||||
$this->_priority
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
ob_end_clean();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
echo $output;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZF-9970
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
private function _makeId($name, $args)
|
||||
{
|
||||
return $this->makeId($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a cache id from the method name and parameters
|
||||
*
|
||||
* @param string $name Method name
|
||||
* @param array $args Method parameters
|
||||
* @return string Cache id
|
||||
*/
|
||||
public function makeId($name, array $args = array())
|
||||
{
|
||||
return md5($this->_cachedEntityLabel . '__' . $name . '__' . serialize($args));
|
||||
}
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
{
|
||||
|
||||
/**
|
||||
* Consts for master_files_mode
|
||||
*/
|
||||
const MODE_AND = 'AND';
|
||||
const MODE_OR = 'OR';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* ====> (string) master_file :
|
||||
* - a complete path of the master file
|
||||
* - deprecated (see master_files)
|
||||
*
|
||||
* ====> (array) master_files :
|
||||
* - an array of complete path of master files
|
||||
* - this option has to be set !
|
||||
*
|
||||
* ====> (string) master_files_mode :
|
||||
* - Zend_Cache_Frontend_File::MODE_AND or Zend_Cache_Frontend_File::MODE_OR
|
||||
* - if MODE_AND, then all master files have to be touched to get a cache invalidation
|
||||
* - if MODE_OR (default), then a single touched master file is enough to get a cache invalidation
|
||||
*
|
||||
* ====> (boolean) ignore_missing_master_files
|
||||
* - if set to true, missing master files are ignored silently
|
||||
* - if set to false (default), an exception is thrown if there is a missing master file
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_specificOptions = array(
|
||||
'master_file' => null,
|
||||
'master_files' => null,
|
||||
'master_files_mode' => 'OR',
|
||||
'ignore_missing_master_files' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Master file mtimes
|
||||
*
|
||||
* Array of int
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_masterFile_mtimes = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
if (!isset($this->_specificOptions['master_files'])) {
|
||||
Zend_Cache::throwException('master_files option must be set');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the master_files option
|
||||
*
|
||||
* @param array $masterFiles the complete paths and name of the master files
|
||||
*/
|
||||
public function setMasterFiles(array $masterFiles)
|
||||
{
|
||||
$this->_specificOptions['master_file'] = null; // to keep a compatibility
|
||||
$this->_specificOptions['master_files'] = null;
|
||||
$this->_masterFile_mtimes = array();
|
||||
|
||||
clearstatcache();
|
||||
$i = 0;
|
||||
foreach ($masterFiles as $masterFile) {
|
||||
if (file_exists($masterFile)) {
|
||||
$mtime = filemtime($masterFile);
|
||||
} else {
|
||||
$mtime = false;
|
||||
}
|
||||
|
||||
if (!$this->_specificOptions['ignore_missing_master_files'] && !$mtime) {
|
||||
Zend_Cache::throwException('Unable to read master_file : ' . $masterFile);
|
||||
}
|
||||
|
||||
$this->_masterFile_mtimes[$i] = $mtime;
|
||||
$this->_specificOptions['master_files'][$i] = $masterFile;
|
||||
if ($i === 0) { // to keep a compatibility
|
||||
$this->_specificOptions['master_file'] = $masterFile;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the master_file option
|
||||
*
|
||||
* To keep the compatibility
|
||||
*
|
||||
* @deprecated
|
||||
* @param string $masterFile the complete path and name of the master file
|
||||
*/
|
||||
public function setMasterFile($masterFile)
|
||||
{
|
||||
$this->setMasterFiles(array($masterFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Public frontend to set an option
|
||||
*
|
||||
* Just a wrapper to get a specific behaviour for master_file
|
||||
*
|
||||
* @param string $name Name of the option
|
||||
* @param mixed $value Value of the option
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($name == 'master_file') {
|
||||
$this->setMasterFile($value);
|
||||
} else if ($name == 'master_files') {
|
||||
$this->setMasterFiles($value);
|
||||
} else {
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
|
||||
* @return mixed|false Cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
|
||||
{
|
||||
if (!$doNotTestCacheValidity) {
|
||||
if ($this->test($id)) {
|
||||
return parent::load($id, true, $doNotUnserialize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return parent::load($id, true, $doNotUnserialize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return int|false Last modified time of cache entry if it is available, false otherwise
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$lastModified = parent::test($id);
|
||||
if ($lastModified) {
|
||||
if ($this->_specificOptions['master_files_mode'] == self::MODE_AND) {
|
||||
// MODE_AND
|
||||
foreach($this->_masterFile_mtimes as $masterFileMTime) {
|
||||
if ($masterFileMTime) {
|
||||
if ($lastModified > $masterFileMTime) {
|
||||
return $lastModified;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// MODE_OR
|
||||
$res = true;
|
||||
foreach($this->_masterFile_mtimes as $masterFileMTime) {
|
||||
if ($masterFileMTime) {
|
||||
if ($lastModified <= $masterFileMTime) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $lastModified;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_Function extends Zend_Cache_Core
|
||||
{
|
||||
/**
|
||||
* This frontend specific options
|
||||
*
|
||||
* ====> (boolean) cache_by_default :
|
||||
* - if true, function calls will be cached by default
|
||||
*
|
||||
* ====> (array) cached_functions :
|
||||
* - an array of function names which will be cached (even if cache_by_default = false)
|
||||
*
|
||||
* ====> (array) non_cached_functions :
|
||||
* - an array of function names which won't be cached (even if cache_by_default = true)
|
||||
*
|
||||
* @var array options
|
||||
*/
|
||||
protected $_specificOptions = array(
|
||||
'cache_by_default' => true,
|
||||
'cached_functions' => array(),
|
||||
'non_cached_functions' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
$this->setOption('automatic_serialization', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method : call the specified function or get the result from cache
|
||||
*
|
||||
* @param callback $callback A valid callback
|
||||
* @param array $parameters Function parameters
|
||||
* @param array $tags Cache tags
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||
* @return mixed Result
|
||||
*/
|
||||
public function call($callback, array $parameters = array(), $tags = array(), $specificLifetime = false, $priority = 8)
|
||||
{
|
||||
if (!is_callable($callback, true, $name)) {
|
||||
Zend_Cache::throwException('Invalid callback');
|
||||
}
|
||||
|
||||
$cacheBool1 = $this->_specificOptions['cache_by_default'];
|
||||
$cacheBool2 = in_array($name, $this->_specificOptions['cached_functions']);
|
||||
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_functions']);
|
||||
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
|
||||
if (!$cache) {
|
||||
// Caching of this callback is disabled
|
||||
return call_user_func_array($callback, $parameters);
|
||||
}
|
||||
|
||||
$id = $this->_makeId($callback, $parameters);
|
||||
if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1])) {
|
||||
// A cache is available
|
||||
$output = $rs[0];
|
||||
$return = $rs[1];
|
||||
} else {
|
||||
// A cache is not available (or not valid for this frontend)
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
$return = call_user_func_array($callback, $parameters);
|
||||
$output = ob_get_clean();
|
||||
$data = array($output, $return);
|
||||
$this->save($data, $id, $tags, $specificLifetime, $priority);
|
||||
}
|
||||
|
||||
echo $output;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* ZF-9970
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
private function _makeId($callback, array $args)
|
||||
{
|
||||
return $this->makeId($callback, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a cache id from the function name and parameters
|
||||
*
|
||||
* @param callback $callback A valid callback
|
||||
* @param array $args Function parameters
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return string Cache id
|
||||
*/
|
||||
public function makeId($callback, array $args = array())
|
||||
{
|
||||
if (!is_callable($callback, true, $name)) {
|
||||
Zend_Cache::throwException('Invalid callback');
|
||||
}
|
||||
|
||||
// functions, methods and classnames are case-insensitive
|
||||
$name = strtolower($name);
|
||||
|
||||
// generate a unique id for object callbacks
|
||||
if (is_object($callback)) { // Closures & __invoke
|
||||
$object = $callback;
|
||||
} elseif (isset($callback[0])) { // array($object, 'method')
|
||||
$object = $callback[0];
|
||||
}
|
||||
if (isset($object)) {
|
||||
try {
|
||||
$tmp = @serialize($callback);
|
||||
} catch (Exception $e) {
|
||||
Zend_Cache::throwException($e->getMessage());
|
||||
}
|
||||
if (!$tmp) {
|
||||
$lastErr = error_get_last();
|
||||
Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
|
||||
}
|
||||
$name.= '__' . $tmp;
|
||||
}
|
||||
|
||||
// generate a unique id for arguments
|
||||
$argsStr = '';
|
||||
if ($args) {
|
||||
try {
|
||||
$argsStr = @serialize(array_values($args));
|
||||
} catch (Exception $e) {
|
||||
Zend_Cache::throwException($e->getMessage());
|
||||
}
|
||||
if (!$argsStr) {
|
||||
$lastErr = error_get_last();
|
||||
throw Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
|
||||
}
|
||||
}
|
||||
|
||||
return md5($name . $argsStr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_Output extends Zend_Cache_Core
|
||||
{
|
||||
|
||||
private $_idStack = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
$this->_idStack = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the cache
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simply returned else)
|
||||
* @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
|
||||
*/
|
||||
public function start($id, $doNotTestCacheValidity = false, $echoData = true)
|
||||
{
|
||||
$data = $this->load($id, $doNotTestCacheValidity);
|
||||
if ($data !== false) {
|
||||
if ( $echoData ) {
|
||||
echo($data);
|
||||
return true;
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
$this->_idStack[] = $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the cache
|
||||
*
|
||||
* @param array $tags Tags array
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param string $forcedDatas If not null, force written datas with this
|
||||
* @param boolean $echoData If set to true, datas are sent to the browser
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||
* @return void
|
||||
*/
|
||||
public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
|
||||
{
|
||||
if ($forcedDatas === null) {
|
||||
$data = ob_get_clean();
|
||||
} else {
|
||||
$data =& $forcedDatas;
|
||||
}
|
||||
$id = array_pop($this->_idStack);
|
||||
if ($id === null) {
|
||||
Zend_Cache::throwException('use of end() without a start()');
|
||||
}
|
||||
$this->save($data, $id, $tags, $specificLifetime, $priority);
|
||||
if ($echoData) {
|
||||
echo($data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,404 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
{
|
||||
/**
|
||||
* This frontend specific options
|
||||
*
|
||||
* ====> (boolean) http_conditional :
|
||||
* - if true, http conditional mode is on
|
||||
* WARNING : http_conditional OPTION IS NOT IMPLEMENTED FOR THE MOMENT (TODO)
|
||||
*
|
||||
* ====> (boolean) debug_header :
|
||||
* - if true, a debug text is added before each cached pages
|
||||
*
|
||||
* ====> (boolean) content_type_memorization :
|
||||
* - deprecated => use memorize_headers instead
|
||||
* - if the Content-Type header is sent after the cache was started, the
|
||||
* corresponding value can be memorized and replayed when the cache is hit
|
||||
* (if false (default), the frontend doesn't take care of Content-Type header)
|
||||
*
|
||||
* ====> (array) memorize_headers :
|
||||
* - an array of strings corresponding to some HTTP headers name. Listed headers
|
||||
* will be stored with cache datas and "replayed" when the cache is hit
|
||||
*
|
||||
* ====> (array) default_options :
|
||||
* - an associative array of default options :
|
||||
* - (boolean) cache : cache is on by default if true
|
||||
* - (boolean) cacheWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
|
||||
* if true, cache is still on even if there are some variables in this superglobal array
|
||||
* if false, cache is off if there are some variables in this superglobal array
|
||||
* - (boolean) makeIdWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
|
||||
* if true, we have to use the content of this superglobal array to make a cache id
|
||||
* if false, the cache id won't be dependent of the content of this superglobal array
|
||||
* - (int) specific_lifetime : cache specific lifetime
|
||||
* (false => global lifetime is used, null => infinite lifetime,
|
||||
* integer => this lifetime is used), this "lifetime" is probably only
|
||||
* usefull when used with "regexps" array
|
||||
* - (array) tags : array of tags (strings)
|
||||
* - (int) priority : integer between 0 (very low priority) and 10 (maximum priority) used by
|
||||
* some particular backends
|
||||
*
|
||||
* ====> (array) regexps :
|
||||
* - an associative array to set options only for some REQUEST_URI
|
||||
* - keys are (pcre) regexps
|
||||
* - values are associative array with specific options to set if the regexp matchs on $_SERVER['REQUEST_URI']
|
||||
* (see default_options for the list of available options)
|
||||
* - if several regexps match the $_SERVER['REQUEST_URI'], only the last one will be used
|
||||
*
|
||||
* @var array options
|
||||
*/
|
||||
protected $_specificOptions = array(
|
||||
'http_conditional' => false,
|
||||
'debug_header' => false,
|
||||
'content_type_memorization' => false,
|
||||
'memorize_headers' => array(),
|
||||
'default_options' => array(
|
||||
'cache_with_get_variables' => false,
|
||||
'cache_with_post_variables' => false,
|
||||
'cache_with_session_variables' => false,
|
||||
'cache_with_files_variables' => false,
|
||||
'cache_with_cookie_variables' => false,
|
||||
'make_id_with_get_variables' => true,
|
||||
'make_id_with_post_variables' => true,
|
||||
'make_id_with_session_variables' => true,
|
||||
'make_id_with_files_variables' => true,
|
||||
'make_id_with_cookie_variables' => true,
|
||||
'cache' => true,
|
||||
'specific_lifetime' => false,
|
||||
'tags' => array(),
|
||||
'priority' => null
|
||||
),
|
||||
'regexps' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Internal array to store some options
|
||||
*
|
||||
* @var array associative array of options
|
||||
*/
|
||||
protected $_activeOptions = array();
|
||||
|
||||
/**
|
||||
* If true, the page won't be cached
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_cancel = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
foreach ($options as $name => $value) {
|
||||
$name = strtolower($name);
|
||||
switch ($name) {
|
||||
case 'regexps':
|
||||
$this->_setRegexps($value);
|
||||
break;
|
||||
case 'default_options':
|
||||
$this->_setDefaultOptions($value);
|
||||
break;
|
||||
case 'content_type_memorization':
|
||||
$this->_setContentTypeMemorization($value);
|
||||
break;
|
||||
default:
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
if (isset($this->_specificOptions['http_conditional'])) {
|
||||
if ($this->_specificOptions['http_conditional']) {
|
||||
Zend_Cache::throwException('http_conditional is not implemented for the moment !');
|
||||
}
|
||||
}
|
||||
$this->setOption('automatic_serialization', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific setter for the 'default_options' option (with some additional tests)
|
||||
*
|
||||
* @param array $options Associative array
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _setDefaultOptions($options)
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
Zend_Cache::throwException('default_options must be an array !');
|
||||
}
|
||||
foreach ($options as $key=>$value) {
|
||||
if (!is_string($key)) {
|
||||
Zend_Cache::throwException("invalid option [$key] !");
|
||||
}
|
||||
$key = strtolower($key);
|
||||
if (isset($this->_specificOptions['default_options'][$key])) {
|
||||
$this->_specificOptions['default_options'][$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the deprecated contentTypeMemorization option
|
||||
*
|
||||
* @param boolean $value value
|
||||
* @return void
|
||||
* @deprecated
|
||||
*/
|
||||
protected function _setContentTypeMemorization($value)
|
||||
{
|
||||
$found = null;
|
||||
foreach ($this->_specificOptions['memorize_headers'] as $key => $value) {
|
||||
if (strtolower($value) == 'content-type') {
|
||||
$found = $key;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
if (!$found) {
|
||||
$this->_specificOptions['memorize_headers'][] = 'Content-Type';
|
||||
}
|
||||
} else {
|
||||
if ($found) {
|
||||
unset($this->_specificOptions['memorize_headers'][$found]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specific setter for the 'regexps' option (with some additional tests)
|
||||
*
|
||||
* @param array $options Associative array
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _setRegexps($regexps)
|
||||
{
|
||||
if (!is_array($regexps)) {
|
||||
Zend_Cache::throwException('regexps option must be an array !');
|
||||
}
|
||||
foreach ($regexps as $regexp=>$conf) {
|
||||
if (!is_array($conf)) {
|
||||
Zend_Cache::throwException('regexps option must be an array of arrays !');
|
||||
}
|
||||
$validKeys = array_keys($this->_specificOptions['default_options']);
|
||||
foreach ($conf as $key=>$value) {
|
||||
if (!is_string($key)) {
|
||||
Zend_Cache::throwException("unknown option [$key] !");
|
||||
}
|
||||
$key = strtolower($key);
|
||||
if (!in_array($key, $validKeys)) {
|
||||
unset($regexps[$regexp][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->setOption('regexps', $regexps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the cache
|
||||
*
|
||||
* @param string $id (optional) A cache id (if you set a value here, maybe you have to use Output frontend instead)
|
||||
* @param boolean $doNotDie For unit testing only !
|
||||
* @return boolean True if the cache is hit (false else)
|
||||
*/
|
||||
public function start($id = false, $doNotDie = false)
|
||||
{
|
||||
$this->_cancel = false;
|
||||
$lastMatchingRegexp = null;
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
foreach ($this->_specificOptions['regexps'] as $regexp => $conf) {
|
||||
if (preg_match("`$regexp`", $_SERVER['REQUEST_URI'])) {
|
||||
$lastMatchingRegexp = $regexp;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_activeOptions = $this->_specificOptions['default_options'];
|
||||
if ($lastMatchingRegexp !== null) {
|
||||
$conf = $this->_specificOptions['regexps'][$lastMatchingRegexp];
|
||||
foreach ($conf as $key=>$value) {
|
||||
$this->_activeOptions[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (!($this->_activeOptions['cache'])) {
|
||||
return false;
|
||||
}
|
||||
if (!$id) {
|
||||
$id = $this->_makeId();
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$array = $this->load($id);
|
||||
if ($array !== false) {
|
||||
$data = $array['data'];
|
||||
$headers = $array['headers'];
|
||||
if (!headers_sent()) {
|
||||
foreach ($headers as $key=>$headerCouple) {
|
||||
$name = $headerCouple[0];
|
||||
$value = $headerCouple[1];
|
||||
header("$name: $value");
|
||||
}
|
||||
}
|
||||
if ($this->_specificOptions['debug_header']) {
|
||||
echo 'DEBUG HEADER : This is a cached page !';
|
||||
}
|
||||
echo $data;
|
||||
if ($doNotDie) {
|
||||
return true;
|
||||
}
|
||||
die();
|
||||
}
|
||||
ob_start(array($this, '_flush'));
|
||||
ob_implicit_flush(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel the current caching process
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
$this->_cancel = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* callback for output buffering
|
||||
* (shouldn't really be called manually)
|
||||
*
|
||||
* @param string $data Buffered output
|
||||
* @return string Data to send to browser
|
||||
*/
|
||||
public function _flush($data)
|
||||
{
|
||||
if ($this->_cancel) {
|
||||
return $data;
|
||||
}
|
||||
$contentType = null;
|
||||
$storedHeaders = array();
|
||||
$headersList = headers_list();
|
||||
foreach($this->_specificOptions['memorize_headers'] as $key=>$headerName) {
|
||||
foreach ($headersList as $headerSent) {
|
||||
$tmp = explode(':', $headerSent);
|
||||
$headerSentName = trim(array_shift($tmp));
|
||||
if (strtolower($headerName) == strtolower($headerSentName)) {
|
||||
$headerSentValue = trim(implode(':', $tmp));
|
||||
$storedHeaders[] = array($headerSentName, $headerSentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
$array = array(
|
||||
'data' => $data,
|
||||
'headers' => $storedHeaders
|
||||
);
|
||||
$this->save($array, null, $this->_activeOptions['tags'], $this->_activeOptions['specific_lifetime'], $this->_activeOptions['priority']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an id depending on REQUEST_URI and superglobal arrays (depending on options)
|
||||
*
|
||||
* @return mixed|false a cache id (string), false if the cache should have not to be used
|
||||
*/
|
||||
protected function _makeId()
|
||||
{
|
||||
$tmp = $_SERVER['REQUEST_URI'];
|
||||
$array = explode('?', $tmp, 2);
|
||||
$tmp = $array[0];
|
||||
foreach (array('Get', 'Post', 'Session', 'Files', 'Cookie') as $arrayName) {
|
||||
$tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']);
|
||||
if ($tmp2===false) {
|
||||
return false;
|
||||
}
|
||||
$tmp = $tmp . $tmp2;
|
||||
}
|
||||
return md5($tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a partial id depending on options
|
||||
*
|
||||
* @param string $arrayName Superglobal array name
|
||||
* @param bool $bool1 If true, cache is still on even if there are some variables in the superglobal array
|
||||
* @param bool $bool2 If true, we have to use the content of the superglobal array to make a partial id
|
||||
* @return mixed|false Partial id (string) or false if the cache should have not to be used
|
||||
*/
|
||||
protected function _makePartialId($arrayName, $bool1, $bool2)
|
||||
{
|
||||
switch ($arrayName) {
|
||||
case 'Get':
|
||||
$var = $_GET;
|
||||
break;
|
||||
case 'Post':
|
||||
$var = $_POST;
|
||||
break;
|
||||
case 'Session':
|
||||
if (isset($_SESSION)) {
|
||||
$var = $_SESSION;
|
||||
} else {
|
||||
$var = null;
|
||||
}
|
||||
break;
|
||||
case 'Cookie':
|
||||
if (isset($_COOKIE)) {
|
||||
$var = $_COOKIE;
|
||||
} else {
|
||||
$var = null;
|
||||
}
|
||||
break;
|
||||
case 'Files':
|
||||
$var = $_FILES;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ($bool1) {
|
||||
if ($bool2) {
|
||||
return serialize($var);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
if (count($var) > 0) {
|
||||
return false;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Cache_Exception */
|
||||
require_once 'Zend/Cache/Exception.php';
|
||||
|
||||
/** @see Zend_Cache */
|
||||
require_once 'Zend/Cache.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Manager
|
||||
{
|
||||
/**
|
||||
* Constant holding reserved name for default Page Cache
|
||||
*/
|
||||
const PAGECACHE = 'page';
|
||||
|
||||
/**
|
||||
* Constant holding reserved name for default Page Tag Cache
|
||||
*/
|
||||
const PAGETAGCACHE = 'pagetag';
|
||||
|
||||
/**
|
||||
* Array of caches stored by the Cache Manager instance
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_caches = array();
|
||||
|
||||
/**
|
||||
* Array of ready made configuration templates for lazy
|
||||
* loading caches.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_optionTemplates = array(
|
||||
// Simple Common Default
|
||||
'default' => array(
|
||||
'frontend' => array(
|
||||
'name' => 'Core',
|
||||
'options' => array(
|
||||
'automatic_serialization' => true,
|
||||
),
|
||||
),
|
||||
'backend' => array(
|
||||
'name' => 'File',
|
||||
'options' => array(
|
||||
// use system temp dir by default of file backend
|
||||
// 'cache_dir' => '../cache',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Static Page HTML Cache
|
||||
'page' => array(
|
||||
'frontend' => array(
|
||||
'name' => 'Capture',
|
||||
'options' => array(
|
||||
'ignore_user_abort' => true,
|
||||
),
|
||||
),
|
||||
'backend' => array(
|
||||
'name' => 'Static',
|
||||
'options' => array(
|
||||
'public_dir' => '../public',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Tag Cache
|
||||
'pagetag' => array(
|
||||
'frontend' => array(
|
||||
'name' => 'Core',
|
||||
'options' => array(
|
||||
'automatic_serialization' => true,
|
||||
'lifetime' => null
|
||||
),
|
||||
),
|
||||
'backend' => array(
|
||||
'name' => 'File',
|
||||
'options' => array(
|
||||
// use system temp dir by default of file backend
|
||||
// 'cache_dir' => '../cache',
|
||||
// use default umask of file backend
|
||||
// 'cache_file_umask' => 0644
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Set a new cache for the Cache Manager to contain
|
||||
*
|
||||
* @param string $name
|
||||
* @param Zend_Cache_Core $cache
|
||||
* @return Zend_Cache_Manager
|
||||
*/
|
||||
public function setCache($name, Zend_Cache_Core $cache)
|
||||
{
|
||||
$this->_caches[$name] = $cache;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Cache Manager contains the named cache object, or a named
|
||||
* configuration template to lazy load the cache object
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCache($name)
|
||||
{
|
||||
if (isset($this->_caches[$name])
|
||||
|| $this->hasCacheTemplate($name)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the named cache object, or instantiate and return a cache object
|
||||
* using a named configuration template
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Cache_Core
|
||||
*/
|
||||
public function getCache($name)
|
||||
{
|
||||
if (isset($this->_caches[$name])) {
|
||||
return $this->_caches[$name];
|
||||
}
|
||||
if (isset($this->_optionTemplates[$name])) {
|
||||
if ($name == self::PAGECACHE
|
||||
&& (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache'])
|
||||
|| !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof Zend_Cache_Core)
|
||||
) {
|
||||
$this->_optionTemplates[$name]['backend']['options']['tag_cache']
|
||||
= $this->getCache(self::PAGETAGCACHE);
|
||||
}
|
||||
|
||||
$this->_caches[$name] = Zend_Cache::factory(
|
||||
$this->_optionTemplates[$name]['frontend']['name'],
|
||||
$this->_optionTemplates[$name]['backend']['name'],
|
||||
isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(),
|
||||
isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(),
|
||||
isset($this->_optionTemplates[$name]['frontend']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['customFrontendNaming'] : false,
|
||||
isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false,
|
||||
isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false
|
||||
);
|
||||
|
||||
return $this->_caches[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all available caches
|
||||
*
|
||||
* @return array An array of all available caches with it's names as key
|
||||
*/
|
||||
public function getCaches()
|
||||
{
|
||||
$caches = $this->_caches;
|
||||
foreach ($this->_optionTemplates as $name => $tmp) {
|
||||
if (!isset($caches[$name])) {
|
||||
$caches[$name] = $this->getCache($name);
|
||||
}
|
||||
}
|
||||
return $caches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a named configuration template from which a cache object can later
|
||||
* be lazy loaded
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return Zend_Cache_Manager
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function setCacheTemplate($name, $options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (!is_array($options)) {
|
||||
require_once 'Zend/Cache/Exception.php';
|
||||
throw new Zend_Cache_Exception('Options passed must be in'
|
||||
. ' an associative array or instance of Zend_Config');
|
||||
}
|
||||
$this->_optionTemplates[$name] = $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the named configuration template
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCacheTemplate($name)
|
||||
{
|
||||
if (isset($this->_optionTemplates[$name])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the named configuration template
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function getCacheTemplate($name)
|
||||
{
|
||||
if (isset($this->_optionTemplates[$name])) {
|
||||
return $this->_optionTemplates[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass an array containing changes to be applied to a named
|
||||
* configuration
|
||||
* template
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return Zend_Cache_Manager
|
||||
* @throws Zend_Cache_Exception for invalid options format or if option templates do not have $name
|
||||
*/
|
||||
public function setTemplateOptions($name, $options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (!is_array($options)) {
|
||||
require_once 'Zend/Cache/Exception.php';
|
||||
throw new Zend_Cache_Exception('Options passed must be in'
|
||||
. ' an associative array or instance of Zend_Config');
|
||||
}
|
||||
if (!isset($this->_optionTemplates[$name])) {
|
||||
throw new Zend_Cache_Exception('A cache configuration template'
|
||||
. 'does not exist with the name "' . $name . '"');
|
||||
}
|
||||
$this->_optionTemplates[$name]
|
||||
= $this->_mergeOptions($this->_optionTemplates[$name], $options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple method to merge two configuration arrays
|
||||
*
|
||||
* @param array $current
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
protected function _mergeOptions(array $current, array $options)
|
||||
{
|
||||
if (isset($options['frontend']['name'])) {
|
||||
$current['frontend']['name'] = $options['frontend']['name'];
|
||||
}
|
||||
if (isset($options['backend']['name'])) {
|
||||
$current['backend']['name'] = $options['backend']['name'];
|
||||
}
|
||||
if (isset($options['frontend']['options'])) {
|
||||
foreach ($options['frontend']['options'] as $key => $value) {
|
||||
$current['frontend']['options'][$key] = $value;
|
||||
}
|
||||
}
|
||||
if (isset($options['backend']['options'])) {
|
||||
foreach ($options['backend']['options'] as $key => $value) {
|
||||
$current['backend']['options'][$key] = $value;
|
||||
}
|
||||
}
|
||||
if (isset($options['frontend']['customFrontendNaming'])) {
|
||||
$current['frontend']['customFrontendNaming'] = $options['frontend']['customFrontendNaming'];
|
||||
}
|
||||
if (isset($options['backend']['customBackendNaming'])) {
|
||||
$current['backend']['customBackendNaming'] = $options['backend']['customBackendNaming'];
|
||||
}
|
||||
if (isset($options['frontendBackendAutoload'])) {
|
||||
$current['frontendBackendAutoload'] = $options['frontendBackendAutoload'];
|
||||
}
|
||||
return $current;
|
||||
}
|
||||
}
|
||||
@@ -1,484 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Config implements Countable, Iterator
|
||||
{
|
||||
/**
|
||||
* Whether in-memory modifications to configuration data are allowed
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_allowModifications;
|
||||
|
||||
/**
|
||||
* Iteration index
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_index;
|
||||
|
||||
/**
|
||||
* Number of elements in configuration data
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_count;
|
||||
|
||||
/**
|
||||
* Contains array of configuration data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* Used when unsetting values during iteration to ensure we do not skip
|
||||
* the next element
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_skipNextIteration;
|
||||
|
||||
/**
|
||||
* Contains which config file sections were loaded. This is null
|
||||
* if all sections were loaded, a string name if one section is loaded
|
||||
* and an array of string names if multiple sections were loaded.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_loadedSection;
|
||||
|
||||
/**
|
||||
* This is used to track section inheritance. The keys are names of sections that
|
||||
* extend other sections, and the values are the extended sections.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_extends = array();
|
||||
|
||||
/**
|
||||
* Load file error string.
|
||||
*
|
||||
* Is null if there was no error while file loading
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_loadFileErrorStr = null;
|
||||
|
||||
/**
|
||||
* Zend_Config provides a property based interface to
|
||||
* an array. The data are read-only unless $allowModifications
|
||||
* is set to true on construction.
|
||||
*
|
||||
* Zend_Config also implements Countable and Iterator to
|
||||
* facilitate easy access to the data.
|
||||
*
|
||||
* @param array $array
|
||||
* @param boolean $allowModifications
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $array, $allowModifications = false)
|
||||
{
|
||||
$this->_allowModifications = (boolean) $allowModifications;
|
||||
$this->_loadedSection = null;
|
||||
$this->_index = 0;
|
||||
$this->_data = array();
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->_data[$key] = new self($value, $this->_allowModifications);
|
||||
} else {
|
||||
$this->_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->_count = count($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a value and return $default if there is no element set.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
$result = $default;
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
$result = $this->_data[$name];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function so that $obj->value will work.
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Only allow setting of a property if $allowModifications
|
||||
* was set to true on construction. Otherwise, throw an exception.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @throws Zend_Config_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if ($this->_allowModifications) {
|
||||
if (is_array($value)) {
|
||||
$this->_data[$name] = new self($value, true);
|
||||
} else {
|
||||
$this->_data[$name] = $value;
|
||||
}
|
||||
$this->_count = count($this->_data);
|
||||
} else {
|
||||
/** @see Zend_Config_Exception */
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Zend_Config is read only');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep clone of this instance to ensure that nested Zend_Configs
|
||||
* are also cloned.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$array = array();
|
||||
foreach ($this->_data as $key => $value) {
|
||||
if ($value instanceof Zend_Config) {
|
||||
$array[$key] = clone $value;
|
||||
} else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->_data = $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of the stored data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = array();
|
||||
$data = $this->_data;
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value instanceof Zend_Config) {
|
||||
$array[$key] = $value->toArray();
|
||||
} else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support isset() overloading on PHP 5.1
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
return isset($this->_data[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support unset() overloading on PHP 5.1
|
||||
*
|
||||
* @param string $name
|
||||
* @throws Zend_Config_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
if ($this->_allowModifications) {
|
||||
unset($this->_data[$name]);
|
||||
$this->_count = count($this->_data);
|
||||
$this->_skipNextIteration = true;
|
||||
} else {
|
||||
/** @see Zend_Config_Exception */
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Zend_Config is read only');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Countable interface
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Iterator interface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$this->_skipNextIteration = false;
|
||||
return current($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Iterator interface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Iterator interface
|
||||
*
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
if ($this->_skipNextIteration) {
|
||||
$this->_skipNextIteration = false;
|
||||
return;
|
||||
}
|
||||
next($this->_data);
|
||||
$this->_index++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Iterator interface
|
||||
*
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_skipNextIteration = false;
|
||||
reset($this->_data);
|
||||
$this->_index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Iterator interface
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return $this->_index < $this->_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the section name(s) loaded.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSectionName()
|
||||
{
|
||||
if(is_array($this->_loadedSection) && count($this->_loadedSection) == 1) {
|
||||
$this->_loadedSection = $this->_loadedSection[0];
|
||||
}
|
||||
return $this->_loadedSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if all sections were loaded
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function areAllSectionsLoaded()
|
||||
{
|
||||
return $this->_loadedSection === null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge another Zend_Config with this one. The items
|
||||
* in $merge will override the same named items in
|
||||
* the current config.
|
||||
*
|
||||
* @param Zend_Config $merge
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function merge(Zend_Config $merge)
|
||||
{
|
||||
foreach($merge as $key => $item) {
|
||||
if(array_key_exists($key, $this->_data)) {
|
||||
if($item instanceof Zend_Config && $this->$key instanceof Zend_Config) {
|
||||
$this->$key = $this->$key->merge(new Zend_Config($item->toArray(), !$this->readOnly()));
|
||||
} else {
|
||||
$this->$key = $item;
|
||||
}
|
||||
} else {
|
||||
if($item instanceof Zend_Config) {
|
||||
$this->$key = new Zend_Config($item->toArray(), !$this->readOnly());
|
||||
} else {
|
||||
$this->$key = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent any more modifications being made to this instance. Useful
|
||||
* after merge() has been used to merge multiple Zend_Config objects
|
||||
* into one object which should then not be modified again.
|
||||
*
|
||||
*/
|
||||
public function setReadOnly()
|
||||
{
|
||||
$this->_allowModifications = false;
|
||||
foreach ($this->_data as $key => $value) {
|
||||
if ($value instanceof Zend_Config) {
|
||||
$value->setReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this Zend_Config object is read only or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function readOnly()
|
||||
{
|
||||
return !$this->_allowModifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current extends
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtends()
|
||||
{
|
||||
return $this->_extends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an extend for Zend_Config_Writer
|
||||
*
|
||||
* @param string $extendingSection
|
||||
* @param string $extendedSection
|
||||
* @return void
|
||||
*/
|
||||
public function setExtend($extendingSection, $extendedSection = null)
|
||||
{
|
||||
if ($extendedSection === null && isset($this->_extends[$extendingSection])) {
|
||||
unset($this->_extends[$extendingSection]);
|
||||
} else if ($extendedSection !== null) {
|
||||
$this->_extends[$extendingSection] = $extendedSection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if $extendingSection may not extend $extendedSection,
|
||||
* and tracks the section extension if it is valid.
|
||||
*
|
||||
* @param string $extendingSection
|
||||
* @param string $extendedSection
|
||||
* @throws Zend_Config_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _assertValidExtend($extendingSection, $extendedSection)
|
||||
{
|
||||
// detect circular section inheritance
|
||||
$extendedSectionCurrent = $extendedSection;
|
||||
while (array_key_exists($extendedSectionCurrent, $this->_extends)) {
|
||||
if ($this->_extends[$extendedSectionCurrent] == $extendingSection) {
|
||||
/** @see Zend_Config_Exception */
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Illegal circular inheritance detected');
|
||||
}
|
||||
$extendedSectionCurrent = $this->_extends[$extendedSectionCurrent];
|
||||
}
|
||||
// remember that this section extends another section
|
||||
$this->_extends[$extendingSection] = $extendedSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle any errors from simplexml_load_file or parse_ini_file
|
||||
*
|
||||
* @param integer $errno
|
||||
* @param string $errstr
|
||||
* @param string $errfile
|
||||
* @param integer $errline
|
||||
*/
|
||||
public function _loadFileErrorHandler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
if ($this->_loadFileErrorStr === null) {
|
||||
$this->_loadFileErrorStr = $errstr;
|
||||
} else {
|
||||
$this->_loadFileErrorStr .= (PHP_EOL . $errstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two arrays recursively, overwriting keys of the same name
|
||||
* in $firstArray with the value in $secondArray.
|
||||
*
|
||||
* @param mixed $firstArray First array
|
||||
* @param mixed $secondArray Second array to merge into first array
|
||||
* @return array
|
||||
*/
|
||||
protected function _arrayMergeRecursive($firstArray, $secondArray)
|
||||
{
|
||||
if (is_array($firstArray) && is_array($secondArray)) {
|
||||
foreach ($secondArray as $key => $value) {
|
||||
if (isset($firstArray[$key])) {
|
||||
$firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
|
||||
} else {
|
||||
if($key === 0) {
|
||||
$firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
|
||||
} else {
|
||||
$firstArray[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$firstArray = $secondArray;
|
||||
}
|
||||
|
||||
return $firstArray;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Config_Exception extends Zend_Exception {}
|
||||
@@ -1,309 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Config
|
||||
*/
|
||||
require_once 'Zend/Config.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Config_Ini extends Zend_Config
|
||||
{
|
||||
/**
|
||||
* String that separates nesting levels of configuration data identifiers
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_nestSeparator = '.';
|
||||
|
||||
/**
|
||||
* String that separates the parent section name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_sectionSeparator = ':';
|
||||
|
||||
/**
|
||||
* Whether to skip extends or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_skipExtends = false;
|
||||
|
||||
/**
|
||||
* Loads the section $section from the config file $filename for
|
||||
* access facilitated by nested object properties.
|
||||
*
|
||||
* If the section name contains a ":" then the section name to the right
|
||||
* is loaded and included into the properties. Note that the keys in
|
||||
* this $section will override any keys of the same
|
||||
* name in the sections that have been included via ":".
|
||||
*
|
||||
* If the $section is null, then all sections in the ini file are loaded.
|
||||
*
|
||||
* If any key includes a ".", then this will act as a separator to
|
||||
* create a sub-property.
|
||||
*
|
||||
* example ini file:
|
||||
* [all]
|
||||
* db.connection = database
|
||||
* hostname = live
|
||||
*
|
||||
* [staging : all]
|
||||
* hostname = staging
|
||||
*
|
||||
* after calling $data = new Zend_Config_Ini($file, 'staging'); then
|
||||
* $data->hostname === "staging"
|
||||
* $data->db->connection === "database"
|
||||
*
|
||||
* The $options parameter may be provided as either a boolean or an array.
|
||||
* If provided as a boolean, this sets the $allowModifications option of
|
||||
* Zend_Config. If provided as an array, there are three configuration
|
||||
* directives that may be set. For example:
|
||||
*
|
||||
* $options = array(
|
||||
* 'allowModifications' => false,
|
||||
* 'nestSeparator' => ':',
|
||||
* 'skipExtends' => false,
|
||||
* );
|
||||
*
|
||||
* @param string $filename
|
||||
* @param mixed $section
|
||||
* @param boolean|array $options
|
||||
* @throws Zend_Config_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($filename, $section = null, $options = false)
|
||||
{
|
||||
if (empty($filename)) {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Filename is not set');
|
||||
}
|
||||
|
||||
$allowModifications = false;
|
||||
if (is_bool($options)) {
|
||||
$allowModifications = $options;
|
||||
} elseif (is_array($options)) {
|
||||
if (isset($options['allowModifications'])) {
|
||||
$allowModifications = (bool) $options['allowModifications'];
|
||||
}
|
||||
if (isset($options['nestSeparator'])) {
|
||||
$this->_nestSeparator = (string) $options['nestSeparator'];
|
||||
}
|
||||
if (isset($options['skipExtends'])) {
|
||||
$this->_skipExtends = (bool) $options['skipExtends'];
|
||||
}
|
||||
}
|
||||
|
||||
$iniArray = $this->_loadIniFile($filename);
|
||||
|
||||
if (null === $section) {
|
||||
// Load entire file
|
||||
$dataArray = array();
|
||||
foreach ($iniArray as $sectionName => $sectionData) {
|
||||
if(!is_array($sectionData)) {
|
||||
$dataArray = $this->_arrayMergeRecursive($dataArray, $this->_processKey(array(), $sectionName, $sectionData));
|
||||
} else {
|
||||
$dataArray[$sectionName] = $this->_processSection($iniArray, $sectionName);
|
||||
}
|
||||
}
|
||||
parent::__construct($dataArray, $allowModifications);
|
||||
} else {
|
||||
// Load one or more sections
|
||||
if (!is_array($section)) {
|
||||
$section = array($section);
|
||||
}
|
||||
$dataArray = array();
|
||||
foreach ($section as $sectionName) {
|
||||
if (!isset($iniArray[$sectionName])) {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $filename");
|
||||
}
|
||||
$dataArray = $this->_arrayMergeRecursive($this->_processSection($iniArray, $sectionName), $dataArray);
|
||||
|
||||
}
|
||||
parent::__construct($dataArray, $allowModifications);
|
||||
}
|
||||
|
||||
$this->_loadedSection = $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the INI file from disk using parse_ini_file(). Use a private error
|
||||
* handler to convert any loading errors into a Zend_Config_Exception
|
||||
*
|
||||
* @param string $filename
|
||||
* @throws Zend_Config_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _parseIniFile($filename)
|
||||
{
|
||||
set_error_handler(array($this, '_loadFileErrorHandler'));
|
||||
$iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed
|
||||
restore_error_handler();
|
||||
|
||||
// Check if there was a error while loading file
|
||||
if ($this->_loadFileErrorStr !== null) {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception($this->_loadFileErrorStr);
|
||||
}
|
||||
|
||||
return $iniArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the ini file and preprocess the section separator (':' in the
|
||||
* section name (that is used for section extension) so that the resultant
|
||||
* array has the correct section names and the extension information is
|
||||
* stored in a sub-key called ';extends'. We use ';extends' as this can
|
||||
* never be a valid key name in an INI file that has been loaded using
|
||||
* parse_ini_file().
|
||||
*
|
||||
* @param string $filename
|
||||
* @throws Zend_Config_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadIniFile($filename)
|
||||
{
|
||||
$loaded = $this->_parseIniFile($filename);
|
||||
$iniArray = array();
|
||||
foreach ($loaded as $key => $data)
|
||||
{
|
||||
$pieces = explode($this->_sectionSeparator, $key);
|
||||
$thisSection = trim($pieces[0]);
|
||||
switch (count($pieces)) {
|
||||
case 1:
|
||||
$iniArray[$thisSection] = $data;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$extendedSection = trim($pieces[1]);
|
||||
$iniArray[$thisSection] = array_merge(array(';extends'=>$extendedSection), $data);
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Section '$thisSection' may not extend multiple sections in $filename");
|
||||
}
|
||||
}
|
||||
|
||||
return $iniArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process each element in the section and handle the ";extends" inheritance
|
||||
* key. Passes control to _processKey() to handle the nest separator
|
||||
* sub-property syntax that may be used within the key name.
|
||||
*
|
||||
* @param array $iniArray
|
||||
* @param string $section
|
||||
* @param array $config
|
||||
* @throws Zend_Config_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _processSection($iniArray, $section, $config = array())
|
||||
{
|
||||
$thisSection = $iniArray[$section];
|
||||
|
||||
foreach ($thisSection as $key => $value) {
|
||||
if (strtolower($key) == ';extends') {
|
||||
if (isset($iniArray[$value])) {
|
||||
$this->_assertValidExtend($section, $value);
|
||||
|
||||
if (!$this->_skipExtends) {
|
||||
$config = $this->_processSection($iniArray, $value, $config);
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Parent section '$section' cannot be found");
|
||||
}
|
||||
} else {
|
||||
$config = $this->_processKey($config, $key, $value);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the key's value to the property list. Handles the
|
||||
* nest separator for sub-properties.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @throws Zend_Config_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _processKey($config, $key, $value)
|
||||
{
|
||||
if (strpos($key, $this->_nestSeparator) !== false) {
|
||||
$pieces = explode($this->_nestSeparator, $key, 2);
|
||||
if (strlen($pieces[0]) && strlen($pieces[1])) {
|
||||
if (!isset($config[$pieces[0]])) {
|
||||
if ($pieces[0] === '0' && !empty($config)) {
|
||||
// convert the current values in $config into an array
|
||||
$config = array($pieces[0] => $config);
|
||||
} else {
|
||||
$config[$pieces[0]] = array();
|
||||
}
|
||||
} elseif (!is_array($config[$pieces[0]])) {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists");
|
||||
}
|
||||
$config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
|
||||
} else {
|
||||
/**
|
||||
* @see Zend_Config_Exception
|
||||
*/
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Invalid key '$key'");
|
||||
}
|
||||
} else {
|
||||
$config[$key] = $value;
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Config
|
||||
*/
|
||||
require_once 'Zend/Config.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Json
|
||||
*/
|
||||
require_once 'Zend/Json.php';
|
||||
|
||||
/**
|
||||
* JSON Adapter for Zend_Config
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Config_Json extends Zend_Config
|
||||
{
|
||||
/**
|
||||
* Name of object key indicating section current section extends
|
||||
*/
|
||||
const EXTENDS_NAME = "_extends";
|
||||
|
||||
/**
|
||||
* Whether or not to ignore constants in the JSON string
|
||||
*
|
||||
* Note: if you do not have constant names in quotations in your JSON
|
||||
* string, they may lead to syntax errors when parsing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_ignoreConstants = false;
|
||||
|
||||
/**
|
||||
* Whether to skip extends or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_skipExtends = false;
|
||||
|
||||
/**
|
||||
* Loads the section $section from the config file encoded as JSON
|
||||
*
|
||||
* Sections are defined as properties of the main object
|
||||
*
|
||||
* In order to extend another section, a section defines the "_extends"
|
||||
* property having a value of the section name from which the extending
|
||||
* section inherits values.
|
||||
*
|
||||
* Note that the keys in $section will override any keys of the same
|
||||
* name in the sections that have been included via "_extends".
|
||||
*
|
||||
* @param string $json JSON file or string to process
|
||||
* @param mixed $section Section to process
|
||||
* @param boolean $options Whether modifiacations are allowed at runtime
|
||||
* @throws Zend_Config_Exception When JSON text is not set or cannot be loaded
|
||||
* @throws Zend_Config_Exception When section $sectionName cannot be found in $json
|
||||
*/
|
||||
public function __construct($json, $section = null, $options = false)
|
||||
{
|
||||
if (empty($json)) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Filename is not set');
|
||||
}
|
||||
|
||||
$allowModifications = false;
|
||||
if (is_bool($options)) {
|
||||
$allowModifications = $options;
|
||||
} elseif (is_array($options)) {
|
||||
foreach ($options as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'allow_modifications':
|
||||
case 'allowmodifications':
|
||||
$allowModifications = (bool) $value;
|
||||
break;
|
||||
case 'skip_extends':
|
||||
case 'skipextends':
|
||||
$this->_skipExtends = (bool) $value;
|
||||
break;
|
||||
case 'ignore_constants':
|
||||
case 'ignoreconstants':
|
||||
$this->_ignoreConstants = (bool) $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed
|
||||
if ($json[0] != '{') {
|
||||
$json = file_get_contents($json);
|
||||
}
|
||||
restore_error_handler();
|
||||
|
||||
// Check if there was a error while loading file
|
||||
if ($this->_loadFileErrorStr !== null) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception($this->_loadFileErrorStr);
|
||||
}
|
||||
|
||||
// Replace constants
|
||||
if (!$this->_ignoreConstants) {
|
||||
$json = $this->_replaceConstants($json);
|
||||
}
|
||||
|
||||
// Parse/decode
|
||||
try {
|
||||
$config = Zend_Json::decode($json);
|
||||
} catch (Zend_Json_Exception $e) {
|
||||
// decode failed
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception("Error parsing JSON data");
|
||||
}
|
||||
|
||||
if ($section === null) {
|
||||
$dataArray = array();
|
||||
foreach ($config as $sectionName => $sectionData) {
|
||||
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
|
||||
}
|
||||
|
||||
parent::__construct($dataArray, $allowModifications);
|
||||
} elseif (is_array($section)) {
|
||||
$dataArray = array();
|
||||
foreach ($section as $sectionName) {
|
||||
if (!isset($config[$sectionName])) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName));
|
||||
}
|
||||
|
||||
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
|
||||
}
|
||||
|
||||
parent::__construct($dataArray, $allowModifications);
|
||||
} else {
|
||||
if (!isset($config[$section])) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
|
||||
}
|
||||
|
||||
$dataArray = $this->_processExtends($config, $section);
|
||||
if (!is_array($dataArray)) {
|
||||
// Section in the JSON data contains just one top level string
|
||||
$dataArray = array($section => $dataArray);
|
||||
}
|
||||
|
||||
parent::__construct($dataArray, $allowModifications);
|
||||
}
|
||||
|
||||
$this->_loadedSection = $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to process each element in the section and handle
|
||||
* the "_extends" inheritance attribute.
|
||||
*
|
||||
* @param array $data Data array to process
|
||||
* @param string $section Section to process
|
||||
* @param array $config Configuration which was parsed yet
|
||||
* @throws Zend_Config_Exception When $section cannot be found
|
||||
* @return array
|
||||
*/
|
||||
protected function _processExtends(array $data, $section, array $config = array())
|
||||
{
|
||||
if (!isset($data[$section])) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
|
||||
}
|
||||
|
||||
$thisSection = $data[$section];
|
||||
|
||||
if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
|
||||
if (is_array($thisSection[self::EXTENDS_NAME])) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received');
|
||||
}
|
||||
$this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
|
||||
|
||||
if (!$this->_skipExtends) {
|
||||
$config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
|
||||
}
|
||||
unset($thisSection[self::EXTENDS_NAME]);
|
||||
}
|
||||
|
||||
$config = $this->_arrayMergeRecursive($config, $thisSection);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace any constants referenced in a string with their values
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function _replaceConstants($value)
|
||||
{
|
||||
foreach ($this->_getConstants() as $constant) {
|
||||
if (strstr($value, $constant)) {
|
||||
// handle backslashes that may represent windows path names for instance
|
||||
$replacement = str_replace('\\', '\\\\', constant($constant));
|
||||
$value = str_replace($constant, $replacement, $value);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (reverse) sorted list of defined constant names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getConstants()
|
||||
{
|
||||
$constants = array_keys(get_defined_constants());
|
||||
rsort($constants, SORT_STRING);
|
||||
return $constants;
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Config_Writer
|
||||
{
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options'
|
||||
);
|
||||
|
||||
/**
|
||||
* Config object to write
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
protected $_config = null;
|
||||
|
||||
/**
|
||||
* Create a new adapter
|
||||
*
|
||||
* $options can only be passed as array or be omitted
|
||||
*
|
||||
* @param null|array $options
|
||||
*/
|
||||
public function __construct(array $options = null)
|
||||
{
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options via a Zend_Config instance
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @return Zend_Config_Writer
|
||||
*/
|
||||
public function setConfig(Zend_Config $config)
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options via an array
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Config_Writer
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . ucfirst($key);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Zend_Config object to it's target
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function write();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Config_Writer
|
||||
*/
|
||||
require_once 'Zend/Config/Writer/FileAbstract.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Config_Writer_Array extends Zend_Config_Writer_FileAbstract
|
||||
{
|
||||
/**
|
||||
* Render a Zend_Config into a PHP Array config string.
|
||||
*
|
||||
* @since 1.10
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$data = $this->_config->toArray();
|
||||
$sectionName = $this->_config->getSectionName();
|
||||
|
||||
if (is_string($sectionName)) {
|
||||
$data = array($sectionName => $data);
|
||||
}
|
||||
|
||||
$arrayString = "<?php\n"
|
||||
. "return " . var_export($data, true) . ";\n";
|
||||
|
||||
return $arrayString;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to [email protected] so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Config
|
||||
* @package Writer
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
require_once "Zend/Config/Writer.php";
|
||||
|
||||
/**
|
||||
* Abstract File Writer
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_package
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
class Zend_Config_Writer_FileAbstract extends Zend_Config_Writer
|
||||
{
|
||||
/**
|
||||
* Filename to write to
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_filename = null;
|
||||
|
||||
/**
|
||||
* Wether to exclusively lock the file or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_exclusiveLock = false;
|
||||
|
||||
/**
|
||||
* Set the target filename
|
||||
*
|
||||
* @param string $filename
|
||||
* @return Zend_Config_Writer_Array
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->_filename = $filename;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set wether to exclusively lock the file or not
|
||||
*
|
||||
* @param boolean $exclusiveLock
|
||||
* @return Zend_Config_Writer_Array
|
||||
*/
|
||||
public function setExclusiveLock($exclusiveLock)
|
||||
{
|
||||
$this->_exclusiveLock = $exclusiveLock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write configuration to file.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param Zend_Config $config
|
||||
* @param bool $exclusiveLock
|
||||
* @return void
|
||||
*/
|
||||
public function write($filename = null, Zend_Config $config = null, $exclusiveLock = null)
|
||||
{
|
||||
if ($filename !== null) {
|
||||
$this->setFilename($filename);
|
||||
}
|
||||
|
||||
if ($config !== null) {
|
||||
$this->setConfig($config);
|
||||
}
|
||||
|
||||
if ($exclusiveLock !== null) {
|
||||
$this->setExclusiveLock($exclusiveLock);
|
||||
}
|
||||
|
||||
if ($this->_filename === null) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('No filename was set');
|
||||
}
|
||||
|
||||
if ($this->_config === null) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('No config was set');
|
||||
}
|
||||
|
||||
$configString = $this->render();
|
||||
|
||||
$flags = 0;
|
||||
|
||||
if ($this->_exclusiveLock) {
|
||||
$flags |= LOCK_EX;
|
||||
}
|
||||
|
||||
$result = @file_put_contents($this->_filename, $configString, $flags);
|
||||
|
||||
if ($result === false) {
|
||||
require_once 'Zend/Config/Exception.php';
|
||||
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a Zend_Config into a config file string.
|
||||
*
|
||||
* @since 1.10
|
||||
* @todo For 2.0 this should be redone into an abstract method.
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user