corretto problema scontistiche non abilitate
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,4 +3,3 @@ nbproject/private/
|
||||
*Thumbs.db
|
||||
#in mancanza del composer i vendor devono essere compresi in git
|
||||
#vendor/*
|
||||
Zend
|
||||
250
Zend/Cache.php
Normal file
250
Zend/Cache.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cache.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 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;
|
||||
}
|
||||
|
||||
}
|
||||
268
Zend/Cache/Backend.php
Normal file
268
Zend/Cache/Backend.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Backend.php 23800 2011-03-10 20:52:08Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 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
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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])) {
|
||||
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
|
||||
* @throws Zend_Cache_Exception
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
355
Zend/Cache/Backend/Apc.php
Normal file
355
Zend/Cache/Backend/Apc.php
Normal file
@@ -0,0 +1,355 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Apc.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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()
|
||||
{
|
||||
$res = array();
|
||||
$array = apc_cache_info('user', false);
|
||||
$records = $array['cache_list'];
|
||||
foreach ($records as $record) {
|
||||
$res[] = $record['info'];
|
||||
}
|
||||
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 = 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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
250
Zend/Cache/Backend/BlackHole.php
Normal file
250
Zend/Cache/Backend/BlackHole.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: BlackHole.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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-2011 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
126
Zend/Cache/Backend/ExtendedInterface.php
Normal file
126
Zend/Cache/Backend/ExtendedInterface.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ExtendedInterface.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 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();
|
||||
|
||||
}
|
||||
1007
Zend/Cache/Backend/File.php
Normal file
1007
Zend/Cache/Backend/File.php
Normal file
File diff suppressed because it is too large
Load Diff
99
Zend/Cache/Backend/Interface.php
Normal file
99
Zend/Cache/Backend/Interface.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 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());
|
||||
|
||||
}
|
||||
484
Zend/Cache/Backend/Libmemcached.php
Normal file
484
Zend/Cache/Backend/Libmemcached.php
Normal file
@@ -0,0 +1,484 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Libmemcached.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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 ($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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
504
Zend/Cache/Backend/Memcached.php
Normal file
504
Zend/Cache/Backend/Memcached.php
Normal file
@@ -0,0 +1,504 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Memcached.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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'];
|
||||
$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 (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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
678
Zend/Cache/Backend/Sqlite.php
Normal file
678
Zend/Cache/Backend/Sqlite.php
Normal file
@@ -0,0 +1,678 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Sqlite.php 24348 2011-08-04 17:51:24Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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;
|
||||
}
|
||||
|
||||
}
|
||||
564
Zend/Cache/Backend/Static.php
Normal file
564
Zend/Cache/Backend/Static.php
Normal file
@@ -0,0 +1,564 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Static.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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-2011 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_umask' => 0600,
|
||||
'cache_directory_umask' => 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 {
|
||||
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)
|
||||
{
|
||||
if ($name == 'tag_cache') {
|
||||
return $this->getInnerCache();
|
||||
} else {
|
||||
if (in_array($name, $this->_options)) {
|
||||
return $this->_options[$name];
|
||||
}
|
||||
if ($name == 'lifetime') {
|
||||
return parent::getLifetime();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_umask']));
|
||||
|
||||
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_umask']), 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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
413
Zend/Cache/Backend/Test.php
Normal file
413
Zend/Cache/Backend/Test.php
Normal file
@@ -0,0 +1,413 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Test.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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'));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
536
Zend/Cache/Backend/TwoLevels.php
Normal file
536
Zend/Cache/Backend/TwoLevels.php
Normal file
@@ -0,0 +1,536 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: TwoLevels.php 24254 2011-07-22 12:04:41Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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_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_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)
|
||||
{
|
||||
$res = $this->_fastBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($res === false) {
|
||||
$res = $this->_slowBackend->load($id, $doNotTestCacheValidity);
|
||||
if ($res === false) {
|
||||
// there is no cache at all for this id
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$array = unserialize($res);
|
||||
// maybe, we have to refresh the fast cache ?
|
||||
if ($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;
|
||||
}
|
||||
|
||||
}
|
||||
349
Zend/Cache/Backend/WinCache.php
Normal file
349
Zend/Cache/Backend/WinCache.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 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-2011 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 = $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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
221
Zend/Cache/Backend/Xcache.php
Normal file
221
Zend/Cache/Backend/Xcache.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Xcache.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @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-2011 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;
|
||||
}
|
||||
|
||||
}
|
||||
317
Zend/Cache/Backend/ZendPlatform.php
Normal file
317
Zend/Cache/Backend/ZendPlatform.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ZendPlatform.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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-2011 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;
|
||||
}
|
||||
|
||||
}
|
||||
207
Zend/Cache/Backend/ZendServer.php
Normal file
207
Zend/Cache/Backend/ZendServer.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ZendServer.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @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-2011 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Zend/Cache/Backend/ZendServer/Disk.php
Normal file
100
Zend/Cache/Backend/ZendServer/Disk.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Disk.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @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-2011 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
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
100
Zend/Cache/Backend/ZendServer/ShMem.php
Normal file
100
Zend/Cache/Backend/ZendServer/ShMem.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ShMem.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** @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-2011 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
|
||||
*
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
764
Zend/Cache/Core.php
Normal file
764
Zend/Cache/Core.php
Normal file
@@ -0,0 +1,764 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Core.php 23800 2011-03-10 20:52:08Z mabe $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 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.");
|
||||
}
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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();
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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");
|
||||
}
|
||||
$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)
|
||||
{
|
||||
if (is_string($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;
|
||||
self::_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
|
||||
self::_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);
|
||||
}
|
||||
self::_validateIdOrTag($id);
|
||||
self::_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
|
||||
self::_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');
|
||||
}
|
||||
self::_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 static 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 static function _validateTagsArray($tags)
|
||||
{
|
||||
if (!is_array($tags)) {
|
||||
Zend_Cache::throwException('Invalid tags array : must be an array');
|
||||
}
|
||||
foreach($tags as $tag) {
|
||||
self::_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
|
||||
}
|
||||
|
||||
}
|
||||
32
Zend/Cache/Exception.php
Normal file
32
Zend/Cache/Exception.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 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 {}
|
||||
88
Zend/Cache/Frontend/Capture.php
Normal file
88
Zend/Cache/Frontend/Capture.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Capture.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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;
|
||||
}
|
||||
}
|
||||
265
Zend/Cache/Frontend/Class.php
Normal file
265
Zend/Cache/Frontend/Class.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Class.php 24032 2011-05-10 21:08:20Z mabe $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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
|
||||
*/
|
||||
private $_tags = array();
|
||||
|
||||
/**
|
||||
* SpecificLifetime value
|
||||
*
|
||||
* false => no specific life time
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_specificLifetime = false;
|
||||
|
||||
/**
|
||||
* The cached object or the name of the cached abstract class
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_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
|
||||
*/
|
||||
private $_cachedEntityLabel = '';
|
||||
|
||||
/**
|
||||
* Priority (used by some particular backends)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_priority = 8;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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 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
|
||||
*/
|
||||
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)) && 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);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
222
Zend/Cache/Frontend/File.php
Normal file
222
Zend/Cache/Frontend/File.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: File.php 24218 2011-07-10 01:22:58Z ramon $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
179
Zend/Cache/Frontend/Function.php
Normal file
179
Zend/Cache/Frontend/Function.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Function.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
105
Zend/Cache/Frontend/Output.php
Normal file
105
Zend/Cache/Frontend/Output.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Output.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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 (simpy 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
404
Zend/Cache/Frontend/Page.php
Normal file
404
Zend/Cache/Frontend/Page.php
Normal file
@@ -0,0 +1,404 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Page.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Core
|
||||
*/
|
||||
require_once 'Zend/Cache/Core.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Frontend
|
||||
* @copyright Copyright (c) 2005-2011 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())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$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 '';
|
||||
}
|
||||
|
||||
}
|
||||
298
Zend/Cache/Manager.php
Normal file
298
Zend/Cache/Manager.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Manager.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** @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-2011 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
return $current;
|
||||
}
|
||||
}
|
||||
95
Zend/Exception.php
Normal file
95
Zend/Exception.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Exception extends Exception
|
||||
{
|
||||
/**
|
||||
* @var null|Exception
|
||||
*/
|
||||
private $_previous = null;
|
||||
|
||||
/**
|
||||
* Construct the exception
|
||||
*
|
||||
* @param string $msg
|
||||
* @param int $code
|
||||
* @param Exception $previous
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($msg = '', $code = 0, Exception $previous = null)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||
parent::__construct($msg, (int) $code);
|
||||
$this->_previous = $previous;
|
||||
} else {
|
||||
parent::__construct($msg, (int) $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading
|
||||
*
|
||||
* For PHP < 5.3.0, provides access to the getPrevious() method.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, array $args)
|
||||
{
|
||||
if ('getprevious' == strtolower($method)) {
|
||||
return $this->_getPrevious();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation of the exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||
if (null !== ($e = $this->getPrevious())) {
|
||||
return $e->__toString()
|
||||
. "\n\nNext "
|
||||
. parent::__toString();
|
||||
}
|
||||
}
|
||||
return parent::__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns previous Exception
|
||||
*
|
||||
* @return Exception|null
|
||||
*/
|
||||
protected function _getPrevious()
|
||||
{
|
||||
return $this->_previous;
|
||||
}
|
||||
}
|
||||
82
Zend/Memory.php
Normal file
82
Zend/Memory.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Memory.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Memory_Exception */
|
||||
require_once 'Zend/Memory/Manager.php';
|
||||
|
||||
/** Zend_Memory_Value */
|
||||
require_once 'Zend/Memory/Value.php';
|
||||
|
||||
/** Zend_Memory_Container */
|
||||
require_once 'Zend/Memory/Container.php';
|
||||
|
||||
/** Zend_Memory_Exception */
|
||||
require_once 'Zend/Cache.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory
|
||||
{
|
||||
/**
|
||||
* Factory
|
||||
*
|
||||
* @param string $backend backend name
|
||||
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||
* @return Zend_Memory_Manager
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
public static function factory($backend, $backendOptions = array())
|
||||
{
|
||||
if (strcasecmp($backend, 'none') == 0) {
|
||||
return new Zend_Memory_Manager();
|
||||
}
|
||||
|
||||
// Look through available backendsand
|
||||
// (that allows to specify it in any case)
|
||||
$backendIsFound = false;
|
||||
foreach (Zend_Cache::$standardBackends as $zendCacheBackend) {
|
||||
if (strcasecmp($backend, $zendCacheBackend) == 0) {
|
||||
$backend = $zendCacheBackend;
|
||||
$backendIsFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$backendIsFound) {
|
||||
require_once 'Zend/Memory/Exception.php';
|
||||
throw new Zend_Memory_Exception("Incorrect backend ($backend)");
|
||||
}
|
||||
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
|
||||
// For perfs reasons, we do not use the Zend_Loader::loadClass() method
|
||||
// (security controls are explicit)
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
|
||||
$backendObject = new $backendClass($backendOptions);
|
||||
|
||||
return new Zend_Memory_Manager($backendObject);
|
||||
}
|
||||
}
|
||||
149
Zend/Memory/AccessController.php
Normal file
149
Zend/Memory/AccessController.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: AccessController.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Memory_Container_Interface
|
||||
*/
|
||||
require_once 'Zend/Memory/Container/Interface.php';
|
||||
|
||||
/**
|
||||
* Memory object container access controller.
|
||||
*
|
||||
* Memory manager stores a list of generated objects to control them.
|
||||
* So container objects always have at least one reference and can't be automatically destroyed.
|
||||
*
|
||||
* This class is intended to be an userland proxy to memory container object.
|
||||
* It's not referenced by memory manager and class destructor is invoked immidiately after gouing
|
||||
* out of scope or unset operation.
|
||||
*
|
||||
* Class also provides Zend_Memory_Container_Interface interface and works as proxy for such cases.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory_AccessController implements Zend_Memory_Container_Interface
|
||||
{
|
||||
/**
|
||||
* Memory container object
|
||||
*
|
||||
* @var Zend_Memory_Container
|
||||
*/
|
||||
private $_memContainer;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Memory_Container_Movable $memoryManager
|
||||
*/
|
||||
public function __construct(Zend_Memory_Container_Movable $memContainer)
|
||||
{
|
||||
$this->_memContainer = $memContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->_memContainer->destroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get string value reference
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @return &string
|
||||
*/
|
||||
public function &getRef()
|
||||
{
|
||||
return $this->_memContainer->getRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal, that value is updated by external code.
|
||||
*
|
||||
* Should be used together with getRef()
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$this->_memContainer->touch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock object in memory.
|
||||
*/
|
||||
public function lock()
|
||||
{
|
||||
$this->_memContainer->lock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unlock object
|
||||
*/
|
||||
public function unlock()
|
||||
{
|
||||
$this->_memContainer->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if object is locked
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocked()
|
||||
{
|
||||
return $this->_memContainer->isLocked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* Loads object if necessary and moves it to the top of loaded objects list.
|
||||
* Swaps objects from the bottom of loaded objects list, if necessary.
|
||||
*
|
||||
* @param string $property
|
||||
* @return string
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
return $this->_memContainer->$property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param string $value
|
||||
* @throws Zend_Exception
|
||||
*/
|
||||
public function __set($property, $value)
|
||||
{
|
||||
$this->_memContainer->$property = $value;
|
||||
}
|
||||
}
|
||||
35
Zend/Memory/Container.php
Normal file
35
Zend/Memory/Container.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Container.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Memory_Container_Interface */
|
||||
require_once 'Zend/Memory/Container/Interface.php';
|
||||
|
||||
/**
|
||||
* Memory value container
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Memory_Container implements Zend_Memory_Container_Interface
|
||||
{
|
||||
}
|
||||
66
Zend/Memory/Container/Interface.php
Normal file
66
Zend/Memory/Container/Interface.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Memory value container interface
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Memory_Container_Interface
|
||||
{
|
||||
/**
|
||||
* Get string value reference
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @return &string
|
||||
*/
|
||||
public function &getRef();
|
||||
|
||||
/**
|
||||
* Signal, that value is updated by external code.
|
||||
*
|
||||
* Should be used together with getRef()
|
||||
*/
|
||||
public function touch();
|
||||
|
||||
/**
|
||||
* Lock object in memory.
|
||||
*/
|
||||
public function lock();
|
||||
|
||||
/**
|
||||
* Unlock object
|
||||
*/
|
||||
public function unlock();
|
||||
|
||||
/**
|
||||
* Return true if object is locked
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocked();
|
||||
}
|
||||
|
||||
113
Zend/Memory/Container/Locked.php
Normal file
113
Zend/Memory/Container/Locked.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Locked.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Memory_Container */
|
||||
require_once 'Zend/Memory/Container.php';
|
||||
|
||||
/**
|
||||
* Memory value container
|
||||
*
|
||||
* Locked (always stored in memory).
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory_Container_Locked extends Zend_Memory_Container
|
||||
{
|
||||
/**
|
||||
* Value object
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Memory_Manager $memoryManager
|
||||
* @param integer $id
|
||||
* @param string $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock object in memory.
|
||||
*/
|
||||
public function lock()
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock object
|
||||
*/
|
||||
public function unlock()
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if object is locked
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocked()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string value reference
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @return &string
|
||||
*/
|
||||
public function &getRef()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal, that value is updated by external code.
|
||||
*
|
||||
* Should be used together with getRef()
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy memory container and remove it from memory manager list
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
}
|
||||
297
Zend/Memory/Container/Movable.php
Normal file
297
Zend/Memory/Container/Movable.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Movable.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Memory_Container */
|
||||
require_once 'Zend/Memory/Container.php';
|
||||
|
||||
/** Zend_Memory_Value */
|
||||
require_once 'Zend/Memory/Value.php';
|
||||
|
||||
/**
|
||||
* Memory value container
|
||||
*
|
||||
* Movable (may be swapped with specified backend and unloaded).
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory_Container_Movable extends Zend_Memory_Container {
|
||||
/**
|
||||
* Internal object Id
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Memory manager reference
|
||||
*
|
||||
* @var Zend_Memory_Manager
|
||||
*/
|
||||
private $_memManager;
|
||||
|
||||
/**
|
||||
* Value object
|
||||
*
|
||||
* @var Zend_Memory_Value
|
||||
*/
|
||||
private $_value;
|
||||
|
||||
/** Value states */
|
||||
const LOADED = 1;
|
||||
const SWAPPED = 2;
|
||||
const LOCKED = 4;
|
||||
|
||||
/**
|
||||
* Value state (LOADED/SWAPPED/LOCKED)
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_state;
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Memory_Manager $memoryManager
|
||||
* @param integer $id
|
||||
* @param string $value
|
||||
*/
|
||||
public function __construct(Zend_Memory_Manager $memoryManager, $id, $value)
|
||||
{
|
||||
$this->_memManager = $memoryManager;
|
||||
$this->_id = $id;
|
||||
$this->_state = self::LOADED;
|
||||
$this->_value = new Zend_Memory_Value($value, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock object in memory.
|
||||
*/
|
||||
public function lock()
|
||||
{
|
||||
if ( !($this->_state & self::LOADED) ) {
|
||||
$this->_memManager->load($this, $this->_id);
|
||||
$this->_state |= self::LOADED;
|
||||
}
|
||||
|
||||
$this->_state |= self::LOCKED;
|
||||
|
||||
/**
|
||||
* @todo
|
||||
* It's possible to set "value" container attribute to avoid modification tracing, while it's locked
|
||||
* Check, if it's more effective
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock object
|
||||
*/
|
||||
public function unlock()
|
||||
{
|
||||
// Clear LOCKED state bit
|
||||
$this->_state &= ~self::LOCKED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if object is locked
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLocked()
|
||||
{
|
||||
return $this->_state & self::LOCKED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* Loads object if necessary and moves it to the top of loaded objects list.
|
||||
* Swaps objects from the bottom of loaded objects list, if necessary.
|
||||
*
|
||||
* @param string $property
|
||||
* @return string
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
if ($property != 'value') {
|
||||
require_once 'Zend/Memory/Exception.php';
|
||||
throw new Zend_Memory_Exception('Unknown property: Zend_Memory_container::$' . $property);
|
||||
}
|
||||
|
||||
if ( !($this->_state & self::LOADED) ) {
|
||||
$this->_memManager->load($this, $this->_id);
|
||||
$this->_state |= self::LOADED;
|
||||
}
|
||||
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param string $value
|
||||
* @throws Zend_Exception
|
||||
*/
|
||||
public function __set($property, $value)
|
||||
{
|
||||
if ($property != 'value') {
|
||||
require_once 'Zend/Memory/Exception.php';
|
||||
throw new Zend_Memory_Exception('Unknown property: Zend_Memory_container::$' . $property);
|
||||
}
|
||||
|
||||
$this->_state = self::LOADED;
|
||||
$this->_value = new Zend_Memory_Value($value, $this);
|
||||
|
||||
$this->_memManager->processUpdate($this, $this->_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get string value reference
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @return &string
|
||||
*/
|
||||
public function &getRef()
|
||||
{
|
||||
if ( !($this->_state & self::LOADED) ) {
|
||||
$this->_memManager->load($this, $this->_id);
|
||||
$this->_state |= self::LOADED;
|
||||
}
|
||||
|
||||
return $this->_value->getRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal, that value is updated by external code.
|
||||
*
|
||||
* Should be used together with getRef()
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$this->_memManager->processUpdate($this, $this->_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process container value update.
|
||||
* Must be called only by value object
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function processUpdate()
|
||||
{
|
||||
// Clear SWAPPED state bit
|
||||
$this->_state &= ~self::SWAPPED;
|
||||
|
||||
$this->_memManager->processUpdate($this, $this->_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start modifications trace
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function startTrace()
|
||||
{
|
||||
if ( !($this->_state & self::LOADED) ) {
|
||||
$this->_memManager->load($this, $this->_id);
|
||||
$this->_state |= self::LOADED;
|
||||
}
|
||||
|
||||
$this->_value->startTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value (used by memory manager when value is loaded)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = new Zend_Memory_Value($value, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear value (used by memory manager when value is swapped)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function unloadValue()
|
||||
{
|
||||
// Clear LOADED state bit
|
||||
$this->_state &= ~self::LOADED;
|
||||
|
||||
$this->_value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark, that object is swapped
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function markAsSwapped()
|
||||
{
|
||||
// Clear LOADED state bit
|
||||
$this->_state |= self::LOADED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is marked as swapped
|
||||
*
|
||||
* @internal
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSwapped()
|
||||
{
|
||||
return $this->_state & self::SWAPPED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object id
|
||||
*
|
||||
* @internal
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
/**
|
||||
* Destroy memory container and remove it from memory manager list
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
/**
|
||||
* We don't clean up swap because of performance considerations
|
||||
* Cleaning is performed by Memory Manager destructor
|
||||
*/
|
||||
|
||||
$this->_memManager->unlink($this, $this->_id);
|
||||
}
|
||||
}
|
||||
35
Zend/Memory/Exception.php
Normal file
35
Zend/Memory/Exception.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Controller_Exception */
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory_Exception extends Zend_Exception
|
||||
{}
|
||||
|
||||
463
Zend/Memory/Manager.php
Normal file
463
Zend/Memory/Manager.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Manager.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Memory_Container_Movable */
|
||||
require_once 'Zend/Memory/Container/Movable.php';
|
||||
|
||||
/** Zend_Memory_Container_Locked */
|
||||
require_once 'Zend/Memory/Container/Locked.php';
|
||||
|
||||
/** Zend_Memory_AccessController */
|
||||
require_once 'Zend/Memory/AccessController.php';
|
||||
|
||||
|
||||
/**
|
||||
* Memory manager
|
||||
*
|
||||
* This class encapsulates memory menagement operations, when PHP works
|
||||
* in limited memory mode.
|
||||
*
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Memory_Manager
|
||||
{
|
||||
/**
|
||||
* Object storage backend
|
||||
*
|
||||
* @var Zend_Cache_Backend_Interface
|
||||
*/
|
||||
private $_backend = null;
|
||||
|
||||
/**
|
||||
* Memory grow limit.
|
||||
* Default value is 2/3 of memory_limit php.ini variable
|
||||
* Negative value means no limit
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_memoryLimit = -1;
|
||||
|
||||
/**
|
||||
* Minimum value size to be swapped.
|
||||
* Default value is 16K
|
||||
* Negative value means that memory objects are never swapped
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_minSize = 16384;
|
||||
|
||||
/**
|
||||
* Overall size of memory, used by values
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_memorySize = 0;
|
||||
|
||||
/**
|
||||
* Id for next Zend_Memory object
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_nextId = 0;
|
||||
|
||||
/**
|
||||
* List of candidates to unload
|
||||
*
|
||||
* It also represents objects access history. Last accessed objects are moved to the end of array
|
||||
*
|
||||
* array(
|
||||
* <id> => <memory container object>,
|
||||
* ...
|
||||
* )
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_unloadCandidates = array();
|
||||
|
||||
/**
|
||||
* List of object sizes.
|
||||
*
|
||||
* This list is used to calculate modification of object sizes
|
||||
*
|
||||
* array( <id> => <size>, ...)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_sizes = array();
|
||||
|
||||
/**
|
||||
* Last modified object
|
||||
*
|
||||
* It's used to reduce number of calls necessary to trace objects' modifications
|
||||
* Modification is not processed by memory manager until we do not switch to another
|
||||
* object.
|
||||
* So we have to trace only _first_ object modification and do nothing for others
|
||||
*
|
||||
* @var Zend_Memory_Container_Movable
|
||||
*/
|
||||
private $_lastModified = null;
|
||||
|
||||
/**
|
||||
* Unique memory manager id
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_managerId;
|
||||
|
||||
/**
|
||||
* Tags array, used by backend to categorize stored values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_tags;
|
||||
|
||||
/**
|
||||
* This function is intended to generate unique id, used by memory manager
|
||||
*/
|
||||
private function _generateMemManagerId()
|
||||
{
|
||||
/**
|
||||
* @todo !!!
|
||||
* uniqid() php function doesn't really garantee the id to be unique
|
||||
* it should be changed by something else
|
||||
* (Ex. backend interface should be extended to provide this functionality)
|
||||
*/
|
||||
$this->_managerId = uniqid('ZendMemManager', true);
|
||||
$this->_tags = array($this->_managerId);
|
||||
$this->_managerId .= '_';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Memory manager constructor
|
||||
*
|
||||
* If backend is not specified, then memory objects are never swapped
|
||||
*
|
||||
* @param Zend_Cache_Backend $backend
|
||||
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||
*/
|
||||
public function __construct($backend = null)
|
||||
{
|
||||
if ($backend === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_backend = $backend;
|
||||
$this->_generateMemManagerId();
|
||||
|
||||
$memoryLimitStr = trim(ini_get('memory_limit'));
|
||||
if ($memoryLimitStr != '' && $memoryLimitStr != -1) {
|
||||
$this->_memoryLimit = (integer)$memoryLimitStr;
|
||||
switch (strtolower($memoryLimitStr[strlen($memoryLimitStr)-1])) {
|
||||
case 'g':
|
||||
$this->_memoryLimit *= 1024;
|
||||
// Break intentionally omitted
|
||||
case 'm':
|
||||
$this->_memoryLimit *= 1024;
|
||||
// Break intentionally omitted
|
||||
case 'k':
|
||||
$this->_memoryLimit *= 1024;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_memoryLimit = (int)($this->_memoryLimit*2/3);
|
||||
} // No limit otherwise
|
||||
}
|
||||
|
||||
/**
|
||||
* Object destructor
|
||||
*
|
||||
* Clean up backend storage
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->_backend !== null) {
|
||||
$this->_backend->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $this->_tags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set memory grow limit
|
||||
*
|
||||
* @param integer $newLimit
|
||||
* @throws Zend_Exception
|
||||
*/
|
||||
public function setMemoryLimit($newLimit)
|
||||
{
|
||||
$this->_memoryLimit = $newLimit;
|
||||
|
||||
$this->_swapCheck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get memory grow limit
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMemoryLimit()
|
||||
{
|
||||
return $this->_memoryLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimum size of values, which may be swapped
|
||||
*
|
||||
* @param integer $newSize
|
||||
*/
|
||||
public function setMinSize($newSize)
|
||||
{
|
||||
$this->_minSize = $newSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum size of values, which may be swapped
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMinSize()
|
||||
{
|
||||
return $this->_minSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Zend_Memory value container
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Memory_Container_Interface
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
public function create($value = '')
|
||||
{
|
||||
return $this->_create($value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Zend_Memory value container, which has value always
|
||||
* locked in memory
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Memory_Container_Interface
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
public function createLocked($value = '')
|
||||
{
|
||||
return $this->_create($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Zend_Memory object
|
||||
*
|
||||
* @param string $value
|
||||
* @param boolean $locked
|
||||
* @return Zend_Memory_Container_Interface
|
||||
* @throws Zend_Memory_Exception
|
||||
*/
|
||||
private function _create($value, $locked)
|
||||
{
|
||||
$id = $this->_nextId++;
|
||||
|
||||
if ($locked || ($this->_backend === null) /* Use only memory locked objects if backend is not specified */) {
|
||||
return new Zend_Memory_Container_Locked($value);
|
||||
}
|
||||
|
||||
// Commit other objects modifications
|
||||
$this->_commit();
|
||||
|
||||
$valueObject = new Zend_Memory_Container_Movable($this, $id, $value);
|
||||
|
||||
// Store last object size as 0
|
||||
$this->_sizes[$id] = 0;
|
||||
// prepare object for next modifications
|
||||
$this->_lastModified = $valueObject;
|
||||
|
||||
return new Zend_Memory_AccessController($valueObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlink value container from memory manager
|
||||
*
|
||||
* Used by Memory container destroy() method
|
||||
*
|
||||
* @internal
|
||||
* @param integer $id
|
||||
* @return Zend_Memory_Container
|
||||
*/
|
||||
public function unlink(Zend_Memory_Container_Movable $container, $id)
|
||||
{
|
||||
if ($this->_lastModified === $container) {
|
||||
// Drop all object modifications
|
||||
$this->_lastModified = null;
|
||||
unset($this->_sizes[$id]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_unloadCandidates[$id])) {
|
||||
unset($this->_unloadCandidates[$id]);
|
||||
}
|
||||
|
||||
$this->_memorySize -= $this->_sizes[$id];
|
||||
unset($this->_sizes[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process value update
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Memory_Container_Movable $container
|
||||
* @param integer $id
|
||||
*/
|
||||
public function processUpdate(Zend_Memory_Container_Movable $container, $id)
|
||||
{
|
||||
/**
|
||||
* This method is automatically invoked by memory container only once per
|
||||
* "modification session", but user may call memory container touch() method
|
||||
* several times depending on used algorithm. So we have to use this check
|
||||
* to optimize this case.
|
||||
*/
|
||||
if ($container === $this->_lastModified) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove just updated object from list of candidates to unload
|
||||
if( isset($this->_unloadCandidates[$id])) {
|
||||
unset($this->_unloadCandidates[$id]);
|
||||
}
|
||||
|
||||
// Reduce used memory mark
|
||||
$this->_memorySize -= $this->_sizes[$id];
|
||||
|
||||
// Commit changes of previously modified object if necessary
|
||||
$this->_commit();
|
||||
|
||||
$this->_lastModified = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit modified object and put it back to the loaded objects list
|
||||
*/
|
||||
private function _commit()
|
||||
{
|
||||
if (($container = $this->_lastModified) === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_lastModified = null;
|
||||
|
||||
$id = $container->getId();
|
||||
|
||||
// Calculate new object size and increase used memory size by this value
|
||||
$this->_memorySize += ($this->_sizes[$id] = strlen($container->getRef()));
|
||||
|
||||
if ($this->_sizes[$id] > $this->_minSize) {
|
||||
// Move object to "unload candidates list"
|
||||
$this->_unloadCandidates[$id] = $container;
|
||||
}
|
||||
|
||||
$container->startTrace();
|
||||
|
||||
$this->_swapCheck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and swap objects if necessary
|
||||
*
|
||||
* @throws Zend_MemoryException
|
||||
*/
|
||||
private function _swapCheck()
|
||||
{
|
||||
if ($this->_memoryLimit < 0 || $this->_memorySize < $this->_memoryLimit) {
|
||||
// Memory limit is not reached
|
||||
// Do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
// walk through loaded objects in access history order
|
||||
foreach ($this->_unloadCandidates as $id => $container) {
|
||||
$this->_swap($container, $id);
|
||||
unset($this->_unloadCandidates[$id]);
|
||||
|
||||
if ($this->_memorySize < $this->_memoryLimit) {
|
||||
// We've swapped enough objects
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'Zend/Memory/Exception.php';
|
||||
throw new Zend_Memory_Exception('Memory manager can\'t get enough space.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Swap object data to disk
|
||||
* Actualy swaps data or only unloads it from memory,
|
||||
* if object is not changed since last swap
|
||||
*
|
||||
* @param Zend_Memory_Container_Movable $container
|
||||
* @param integer $id
|
||||
*/
|
||||
private function _swap(Zend_Memory_Container_Movable $container, $id)
|
||||
{
|
||||
if ($container->isLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$container->isSwapped()) {
|
||||
$this->_backend->save($container->getRef(), $this->_managerId . $id, $this->_tags);
|
||||
}
|
||||
|
||||
$this->_memorySize -= $this->_sizes[$id];
|
||||
|
||||
$container->markAsSwapped();
|
||||
$container->unloadValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load value from swap file.
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Memory_Container_Movable $container
|
||||
* @param integer $id
|
||||
*/
|
||||
public function load(Zend_Memory_Container_Movable $container, $id)
|
||||
{
|
||||
$value = $this->_backend->load($this->_managerId . $id, true);
|
||||
|
||||
// Try to swap other objects if necessary
|
||||
// (do not include specified object into check)
|
||||
$this->_memorySize += strlen($value);
|
||||
$this->_swapCheck();
|
||||
|
||||
// Add loaded obect to the end of loaded objects list
|
||||
$container->setValue($value);
|
||||
|
||||
if ($this->_sizes[$id] > $this->_minSize) {
|
||||
// Add object to the end of "unload candidates list"
|
||||
$this->_unloadCandidates[$id] = $container;
|
||||
}
|
||||
}
|
||||
}
|
||||
177
Zend/Memory/Value.php
Normal file
177
Zend/Memory/Value.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Value.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* String value object
|
||||
*
|
||||
* It's an OO string wrapper.
|
||||
* Used to intercept string updates.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Memory
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @todo also implement Countable for PHP 5.1 but not yet to stay 5.0 compatible
|
||||
*/
|
||||
class Zend_Memory_Value implements ArrayAccess {
|
||||
/**
|
||||
* Value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_value;
|
||||
|
||||
/**
|
||||
* Container
|
||||
*
|
||||
* @var Zend_Memory_Container_Interface
|
||||
*/
|
||||
private $_container;
|
||||
|
||||
/**
|
||||
* Boolean flag which signals to trace value modifications
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_trace;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $value
|
||||
* @param Zend_Memory_Container_Movable $container
|
||||
*/
|
||||
public function __construct($value, Zend_Memory_Container_Movable $container)
|
||||
{
|
||||
$this->_container = $container;
|
||||
|
||||
$this->_value = (string)$value;
|
||||
|
||||
/**
|
||||
* Object is marked as just modified by memory manager
|
||||
* So we don't need to trace followed object modifications and
|
||||
* object is processed (and marked as traced) when another
|
||||
* memory object is modified.
|
||||
*
|
||||
* It reduces overall numberr of calls necessary to modification trace
|
||||
*/
|
||||
$this->_trace = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ArrayAccess interface method
|
||||
* returns true if string offset exists
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return $offset >= 0 && $offset < strlen($this->_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess interface method
|
||||
* Get character at $offset position
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return string
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->_value[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess interface method
|
||||
* Set character at $offset position
|
||||
*
|
||||
* @param integer $offset
|
||||
* @param string $char
|
||||
*/
|
||||
public function offsetSet($offset, $char)
|
||||
{
|
||||
$this->_value[$offset] = $char;
|
||||
|
||||
if ($this->_trace) {
|
||||
$this->_trace = false;
|
||||
$this->_container->processUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ArrayAccess interface method
|
||||
* Unset character at $offset position
|
||||
*
|
||||
* @param integer $offset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->_value[$offset]);
|
||||
|
||||
if ($this->_trace) {
|
||||
$this->_trace = false;
|
||||
$this->_container->processUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To string conversion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get string value reference
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @internal
|
||||
* @return string
|
||||
*/
|
||||
public function &getRef()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start modifications trace
|
||||
*
|
||||
* _Must_ be used for value access before PHP v 5.2
|
||||
* or _may_ be used for performance considerations
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function startTrace()
|
||||
{
|
||||
$this->_trace = true;
|
||||
}
|
||||
}
|
||||
1428
Zend/Pdf.php
Normal file
1428
Zend/Pdf.php
Normal file
File diff suppressed because it is too large
Load Diff
404
Zend/Pdf/Action.php
Normal file
404
Zend/Pdf/Action.php
Normal file
@@ -0,0 +1,404 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Action.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Target */
|
||||
require_once 'Zend/Pdf/Target.php';
|
||||
|
||||
|
||||
/**
|
||||
* Abstract PDF action representation class
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Action extends Zend_Pdf_Target implements RecursiveIterator, Countable
|
||||
{
|
||||
/**
|
||||
* Action dictionary
|
||||
*
|
||||
* @var Zend_Pdf_Element_Dictionary|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference
|
||||
*/
|
||||
protected $_actionDictionary;
|
||||
|
||||
|
||||
/**
|
||||
* An original list of chained actions
|
||||
*
|
||||
* @var array Array of Zend_Pdf_Action objects
|
||||
*/
|
||||
protected $_originalNextList;
|
||||
|
||||
/**
|
||||
* A list of next actions in actions tree (used for actions chaining)
|
||||
*
|
||||
* @var array Array of Zend_Pdf_Action objects
|
||||
*/
|
||||
public $next = array();
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element_Dictionary $dictionary
|
||||
* @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
|
||||
{
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
|
||||
}
|
||||
|
||||
$this->_actionDictionary = $dictionary;
|
||||
|
||||
if ($dictionary->Next !== null) {
|
||||
if ($dictionary->Next instanceof Zend_Pdf_Element_Dictionary) {
|
||||
// Check if dictionary object is not already processed
|
||||
if (!$processedActions->contains($dictionary->Next)) {
|
||||
$processedActions->attach($dictionary->Next);
|
||||
$this->next[] = Zend_Pdf_Action::load($dictionary->Next, $processedActions);
|
||||
}
|
||||
} else if ($dictionary->Next instanceof Zend_Pdf_Element_Array) {
|
||||
foreach ($dictionary->Next->items as $chainedActionDictionary) {
|
||||
// Check if dictionary object is not already processed
|
||||
if (!$processedActions->contains($chainedActionDictionary)) {
|
||||
$processedActions->attach($chainedActionDictionary);
|
||||
$this->next[] = Zend_Pdf_Action::load($chainedActionDictionary, $processedActions);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('PDF Action dictionary Next entry must be a dictionary or an array.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_originalNextList = $this->next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PDF action object using specified dictionary
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Pdf_Element $dictionary (It's actually Dictionary or Dictionary Object or Reference to a Dictionary Object)
|
||||
* @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
|
||||
* @return Zend_Pdf_Action
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function load(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions = null)
|
||||
{
|
||||
if ($processedActions === null) {
|
||||
$processedActions = new SplObjectStorage();
|
||||
}
|
||||
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
|
||||
}
|
||||
if (isset($dictionary->Type) && $dictionary->Type->value != 'Action') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Action dictionary Type entry must be set to \'Action\'.');
|
||||
}
|
||||
|
||||
if ($dictionary->S === null) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Action dictionary must contain S entry');
|
||||
}
|
||||
|
||||
switch ($dictionary->S->value) {
|
||||
case 'GoTo':
|
||||
require_once 'Zend/Pdf/Action/GoTo.php';
|
||||
return new Zend_Pdf_Action_GoTo($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'GoToR':
|
||||
require_once 'Zend/Pdf/Action/GoToR.php';
|
||||
return new Zend_Pdf_Action_GoToR($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'GoToE':
|
||||
require_once 'Zend/Pdf/Action/GoToE.php';
|
||||
return new Zend_Pdf_Action_GoToE($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Launch':
|
||||
require_once 'Zend/Pdf/Action/Launch.php';
|
||||
return new Zend_Pdf_Action_Launch($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Thread':
|
||||
require_once 'Zend/Pdf/Action/Thread.php';
|
||||
return new Zend_Pdf_Action_Thread($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'URI':
|
||||
require_once 'Zend/Pdf/Action/URI.php';
|
||||
return new Zend_Pdf_Action_URI($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Sound':
|
||||
require_once 'Zend/Pdf/Action/Sound.php';
|
||||
return new Zend_Pdf_Action_Sound($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Movie':
|
||||
require_once 'Zend/Pdf/Action/Movie.php';
|
||||
return new Zend_Pdf_Action_Movie($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Hide':
|
||||
require_once 'Zend/Pdf/Action/Hide.php';
|
||||
return new Zend_Pdf_Action_Hide($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Named':
|
||||
require_once 'Zend/Pdf/Action/Named.php';
|
||||
return new Zend_Pdf_Action_Named($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'SubmitForm':
|
||||
require_once 'Zend/Pdf/Action/SubmitForm.php';
|
||||
return new Zend_Pdf_Action_SubmitForm($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'ResetForm':
|
||||
require_once 'Zend/Pdf/Action/ResetForm.php';
|
||||
return new Zend_Pdf_Action_ResetForm($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'ImportData':
|
||||
require_once 'Zend/Pdf/Action/ImportData.php';
|
||||
return new Zend_Pdf_Action_ImportData($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'JavaScript':
|
||||
require_once 'Zend/Pdf/Action/JavaScript.php';
|
||||
return new Zend_Pdf_Action_JavaScript($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'SetOCGState':
|
||||
require_once 'Zend/Pdf/Action/SetOCGState.php';
|
||||
return new Zend_Pdf_Action_SetOCGState($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Rendition':
|
||||
require_once 'Zend/Pdf/Action/Rendition.php';
|
||||
return new Zend_Pdf_Action_Rendition($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'Trans':
|
||||
require_once 'Zend/Pdf/Action/Trans.php';
|
||||
return new Zend_Pdf_Action_Trans($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
case 'GoTo3DView':
|
||||
require_once 'Zend/Pdf/Action/GoTo3DView.php';
|
||||
return new Zend_Pdf_Action_GoTo3DView($dictionary, $processedActions);
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Action/Unknown.php';
|
||||
return new Zend_Pdf_Action_Unknown($dictionary, $processedActions);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource
|
||||
*
|
||||
* @internal
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->_actionDictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump Action and its child actions into PDF structures
|
||||
*
|
||||
* Returns dictionary indirect object or reference
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Pdf_ElementFactory $factory Object factory for newly created indirect objects
|
||||
* @param SplObjectStorage $processedActions list of already processed actions (used to prevent infinity loop caused by cyclic references)
|
||||
* @return Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference Dictionary indirect object
|
||||
*/
|
||||
public function dumpAction(Zend_Pdf_ElementFactory_Interface $factory, SplObjectStorage $processedActions = null)
|
||||
{
|
||||
if ($processedActions === null) {
|
||||
$processedActions = new SplObjectStorage();
|
||||
}
|
||||
if ($processedActions->contains($this)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Action chain cyclyc reference is detected.');
|
||||
}
|
||||
$processedActions->attach($this);
|
||||
|
||||
$childListUpdated = false;
|
||||
if (count($this->_originalNextList) != count($this->next)) {
|
||||
// If original and current children arrays have different size then children list was updated
|
||||
$childListUpdated = true;
|
||||
} else if ( !(array_keys($this->_originalNextList) === array_keys($this->next)) ) {
|
||||
// If original and current children arrays have different keys (with a glance to an order) then children list was updated
|
||||
$childListUpdated = true;
|
||||
} else {
|
||||
foreach ($this->next as $key => $childAction) {
|
||||
if ($this->_originalNextList[$key] !== $childAction) {
|
||||
$childListUpdated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($childListUpdated) {
|
||||
$this->_actionDictionary->touch();
|
||||
switch (count($this->next)) {
|
||||
case 0:
|
||||
$this->_actionDictionary->Next = null;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$child = reset($this->next);
|
||||
$this->_actionDictionary->Next = $child->dumpAction($factory, $processedActions);
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
$pdfChildArray = new Zend_Pdf_Element_Array();
|
||||
foreach ($this->next as $child) {
|
||||
|
||||
$pdfChildArray->items[] = $child->dumpAction($factory, $processedActions);
|
||||
}
|
||||
$this->_actionDictionary->Next = $pdfChildArray;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
foreach ($this->next as $child) {
|
||||
$child->dumpAction($factory, $processedActions);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_actionDictionary instanceof Zend_Pdf_Element_Dictionary) {
|
||||
// It's a newly created action. Register it within object factory and return indirect object
|
||||
return $factory->newObject($this->_actionDictionary);
|
||||
} else {
|
||||
// It's a loaded object
|
||||
return $this->_actionDictionary;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// RecursiveIterator interface methods
|
||||
//////////////
|
||||
|
||||
/**
|
||||
* Returns current child action.
|
||||
*
|
||||
* @return Zend_Pdf_Action
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current iterator key
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to next child
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind children
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current position is valid
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return current($this->next) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the child action.
|
||||
*
|
||||
* @return Zend_Pdf_Action|null
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return current($this->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements RecursiveIterator interface.
|
||||
*
|
||||
* @return bool whether container has any pages
|
||||
*/
|
||||
public function hasChildren()
|
||||
{
|
||||
return count($this->next) > 0;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Countable interface methods
|
||||
//////////////
|
||||
|
||||
/**
|
||||
* count()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->childOutlines);
|
||||
}
|
||||
}
|
||||
116
Zend/Pdf/Action/GoTo.php
Normal file
116
Zend/Pdf/Action/GoTo.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: GoTo.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Destination.php';
|
||||
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
/**
|
||||
* PDF 'Go to' action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_GoTo extends Zend_Pdf_Action
|
||||
{
|
||||
/**
|
||||
* GoTo Action destination
|
||||
*
|
||||
* @var Zend_Pdf_Destination
|
||||
*/
|
||||
protected $_destination;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element_Dictionary $dictionary
|
||||
* @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
|
||||
{
|
||||
parent::__construct($dictionary, $processedActions);
|
||||
|
||||
$this->_destination = Zend_Pdf_Destination::load($dictionary->D);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Zend_Pdf_Action_GoTo object using specified destination
|
||||
*
|
||||
* @param Zend_Pdf_Destination|string $destination
|
||||
* @return Zend_Pdf_Action_GoTo
|
||||
*/
|
||||
public static function create($destination)
|
||||
{
|
||||
if (is_string($destination)) {
|
||||
require_once 'Zend/Pdf/Destination/Named.php';
|
||||
$destination = Zend_Pdf_Destination_Named::create($destination);
|
||||
}
|
||||
|
||||
if (!$destination instanceof Zend_Pdf_Destination) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$destination parameter must be a Zend_Pdf_Destination object or string.');
|
||||
}
|
||||
|
||||
$dictionary = new Zend_Pdf_Element_Dictionary();
|
||||
$dictionary->Type = new Zend_Pdf_Element_Name('Action');
|
||||
$dictionary->S = new Zend_Pdf_Element_Name('GoTo');
|
||||
$dictionary->Next = null;
|
||||
$dictionary->D = $destination->getResource();
|
||||
|
||||
return new Zend_Pdf_Action_GoTo($dictionary, new SplObjectStorage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set goto action destination
|
||||
*
|
||||
* @param Zend_Pdf_Destination|string $destination
|
||||
* @return Zend_Pdf_Action_GoTo
|
||||
*/
|
||||
public function setDestination(Zend_Pdf_Destination $destination)
|
||||
{
|
||||
$this->_destination = $destination;
|
||||
|
||||
$this->_actionDictionary->touch();
|
||||
$this->_actionDictionary->D = $destination->getResource();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get goto action destination
|
||||
*
|
||||
* @return Zend_Pdf_Destination
|
||||
*/
|
||||
public function getDestination()
|
||||
{
|
||||
return $this->_destination;
|
||||
}
|
||||
}
|
||||
39
Zend/Pdf/Action/GoTo3DView.php
Normal file
39
Zend/Pdf/Action/GoTo3DView.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: GoTo3DView.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Set the current view of a 3D annotation' action
|
||||
* PDF 1.6+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_GoTo3DView extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
38
Zend/Pdf/Action/GoToE.php
Normal file
38
Zend/Pdf/Action/GoToE.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: GoToE.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Go to a destination in an embedded file' action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_GoToE extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
38
Zend/Pdf/Action/GoToR.php
Normal file
38
Zend/Pdf/Action/GoToR.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: GoToR.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Go to a destination in another document' action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_GoToR extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/Hide.php
Normal file
39
Zend/Pdf/Action/Hide.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hide.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Set an annotation’s Hidden flag' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Hide extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/ImportData.php
Normal file
39
Zend/Pdf/Action/ImportData.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ImportData.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Import field values from a file' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_ImportData extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/JavaScript.php
Normal file
39
Zend/Pdf/Action/JavaScript.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: JavaScript.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Execute a JavaScript script' action
|
||||
* PDF 1.3+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_JavaScript extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
38
Zend/Pdf/Action/Launch.php
Normal file
38
Zend/Pdf/Action/Launch.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Launch.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Launch an application, usually to open a file' action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Launch extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
38
Zend/Pdf/Action/Movie.php
Normal file
38
Zend/Pdf/Action/Movie.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Movie.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Play a movie' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Movie extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
39
Zend/Pdf/Action/Named.php
Normal file
39
Zend/Pdf/Action/Named.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Named.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Execute an action predefined by the viewer application' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Named extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/Rendition.php
Normal file
39
Zend/Pdf/Action/Rendition.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Rendition.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Controls the playing of multimedia content' action
|
||||
* PDF 1.5+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Rendition extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/ResetForm.php
Normal file
39
Zend/Pdf/Action/ResetForm.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ResetForm.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Set fields to their default values' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_ResetForm extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/SetOCGState.php
Normal file
39
Zend/Pdf/Action/SetOCGState.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SetOCGState.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Set the states of optional content groups' action
|
||||
* PDF 1.5+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_SetOCGState extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/Sound.php
Normal file
39
Zend/Pdf/Action/Sound.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Sound.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Play a sound' action representation class
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Sound extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/SubmitForm.php
Normal file
39
Zend/Pdf/Action/SubmitForm.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SubmitForm.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Send data to a uniform resource locator' action
|
||||
* PDF 1.2+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_SubmitForm extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
38
Zend/Pdf/Action/Thread.php
Normal file
38
Zend/Pdf/Action/Thread.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Thread.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Begin reading an article thread' action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Thread extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
39
Zend/Pdf/Action/Trans.php
Normal file
39
Zend/Pdf/Action/Trans.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Trans.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Updates the display of a document, using a transition dictionary' action
|
||||
* PDF 1.5+ feature
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Trans extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
167
Zend/Pdf/Action/URI.php
Normal file
167
Zend/Pdf/Action/URI.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: URI.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
require_once 'Zend/Pdf/Element/Boolean.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF 'Resolve a uniform resource identifier' action
|
||||
*
|
||||
* A URI action causes a URI to be resolved.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_URI extends Zend_Pdf_Action
|
||||
{
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element_Dictionary $dictionary
|
||||
* @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
|
||||
{
|
||||
parent::__construct($dictionary, $processedActions);
|
||||
|
||||
if ($dictionary->URI === null) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('URI action dictionary entry is required');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate URI
|
||||
*
|
||||
* @param string $uri
|
||||
* @return true
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
protected static function _validateUri($uri)
|
||||
{
|
||||
$scheme = parse_url((string)$uri, PHP_URL_SCHEME);
|
||||
if ($scheme === false || $scheme === null) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Invalid URI');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Zend_Pdf_Action_URI object using specified uri
|
||||
*
|
||||
* @param string $uri The URI to resolve, encoded in 7-bit ASCII
|
||||
* @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved
|
||||
* @return Zend_Pdf_Action_URI
|
||||
*/
|
||||
public static function create($uri, $isMap = false)
|
||||
{
|
||||
self::_validateUri($uri);
|
||||
|
||||
$dictionary = new Zend_Pdf_Element_Dictionary();
|
||||
$dictionary->Type = new Zend_Pdf_Element_Name('Action');
|
||||
$dictionary->S = new Zend_Pdf_Element_Name('URI');
|
||||
$dictionary->Next = null;
|
||||
$dictionary->URI = new Zend_Pdf_Element_String($uri);
|
||||
if ($isMap) {
|
||||
$dictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
|
||||
}
|
||||
|
||||
return new Zend_Pdf_Action_URI($dictionary, new SplObjectStorage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set URI to resolve
|
||||
*
|
||||
* @param string $uri The uri to resolve, encoded in 7-bit ASCII.
|
||||
* @return Zend_Pdf_Action_URI
|
||||
*/
|
||||
public function setUri($uri)
|
||||
{
|
||||
$this->_validateUri($uri);
|
||||
|
||||
$this->_actionDictionary->touch();
|
||||
$this->_actionDictionary->URI = new Zend_Pdf_Element_String($uri);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URI to resolve
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->_actionDictionary->URI->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set IsMap property
|
||||
*
|
||||
* If the IsMap flag is true and the user has triggered the URI action by clicking
|
||||
* an annotation, the coordinates of the mouse position at the time the action is
|
||||
* performed should be transformed from device space to user space and then offset
|
||||
* relative to the upper-left corner of the annotation rectangle.
|
||||
*
|
||||
* @param boolean $isMap A flag specifying whether to track the mouse position when the URI is resolved
|
||||
* @return Zend_Pdf_Action_URI
|
||||
*/
|
||||
public function setIsMap($isMap)
|
||||
{
|
||||
$this->_actionDictionary->touch();
|
||||
|
||||
if ($isMap) {
|
||||
$this->_actionDictionary->IsMap = new Zend_Pdf_Element_Boolean(true);
|
||||
} else {
|
||||
$this->_actionDictionary->IsMap = null;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IsMap property
|
||||
*
|
||||
* If the IsMap flag is true and the user has triggered the URI action by clicking
|
||||
* an annotation, the coordinates of the mouse position at the time the action is
|
||||
* performed should be transformed from device space to user space and then offset
|
||||
* relative to the upper-left corner of the annotation rectangle.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsMap()
|
||||
{
|
||||
return $this->_actionDictionary->IsMap !== null &&
|
||||
$this->_actionDictionary->IsMap->value;
|
||||
}
|
||||
}
|
||||
38
Zend/Pdf/Action/Unknown.php
Normal file
38
Zend/Pdf/Action/Unknown.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Unknown.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Action */
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
|
||||
|
||||
/**
|
||||
* Unrecognized PDF action
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Actions
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Action_Unknown extends Zend_Pdf_Action
|
||||
{
|
||||
}
|
||||
|
||||
230
Zend/Pdf/Annotation.php
Normal file
230
Zend/Pdf/Annotation.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Annotation.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
/**
|
||||
* Abstract PDF annotation representation class
|
||||
*
|
||||
* An annotation associates an object such as a note, sound, or movie with a location
|
||||
* on a page of a PDF document, or provides a way to interact with the user by
|
||||
* means of the mouse and keyboard.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Annotation
|
||||
{
|
||||
/**
|
||||
* Annotation dictionary
|
||||
*
|
||||
* @var Zend_Pdf_Element_Dictionary|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference
|
||||
*/
|
||||
protected $_annotationDictionary;
|
||||
|
||||
/**
|
||||
* Get annotation dictionary
|
||||
*
|
||||
* @internal
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->_annotationDictionary;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set bottom edge of the annotation rectangle.
|
||||
*
|
||||
* @param float $bottom
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public function setBottom($bottom) {
|
||||
$this->_annotationDictionary->Rect->items[1]->touch();
|
||||
$this->_annotationDictionary->Rect->items[1]->value = $bottom;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom edge of the annotation rectangle.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getBottom() {
|
||||
return $this->_annotationDictionary->Rect->items[1]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top edge of the annotation rectangle.
|
||||
*
|
||||
* @param float $top
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public function setTop($top) {
|
||||
$this->_annotationDictionary->Rect->items[3]->touch();
|
||||
$this->_annotationDictionary->Rect->items[3]->value = $top;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top edge of the annotation rectangle.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTop() {
|
||||
return $this->_annotationDictionary->Rect->items[3]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right edge of the annotation rectangle.
|
||||
*
|
||||
* @param float $right
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public function setRight($right) {
|
||||
$this->_annotationDictionary->Rect->items[2]->touch();
|
||||
$this->_annotationDictionary->Rect->items[2]->value = $right;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get right edge of the annotation rectangle.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRight() {
|
||||
return $this->_annotationDictionary->Rect->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left edge of the annotation rectangle.
|
||||
*
|
||||
* @param float $left
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public function setLeft($left) {
|
||||
$this->_annotationDictionary->Rect->items[0]->touch();
|
||||
$this->_annotationDictionary->Rect->items[0]->value = $left;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left edge of the annotation rectangle.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getLeft() {
|
||||
return $this->_annotationDictionary->Rect->items[0]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return text to be displayed for the annotation or, if this type of annotation
|
||||
* does not display text, an alternate description of the annotation’s contents
|
||||
* in human-readable form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText() {
|
||||
if ($this->_annotationDictionary->Contents === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->_annotationDictionary->Contents->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text to be displayed for the annotation or, if this type of annotation
|
||||
* does not display text, an alternate description of the annotation’s contents
|
||||
* in human-readable form.
|
||||
*
|
||||
* @param string $text
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public function setText($text) {
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
|
||||
if ($this->_annotationDictionary->Contents === null) {
|
||||
$this->_annotationDictionary->touch();
|
||||
$this->_annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
|
||||
} else {
|
||||
$this->_annotationDictionary->Contents->touch();
|
||||
$this->_annotationDictionary->Contents->value = new Zend_Pdf_Element_String($text);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation object constructor
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $annotationDictionary)
|
||||
{
|
||||
if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
|
||||
}
|
||||
|
||||
$this->_annotationDictionary = $annotationDictionary;
|
||||
|
||||
if ($this->_annotationDictionary->Type !== null &&
|
||||
$this->_annotationDictionary->Type->value != 'Annot') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Wrong resource type. \'Annot\' expected.');
|
||||
}
|
||||
|
||||
if ($this->_annotationDictionary->Rect === null) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('\'Rect\' dictionary entry is required.');
|
||||
}
|
||||
|
||||
if (count($this->_annotationDictionary->Rect->items) != 4 ||
|
||||
$this->_annotationDictionary->Rect->items[0]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
|
||||
$this->_annotationDictionary->Rect->items[1]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
|
||||
$this->_annotationDictionary->Rect->items[2]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
|
||||
$this->_annotationDictionary->Rect->items[3]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('\'Rect\' dictionary entry must be an array of four numeric elements.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Annotation object from a specified resource
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Pdf_Element $resource
|
||||
* @return Zend_Pdf_Annotation
|
||||
*/
|
||||
public static function load(Zend_Pdf_Element $resource)
|
||||
{
|
||||
/** @todo implementation */
|
||||
}
|
||||
}
|
||||
101
Zend/Pdf/Annotation/FileAttachment.php
Normal file
101
Zend/Pdf/Annotation/FileAttachment.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FileAttachment.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Annotation */
|
||||
require_once 'Zend/Pdf/Annotation.php';
|
||||
|
||||
/**
|
||||
* A file attachment annotation contains a reference to a file,
|
||||
* which typically is embedded in the PDF file.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Annotation_FileAttachment extends Zend_Pdf_Annotation
|
||||
{
|
||||
/**
|
||||
* Annotation object constructor
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $annotationDictionary)
|
||||
{
|
||||
if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
|
||||
}
|
||||
|
||||
if ($annotationDictionary->Subtype === null ||
|
||||
$annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
|
||||
$annotationDictionary->Subtype->value != 'FileAttachment') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Subtype => FileAttachment entry is requires');
|
||||
}
|
||||
|
||||
parent::__construct($annotationDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create link annotation object
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param string $fileSpecification
|
||||
* @return Zend_Pdf_Annotation_FileAttachment
|
||||
*/
|
||||
public static function create($x1, $y1, $x2, $y2, $fileSpecification)
|
||||
{
|
||||
$annotationDictionary = new Zend_Pdf_Element_Dictionary();
|
||||
|
||||
$annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
|
||||
$annotationDictionary->Subtype = new Zend_Pdf_Element_Name('FileAttachment');
|
||||
|
||||
$rectangle = new Zend_Pdf_Element_Array();
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
|
||||
$annotationDictionary->Rect = $rectangle;
|
||||
|
||||
$fsDictionary = new Zend_Pdf_Element_Dictionary();
|
||||
$fsDictionary->Type = new Zend_Pdf_Element_Name('Filespec');
|
||||
$fsDictionary->F = new Zend_Pdf_Element_String($fileSpecification);
|
||||
|
||||
$annotationDictionary->FS = $fsDictionary;
|
||||
|
||||
|
||||
return new Zend_Pdf_Annotation_FileAttachment($annotationDictionary);
|
||||
}
|
||||
}
|
||||
162
Zend/Pdf/Annotation/Link.php
Normal file
162
Zend/Pdf/Annotation/Link.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Link.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Annotation */
|
||||
require_once 'Zend/Pdf/Annotation.php';
|
||||
|
||||
/**
|
||||
* A link annotation represents either a hypertext link to a destination elsewhere in
|
||||
* the document or an action to be performed.
|
||||
*
|
||||
* Only destinations are used now since only GoTo action can be created by user
|
||||
* in current implementation.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Annotation_Link extends Zend_Pdf_Annotation
|
||||
{
|
||||
/**
|
||||
* Annotation object constructor
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $annotationDictionary)
|
||||
{
|
||||
if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
|
||||
}
|
||||
|
||||
if ($annotationDictionary->Subtype === null ||
|
||||
$annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
|
||||
$annotationDictionary->Subtype->value != 'Link') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Subtype => Link entry is requires');
|
||||
}
|
||||
|
||||
parent::__construct($annotationDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create link annotation object
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param Zend_Pdf_Target|string $target
|
||||
* @return Zend_Pdf_Annotation_Link
|
||||
*/
|
||||
public static function create($x1, $y1, $x2, $y2, $target)
|
||||
{
|
||||
if (is_string($target)) {
|
||||
require_once 'Zend/Pdf/Destination/Named.php';
|
||||
$destination = Zend_Pdf_Destination_Named::create($target);
|
||||
}
|
||||
if (!$target instanceof Zend_Pdf_Target) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
|
||||
}
|
||||
|
||||
$annotationDictionary = new Zend_Pdf_Element_Dictionary();
|
||||
|
||||
$annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
|
||||
$annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Link');
|
||||
|
||||
$rectangle = new Zend_Pdf_Element_Array();
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
|
||||
$annotationDictionary->Rect = $rectangle;
|
||||
|
||||
if ($target instanceof Zend_Pdf_Destination) {
|
||||
$annotationDictionary->Dest = $target->getResource();
|
||||
} else {
|
||||
$annotationDictionary->A = $target->getResource();
|
||||
}
|
||||
|
||||
return new Zend_Pdf_Annotation_Link($annotationDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set link annotation destination
|
||||
*
|
||||
* @param Zend_Pdf_Target|string $target
|
||||
* @return Zend_Pdf_Annotation_Link
|
||||
*/
|
||||
public function setDestination($target)
|
||||
{
|
||||
if (is_string($target)) {
|
||||
require_once 'Zend/Pdf/Destination/Named.php';
|
||||
$destination = Zend_Pdf_Destination_Named::create($target);
|
||||
}
|
||||
if (!$target instanceof Zend_Pdf_Target) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
|
||||
}
|
||||
|
||||
$this->_annotationDictionary->touch();
|
||||
$this->_annotationDictionary->Dest = $destination->getResource();
|
||||
if ($target instanceof Zend_Pdf_Destination) {
|
||||
$this->_annotationDictionary->Dest = $target->getResource();
|
||||
$this->_annotationDictionary->A = null;
|
||||
} else {
|
||||
$this->_annotationDictionary->Dest = null;
|
||||
$this->_annotationDictionary->A = $target->getResource();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link annotation destination
|
||||
*
|
||||
* @return Zend_Pdf_Target|null
|
||||
*/
|
||||
public function getDestination()
|
||||
{
|
||||
if ($this->_annotationDictionary->Dest === null &&
|
||||
$this->_annotationDictionary->A === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->_annotationDictionary->Dest !== null) {
|
||||
require_once 'Zend/Pdf/Destination.php';
|
||||
return Zend_Pdf_Destination::load($this->_annotationDictionary->Dest);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Action.php';
|
||||
return Zend_Pdf_Action::load($this->_annotationDictionary->A);
|
||||
}
|
||||
}
|
||||
}
|
||||
142
Zend/Pdf/Annotation/Markup.php
Normal file
142
Zend/Pdf/Annotation/Markup.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Markup.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Annotation */
|
||||
require_once 'Zend/Pdf/Annotation.php';
|
||||
|
||||
/**
|
||||
* A markup annotation
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Annotation_Markup extends Zend_Pdf_Annotation
|
||||
{
|
||||
/**
|
||||
* Annotation subtypes
|
||||
*/
|
||||
const SUBTYPE_HIGHLIGHT = 'Highlight';
|
||||
const SUBTYPE_UNDERLINE = 'Underline';
|
||||
const SUBTYPE_SQUIGGLY = 'Squiggly';
|
||||
const SUBTYPE_STRIKEOUT = 'StrikeOut';
|
||||
|
||||
/**
|
||||
* Annotation object constructor
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $annotationDictionary)
|
||||
{
|
||||
if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
|
||||
}
|
||||
|
||||
if ($annotationDictionary->Subtype === null ||
|
||||
$annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
|
||||
!in_array( $annotationDictionary->Subtype->value,
|
||||
array(self::SUBTYPE_HIGHLIGHT,
|
||||
self::SUBTYPE_UNDERLINE,
|
||||
self::SUBTYPE_SQUIGGLY,
|
||||
self::SUBTYPE_STRIKEOUT) )) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Subtype => Markup entry is omitted or has wrong value.');
|
||||
}
|
||||
|
||||
parent::__construct($annotationDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create markup annotation object
|
||||
*
|
||||
* Text markup annotations appear as highlights, underlines, strikeouts or
|
||||
* jagged ("squiggly") underlines in the text of a document. When opened,
|
||||
* they display a pop-up window containing the text of the associated note.
|
||||
*
|
||||
* $subType parameter may contain
|
||||
* Zend_Pdf_Annotation_Markup::SUBTYPE_HIGHLIGHT
|
||||
* Zend_Pdf_Annotation_Markup::SUBTYPE_UNDERLINE
|
||||
* Zend_Pdf_Annotation_Markup::SUBTYPE_SQUIGGLY
|
||||
* Zend_Pdf_Annotation_Markup::SUBTYPE_STRIKEOUT
|
||||
* for for a highlight, underline, squiggly-underline, or strikeout annotation,
|
||||
* respectively.
|
||||
*
|
||||
* $quadPoints is an array of 8xN numbers specifying the coordinates of
|
||||
* N quadrilaterals default user space. Each quadrilateral encompasses a word or
|
||||
* group of contiguous words in the text underlying the annotation.
|
||||
* The coordinates for each quadrilateral are given in the order
|
||||
* x1 y1 x2 y2 x3 y3 x4 y4
|
||||
* specifying the quadrilateral’s four vertices in counterclockwise order
|
||||
* starting from left bottom corner.
|
||||
* The text is oriented with respect to the edge connecting points
|
||||
* (x1, y1) and (x2, y2).
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param string $text
|
||||
* @param string $subType
|
||||
* @param array $quadPoints [x1 y1 x2 y2 x3 y3 x4 y4]
|
||||
* @return Zend_Pdf_Annotation_Markup
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($x1, $y1, $x2, $y2, $text, $subType, $quadPoints)
|
||||
{
|
||||
$annotationDictionary = new Zend_Pdf_Element_Dictionary();
|
||||
|
||||
$annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
|
||||
$annotationDictionary->Subtype = new Zend_Pdf_Element_Name($subType);
|
||||
|
||||
$rectangle = new Zend_Pdf_Element_Array();
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
|
||||
$annotationDictionary->Rect = $rectangle;
|
||||
|
||||
$annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
|
||||
|
||||
if (!is_array($quadPoints) || count($quadPoints) == 0 || count($quadPoints) % 8 != 0) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('$quadPoints parameter must be an array of 8xN numbers');
|
||||
}
|
||||
$points = new Zend_Pdf_Element_Array();
|
||||
foreach ($quadPoints as $quadPoint) {
|
||||
$points->items[] = new Zend_Pdf_Element_Numeric($quadPoint);
|
||||
}
|
||||
$annotationDictionary->QuadPoints = $points;
|
||||
|
||||
return new Zend_Pdf_Annotation_Markup($annotationDictionary);
|
||||
}
|
||||
}
|
||||
95
Zend/Pdf/Annotation/Text.php
Normal file
95
Zend/Pdf/Annotation/Text.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Text.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Annotation */
|
||||
require_once 'Zend/Pdf/Annotation.php';
|
||||
|
||||
/**
|
||||
* A text annotation represents a "sticky note" attached to a point in the PDF document.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Annotation
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Annotation_Text extends Zend_Pdf_Annotation
|
||||
{
|
||||
/**
|
||||
* Annotation object constructor
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $annotationDictionary)
|
||||
{
|
||||
if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
|
||||
}
|
||||
|
||||
if ($annotationDictionary->Subtype === null ||
|
||||
$annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
|
||||
$annotationDictionary->Subtype->value != 'Text') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Subtype => Text entry is requires');
|
||||
}
|
||||
|
||||
parent::__construct($annotationDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create link annotation object
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param string $text
|
||||
* @return Zend_Pdf_Annotation_Text
|
||||
*/
|
||||
public static function create($x1, $y1, $x2, $y2, $text)
|
||||
{
|
||||
$annotationDictionary = new Zend_Pdf_Element_Dictionary();
|
||||
|
||||
$annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
|
||||
$annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Text');
|
||||
|
||||
$rectangle = new Zend_Pdf_Element_Array();
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
|
||||
$rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
|
||||
$annotationDictionary->Rect = $rectangle;
|
||||
|
||||
$annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
|
||||
|
||||
return new Zend_Pdf_Annotation_Text($annotationDictionary);
|
||||
}
|
||||
}
|
||||
182
Zend/Pdf/Canvas.php
Normal file
182
Zend/Pdf/Canvas.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
require_once 'Zend/Pdf/Canvas/Abstract.php';
|
||||
|
||||
/**
|
||||
* Canvas is an abstract rectangle drawing area which can be dropped into
|
||||
* page object at specified place.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Canvas extends Zend_Pdf_Canvas_Abstract
|
||||
{
|
||||
/**
|
||||
* Canvas procedure sets.
|
||||
*
|
||||
* Allowed values: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_procSet = array();
|
||||
|
||||
/**
|
||||
* Canvas width expressed in default user space units (1/72 inch)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $_width;
|
||||
|
||||
/**
|
||||
* Canvas height expressed in default user space units (1/72 inch)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $_height;
|
||||
|
||||
protected $_resources = array('Font' => array(),
|
||||
'XObject' => array(),
|
||||
'ExtGState' => array());
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
*/
|
||||
public function __construct($width, $height)
|
||||
{
|
||||
$this->_width = $width;
|
||||
$this->_height = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add procedure set to the canvas description
|
||||
*
|
||||
* @param string $procSetName
|
||||
*/
|
||||
protected function _addProcSet($procSetName)
|
||||
{
|
||||
$this->_procset[$procSetName] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach resource to the canvas
|
||||
*
|
||||
* Method returns a name of the resource which can be used
|
||||
* as a resource reference within drawing instructions stream
|
||||
* Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading',
|
||||
* 'XObject', 'Font', 'Properties'
|
||||
*
|
||||
* @param string $type
|
||||
* @param Zend_Pdf_Resource $resource
|
||||
* @return string
|
||||
*/
|
||||
protected function _attachResource($type, Zend_Pdf_Resource $resource)
|
||||
{
|
||||
// Check, that resource is already attached to resource set.
|
||||
$resObject = $resource->getResource();
|
||||
foreach ($this->_resources[$type] as $resName => $collectedResObject) {
|
||||
if ($collectedResObject === $resObject) {
|
||||
return $resName;
|
||||
}
|
||||
}
|
||||
|
||||
$idCounter = 1;
|
||||
do {
|
||||
$newResName = $type[0] . $idCounter++;
|
||||
} while (isset($this->_resources[$type][$newResName]));
|
||||
|
||||
$this->_resources[$type][$newResName] = $resObject;
|
||||
|
||||
return $newResName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns dictionaries of used resources.
|
||||
*
|
||||
* Used for canvas implementations interoperability
|
||||
*
|
||||
* Structure of the returned array:
|
||||
* array(
|
||||
* <resTypeName> => array(
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* ...
|
||||
* ),
|
||||
* <resTypeName> => array(
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* ...
|
||||
* ),
|
||||
* ...
|
||||
* 'ProcSet' => array()
|
||||
* )
|
||||
*
|
||||
* where ProcSet array is a list of used procedure sets names (strings).
|
||||
* Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
|
||||
*
|
||||
* @internal
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
$this->_resources['ProcSet'] = array_keys($this->_procSet);
|
||||
return $this->_resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get drawing instructions stream
|
||||
*
|
||||
* It has to be returned as a PDF stream object to make it reusable.
|
||||
*
|
||||
* @internal
|
||||
* @returns Zend_Pdf_Resource_ContentStream
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
/** @todo implementation */
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of this page in points.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->_height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of this page in points.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->_width;
|
||||
}
|
||||
}
|
||||
1214
Zend/Pdf/Canvas/Abstract.php
Normal file
1214
Zend/Pdf/Canvas/Abstract.php
Normal file
File diff suppressed because it is too large
Load Diff
493
Zend/Pdf/Canvas/Interface.php
Normal file
493
Zend/Pdf/Canvas/Interface.php
Normal file
@@ -0,0 +1,493 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Canvas is an abstract rectangle drawing area which can be dropped into
|
||||
* page object at specified place.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Pdf_Canvas_Interface
|
||||
{
|
||||
/**
|
||||
* Returns dictionaries of used resources.
|
||||
*
|
||||
* Used for canvas implementations interoperability
|
||||
*
|
||||
* Structure of the returned array:
|
||||
* array(
|
||||
* <resTypeName> => array(
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* ...
|
||||
* ),
|
||||
* <resTypeName> => array(
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* <resName> => <Zend_Pdf_Resource object>,
|
||||
* ...
|
||||
* ),
|
||||
* ...
|
||||
* 'ProcSet' => array()
|
||||
* )
|
||||
*
|
||||
* where ProcSet array is a list of used procedure sets names (strings).
|
||||
* Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
|
||||
*
|
||||
* @internal
|
||||
* @return array
|
||||
*/
|
||||
public function getResources();
|
||||
|
||||
/**
|
||||
* Get drawing instructions stream
|
||||
*
|
||||
* It has to be returned as a PDF stream object to make it reusable.
|
||||
*
|
||||
* @internal
|
||||
* @returns Zend_Pdf_Resource_ContentStream
|
||||
*/
|
||||
public function getContents();
|
||||
|
||||
/**
|
||||
* Return canvas height.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getHeight();
|
||||
|
||||
/**
|
||||
* Return canvas width.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getWidth();
|
||||
|
||||
/**
|
||||
* Draw a canvas at the specified location
|
||||
*
|
||||
* If upper right corner is not specified then canvas heght and width
|
||||
* are used.
|
||||
*
|
||||
* @param Zend_Pdf_Canvas_Interface $canvas
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawCanvas(Zend_Pdf_Canvas_Interface $canvas, $x1, $y1, $x2 = null, $y2 = null);
|
||||
|
||||
/**
|
||||
* Set fill color.
|
||||
*
|
||||
* @param Zend_Pdf_Color $color
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setFillColor(Zend_Pdf_Color $color);
|
||||
|
||||
/**
|
||||
* Set line color.
|
||||
*
|
||||
* @param Zend_Pdf_Color $color
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setLineColor(Zend_Pdf_Color $color);
|
||||
|
||||
/**
|
||||
* Set line width.
|
||||
*
|
||||
* @param float $width
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setLineWidth($width);
|
||||
|
||||
/**
|
||||
* Set line dashing pattern
|
||||
*
|
||||
* Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
|
||||
* or Zend_Pdf_Page::LINE_DASHING_SOLID constant
|
||||
* Phase is shift from the beginning of line.
|
||||
*
|
||||
* @param mixed $pattern
|
||||
* @param array $phase
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setLineDashingPattern($pattern, $phase = 0);
|
||||
|
||||
/**
|
||||
* Set current font.
|
||||
*
|
||||
* @param Zend_Pdf_Resource_Font $font
|
||||
* @param float $fontSize
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setFont(Zend_Pdf_Resource_Font $font, $fontSize);
|
||||
|
||||
/**
|
||||
* Set the style to use for future drawing operations on this page
|
||||
*
|
||||
* @param Zend_Pdf_Style $style
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setStyle(Zend_Pdf_Style $style);
|
||||
|
||||
/**
|
||||
* Get current font.
|
||||
*
|
||||
* @return Zend_Pdf_Resource_Font $font
|
||||
*/
|
||||
public function getFont();
|
||||
|
||||
/**
|
||||
* Get current font size
|
||||
*
|
||||
* @return float $fontSize
|
||||
*/
|
||||
public function getFontSize();
|
||||
|
||||
/**
|
||||
* Return the style, applied to the page.
|
||||
*
|
||||
* @return Zend_Pdf_Style|null
|
||||
*/
|
||||
public function getStyle();
|
||||
|
||||
/**
|
||||
* Save the graphics state of this page.
|
||||
* This takes a snapshot of the currently applied style, position, clipping area and
|
||||
* any rotation/translation/scaling that has been applied.
|
||||
*
|
||||
* @throws Zend_Pdf_Exception - if a save is performed with an open path
|
||||
* @return Zend_Pdf_Page
|
||||
*/
|
||||
public function saveGS();
|
||||
|
||||
/**
|
||||
* Set the transparancy
|
||||
*
|
||||
* $alpha == 0 - transparent
|
||||
* $alpha == 1 - opaque
|
||||
*
|
||||
* Transparency modes, supported by PDF:
|
||||
* Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
|
||||
* SoftLight, Difference, Exclusion
|
||||
*
|
||||
* @param float $alpha
|
||||
* @param string $mode
|
||||
* @throws Zend_Pdf_Exception
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function setAlpha($alpha, $mode = 'Normal');
|
||||
|
||||
/**
|
||||
* Intersect current clipping area with a circle.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $radius
|
||||
* @param float $startAngle
|
||||
* @param float $endAngle
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null);
|
||||
|
||||
/**
|
||||
* Intersect current clipping area with a polygon.
|
||||
*
|
||||
* Method signatures:
|
||||
* drawEllipse($x1, $y1, $x2, $y2);
|
||||
* drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
|
||||
*
|
||||
* @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param float $startAngle
|
||||
* @param float $endAngle
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null);
|
||||
|
||||
/**
|
||||
* Intersect current clipping area with a polygon.
|
||||
*
|
||||
* @param array $x - array of float (the X co-ordinates of the vertices)
|
||||
* @param array $y - array of float (the Y co-ordinates of the vertices)
|
||||
* @param integer $fillMethod
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
|
||||
|
||||
/**
|
||||
* Intersect current clipping area with a rectangle.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function clipRectangle($x1, $y1, $x2, $y2);
|
||||
|
||||
/**
|
||||
* Draw a circle centered on x, y with a radius of radius.
|
||||
*
|
||||
* Method signatures:
|
||||
* drawCircle($x, $y, $radius);
|
||||
* drawCircle($x, $y, $radius, $fillType);
|
||||
* drawCircle($x, $y, $radius, $startAngle, $endAngle);
|
||||
* drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
|
||||
*
|
||||
*
|
||||
* It's not a really circle, because PDF supports only cubic Bezier curves.
|
||||
* But _very_ good approximation.
|
||||
* It differs from a real circle on a maximum 0.00026 radiuses
|
||||
* (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
|
||||
* At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param float $radius
|
||||
* @param mixed $param4
|
||||
* @param mixed $param5
|
||||
* @param mixed $param6
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null);
|
||||
|
||||
/**
|
||||
* Draw an ellipse inside the specified rectangle.
|
||||
*
|
||||
* Method signatures:
|
||||
* drawEllipse($x1, $y1, $x2, $y2);
|
||||
* drawEllipse($x1, $y1, $x2, $y2, $fillType);
|
||||
* drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
|
||||
* drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
|
||||
*
|
||||
* @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param mixed $param5
|
||||
* @param mixed $param6
|
||||
* @param mixed $param7
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null);
|
||||
|
||||
/**
|
||||
* Draw an image at the specified position on the page.
|
||||
*
|
||||
* @param Zend_Pdf_Image $image
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2);
|
||||
|
||||
/**
|
||||
* Draw a LayoutBox at the specified position on the page.
|
||||
*
|
||||
* @internal (not implemented now)
|
||||
*
|
||||
* @param Zend_Pdf_Element_LayoutBox $box
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawLayoutBox($box, $x, $y);
|
||||
|
||||
/**
|
||||
* Draw a line from x1,y1 to x2,y2.
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawLine($x1, $y1, $x2, $y2);
|
||||
|
||||
/**
|
||||
* Draw a polygon.
|
||||
*
|
||||
* If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
|
||||
* See detailed description of these methods in a PDF documentation
|
||||
* (section 4.4.2 Path painting Operators, Filling)
|
||||
*
|
||||
* @param array $x - array of float (the X co-ordinates of the vertices)
|
||||
* @param array $y - array of float (the Y co-ordinates of the vertices)
|
||||
* @param integer $fillType
|
||||
* @param integer $fillMethod
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawPolygon($x, $y,
|
||||
$fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
|
||||
$fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
|
||||
/**
|
||||
* Draw a rectangle.
|
||||
*
|
||||
* Fill types:
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param integer $fillType
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
|
||||
|
||||
/**
|
||||
* Draw a rounded rectangle.
|
||||
*
|
||||
* Fill types:
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
|
||||
* Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
|
||||
*
|
||||
* radius is an integer representing radius of the four corners, or an array
|
||||
* of four integers representing the radius starting at top left, going
|
||||
* clockwise
|
||||
*
|
||||
* @param float $x1
|
||||
* @param float $y1
|
||||
* @param float $x2
|
||||
* @param float $y2
|
||||
* @param integer|array $radius
|
||||
* @param integer $fillType
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
|
||||
$fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
|
||||
|
||||
/**
|
||||
* Draw a line of text at the specified position.
|
||||
*
|
||||
* @param string $text
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
* @param string $charEncoding (optional) Character encoding of source text.
|
||||
* Defaults to current locale.
|
||||
* @throws Zend_Pdf_Exception
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function drawText($text, $x, $y, $charEncoding = '');
|
||||
|
||||
/**
|
||||
* Close the path by drawing a straight line back to it's beginning.
|
||||
*
|
||||
* @internal (needs implementation)
|
||||
*
|
||||
* @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function pathClose();
|
||||
|
||||
/**
|
||||
* Continue the open path in a straight line to the specified position.
|
||||
*
|
||||
* @internal (needs implementation)
|
||||
*
|
||||
* @param float $x - the X co-ordinate to move to
|
||||
* @param float $y - the Y co-ordinate to move to
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function pathLine($x, $y);
|
||||
|
||||
/**
|
||||
* Start a new path at the specified position. If a path has already been started,
|
||||
* move the cursor without drawing a line.
|
||||
*
|
||||
* @internal (needs implementation)
|
||||
*
|
||||
* @param float $x - the X co-ordinate to move to
|
||||
* @param float $y - the Y co-ordinate to move to
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function pathMove($x, $y);
|
||||
|
||||
/**
|
||||
* Rotate the page.
|
||||
*
|
||||
* @param float $x - the X co-ordinate of rotation point
|
||||
* @param float $y - the Y co-ordinate of rotation point
|
||||
* @param float $angle - rotation angle
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function rotate($x, $y, $angle);
|
||||
|
||||
/**
|
||||
* Scale coordination system.
|
||||
*
|
||||
* @param float $xScale - X dimention scale factor
|
||||
* @param float $yScale - Y dimention scale factor
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function scale($xScale, $yScale);
|
||||
|
||||
/**
|
||||
* Translate coordination system.
|
||||
*
|
||||
* @param float $xShift - X coordinate shift
|
||||
* @param float $yShift - Y coordinate shift
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function translate($xShift, $yShift);
|
||||
|
||||
/**
|
||||
* Translate coordination system.
|
||||
*
|
||||
* @param float $x - the X co-ordinate of axis skew point
|
||||
* @param float $y - the Y co-ordinate of axis skew point
|
||||
* @param float $xAngle - X axis skew angle
|
||||
* @param float $yAngle - Y axis skew angle
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function skew($x, $y, $xAngle, $yAngle);
|
||||
|
||||
/**
|
||||
* Writes the raw data to the page's content stream.
|
||||
*
|
||||
* Be sure to consult the PDF reference to ensure your syntax is correct. No
|
||||
* attempt is made to ensure the validity of the stream data.
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $procSet (optional) Name of ProcSet to add.
|
||||
* @return Zend_Pdf_Canvas_Interface
|
||||
*/
|
||||
public function rawWrite($data, $procSet = null);
|
||||
}
|
||||
336
Zend/Pdf/Cmap.php
Normal file
336
Zend/Pdf/Cmap.php
Normal file
@@ -0,0 +1,336 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cmap.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Abstract helper class for {@link Zend_Pdf_Resource_Font} which manages font
|
||||
* character maps.
|
||||
*
|
||||
* Defines the public interface for concrete subclasses which are responsible
|
||||
* for mapping Unicode characters to the font's glyph numbers. Also provides
|
||||
* shared utility methods.
|
||||
*
|
||||
* Cmap objects should ordinarily be obtained through the factory method
|
||||
* {@link cmapWithTypeData()}.
|
||||
*
|
||||
* The supported character map types are those found in the OpenType spec. For
|
||||
* additional detail on the internal binary format of these tables, see:
|
||||
* <ul>
|
||||
* <li>{@link http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6cmap.html}
|
||||
* <li>{@link http://www.microsoft.com/OpenType/OTSpec/cmap.htm}
|
||||
* <li>{@link http://partners.adobe.com/public/developer/opentype/index_cmap.html}
|
||||
* </ul>
|
||||
*
|
||||
* @todo Write code for Zend_Pdf_FontCmap_HighByteMapping class.
|
||||
* @todo Write code for Zend_Pdf_FontCmap_MixedCoverage class.
|
||||
* @todo Write code for Zend_Pdf_FontCmap_TrimmedArray class.
|
||||
* @todo Write code for Zend_Pdf_FontCmap_SegmentedCoverage class.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Cmap
|
||||
{
|
||||
/**** Class Constants ****/
|
||||
|
||||
|
||||
/* Cmap Table Types */
|
||||
|
||||
/**
|
||||
* Byte Encoding character map table type.
|
||||
*/
|
||||
const TYPE_BYTE_ENCODING = 0x00;
|
||||
|
||||
/**
|
||||
* High Byte Mapping character map table type.
|
||||
*/
|
||||
const TYPE_HIGH_BYTE_MAPPING = 0x02;
|
||||
|
||||
/**
|
||||
* Segment Value to Delta Mapping character map table type.
|
||||
*/
|
||||
const TYPE_SEGMENT_TO_DELTA = 0x04;
|
||||
|
||||
/**
|
||||
* Trimmed Table character map table type.
|
||||
*/
|
||||
const TYPE_TRIMMED_TABLE = 0x06;
|
||||
|
||||
/**
|
||||
* Mixed Coverage character map table type.
|
||||
*/
|
||||
const TYPE_MIXED_COVERAGE = 0x08;
|
||||
|
||||
/**
|
||||
* Trimmed Array character map table type.
|
||||
*/
|
||||
const TYPE_TRIMMED_ARRAY = 0x0a;
|
||||
|
||||
/**
|
||||
* Segmented Coverage character map table type.
|
||||
*/
|
||||
const TYPE_SEGMENTED_COVERAGE = 0x0c;
|
||||
|
||||
/**
|
||||
* Static Byte Encoding character map table type. Variant of
|
||||
* {@link TYPE_BYTEENCODING}.
|
||||
*/
|
||||
const TYPE_BYTE_ENCODING_STATIC = 0xf1;
|
||||
|
||||
/**
|
||||
* Unknown character map table type.
|
||||
*/
|
||||
const TYPE_UNKNOWN = 0xff;
|
||||
|
||||
|
||||
/* Special Glyph Names */
|
||||
|
||||
/**
|
||||
* Glyph representing missing characters.
|
||||
*/
|
||||
const MISSING_CHARACTER_GLYPH = 0x00;
|
||||
|
||||
|
||||
|
||||
/**** Public Interface ****/
|
||||
|
||||
|
||||
/* Factory Methods */
|
||||
|
||||
/**
|
||||
* Instantiates the appropriate concrete subclass based on the type of cmap
|
||||
* table and returns the instance.
|
||||
*
|
||||
* The cmap type must be one of the following values:
|
||||
* <ul>
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_BYTE_ENCODING}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_BYTE_ENCODING_STATIC}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_HIGH_BYTE_MAPPING}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_SEGMENT_TO_DELTA}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_TRIMMED_TABLE}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_MIXED_COVERAGE}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_TRIMMED_ARRAY}
|
||||
* <li>{@link Zend_Pdf_Cmap::TYPE_SEGMENTED_COVERAGE}
|
||||
* </ul>
|
||||
*
|
||||
* Throws an exception if the table type is invalid or the cmap table data
|
||||
* cannot be validated.
|
||||
*
|
||||
* @param integer $cmapType Type of cmap.
|
||||
* @param mixed $cmapData Cmap table data. Usually a string or array.
|
||||
* @return Zend_Pdf_Cmap
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function cmapWithTypeData($cmapType, $cmapData)
|
||||
{
|
||||
switch ($cmapType) {
|
||||
case Zend_Pdf_Cmap::TYPE_BYTE_ENCODING:
|
||||
require_once 'Zend/Pdf/Cmap/ByteEncoding.php';
|
||||
return new Zend_Pdf_Cmap_ByteEncoding($cmapData);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_BYTE_ENCODING_STATIC:
|
||||
require_once 'Zend/Pdf/Cmap/ByteEncoding/Static.php';
|
||||
return new Zend_Pdf_Cmap_ByteEncoding_Static($cmapData);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_HIGH_BYTE_MAPPING:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('High byte mapping cmap currently unsupported',
|
||||
Zend_Pdf_Exception::CMAP_TYPE_UNSUPPORTED);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_SEGMENT_TO_DELTA:
|
||||
require_once 'Zend/Pdf/Cmap/SegmentToDelta.php';
|
||||
return new Zend_Pdf_Cmap_SegmentToDelta($cmapData);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_TRIMMED_TABLE:
|
||||
require_once 'Zend/Pdf/Cmap/TrimmedTable.php';
|
||||
return new Zend_Pdf_Cmap_TrimmedTable($cmapData);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_MIXED_COVERAGE:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Mixed coverage cmap currently unsupported',
|
||||
Zend_Pdf_Exception::CMAP_TYPE_UNSUPPORTED);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_TRIMMED_ARRAY:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Trimmed array cmap currently unsupported',
|
||||
Zend_Pdf_Exception::CMAP_TYPE_UNSUPPORTED);
|
||||
|
||||
case Zend_Pdf_Cmap::TYPE_SEGMENTED_COVERAGE:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Segmented coverage cmap currently unsupported',
|
||||
Zend_Pdf_Exception::CMAP_TYPE_UNSUPPORTED);
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Unknown cmap type: $cmapType",
|
||||
Zend_Pdf_Exception::CMAP_UNKNOWN_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Abstract Methods */
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* Parses the raw binary table data. Throws an exception if the table is
|
||||
* malformed.
|
||||
*
|
||||
* @param string $cmapData Raw binary cmap table data.
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
abstract public function __construct($cmapData);
|
||||
|
||||
/**
|
||||
* Returns an array of glyph numbers corresponding to the Unicode characters.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumberForCharacter()}.
|
||||
*
|
||||
* @param array $characterCodes Array of Unicode character codes (code points).
|
||||
* @return array Array of glyph numbers.
|
||||
*/
|
||||
abstract public function glyphNumbersForCharacters($characterCodes);
|
||||
|
||||
/**
|
||||
* Returns the glyph number corresponding to the Unicode character.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumbersForCharacters()} which is optimized for bulk
|
||||
* operations.
|
||||
*
|
||||
* @param integer $characterCode Unicode character code (code point).
|
||||
* @return integer Glyph number.
|
||||
*/
|
||||
abstract public function glyphNumberForCharacter($characterCode);
|
||||
|
||||
/**
|
||||
* Returns an array containing the Unicode characters that have entries in
|
||||
* this character map.
|
||||
*
|
||||
* @return array Unicode character codes.
|
||||
*/
|
||||
abstract public function getCoveredCharacters();
|
||||
|
||||
/**
|
||||
* Returns an array containing the glyphs numbers that have entries in this character map.
|
||||
* Keys are Unicode character codes (integers)
|
||||
*
|
||||
* This functionality is partially covered by glyphNumbersForCharacters(getCoveredCharacters())
|
||||
* call, but this method do it in more effective way (prepare complete list instead of searching
|
||||
* glyph for each character code).
|
||||
*
|
||||
* @internal
|
||||
* @return array Array representing <Unicode character code> => <glyph number> pairs.
|
||||
*/
|
||||
abstract public function getCoveredCharactersGlyphs();
|
||||
|
||||
|
||||
/**** Internal Methods ****/
|
||||
|
||||
|
||||
/* Internal Utility Methods */
|
||||
|
||||
/**
|
||||
* Extracts a signed 2-byte integer from a string.
|
||||
*
|
||||
* Integers are always big-endian. Throws an exception if the index is out
|
||||
* of range.
|
||||
*
|
||||
* @param string &$data
|
||||
* @param integer $index Position in string of integer.
|
||||
* @return integer
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
protected function _extractInt2(&$data, $index)
|
||||
{
|
||||
if (($index < 0) | (($index + 1) > strlen($data))) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Index out of range: $index",
|
||||
Zend_Pdf_Exception::INDEX_OUT_OF_RANGE);
|
||||
}
|
||||
$number = ord($data[$index]);
|
||||
if (($number & 0x80) == 0x80) { // negative
|
||||
$number = ~((((~ $number) & 0xff) << 8) | ((~ ord($data[++$index])) & 0xff));
|
||||
} else {
|
||||
$number = ($number << 8) | ord($data[++$index]);
|
||||
}
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts an unsigned 2-byte integer from a string.
|
||||
*
|
||||
* Integers are always big-endian. Throws an exception if the index is out
|
||||
* of range.
|
||||
*
|
||||
* @param string &$data
|
||||
* @param integer $index Position in string of integer.
|
||||
* @return integer
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
protected function _extractUInt2(&$data, $index)
|
||||
{
|
||||
if (($index < 0) | (($index + 1) > strlen($data))) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Index out of range: $index",
|
||||
Zend_Pdf_Exception::INDEX_OUT_OF_RANGE);
|
||||
}
|
||||
$number = (ord($data[$index]) << 8) | ord($data[++$index]);
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts an unsigned 4-byte integer from a string.
|
||||
*
|
||||
* Integers are always big-endian. Throws an exception if the index is out
|
||||
* of range.
|
||||
*
|
||||
* NOTE: If you ask for a 4-byte unsigned integer on a 32-bit machine, the
|
||||
* resulting value WILL BE SIGNED because PHP uses signed integers internally
|
||||
* for everything. To guarantee portability, be sure to use bitwise or
|
||||
* similar operators on large integers!
|
||||
*
|
||||
* @param string &$data
|
||||
* @param integer $index Position in string of integer.
|
||||
* @return integer
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
protected function _extractUInt4(&$data, $index)
|
||||
{
|
||||
if (($index < 0) | (($index + 3) > strlen($data))) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Index out of range: $index",
|
||||
Zend_Pdf_Exception::INDEX_OUT_OF_RANGE);
|
||||
}
|
||||
$number = (ord($data[$index]) << 24) | (ord($data[++$index]) << 16) |
|
||||
(ord($data[++$index]) << 8) | ord($data[++$index]);
|
||||
return $number;
|
||||
}
|
||||
|
||||
}
|
||||
447
Zend/Pdf/Cmap/ByteEncoding.php
Normal file
447
Zend/Pdf/Cmap/ByteEncoding.php
Normal file
@@ -0,0 +1,447 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ByteEncoding.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Cmap */
|
||||
require_once 'Zend/Pdf/Cmap.php';
|
||||
|
||||
|
||||
/**
|
||||
* Implements the "byte encoding" character map (type 0).
|
||||
*
|
||||
* This is the (legacy) Apple standard encoding mechanism and provides coverage
|
||||
* for characters in the Mac Roman character set only. Consequently, this cmap
|
||||
* type should be used only as a last resort.
|
||||
*
|
||||
* The mapping from Mac Roman to Unicode can be found at
|
||||
* {@link http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT}.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Cmap_ByteEncoding extends Zend_Pdf_Cmap
|
||||
{
|
||||
/**** Instance Variables ****/
|
||||
|
||||
|
||||
/**
|
||||
* Glyph index array. Stores the actual glyph numbers. The array keys are
|
||||
* the translated Unicode code points.
|
||||
* @var array
|
||||
*/
|
||||
protected $_glyphIndexArray = array();
|
||||
|
||||
|
||||
|
||||
/**** Public Interface ****/
|
||||
|
||||
|
||||
/* Concrete Class Implementation */
|
||||
|
||||
/**
|
||||
* Returns an array of glyph numbers corresponding to the Unicode characters.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumberForCharacter()}.
|
||||
*
|
||||
* @param array $characterCodes Array of Unicode character codes (code points).
|
||||
* @return array Array of glyph numbers.
|
||||
*/
|
||||
public function glyphNumbersForCharacters($characterCodes)
|
||||
{
|
||||
$glyphNumbers = array();
|
||||
foreach ($characterCodes as $key => $characterCode) {
|
||||
|
||||
if (! isset($this->_glyphIndexArray[$characterCode])) {
|
||||
$glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
continue;
|
||||
}
|
||||
|
||||
$glyphNumbers[$key] = $this->_glyphIndexArray[$characterCode];
|
||||
|
||||
}
|
||||
return $glyphNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the glyph number corresponding to the Unicode character.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumbersForCharacters()} which is optimized for bulk
|
||||
* operations.
|
||||
*
|
||||
* @param integer $characterCode Unicode character code (code point).
|
||||
* @return integer Glyph number.
|
||||
*/
|
||||
public function glyphNumberForCharacter($characterCode)
|
||||
{
|
||||
if (! isset($this->_glyphIndexArray[$characterCode])) {
|
||||
return Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
}
|
||||
return $this->_glyphIndexArray[$characterCode];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the Unicode characters that have entries in
|
||||
* this character map.
|
||||
*
|
||||
* @return array Unicode character codes.
|
||||
*/
|
||||
public function getCoveredCharacters()
|
||||
{
|
||||
return array_keys($this->_glyphIndexArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the glyphs numbers that have entries in this character map.
|
||||
* Keys are Unicode character codes (integers)
|
||||
*
|
||||
* This functionality is partially covered by glyphNumbersForCharacters(getCoveredCharacters())
|
||||
* call, but this method do it in more effective way (prepare complete list instead of searching
|
||||
* glyph for each character code).
|
||||
*
|
||||
* @internal
|
||||
* @return array Array representing <Unicode character code> => <glyph number> pairs.
|
||||
*/
|
||||
public function getCoveredCharactersGlyphs()
|
||||
{
|
||||
return $this->_glyphIndexArray;
|
||||
}
|
||||
|
||||
|
||||
/* Object Lifecycle */
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* Parses the raw binary table data. Throws an exception if the table is
|
||||
* malformed.
|
||||
*
|
||||
* @param string $cmapData Raw binary cmap table data.
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($cmapData)
|
||||
{
|
||||
/* Sanity check: This table must be exactly 262 bytes long.
|
||||
*/
|
||||
$actualLength = strlen($cmapData);
|
||||
if ($actualLength != 262) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Insufficient table data',
|
||||
Zend_Pdf_Exception::CMAP_TABLE_DATA_TOO_SMALL);
|
||||
}
|
||||
|
||||
/* Sanity check: Make sure this is right data for this table type.
|
||||
*/
|
||||
$type = $this->_extractUInt2($cmapData, 0);
|
||||
if ($type != Zend_Pdf_Cmap::TYPE_BYTE_ENCODING) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Wrong cmap table type',
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_TYPE);
|
||||
}
|
||||
|
||||
$length = $this->_extractUInt2($cmapData, 2);
|
||||
if ($length != $actualLength) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Table length ($length) does not match actual length ($actualLength)",
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_LENGTH);
|
||||
}
|
||||
|
||||
/* Mapping tables should be language-independent. The font may not work
|
||||
* as expected if they are not. Unfortunately, many font files in the
|
||||
* wild incorrectly record a language ID in this field, so we can't
|
||||
* call this a failure.
|
||||
*/
|
||||
$language = $this->_extractUInt2($cmapData, 4);
|
||||
if ($language != 0) {
|
||||
// Record a warning here somehow?
|
||||
}
|
||||
|
||||
/* The mapping between the Mac Roman and Unicode characters is static.
|
||||
* For simplicity, just put all 256 glyph indices into one array keyed
|
||||
* off the corresponding Unicode character.
|
||||
*/
|
||||
$i = 6;
|
||||
$this->_glyphIndexArray[0x00] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x01] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x03] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x04] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x05] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x06] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x07] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x08] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x09] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x10] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x11] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x12] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x13] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x14] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x15] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x16] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x17] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x18] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x19] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x1f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x20] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x21] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x22] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x23] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x24] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x25] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x26] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x27] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x28] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x29] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x30] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x31] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x32] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x33] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x34] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x35] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x36] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x37] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x38] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x39] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x3f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x40] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x41] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x42] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x43] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x44] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x45] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x46] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x47] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x48] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x49] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x4f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x50] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x51] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x52] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x53] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x54] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x55] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x56] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x57] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x58] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x59] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x5f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x60] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x61] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x62] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x63] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x64] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x65] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x66] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x67] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x68] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x69] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x6f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x70] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x71] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x72] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x73] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x74] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x75] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x76] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x77] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x78] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x79] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x7f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc4] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc7] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xdc] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe0] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe2] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe4] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe3] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe7] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xea] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xeb] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xed] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xec] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xee] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xef] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf3] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf2] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf4] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xfa] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xfb] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xfc] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2020] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb0] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa2] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa3] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa7] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2022] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xdf] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xae] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2122] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb4] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2260] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x221e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2264] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2265] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2202] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2211] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x220f] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x03c0] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x222b] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xaa] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xba] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x03a9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xe6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xbf] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xac] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x221a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0192] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2248] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2206] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xab] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xbb] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2026] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xa0] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc0] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc3] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd5] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0152] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0153] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2013] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2014] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x201c] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x201d] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2018] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2019] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf7] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x25ca] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xff] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0178] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2044] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x20ac] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2039] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x203a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xfb01] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xfb02] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2021] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb7] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x201a] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x201e] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x2030] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc2] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xca] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc1] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xcb] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xc8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xcd] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xce] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xcf] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xcc] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd3] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd4] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xf8ff] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd2] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xda] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xdb] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xd9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x0131] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02c6] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02dc] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xaf] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02d8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02d9] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02da] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0xb8] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02dd] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02db] = ord($cmapData[$i++]);
|
||||
$this->_glyphIndexArray[0x02c7] = ord($cmapData[$i]);
|
||||
}
|
||||
|
||||
}
|
||||
62
Zend/Pdf/Cmap/ByteEncoding/Static.php
Normal file
62
Zend/Pdf/Cmap/ByteEncoding/Static.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Static.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Cmap_ByteEncoding */
|
||||
require_once 'Zend/Pdf/Cmap/ByteEncoding.php';
|
||||
|
||||
|
||||
/**
|
||||
* Custom cmap type used for the Adobe Standard 14 PDF fonts.
|
||||
*
|
||||
* Just like {@link Zend_Pdf_Cmap_ByteEncoding} except that the constructor
|
||||
* takes a predefined array of glyph numbers and can cover any Unicode character.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Cmap_ByteEncoding_Static extends Zend_Pdf_Cmap_ByteEncoding
|
||||
{
|
||||
/**** Public Interface ****/
|
||||
|
||||
|
||||
/* Object Lifecycle */
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param array $cmapData Array whose keys are Unicode character codes and
|
||||
* values are glyph numbers.
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($cmapData)
|
||||
{
|
||||
if (! is_array($cmapData)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Constructor parameter must be an array',
|
||||
Zend_Pdf_Exception::BAD_PARAMETER_TYPE);
|
||||
}
|
||||
$this->_glyphIndexArray = $cmapData;
|
||||
}
|
||||
|
||||
}
|
||||
407
Zend/Pdf/Cmap/SegmentToDelta.php
Normal file
407
Zend/Pdf/Cmap/SegmentToDelta.php
Normal file
@@ -0,0 +1,407 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: SegmentToDelta.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Cmap */
|
||||
require_once 'Zend/Pdf/Cmap.php';
|
||||
|
||||
|
||||
/**
|
||||
* Implements the "segment mapping to delta values" character map (type 4).
|
||||
*
|
||||
* This is the Microsoft standard mapping table type for OpenType fonts. It
|
||||
* provides the ability to cover multiple contiguous ranges of the Unicode
|
||||
* character set, with the exception of Unicode Surrogates (U+D800 - U+DFFF).
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Cmap_SegmentToDelta extends Zend_Pdf_Cmap
|
||||
{
|
||||
/**** Instance Variables ****/
|
||||
|
||||
|
||||
/**
|
||||
* The number of segments in the table.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_segmentCount = 0;
|
||||
|
||||
/**
|
||||
* The size of the binary search range for segments.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_searchRange = 0;
|
||||
|
||||
/**
|
||||
* The number of binary search steps required to cover the entire search
|
||||
* range.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_searchIterations = 0;
|
||||
|
||||
/**
|
||||
* Array of ending character codes for each segment.
|
||||
* @var array
|
||||
*/
|
||||
protected $_segmentTableEndCodes = array();
|
||||
|
||||
/**
|
||||
* The ending character code for the segment at the end of the low search
|
||||
* range.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_searchRangeEndCode = 0;
|
||||
|
||||
/**
|
||||
* Array of starting character codes for each segment.
|
||||
* @var array
|
||||
*/
|
||||
protected $_segmentTableStartCodes = array();
|
||||
|
||||
/**
|
||||
* Array of character code to glyph delta values for each segment.
|
||||
* @var array
|
||||
*/
|
||||
protected $_segmentTableIdDeltas = array();
|
||||
|
||||
/**
|
||||
* Array of offsets into the glyph index array for each segment.
|
||||
* @var array
|
||||
*/
|
||||
protected $_segmentTableIdRangeOffsets = array();
|
||||
|
||||
/**
|
||||
* Glyph index array. Stores glyph numbers, used with range offset.
|
||||
* @var array
|
||||
*/
|
||||
protected $_glyphIndexArray = array();
|
||||
|
||||
|
||||
|
||||
/**** Public Interface ****/
|
||||
|
||||
|
||||
/* Concrete Class Implementation */
|
||||
|
||||
/**
|
||||
* Returns an array of glyph numbers corresponding to the Unicode characters.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumberForCharacter()}.
|
||||
*
|
||||
* @param array $characterCodes Array of Unicode character codes (code points).
|
||||
* @return array Array of glyph numbers.
|
||||
*/
|
||||
public function glyphNumbersForCharacters($characterCodes)
|
||||
{
|
||||
$glyphNumbers = array();
|
||||
foreach ($characterCodes as $key => $characterCode) {
|
||||
|
||||
/* These tables only cover the 16-bit character range.
|
||||
*/
|
||||
if ($characterCode > 0xffff) {
|
||||
$glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Determine where to start the binary search. The segments are
|
||||
* ordered from lowest-to-highest. We are looking for the first
|
||||
* segment whose end code is greater than or equal to our character
|
||||
* code.
|
||||
*
|
||||
* If the end code at the top of the search range is larger, then
|
||||
* our target is probably below it.
|
||||
*
|
||||
* If it is smaller, our target is probably above it, so move the
|
||||
* search range to the end of the segment list.
|
||||
*/
|
||||
if ($this->_searchRangeEndCode >= $characterCode) {
|
||||
$searchIndex = $this->_searchRange;
|
||||
} else {
|
||||
$searchIndex = $this->_segmentCount;
|
||||
}
|
||||
|
||||
/* Now do a binary search to find the first segment whose end code
|
||||
* is greater or equal to our character code. No matter the number
|
||||
* of segments (there may be hundreds in a large font), we will only
|
||||
* need to perform $this->_searchIterations.
|
||||
*/
|
||||
for ($i = 1; $i <= $this->_searchIterations; $i++) {
|
||||
if ($this->_segmentTableEndCodes[$searchIndex] >= $characterCode) {
|
||||
$subtableIndex = $searchIndex;
|
||||
$searchIndex -= $this->_searchRange >> $i;
|
||||
} else {
|
||||
$searchIndex += $this->_searchRange >> $i;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the segment's start code is greater than our character code,
|
||||
* that character is not represented in this font. Move on.
|
||||
*/
|
||||
if ($this->_segmentTableStartCodes[$subtableIndex] > $characterCode) {
|
||||
$glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->_segmentTableIdRangeOffsets[$subtableIndex] == 0) {
|
||||
/* This segment uses a simple mapping from character code to
|
||||
* glyph number.
|
||||
*/
|
||||
$glyphNumbers[$key] = ($characterCode + $this->_segmentTableIdDeltas[$subtableIndex]) % 65536;
|
||||
|
||||
} else {
|
||||
/* This segment relies on the glyph index array to determine the
|
||||
* glyph number. The calculation below determines the correct
|
||||
* index into that array. It's a little odd because the range
|
||||
* offset in the font file is designed to quickly provide an
|
||||
* address of the index in the raw binary data instead of the
|
||||
* index itself. Since we've parsed the data into arrays, we
|
||||
* must process it a bit differently.
|
||||
*/
|
||||
$glyphIndex = ($characterCode - $this->_segmentTableStartCodes[$subtableIndex] +
|
||||
$this->_segmentTableIdRangeOffsets[$subtableIndex] - $this->_segmentCount +
|
||||
$subtableIndex - 1);
|
||||
$glyphNumbers[$key] = $this->_glyphIndexArray[$glyphIndex];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $glyphNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the glyph number corresponding to the Unicode character.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumbersForCharacters()} which is optimized for bulk
|
||||
* operations.
|
||||
*
|
||||
* @param integer $characterCode Unicode character code (code point).
|
||||
* @return integer Glyph number.
|
||||
*/
|
||||
public function glyphNumberForCharacter($characterCode)
|
||||
{
|
||||
/* This code is pretty much a copy of glyphNumbersForCharacters().
|
||||
* See that method for inline documentation.
|
||||
*/
|
||||
|
||||
if ($characterCode > 0xffff) {
|
||||
return Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
}
|
||||
|
||||
if ($this->_searchRangeEndCode >= $characterCode) {
|
||||
$searchIndex = $this->_searchRange;
|
||||
} else {
|
||||
$searchIndex = $this->_segmentCount;
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $this->_searchIterations; $i++) {
|
||||
if ($this->_segmentTableEndCodes[$searchIndex] >= $characterCode) {
|
||||
$subtableIndex = $searchIndex;
|
||||
$searchIndex -= $this->_searchRange >> $i;
|
||||
} else {
|
||||
$searchIndex += $this->_searchRange >> $i;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_segmentTableStartCodes[$subtableIndex] > $characterCode) {
|
||||
return Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
}
|
||||
|
||||
if ($this->_segmentTableIdRangeOffsets[$subtableIndex] == 0) {
|
||||
$glyphNumber = ($characterCode + $this->_segmentTableIdDeltas[$subtableIndex]) % 65536;
|
||||
} else {
|
||||
$glyphIndex = ($characterCode - $this->_segmentTableStartCodes[$subtableIndex] +
|
||||
$this->_segmentTableIdRangeOffsets[$subtableIndex] - $this->_segmentCount +
|
||||
$subtableIndex - 1);
|
||||
$glyphNumber = $this->_glyphIndexArray[$glyphIndex];
|
||||
}
|
||||
return $glyphNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the Unicode characters that have entries in
|
||||
* this character map.
|
||||
*
|
||||
* @return array Unicode character codes.
|
||||
*/
|
||||
public function getCoveredCharacters()
|
||||
{
|
||||
$characterCodes = array();
|
||||
for ($i = 1; $i <= $this->_segmentCount; $i++) {
|
||||
for ($code = $this->_segmentTableStartCodes[$i]; $code <= $this->_segmentTableEndCodes[$i]; $code++) {
|
||||
$characterCodes[] = $code;
|
||||
}
|
||||
}
|
||||
return $characterCodes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the glyphs numbers that have entries in this character map.
|
||||
* Keys are Unicode character codes (integers)
|
||||
*
|
||||
* This functionality is partially covered by glyphNumbersForCharacters(getCoveredCharacters())
|
||||
* call, but this method do it in more effective way (prepare complete list instead of searching
|
||||
* glyph for each character code).
|
||||
*
|
||||
* @internal
|
||||
* @return array Array representing <Unicode character code> => <glyph number> pairs.
|
||||
*/
|
||||
public function getCoveredCharactersGlyphs()
|
||||
{
|
||||
$glyphNumbers = array();
|
||||
|
||||
for ($segmentNum = 1; $segmentNum <= $this->_segmentCount; $segmentNum++) {
|
||||
if ($this->_segmentTableIdRangeOffsets[$segmentNum] == 0) {
|
||||
$delta = $this->_segmentTableIdDeltas[$segmentNum];
|
||||
|
||||
for ($code = $this->_segmentTableStartCodes[$segmentNum];
|
||||
$code <= $this->_segmentTableEndCodes[$segmentNum];
|
||||
$code++) {
|
||||
$glyphNumbers[$code] = ($code + $delta) % 65536;
|
||||
}
|
||||
} else {
|
||||
$code = $this->_segmentTableStartCodes[$segmentNum];
|
||||
$glyphIndex = $this->_segmentTableIdRangeOffsets[$segmentNum] - ($this->_segmentCount - $segmentNum) - 1;
|
||||
|
||||
while ($code <= $this->_segmentTableEndCodes[$segmentNum]) {
|
||||
$glyphNumbers[$code] = $this->_glyphIndexArray[$glyphIndex];
|
||||
|
||||
$code++;
|
||||
$glyphIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $glyphNumbers;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Object Lifecycle */
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* Parses the raw binary table data. Throws an exception if the table is
|
||||
* malformed.
|
||||
*
|
||||
* @param string $cmapData Raw binary cmap table data.
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($cmapData)
|
||||
{
|
||||
/* Sanity check: The table should be at least 23 bytes in size.
|
||||
*/
|
||||
$actualLength = strlen($cmapData);
|
||||
if ($actualLength < 23) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Insufficient table data',
|
||||
Zend_Pdf_Exception::CMAP_TABLE_DATA_TOO_SMALL);
|
||||
}
|
||||
|
||||
/* Sanity check: Make sure this is right data for this table type.
|
||||
*/
|
||||
$type = $this->_extractUInt2($cmapData, 0);
|
||||
if ($type != Zend_Pdf_Cmap::TYPE_SEGMENT_TO_DELTA) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Wrong cmap table type',
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_TYPE);
|
||||
}
|
||||
|
||||
$length = $this->_extractUInt2($cmapData, 2);
|
||||
if ($length != $actualLength) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Table length ($length) does not match actual length ($actualLength)",
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_LENGTH);
|
||||
}
|
||||
|
||||
/* Mapping tables should be language-independent. The font may not work
|
||||
* as expected if they are not. Unfortunately, many font files in the
|
||||
* wild incorrectly record a language ID in this field, so we can't
|
||||
* call this a failure.
|
||||
*/
|
||||
$language = $this->_extractUInt2($cmapData, 4);
|
||||
if ($language != 0) {
|
||||
// Record a warning here somehow?
|
||||
}
|
||||
|
||||
/* These two values are stored premultiplied by two which is convienent
|
||||
* when using the binary data directly, but we're parsing it out to
|
||||
* native PHP data types, so divide by two.
|
||||
*/
|
||||
$this->_segmentCount = $this->_extractUInt2($cmapData, 6) >> 1;
|
||||
$this->_searchRange = $this->_extractUInt2($cmapData, 8) >> 1;
|
||||
|
||||
$this->_searchIterations = $this->_extractUInt2($cmapData, 10) + 1;
|
||||
|
||||
$offset = 14;
|
||||
for ($i = 1; $i <= $this->_segmentCount; $i++, $offset += 2) {
|
||||
$this->_segmentTableEndCodes[$i] = $this->_extractUInt2($cmapData, $offset);
|
||||
}
|
||||
|
||||
$this->_searchRangeEndCode = $this->_segmentTableEndCodes[$this->_searchRange];
|
||||
|
||||
$offset += 2; // reserved bytes
|
||||
|
||||
for ($i = 1; $i <= $this->_segmentCount; $i++, $offset += 2) {
|
||||
$this->_segmentTableStartCodes[$i] = $this->_extractUInt2($cmapData, $offset);
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $this->_segmentCount; $i++, $offset += 2) {
|
||||
$this->_segmentTableIdDeltas[$i] = $this->_extractInt2($cmapData, $offset); // signed
|
||||
}
|
||||
|
||||
/* The range offset helps determine the index into the glyph index array.
|
||||
* Like the segment count and search range above, it's stored as a byte
|
||||
* multiple in the font, so divide by two as we extract the values.
|
||||
*/
|
||||
for ($i = 1; $i <= $this->_segmentCount; $i++, $offset += 2) {
|
||||
$this->_segmentTableIdRangeOffsets[$i] = $this->_extractUInt2($cmapData, $offset) >> 1;
|
||||
}
|
||||
|
||||
/* The size of the glyph index array varies by font and depends on the
|
||||
* extent of the usage of range offsets versus deltas. Some fonts may
|
||||
* not have any entries in this array.
|
||||
*/
|
||||
for (; $offset < $length; $offset += 2) {
|
||||
$this->_glyphIndexArray[] = $this->_extractUInt2($cmapData, $offset);
|
||||
}
|
||||
|
||||
/* Sanity check: After reading all of the data, we should be at the end
|
||||
* of the table.
|
||||
*/
|
||||
if ($offset != $length) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Ending offset ($offset) does not match length ($length)",
|
||||
Zend_Pdf_Exception::CMAP_FINAL_OFFSET_NOT_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
231
Zend/Pdf/Cmap/TrimmedTable.php
Normal file
231
Zend/Pdf/Cmap/TrimmedTable.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: TrimmedTable.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Cmap */
|
||||
require_once 'Zend/Pdf/Cmap.php';
|
||||
|
||||
|
||||
/**
|
||||
* Implements the "trimmed table mapping" character map (type 6).
|
||||
*
|
||||
* This table type is preferred over the {@link Zend_Pdf_Cmap_SegmentToDelta}
|
||||
* table when the Unicode characters covered by the font fall into a single
|
||||
* contiguous range.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Fonts
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Cmap_TrimmedTable extends Zend_Pdf_Cmap
|
||||
{
|
||||
/**** Instance Variables ****/
|
||||
|
||||
|
||||
/**
|
||||
* The starting character code covered by this table.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_startCode = 0;
|
||||
|
||||
/**
|
||||
* The ending character code covered by this table.
|
||||
* @var integer
|
||||
*/
|
||||
protected $_endCode = 0;
|
||||
|
||||
/**
|
||||
* Glyph index array. Stores the actual glyph numbers.
|
||||
* @var array
|
||||
*/
|
||||
protected $_glyphIndexArray = array();
|
||||
|
||||
|
||||
|
||||
/**** Public Interface ****/
|
||||
|
||||
|
||||
/* Concrete Class Implementation */
|
||||
|
||||
/**
|
||||
* Returns an array of glyph numbers corresponding to the Unicode characters.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumberForCharacter()}.
|
||||
*
|
||||
* @param array $characterCodes Array of Unicode character codes (code points).
|
||||
* @return array Array of glyph numbers.
|
||||
*/
|
||||
public function glyphNumbersForCharacters($characterCodes)
|
||||
{
|
||||
$glyphNumbers = array();
|
||||
foreach ($characterCodes as $key => $characterCode) {
|
||||
|
||||
if (($characterCode < $this->_startCode) || ($characterCode > $this->_endCode)) {
|
||||
$glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
continue;
|
||||
}
|
||||
|
||||
$glyphIndex = $characterCode - $this->_startCode;
|
||||
$glyphNumbers[$key] = $this->_glyphIndexArray[$glyphIndex];
|
||||
|
||||
}
|
||||
return $glyphNumbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the glyph number corresponding to the Unicode character.
|
||||
*
|
||||
* If a particular character doesn't exist in this font, the special 'missing
|
||||
* character glyph' will be substituted.
|
||||
*
|
||||
* See also {@link glyphNumbersForCharacters()} which is optimized for bulk
|
||||
* operations.
|
||||
*
|
||||
* @param integer $characterCode Unicode character code (code point).
|
||||
* @return integer Glyph number.
|
||||
*/
|
||||
public function glyphNumberForCharacter($characterCode)
|
||||
{
|
||||
if (($characterCode < $this->_startCode) || ($characterCode > $this->_endCode)) {
|
||||
return Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
|
||||
}
|
||||
$glyphIndex = $characterCode - $this->_startCode;
|
||||
return $this->_glyphIndexArray[$glyphIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the Unicode characters that have entries in
|
||||
* this character map.
|
||||
*
|
||||
* @return array Unicode character codes.
|
||||
*/
|
||||
public function getCoveredCharacters()
|
||||
{
|
||||
$characterCodes = array();
|
||||
for ($code = $this->_startCode; $code <= $this->_endCode; $code++) {
|
||||
$characterCodes[] = $code;
|
||||
}
|
||||
return $characterCodes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the glyphs numbers that have entries in this character map.
|
||||
* Keys are Unicode character codes (integers)
|
||||
*
|
||||
* This functionality is partially covered by glyphNumbersForCharacters(getCoveredCharacters())
|
||||
* call, but this method do it in more effective way (prepare complete list instead of searching
|
||||
* glyph for each character code).
|
||||
*
|
||||
* @internal
|
||||
* @return array Array representing <Unicode character code> => <glyph number> pairs.
|
||||
*/
|
||||
public function getCoveredCharactersGlyphs()
|
||||
{
|
||||
$glyphNumbers = array();
|
||||
for ($code = $this->_startCode; $code <= $this->_endCode; $code++) {
|
||||
$glyphNumbers[$code] = $this->_glyphIndexArray[$code - $this->_startCode];
|
||||
}
|
||||
|
||||
return $glyphNumbers;
|
||||
}
|
||||
|
||||
|
||||
/* Object Lifecycle */
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* Parses the raw binary table data. Throws an exception if the table is
|
||||
* malformed.
|
||||
*
|
||||
* @param string $cmapData Raw binary cmap table data.
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($cmapData)
|
||||
{
|
||||
/* Sanity check: The table should be at least 9 bytes in size.
|
||||
*/
|
||||
$actualLength = strlen($cmapData);
|
||||
if ($actualLength < 9) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Insufficient table data',
|
||||
Zend_Pdf_Exception::CMAP_TABLE_DATA_TOO_SMALL);
|
||||
}
|
||||
|
||||
/* Sanity check: Make sure this is right data for this table type.
|
||||
*/
|
||||
$type = $this->_extractUInt2($cmapData, 0);
|
||||
if ($type != Zend_Pdf_Cmap::TYPE_TRIMMED_TABLE) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Wrong cmap table type',
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_TYPE);
|
||||
}
|
||||
|
||||
$length = $this->_extractUInt2($cmapData, 2);
|
||||
if ($length != $actualLength) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Table length ($length) does not match actual length ($actualLength)",
|
||||
Zend_Pdf_Exception::CMAP_WRONG_TABLE_LENGTH);
|
||||
}
|
||||
|
||||
/* Mapping tables should be language-independent. The font may not work
|
||||
* as expected if they are not. Unfortunately, many font files in the
|
||||
* wild incorrectly record a language ID in this field, so we can't
|
||||
* call this a failure.
|
||||
*/
|
||||
$language = $this->_extractUInt2($cmapData, 4);
|
||||
if ($language != 0) {
|
||||
// Record a warning here somehow?
|
||||
}
|
||||
|
||||
$this->_startCode = $this->_extractUInt2($cmapData, 6);
|
||||
|
||||
$entryCount = $this->_extractUInt2($cmapData, 8);
|
||||
$expectedCount = ($length - 10) >> 1;
|
||||
if ($entryCount != $expectedCount) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Entry count is wrong; expected: $expectedCount; actual: $entryCount",
|
||||
Zend_Pdf_Exception::CMAP_WRONG_ENTRY_COUNT);
|
||||
}
|
||||
|
||||
$this->_endCode = $this->_startCode + $entryCount - 1;
|
||||
|
||||
$offset = 10;
|
||||
for ($i = 0; $i < $entryCount; $i++, $offset += 2) {
|
||||
$this->_glyphIndexArray[] = $this->_extractUInt2($cmapData, $offset);
|
||||
}
|
||||
|
||||
/* Sanity check: After reading all of the data, we should be at the end
|
||||
* of the table.
|
||||
*/
|
||||
if ($offset != $length) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception("Ending offset ($offset) does not match length ($length)",
|
||||
Zend_Pdf_Exception::CMAP_FINAL_OFFSET_NOT_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
53
Zend/Pdf/Color.php
Normal file
53
Zend/Pdf/Color.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Color.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PDF provides a powerfull facilities for specifying the colors of graphics objects.
|
||||
* This class encapsulates color behaviour.
|
||||
*
|
||||
* Some colors interact with PDF document (create additional objects in a PDF),
|
||||
* others don't do it. That is defined in a subclasses.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Color
|
||||
{
|
||||
/**
|
||||
* Instructions, which can be directly inserted into content stream
|
||||
* to switch color.
|
||||
* Color set instructions differ for stroking and nonstroking operations.
|
||||
*
|
||||
* @param boolean $stroking
|
||||
* @return string
|
||||
*/
|
||||
abstract public function instructions($stroking);
|
||||
|
||||
/**
|
||||
* Get color components (color space dependent)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getComponents();
|
||||
}
|
||||
|
||||
126
Zend/Pdf/Color/Cmyk.php
Normal file
126
Zend/Pdf/Color/Cmyk.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cmyk.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Color */
|
||||
require_once 'Zend/Pdf/Color.php';
|
||||
|
||||
/**
|
||||
* CMYK color implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Color_Cmyk extends Zend_Pdf_Color
|
||||
{
|
||||
/**
|
||||
* Cyan level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_c;
|
||||
|
||||
/**
|
||||
* Magenta level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_m;
|
||||
|
||||
/**
|
||||
* Yellow level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_y;
|
||||
|
||||
/**
|
||||
* Key (BlacK) level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_k;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param float $c
|
||||
* @param float $m
|
||||
* @param float $y
|
||||
* @param float $k
|
||||
*/
|
||||
public function __construct($c, $m, $y, $k)
|
||||
{
|
||||
if ($c < 0) { $c = 0; }
|
||||
if ($c > 1) { $c = 1; }
|
||||
|
||||
if ($m < 0) { $m = 0; }
|
||||
if ($m > 1) { $m = 1; }
|
||||
|
||||
if ($y < 0) { $y = 0; }
|
||||
if ($y > 1) { $y = 1; }
|
||||
|
||||
if ($k < 0) { $k = 0; }
|
||||
if ($k > 1) { $k = 1; }
|
||||
|
||||
$this->_c = new Zend_Pdf_Element_Numeric($c);
|
||||
$this->_m = new Zend_Pdf_Element_Numeric($m);
|
||||
$this->_y = new Zend_Pdf_Element_Numeric($y);
|
||||
$this->_k = new Zend_Pdf_Element_Numeric($k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions, which can be directly inserted into content stream
|
||||
* to switch color.
|
||||
* Color set instructions differ for stroking and nonstroking operations.
|
||||
*
|
||||
* @param boolean $stroking
|
||||
* @return string
|
||||
*/
|
||||
public function instructions($stroking)
|
||||
{
|
||||
return $this->_c->toString() . ' '
|
||||
. $this->_m->toString() . ' '
|
||||
. $this->_y->toString() . ' '
|
||||
. $this->_k->toString() . ($stroking? " K\n" : " k\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color components (color space dependent)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return array($this->_c->value, $this->_m->value, $this->_y->value, $this->_k->value);
|
||||
}
|
||||
}
|
||||
|
||||
84
Zend/Pdf/Color/GrayScale.php
Normal file
84
Zend/Pdf/Color/GrayScale.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: GrayScale.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Color */
|
||||
require_once 'Zend/Pdf/Color.php';
|
||||
|
||||
/**
|
||||
* GrayScale color implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Color_GrayScale extends Zend_Pdf_Color
|
||||
{
|
||||
/**
|
||||
* GrayLevel.
|
||||
* 0.0 (black) - 1.0 (white)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_grayLevel;
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param float $grayLevel
|
||||
*/
|
||||
public function __construct($grayLevel)
|
||||
{
|
||||
if ($grayLevel < 0) { $grayLevel = 0; }
|
||||
if ($grayLevel > 1) { $grayLevel = 1; }
|
||||
|
||||
$this->_grayLevel = new Zend_Pdf_Element_Numeric($grayLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions, which can be directly inserted into content stream
|
||||
* to switch color.
|
||||
* Color set instructions differ for stroking and nonstroking operations.
|
||||
*
|
||||
* @param boolean $stroking
|
||||
* @return string
|
||||
*/
|
||||
public function instructions($stroking)
|
||||
{
|
||||
return $this->_grayLevel->toString() . ($stroking? " G\n" : " g\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color components (color space dependent)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return array($this->_grayLevel->value);
|
||||
}
|
||||
}
|
||||
|
||||
412
Zend/Pdf/Color/Html.php
Normal file
412
Zend/Pdf/Color/Html.php
Normal file
@@ -0,0 +1,412 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Html.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Color */
|
||||
require_once 'Zend/Pdf/Color.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTML color implementation
|
||||
*
|
||||
* Factory class which vends Zend_Pdf_Color objects from typical HTML
|
||||
* representations.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Color_Html extends Zend_Pdf_Color
|
||||
{
|
||||
|
||||
/**
|
||||
* Color
|
||||
*
|
||||
* @var Zend_Pdf_Color
|
||||
*/
|
||||
private $_color;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param mixed $color
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($color)
|
||||
{
|
||||
$this->_color = self::color($color);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instructions, which can be directly inserted into content stream
|
||||
* to switch color.
|
||||
* Color set instructions differ for stroking and nonstroking operations.
|
||||
*
|
||||
* @param boolean $stroking
|
||||
* @return string
|
||||
*/
|
||||
public function instructions($stroking)
|
||||
{
|
||||
return $this->_color->instructions($stroking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color components (color space dependent)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return $this->_color->getComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Zend_Pdf_Color object from the HTML representation.
|
||||
*
|
||||
* @param string $color May either be a hexidecimal number of the form
|
||||
* #rrggbb or one of the 140 well-known names (black, white, blue, etc.)
|
||||
* @return Zend_Pdf_Color
|
||||
*/
|
||||
public static function color($color)
|
||||
{
|
||||
$pattern = '/^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$/';
|
||||
if (preg_match($pattern, $color, $matches)) {
|
||||
$r = round((hexdec($matches[1]) / 255), 3);
|
||||
$g = round((hexdec($matches[2]) / 255), 3);
|
||||
$b = round((hexdec($matches[3]) / 255), 3);
|
||||
if (($r == $g) && ($g == $b)) {
|
||||
require_once 'Zend/Pdf/Color/GrayScale.php';
|
||||
return new Zend_Pdf_Color_GrayScale($r);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Color/Rgb.php';
|
||||
return new Zend_Pdf_Color_Rgb($r, $g, $b);
|
||||
}
|
||||
} else {
|
||||
return Zend_Pdf_Color_Html::namedColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Zend_Pdf_Color object from the named color.
|
||||
*
|
||||
* @param string $color One of the 140 well-known color names (black, white,
|
||||
* blue, etc.)
|
||||
* @return Zend_Pdf_Color
|
||||
*/
|
||||
public static function namedColor($color)
|
||||
{
|
||||
switch (strtolower($color)) {
|
||||
case 'aqua':
|
||||
$r = 0.0; $g = 1.0; $b = 1.0; break;
|
||||
case 'black':
|
||||
$r = 0.0; $g = 0.0; $b = 0.0; break;
|
||||
case 'blue':
|
||||
$r = 0.0; $g = 0.0; $b = 1.0; break;
|
||||
case 'fuchsia':
|
||||
$r = 1.0; $g = 0.0; $b = 1.0; break;
|
||||
case 'gray':
|
||||
$r = 0.502; $g = 0.502; $b = 0.502; break;
|
||||
case 'green':
|
||||
$r = 0.0; $g = 0.502; $b = 0.0; break;
|
||||
case 'lime':
|
||||
$r = 0.0; $g = 1.0; $b = 0.0; break;
|
||||
case 'maroon':
|
||||
$r = 0.502; $g = 0.0; $b = 0.0; break;
|
||||
case 'navy':
|
||||
$r = 0.0; $g = 0.0; $b = 0.502; break;
|
||||
case 'olive':
|
||||
$r = 0.502; $g = 0.502; $b = 0.0; break;
|
||||
case 'purple':
|
||||
$r = 0.502; $g = 0.0; $b = 0.502; break;
|
||||
case 'red':
|
||||
$r = 1.0; $g = 0.0; $b = 0.0; break;
|
||||
case 'silver':
|
||||
$r = 0.753; $g = 0.753; $b = 0.753; break;
|
||||
case 'teal':
|
||||
$r = 0.0; $g = 0.502; $b = 0.502; break;
|
||||
case 'white':
|
||||
$r = 1.0; $g = 1.0; $b = 1.0; break;
|
||||
case 'yellow':
|
||||
$r = 1.0; $g = 1.0; $b = 0.0; break;
|
||||
|
||||
case 'aliceblue':
|
||||
$r = 0.941; $g = 0.973; $b = 1.0; break;
|
||||
case 'antiquewhite':
|
||||
$r = 0.980; $g = 0.922; $b = 0.843; break;
|
||||
case 'aquamarine':
|
||||
$r = 0.498; $g = 1.0; $b = 0.831; break;
|
||||
case 'azure':
|
||||
$r = 0.941; $g = 1.0; $b = 1.0; break;
|
||||
case 'beige':
|
||||
$r = 0.961; $g = 0.961; $b = 0.863; break;
|
||||
case 'bisque':
|
||||
$r = 1.0; $g = 0.894; $b = 0.769; break;
|
||||
case 'blanchedalmond':
|
||||
$r = 1.0; $g = 1.0; $b = 0.804; break;
|
||||
case 'blueviolet':
|
||||
$r = 0.541; $g = 0.169; $b = 0.886; break;
|
||||
case 'brown':
|
||||
$r = 0.647; $g = 0.165; $b = 0.165; break;
|
||||
case 'burlywood':
|
||||
$r = 0.871; $g = 0.722; $b = 0.529; break;
|
||||
case 'cadetblue':
|
||||
$r = 0.373; $g = 0.620; $b = 0.627; break;
|
||||
case 'chartreuse':
|
||||
$r = 0.498; $g = 1.0; $b = 0.0; break;
|
||||
case 'chocolate':
|
||||
$r = 0.824; $g = 0.412; $b = 0.118; break;
|
||||
case 'coral':
|
||||
$r = 1.0; $g = 0.498; $b = 0.314; break;
|
||||
case 'cornflowerblue':
|
||||
$r = 0.392; $g = 0.584; $b = 0.929; break;
|
||||
case 'cornsilk':
|
||||
$r = 1.0; $g = 0.973; $b = 0.863; break;
|
||||
case 'crimson':
|
||||
$r = 0.863; $g = 0.078; $b = 0.235; break;
|
||||
case 'cyan':
|
||||
$r = 0.0; $g = 1.0; $b = 1.0; break;
|
||||
case 'darkblue':
|
||||
$r = 0.0; $g = 0.0; $b = 0.545; break;
|
||||
case 'darkcyan':
|
||||
$r = 0.0; $g = 0.545; $b = 0.545; break;
|
||||
case 'darkgoldenrod':
|
||||
$r = 0.722; $g = 0.525; $b = 0.043; break;
|
||||
case 'darkgray':
|
||||
$r = 0.663; $g = 0.663; $b = 0.663; break;
|
||||
case 'darkgreen':
|
||||
$r = 0.0; $g = 0.392; $b = 0.0; break;
|
||||
case 'darkkhaki':
|
||||
$r = 0.741; $g = 0.718; $b = 0.420; break;
|
||||
case 'darkmagenta':
|
||||
$r = 0.545; $g = 0.0; $b = 0.545; break;
|
||||
case 'darkolivegreen':
|
||||
$r = 0.333; $g = 0.420; $b = 0.184; break;
|
||||
case 'darkorange':
|
||||
$r = 1.0; $g = 0.549; $b = 0.0; break;
|
||||
case 'darkorchid':
|
||||
$r = 0.6; $g = 0.196; $b = 0.8; break;
|
||||
case 'darkred':
|
||||
$r = 0.545; $g = 0.0; $b = 0.0; break;
|
||||
case 'darksalmon':
|
||||
$r = 0.914; $g = 0.588; $b = 0.478; break;
|
||||
case 'darkseagreen':
|
||||
$r = 0.561; $g = 0.737; $b = 0.561; break;
|
||||
case 'darkslateblue':
|
||||
$r = 0.282; $g = 0.239; $b = 0.545; break;
|
||||
case 'darkslategray':
|
||||
$r = 0.184; $g = 0.310; $b = 0.310; break;
|
||||
case 'darkturquoise':
|
||||
$r = 0.0; $g = 0.808; $b = 0.820; break;
|
||||
case 'darkviolet':
|
||||
$r = 0.580; $g = 0.0; $b = 0.827; break;
|
||||
case 'deeppink':
|
||||
$r = 1.0; $g = 0.078; $b = 0.576; break;
|
||||
case 'deepskyblue':
|
||||
$r = 0.0; $g = 0.749; $b = 1.0; break;
|
||||
case 'dimgray':
|
||||
$r = 0.412; $g = 0.412; $b = 0.412; break;
|
||||
case 'dodgerblue':
|
||||
$r = 0.118; $g = 0.565; $b = 1.0; break;
|
||||
case 'firebrick':
|
||||
$r = 0.698; $g = 0.133; $b = 0.133; break;
|
||||
case 'floralwhite':
|
||||
$r = 1.0; $g = 0.980; $b = 0.941; break;
|
||||
case 'forestgreen':
|
||||
$r = 0.133; $g = 0.545; $b = 0.133; break;
|
||||
case 'gainsboro':
|
||||
$r = 0.863; $g = 0.863; $b = 0.863; break;
|
||||
case 'ghostwhite':
|
||||
$r = 0.973; $g = 0.973; $b = 1.0; break;
|
||||
case 'gold':
|
||||
$r = 1.0; $g = 0.843; $b = 0.0; break;
|
||||
case 'goldenrod':
|
||||
$r = 0.855; $g = 0.647; $b = 0.125; break;
|
||||
case 'greenyellow':
|
||||
$r = 0.678; $g = 1.0; $b = 0.184; break;
|
||||
case 'honeydew':
|
||||
$r = 0.941; $g = 1.0; $b = 0.941; break;
|
||||
case 'hotpink':
|
||||
$r = 1.0; $g = 0.412; $b = 0.706; break;
|
||||
case 'indianred':
|
||||
$r = 0.804; $g = 0.361; $b = 0.361; break;
|
||||
case 'indigo':
|
||||
$r = 0.294; $g = 0.0; $b = 0.510; break;
|
||||
case 'ivory':
|
||||
$r = 1.0; $g = 0.941; $b = 0.941; break;
|
||||
case 'khaki':
|
||||
$r = 0.941; $g = 0.902; $b = 0.549; break;
|
||||
case 'lavender':
|
||||
$r = 0.902; $g = 0.902; $b = 0.980; break;
|
||||
case 'lavenderblush':
|
||||
$r = 1.0; $g = 0.941; $b = 0.961; break;
|
||||
case 'lawngreen':
|
||||
$r = 0.486; $g = 0.988; $b = 0.0; break;
|
||||
case 'lemonchiffon':
|
||||
$r = 1.0; $g = 0.980; $b = 0.804; break;
|
||||
case 'lightblue':
|
||||
$r = 0.678; $g = 0.847; $b = 0.902; break;
|
||||
case 'lightcoral':
|
||||
$r = 0.941; $g = 0.502; $b = 0.502; break;
|
||||
case 'lightcyan':
|
||||
$r = 0.878; $g = 1.0; $b = 1.0; break;
|
||||
case 'lightgoldenrodyellow':
|
||||
$r = 0.980; $g = 0.980; $b = 0.824; break;
|
||||
case 'lightgreen':
|
||||
$r = 0.565; $g = 0.933; $b = 0.565; break;
|
||||
case 'lightgrey':
|
||||
$r = 0.827; $g = 0.827; $b = 0.827; break;
|
||||
case 'lightpink':
|
||||
$r = 1.0; $g = 0.714; $b = 0.757; break;
|
||||
case 'lightsalmon':
|
||||
$r = 1.0; $g = 0.627; $b = 0.478; break;
|
||||
case 'lightseagreen':
|
||||
$r = 0.125; $g = 0.698; $b = 0.667; break;
|
||||
case 'lightskyblue':
|
||||
$r = 0.529; $g = 0.808; $b = 0.980; break;
|
||||
case 'lightslategray':
|
||||
$r = 0.467; $g = 0.533; $b = 0.6; break;
|
||||
case 'lightsteelblue':
|
||||
$r = 0.690; $g = 0.769; $b = 0.871; break;
|
||||
case 'lightyellow':
|
||||
$r = 1.0; $g = 1.0; $b = 0.878; break;
|
||||
case 'limegreen':
|
||||
$r = 0.196; $g = 0.804; $b = 0.196; break;
|
||||
case 'linen':
|
||||
$r = 0.980; $g = 0.941; $b = 0.902; break;
|
||||
case 'magenta':
|
||||
$r = 1.0; $g = 0.0; $b = 1.0; break;
|
||||
case 'mediumaquamarine':
|
||||
$r = 0.4; $g = 0.804; $b = 0.667; break;
|
||||
case 'mediumblue':
|
||||
$r = 0.0; $g = 0.0; $b = 0.804; break;
|
||||
case 'mediumorchid':
|
||||
$r = 0.729; $g = 0.333; $b = 0.827; break;
|
||||
case 'mediumpurple':
|
||||
$r = 0.576; $g = 0.439; $b = 0.859; break;
|
||||
case 'mediumseagreen':
|
||||
$r = 0.235; $g = 0.702; $b = 0.443; break;
|
||||
case 'mediumslateblue':
|
||||
$r = 0.482; $g = 0.408; $b = 0.933; break;
|
||||
case 'mediumspringgreen':
|
||||
$r = 0.0; $g = 0.980; $b = 0.604; break;
|
||||
case 'mediumturquoise':
|
||||
$r = 0.282; $g = 0.820; $b = 0.8; break;
|
||||
case 'mediumvioletred':
|
||||
$r = 0.780; $g = 0.082; $b = 0.522; break;
|
||||
case 'midnightblue':
|
||||
$r = 0.098; $g = 0.098; $b = 0.439; break;
|
||||
case 'mintcream':
|
||||
$r = 0.961; $g = 1.0; $b = 0.980; break;
|
||||
case 'mistyrose':
|
||||
$r = 1.0; $g = 0.894; $b = 0.882; break;
|
||||
case 'moccasin':
|
||||
$r = 1.0; $g = 0.894; $b = 0.710; break;
|
||||
case 'navajowhite':
|
||||
$r = 1.0; $g = 0.871; $b = 0.678; break;
|
||||
case 'oldlace':
|
||||
$r = 0.992; $g = 0.961; $b = 0.902; break;
|
||||
case 'olivedrab':
|
||||
$r = 0.420; $g = 0.557; $b = 0.137; break;
|
||||
case 'orange':
|
||||
$r = 1.0; $g = 0.647; $b = 0.0; break;
|
||||
case 'orangered':
|
||||
$r = 1.0; $g = 0.271; $b = 0.0; break;
|
||||
case 'orchid':
|
||||
$r = 0.855; $g = 0.439; $b = 0.839; break;
|
||||
case 'palegoldenrod':
|
||||
$r = 0.933; $g = 0.910; $b = 0.667; break;
|
||||
case 'palegreen':
|
||||
$r = 0.596; $g = 0.984; $b = 0.596; break;
|
||||
case 'paleturquoise':
|
||||
$r = 0.686; $g = 0.933; $b = 0.933; break;
|
||||
case 'palevioletred':
|
||||
$r = 0.859; $g = 0.439; $b = 0.576; break;
|
||||
case 'papayawhip':
|
||||
$r = 1.0; $g = 0.937; $b = 0.835; break;
|
||||
case 'peachpuff':
|
||||
$r = 1.0; $g = 0.937; $b = 0.835; break;
|
||||
case 'peru':
|
||||
$r = 0.804; $g = 0.522; $b = 0.247; break;
|
||||
case 'pink':
|
||||
$r = 1.0; $g = 0.753; $b = 0.796; break;
|
||||
case 'plum':
|
||||
$r = 0.867; $g = 0.627; $b = 0.867; break;
|
||||
case 'powderblue':
|
||||
$r = 0.690; $g = 0.878; $b = 0.902; break;
|
||||
case 'rosybrown':
|
||||
$r = 0.737; $g = 0.561; $b = 0.561; break;
|
||||
case 'royalblue':
|
||||
$r = 0.255; $g = 0.412; $b = 0.882; break;
|
||||
case 'saddlebrown':
|
||||
$r = 0.545; $g = 0.271; $b = 0.075; break;
|
||||
case 'salmon':
|
||||
$r = 0.980; $g = 0.502; $b = 0.447; break;
|
||||
case 'sandybrown':
|
||||
$r = 0.957; $g = 0.643; $b = 0.376; break;
|
||||
case 'seagreen':
|
||||
$r = 0.180; $g = 0.545; $b = 0.341; break;
|
||||
case 'seashell':
|
||||
$r = 1.0; $g = 0.961; $b = 0.933; break;
|
||||
case 'sienna':
|
||||
$r = 0.627; $g = 0.322; $b = 0.176; break;
|
||||
case 'skyblue':
|
||||
$r = 0.529; $g = 0.808; $b = 0.922; break;
|
||||
case 'slateblue':
|
||||
$r = 0.416; $g = 0.353; $b = 0.804; break;
|
||||
case 'slategray':
|
||||
$r = 0.439; $g = 0.502; $b = 0.565; break;
|
||||
case 'snow':
|
||||
$r = 1.0; $g = 0.980; $b = 0.980; break;
|
||||
case 'springgreen':
|
||||
$r = 0.0; $g = 1.0; $b = 0.498; break;
|
||||
case 'steelblue':
|
||||
$r = 0.275; $g = 0.510; $b = 0.706; break;
|
||||
case 'tan':
|
||||
$r = 0.824; $g = 0.706; $b = 0.549; break;
|
||||
case 'thistle':
|
||||
$r = 0.847; $g = 0.749; $b = 0.847; break;
|
||||
case 'tomato':
|
||||
$r = 0.992; $g = 0.388; $b = 0.278; break;
|
||||
case 'turquoise':
|
||||
$r = 0.251; $g = 0.878; $b = 0.816; break;
|
||||
case 'violet':
|
||||
$r = 0.933; $g = 0.510; $b = 0.933; break;
|
||||
case 'wheat':
|
||||
$r = 0.961; $g = 0.871; $b = 0.702; break;
|
||||
case 'whitesmoke':
|
||||
$r = 0.961; $g = 0.961; $b = 0.961; break;
|
||||
case 'yellowgreen':
|
||||
$r = 0.604; $g = 0.804; $b = 0.196; break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unknown color name: ' . $color);
|
||||
}
|
||||
if (($r == $g) && ($g == $b)) {
|
||||
require_once 'Zend/Pdf/Color/GrayScale.php';
|
||||
return new Zend_Pdf_Color_GrayScale($r);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Color/Rgb.php';
|
||||
return new Zend_Pdf_Color_Rgb($r, $g, $b);
|
||||
}
|
||||
}
|
||||
}
|
||||
114
Zend/Pdf/Color/Rgb.php
Normal file
114
Zend/Pdf/Color/Rgb.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Rgb.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Color */
|
||||
require_once 'Zend/Pdf/Color.php';
|
||||
|
||||
/**
|
||||
* RGB color implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Color_Rgb extends Zend_Pdf_Color
|
||||
{
|
||||
/**
|
||||
* Red level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_r;
|
||||
|
||||
/**
|
||||
* Green level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_g;
|
||||
|
||||
/**
|
||||
* Blue level.
|
||||
* 0.0 (zero concentration) - 1.0 (maximum concentration)
|
||||
*
|
||||
* @var Zend_Pdf_Element_Numeric
|
||||
*/
|
||||
private $_b;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param float $r
|
||||
* @param float $g
|
||||
* @param float $b
|
||||
*/
|
||||
public function __construct($r, $g, $b)
|
||||
{
|
||||
/** Clamp values to legal limits. */
|
||||
if ($r < 0) { $r = 0; }
|
||||
if ($r > 1) { $r = 1; }
|
||||
|
||||
if ($g < 0) { $g = 0; }
|
||||
if ($g > 1) { $g = 1; }
|
||||
|
||||
if ($b < 0) { $b = 0; }
|
||||
if ($b > 1) { $b = 1; }
|
||||
|
||||
$this->_r = new Zend_Pdf_Element_Numeric($r);
|
||||
$this->_g = new Zend_Pdf_Element_Numeric($g);
|
||||
$this->_b = new Zend_Pdf_Element_Numeric($b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructions, which can be directly inserted into content stream
|
||||
* to switch color.
|
||||
* Color set instructions differ for stroking and nonstroking operations.
|
||||
*
|
||||
* @param boolean $stroking
|
||||
* @return string
|
||||
*/
|
||||
public function instructions($stroking)
|
||||
{
|
||||
return $this->_r->toString() . ' '
|
||||
. $this->_g->toString() . ' '
|
||||
. $this->_b->toString() . ($stroking? " RG\n" : " rg\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color components (color space dependent)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents()
|
||||
{
|
||||
return array($this->_r->value, $this->_g->value, $this->_b->value);
|
||||
}
|
||||
}
|
||||
|
||||
113
Zend/Pdf/Destination.php
Normal file
113
Zend/Pdf/Destination.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Destination.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Target */
|
||||
require_once 'Zend/Pdf/Target.php';
|
||||
|
||||
|
||||
/**
|
||||
* Abstract PDF destination representation class
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Destination extends Zend_Pdf_Target
|
||||
{
|
||||
/**
|
||||
* Load Destination object from a specified resource
|
||||
*
|
||||
* @internal
|
||||
* @param Zend_Pdf_Element $resource
|
||||
* @return Zend_Pdf_Destination
|
||||
*/
|
||||
public static function load(Zend_Pdf_Element $resource)
|
||||
{
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
if ($resource->getType() == Zend_Pdf_Element::TYPE_NAME || $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
|
||||
require_once 'Zend/Pdf/Destination/Named.php';
|
||||
return new Zend_Pdf_Destination_Named($resource);
|
||||
}
|
||||
|
||||
if ($resource->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('An explicit destination must be a direct or an indirect array object.');
|
||||
}
|
||||
if (count($resource->items) < 2) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('An explicit destination array must contain at least two elements.');
|
||||
}
|
||||
|
||||
switch ($resource->items[1]->value) {
|
||||
case 'XYZ':
|
||||
require_once 'Zend/Pdf/Destination/Zoom.php';
|
||||
return new Zend_Pdf_Destination_Zoom($resource);
|
||||
break;
|
||||
|
||||
case 'Fit':
|
||||
require_once 'Zend/Pdf/Destination/Fit.php';
|
||||
return new Zend_Pdf_Destination_Fit($resource);
|
||||
break;
|
||||
|
||||
case 'FitH':
|
||||
require_once 'Zend/Pdf/Destination/FitHorizontally.php';
|
||||
return new Zend_Pdf_Destination_FitHorizontally($resource);
|
||||
break;
|
||||
|
||||
case 'FitV':
|
||||
require_once 'Zend/Pdf/Destination/FitVertically.php';
|
||||
return new Zend_Pdf_Destination_FitVertically($resource);
|
||||
break;
|
||||
|
||||
case 'FitR':
|
||||
require_once 'Zend/Pdf/Destination/FitRectangle.php';
|
||||
return new Zend_Pdf_Destination_FitRectangle($resource);
|
||||
break;
|
||||
|
||||
case 'FitB':
|
||||
require_once 'Zend/Pdf/Destination/FitBoundingBox.php';
|
||||
return new Zend_Pdf_Destination_FitBoundingBox($resource);
|
||||
break;
|
||||
|
||||
case 'FitBH':
|
||||
require_once 'Zend/Pdf/Destination/FitBoundingBoxHorizontally.php';
|
||||
return new Zend_Pdf_Destination_FitBoundingBoxHorizontally($resource);
|
||||
break;
|
||||
|
||||
case 'FitBV':
|
||||
require_once 'Zend/Pdf/Destination/FitBoundingBoxVertically.php';
|
||||
return new Zend_Pdf_Destination_FitBoundingBoxVertically($resource);
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Destination/Unknown.php';
|
||||
return new Zend_Pdf_Destination_Unknown($resource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
122
Zend/Pdf/Destination/Explicit.php
Normal file
122
Zend/Pdf/Destination/Explicit.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Explicit.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination */
|
||||
require_once 'Zend/Pdf/Destination.php';
|
||||
|
||||
/**
|
||||
* Abstract PDF explicit destination representation class
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Destination_Explicit extends Zend_Pdf_Destination
|
||||
{
|
||||
/**
|
||||
* Destination description array
|
||||
*
|
||||
* @var Zend_Pdf_Element_Array
|
||||
*/
|
||||
protected $_destinationArray;
|
||||
|
||||
/**
|
||||
* True if it's a remote destination
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isRemote;
|
||||
|
||||
/**
|
||||
* Explicit destination object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element $destinationArray
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $destinationArray)
|
||||
{
|
||||
if ($destinationArray->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Explicit destination resource Array must be a direct or an indirect array object.');
|
||||
}
|
||||
|
||||
$this->_destinationArray = $destinationArray;
|
||||
|
||||
switch (count($this->_destinationArray->items)) {
|
||||
case 0:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Destination array must contain a page reference.');
|
||||
break;
|
||||
|
||||
case 1:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Destination array must contain a destination type name.');
|
||||
break;
|
||||
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($this->_destinationArray->items[0]->getType()) {
|
||||
case Zend_Pdf_Element::TYPE_NUMERIC:
|
||||
$this->_isRemote = true;
|
||||
break;
|
||||
|
||||
case Zend_Pdf_Element::TYPE_DICTIONARY:
|
||||
$this->_isRemote = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Destination target must be a page number or page dictionary object.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it's a remote destination
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isRemote()
|
||||
{
|
||||
return $this->_isRemote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource
|
||||
*
|
||||
* @internal
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->_destinationArray;
|
||||
}
|
||||
}
|
||||
75
Zend/Pdf/Destination/Fit.php
Normal file
75
Zend/Pdf/Destination/Fit.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Fit.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_Fit explicit detination
|
||||
*
|
||||
* Destination array: [page /Fit]
|
||||
*
|
||||
* Display the page designated by page, with its contents magnified just enough
|
||||
* to fit the entire page within the window both horizontally and vertically. If
|
||||
* the required horizontal and vertical magnification factors are different, use
|
||||
* the smaller of the two, centering the page within the window in the other
|
||||
* dimension.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_Fit extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @return Zend_Pdf_Destination_Fit
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('Fit');
|
||||
|
||||
return new Zend_Pdf_Destination_Fit($destinationArray);
|
||||
}
|
||||
}
|
||||
75
Zend/Pdf/Destination/FitBoundingBox.php
Normal file
75
Zend/Pdf/Destination/FitBoundingBox.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitBoundingBox.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitBoundingBox explicit detination
|
||||
*
|
||||
* Destination array: [page /FitB]
|
||||
*
|
||||
* (PDF 1.1) Display the page designated by page, with its contents magnified
|
||||
* just enough to fit its bounding box entirely within the window both horizontally
|
||||
* and vertically. If the required horizontal and vertical magnification
|
||||
* factors are different, use the smaller of the two, centering the bounding box
|
||||
* within the window in the other dimension.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitBoundingBox extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @return Zend_Pdf_Destination_FitBoundingBox
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitB');
|
||||
|
||||
return new Zend_Pdf_Destination_FitBoundingBox($destinationArray);
|
||||
}
|
||||
}
|
||||
98
Zend/Pdf/Destination/FitBoundingBoxHorizontally.php
Normal file
98
Zend/Pdf/Destination/FitBoundingBoxHorizontally.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitBoundingBoxHorizontally.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitBoundingBoxHorizontally explicit detination
|
||||
*
|
||||
* Destination array: [page /FitBH top]
|
||||
*
|
||||
* (PDF 1.1) Display the page designated by page, with the vertical coordinate
|
||||
* top positioned at the top edge of the window and the contents of the page
|
||||
* magnified just enough to fit the entire width of its bounding box within the
|
||||
* window.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitBoundingBoxHorizontally extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $top Top edge of displayed page
|
||||
* @return Zend_Pdf_Destination_FitBoundingBoxHorizontally
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $top)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitBH');
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
|
||||
|
||||
return new Zend_Pdf_Destination_FitBoundingBoxHorizontally($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTopEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top edge of the displayed page
|
||||
*
|
||||
* @param float $top
|
||||
* @return Zend_Pdf_Action_FitBoundingBoxHorizontally
|
||||
*/
|
||||
public function setTopEdge($top)
|
||||
{
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($top);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
98
Zend/Pdf/Destination/FitBoundingBoxVertically.php
Normal file
98
Zend/Pdf/Destination/FitBoundingBoxVertically.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitBoundingBoxVertically.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitBoundingBoxVertically explicit detination
|
||||
*
|
||||
* Destination array: [page /FitBV left]
|
||||
*
|
||||
* (PDF 1.1) Display the page designated by page, with the horizontal coordinate
|
||||
* left positioned at the left edge of the window and the contents of the page
|
||||
* magnified just enough to fit the entire height of its bounding box within the
|
||||
* window.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitBoundingBoxVertically extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $left Left edge of displayed page
|
||||
* @return Zend_Pdf_Destination_FitBoundingBoxVertically
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $left)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitBV');
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
|
||||
|
||||
return new Zend_Pdf_Destination_FitBoundingBoxVertically($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getLeftEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left edge of the displayed page
|
||||
*
|
||||
* @param float $left
|
||||
* @return Zend_Pdf_Action_FitBoundingBoxVertically
|
||||
*/
|
||||
public function setLeftEdge($left)
|
||||
{
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
98
Zend/Pdf/Destination/FitHorizontally.php
Normal file
98
Zend/Pdf/Destination/FitHorizontally.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitHorizontally.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitHorizontally explicit detination
|
||||
*
|
||||
* Destination array: [page /FitH top]
|
||||
*
|
||||
* Display the page designated by page, with the vertical coordinate top positioned
|
||||
* at the top edge of the window and the contents of the page magnified
|
||||
* just enough to fit the entire width of the page within the window.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitHorizontally extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $top Top edge of displayed page
|
||||
* @return Zend_Pdf_Destination_FitHorizontally
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $top)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitH');
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
|
||||
|
||||
return new Zend_Pdf_Destination_FitHorizontally($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTopEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top edge of the displayed page
|
||||
*
|
||||
* @param float $top
|
||||
* @return Zend_Pdf_Action_FitHorizontally
|
||||
*/
|
||||
public function setTopEdge($top)
|
||||
{
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($top);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
171
Zend/Pdf/Destination/FitRectangle.php
Normal file
171
Zend/Pdf/Destination/FitRectangle.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitRectangle.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitRectangle explicit detination
|
||||
*
|
||||
* Destination array: [page /FitR left bottom right top]
|
||||
*
|
||||
* Display the page designated by page, with its contents magnified just enough
|
||||
* to fit the rectangle specified by the coordinates left, bottom, right, and top
|
||||
* entirely within the window both horizontally and vertically. If the required
|
||||
* horizontal and vertical magnification factors are different, use the smaller of
|
||||
* the two, centering the rectangle within the window in the other dimension.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitRectangle extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $left Left edge of displayed page
|
||||
* @param float $bottom Bottom edge of displayed page
|
||||
* @param float $right Right edge of displayed page
|
||||
* @param float $top Top edge of displayed page
|
||||
* @return Zend_Pdf_Destination_FitRectangle
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $left, $bottom, $right, $top)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitR');
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($bottom);
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($right);
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
|
||||
|
||||
return new Zend_Pdf_Destination_FitRectangle($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getLeftEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left edge of the displayed page
|
||||
*
|
||||
* @param float $left
|
||||
* @return Zend_Pdf_Action_FitRectangle
|
||||
*/
|
||||
public function setLeftEdge($left)
|
||||
{
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getBottomEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[3]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bottom edge of the displayed page
|
||||
*
|
||||
* @param float $bottom
|
||||
* @return Zend_Pdf_Action_FitRectangle
|
||||
*/
|
||||
public function setBottomEdge($bottom)
|
||||
{
|
||||
$this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($bottom);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get right edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRightEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[4]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right edge of the displayed page
|
||||
*
|
||||
* @param float $right
|
||||
* @return Zend_Pdf_Action_FitRectangle
|
||||
*/
|
||||
public function setRightEdge($right)
|
||||
{
|
||||
$this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($right);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTopEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[5]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top edge of the displayed page
|
||||
*
|
||||
* @param float $top
|
||||
* @return Zend_Pdf_Action_FitRectangle
|
||||
*/
|
||||
public function setTopEdge($top)
|
||||
{
|
||||
$this->_destinationArray->items[5] = new Zend_Pdf_Element_Numeric($top);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
98
Zend/Pdf/Destination/FitVertically.php
Normal file
98
Zend/Pdf/Destination/FitVertically.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FitVertically.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_FitVertically explicit detination
|
||||
*
|
||||
* Destination array: [page /FitV left]
|
||||
*
|
||||
* Display the page designated by page, with the horizontal coordinate left positioned
|
||||
* at the left edge of the window and the contents of the page magnified
|
||||
* just enough to fit the entire height of the page within the window.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_FitVertically extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $left Left edge of displayed page
|
||||
* @return Zend_Pdf_Destination_FitVertically
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $left)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('FitV');
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
|
||||
|
||||
return new Zend_Pdf_Destination_FitVertically($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left edge of the displayed page
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getLeftEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left edge of the displayed page
|
||||
*
|
||||
* @param float $left
|
||||
* @return Zend_Pdf_Action_FitVertically
|
||||
*/
|
||||
public function setLeftEdge($left)
|
||||
{
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
101
Zend/Pdf/Destination/Named.php
Normal file
101
Zend/Pdf/Destination/Named.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Named.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination */
|
||||
require_once 'Zend/Pdf/Destination.php';
|
||||
|
||||
/**
|
||||
* Destination array: [page /Fit]
|
||||
*
|
||||
* Display the page designated by page, with its contents magnified just enough
|
||||
* to fit the entire page within the window both horizontally and vertically. If
|
||||
* the required horizontal and vertical magnification factors are different, use
|
||||
* the smaller of the two, centering the page within the window in the other
|
||||
* dimension.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_Named extends Zend_Pdf_Destination
|
||||
{
|
||||
/**
|
||||
* Destination name
|
||||
*
|
||||
* @var Zend_Pdf_Element_Name|Zend_Pdf_Element_String
|
||||
*/
|
||||
protected $_nameElement;
|
||||
|
||||
/**
|
||||
* Named destination object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element $resource
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $resource)
|
||||
{
|
||||
if ($resource->getType() != Zend_Pdf_Element::TYPE_NAME && $resource->getType() != Zend_Pdf_Element::TYPE_STRING) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Named destination resource must be a PDF name or a PDF string.');
|
||||
}
|
||||
|
||||
$this->_nameElement = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create named destination object
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Pdf_Destination_Named
|
||||
*/
|
||||
public static function create($name)
|
||||
{
|
||||
return new Zend_Pdf_Destination_Named(new Zend_Pdf_Element_String($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_nameElement->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource
|
||||
*
|
||||
* @internal
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->_nameElement;
|
||||
}
|
||||
}
|
||||
37
Zend/Pdf/Destination/Unknown.php
Normal file
37
Zend/Pdf/Destination/Unknown.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Unknown.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
|
||||
/**
|
||||
* Unrecognized explicit destination representation class
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_Unknown extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
}
|
||||
177
Zend/Pdf/Destination/Zoom.php
Normal file
177
Zend/Pdf/Destination/Zoom.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Zoom.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
require_once 'Zend/Pdf/Element/Null.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Destination_Explicit */
|
||||
require_once 'Zend/Pdf/Destination/Explicit.php';
|
||||
|
||||
/**
|
||||
* Zend_Pdf_Destination_Zoom explicit detination
|
||||
*
|
||||
* Destination array: [page /XYZ left top zoom]
|
||||
*
|
||||
* Display the page designated by page, with the coordinates (left, top) positioned
|
||||
* at the upper-left corner of the window and the contents of the page
|
||||
* magnified by the factor zoom. A null value for any of the parameters left, top,
|
||||
* or zoom specifies that the current value of that parameter is to be retained unchanged.
|
||||
* A zoom value of 0 has the same meaning as a null value.
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @subpackage Destination
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Destination_Zoom extends Zend_Pdf_Destination_Explicit
|
||||
{
|
||||
/**
|
||||
* Create destination object
|
||||
*
|
||||
* @param Zend_Pdf_Page|integer $page Page object or page number
|
||||
* @param float $left Left edge of displayed page
|
||||
* @param float $top Top edge of displayed page
|
||||
* @param float $zoom Zoom factor
|
||||
* @return Zend_Pdf_Destination_Zoom
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public static function create($page, $left = null, $top = null, $zoom = null)
|
||||
{
|
||||
$destinationArray = new Zend_Pdf_Element_Array();
|
||||
|
||||
if ($page instanceof Zend_Pdf_Page) {
|
||||
$destinationArray->items[] = $page->getPageDictionary();
|
||||
} else if (is_integer($page)) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($page);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Page entry must be a Zend_Pdf_Page object or a page number.');
|
||||
}
|
||||
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Name('XYZ');
|
||||
|
||||
if ($left === null) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($left);
|
||||
}
|
||||
|
||||
if ($top === null) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($top);
|
||||
}
|
||||
|
||||
if ($zoom === null) {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$destinationArray->items[] = new Zend_Pdf_Element_Numeric($zoom);
|
||||
}
|
||||
|
||||
return new Zend_Pdf_Destination_Zoom($destinationArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left edge of the displayed page (null means viewer application 'current value')
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getLeftEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[2]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left edge of the displayed page (null means viewer application 'current value')
|
||||
*
|
||||
* @param float $left
|
||||
* @return Zend_Pdf_Action_Zoom
|
||||
*/
|
||||
public function setLeftEdge($left)
|
||||
{
|
||||
if ($left === null) {
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$this->_destinationArray->items[2] = new Zend_Pdf_Element_Numeric($left);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top edge of the displayed page (null means viewer application 'current value')
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTopEdge()
|
||||
{
|
||||
return $this->_destinationArray->items[3]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top edge of the displayed page (null means viewer application 'current viewer')
|
||||
*
|
||||
* @param float $top
|
||||
* @return Zend_Pdf_Action_Zoom
|
||||
*/
|
||||
public function setTopEdge($top)
|
||||
{
|
||||
if ($top === null) {
|
||||
$this->_destinationArray->items[3] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$this->_destinationArray->items[3] = new Zend_Pdf_Element_Numeric($top);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ZoomFactor of the displayed page (null or 0 means viewer application 'current value')
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getZoomFactor()
|
||||
{
|
||||
return $this->_destinationArray->items[4]->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ZoomFactor of the displayed page (null or 0 means viewer application 'current viewer')
|
||||
*
|
||||
* @param float $zoom
|
||||
* @return Zend_Pdf_Action_Zoom
|
||||
*/
|
||||
public function setZoomFactor($zoom)
|
||||
{
|
||||
if ($zoom === null) {
|
||||
$this->_destinationArray->items[4] = new Zend_Pdf_Element_Null();
|
||||
} else {
|
||||
$this->_destinationArray->items[4] = new Zend_Pdf_Element_Numeric($zoom);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
176
Zend/Pdf/Element.php
Normal file
176
Zend/Pdf/Element.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Element.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PDF file element implementation
|
||||
*
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Pdf_Element
|
||||
{
|
||||
const TYPE_BOOL = 1;
|
||||
const TYPE_NUMERIC = 2;
|
||||
const TYPE_STRING = 3;
|
||||
const TYPE_NAME = 4;
|
||||
const TYPE_ARRAY = 5;
|
||||
const TYPE_DICTIONARY = 6;
|
||||
const TYPE_STREAM = 7;
|
||||
const TYPE_NULL = 11;
|
||||
|
||||
/**
|
||||
* Reference to the top level indirect object, which contains this element.
|
||||
*
|
||||
* @var Zend_Pdf_Element_Object
|
||||
*/
|
||||
private $_parentObject = null;
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
* See ZPdfPDFConst for possible values
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function getType();
|
||||
|
||||
/**
|
||||
* Convert element to a string, which can be directly
|
||||
* written to a PDF file.
|
||||
*
|
||||
* $factory parameter defines operation context.
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
abstract public function toString($factory = null);
|
||||
|
||||
const CLONE_MODE_SKIP_PAGES = 1; // Do not follow pages during deep copy process
|
||||
const CLONE_MODE_FORCE_CLONING = 2; // Force top level object cloning even it's already processed
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @todo It's nevessry to check if SplObjectStorage class works faster
|
||||
* (Needs PHP 5.3.x to attach object _with_ additional data to storage)
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top level parent indirect object.
|
||||
*
|
||||
* @param Zend_Pdf_Element_Object $parent
|
||||
*/
|
||||
public function setParentObject(Zend_Pdf_Element_Object $parent)
|
||||
{
|
||||
$this->_parentObject = $parent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get top level parent indirect object.
|
||||
*
|
||||
* @return Zend_Pdf_Element_Object
|
||||
*/
|
||||
public function getParentObject()
|
||||
{
|
||||
return $this->_parentObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark object as modified, to include it into new PDF file segment.
|
||||
*
|
||||
* We don't automate this action to keep control on PDF update process.
|
||||
* All new objects are treated as "modified" automatically.
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
if ($this->_parentObject !== null) {
|
||||
$this->_parentObject->touch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources, used by object
|
||||
*/
|
||||
public function cleanUp()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PDF element to PHP type.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function toPhp()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PHP value into PDF element.
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return Zend_Pdf_Element
|
||||
*/
|
||||
public static function phpToPdf($input)
|
||||
{
|
||||
if (is_numeric($input)) {
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
return new Zend_Pdf_Element_Numeric($input);
|
||||
} else if (is_bool($input)) {
|
||||
require_once 'Zend/Pdf/Element/Boolean.php';
|
||||
return new Zend_Pdf_Element_Boolean($input);
|
||||
} else if (is_array($input)) {
|
||||
$pdfElementsArray = array();
|
||||
$isDictionary = false;
|
||||
|
||||
foreach ($input as $key => $value) {
|
||||
if (is_string($key)) {
|
||||
$isDictionary = true;
|
||||
}
|
||||
$pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
|
||||
}
|
||||
|
||||
if ($isDictionary) {
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Element/Array.php';
|
||||
return new Zend_Pdf_Element_Array($pdfElementsArray);
|
||||
}
|
||||
} else {
|
||||
require_once 'Zend/Pdf/Element/String.php';
|
||||
return new Zend_Pdf_Element_String((string)$input);
|
||||
}
|
||||
}
|
||||
}
|
||||
181
Zend/Pdf/Element/Array.php
Normal file
181
Zend/Pdf/Element/Array.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Array.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'array' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Array extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Array element items
|
||||
*
|
||||
* Array of Zend_Pdf_Element objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $items;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param array $val - array of Zend_Pdf_Element objects
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val = null)
|
||||
{
|
||||
$this->items = new ArrayObject();
|
||||
|
||||
if ($val !== null && is_array($val)) {
|
||||
foreach ($val as $element) {
|
||||
if (!$element instanceof Zend_Pdf_Element) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
|
||||
}
|
||||
$this->items[] = $element;
|
||||
}
|
||||
} else if ($val !== null){
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Argument must be an array');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
* @param string $property
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __get($property) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param mixed $value
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __set($property, $value) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
$outStr = '[';
|
||||
$lastNL = 0;
|
||||
|
||||
foreach ($this->items as $element) {
|
||||
if (strlen($outStr) - $lastNL > 128) {
|
||||
$outStr .= "\n";
|
||||
$lastNL = strlen($outStr);
|
||||
}
|
||||
|
||||
$outStr .= $element->toString($factory) . ' ';
|
||||
}
|
||||
$outStr .= ']';
|
||||
|
||||
return $outStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
$newArray = new self();
|
||||
|
||||
foreach ($this->items as $key => $value) {
|
||||
$newArray->items[$key] = $value->makeClone($factory, $processed, $mode);
|
||||
}
|
||||
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top level parent indirect object.
|
||||
*
|
||||
* @param Zend_Pdf_Element_Object $parent
|
||||
*/
|
||||
public function setParentObject(Zend_Pdf_Element_Object $parent)
|
||||
{
|
||||
parent::setParentObject($parent);
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
$item->setParentObject($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PDF element to PHP type.
|
||||
*
|
||||
* Dictionary is returned as an associative array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function toPhp()
|
||||
{
|
||||
$phpArray = array();
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
$phpArray[] = $item->toPhp();
|
||||
}
|
||||
|
||||
return $phpArray;
|
||||
}
|
||||
}
|
||||
83
Zend/Pdf/Element/Boolean.php
Normal file
83
Zend/Pdf/Element/Boolean.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Boolean.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'boolean' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Boolean extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $value;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param boolean $val
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val)
|
||||
{
|
||||
if (! is_bool($val)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Argument must be boolean.');
|
||||
}
|
||||
|
||||
$this->value = $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_BOOL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
return $this->value ? 'true' : 'false';
|
||||
}
|
||||
}
|
||||
236
Zend/Pdf/Element/Dictionary.php
Normal file
236
Zend/Pdf/Element/Dictionary.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Dictionary.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Name.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
/**
|
||||
* PDF file 'dictionary' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Dictionary extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Dictionary elements
|
||||
* Array of Zend_Pdf_Element objects ('name' => Zend_Pdf_Element)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_items = array();
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param array $val - array of Zend_Pdf_Element objects
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val = null)
|
||||
{
|
||||
if ($val === null) {
|
||||
return;
|
||||
} else if (!is_array($val)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Argument must be an array');
|
||||
}
|
||||
|
||||
foreach ($val as $name => $element) {
|
||||
if (!$element instanceof Zend_Pdf_Element) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
|
||||
}
|
||||
if (!is_string($name)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Array keys must be strings');
|
||||
}
|
||||
$this->_items[$name] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add element to an array
|
||||
*
|
||||
* @name Zend_Pdf_Element_Name $name
|
||||
* @param Zend_Pdf_Element $val - Zend_Pdf_Element object
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function add(Zend_Pdf_Element_Name $name, Zend_Pdf_Element $val)
|
||||
{
|
||||
$this->_items[$name->value] = $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return dictionary keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
return array_keys($this->_items);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* @param string $property
|
||||
* @return Zend_Pdf_Element | null
|
||||
*/
|
||||
public function __get($item)
|
||||
{
|
||||
$element = isset($this->_items[$item]) ? $this->_items[$item]
|
||||
: null;
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($item, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
unset($this->_items[$item]);
|
||||
} else {
|
||||
$this->_items[$item] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_DICTIONARY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
$outStr = '<<';
|
||||
$lastNL = 0;
|
||||
|
||||
foreach ($this->_items as $name => $element) {
|
||||
if (!is_object($element)) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Wrong data');
|
||||
}
|
||||
|
||||
if (strlen($outStr) - $lastNL > 128) {
|
||||
$outStr .= "\n";
|
||||
$lastNL = strlen($outStr);
|
||||
}
|
||||
|
||||
$nameObj = new Zend_Pdf_Element_Name($name);
|
||||
$outStr .= $nameObj->toString($factory) . ' ' . $element->toString($factory) . ' ';
|
||||
}
|
||||
$outStr .= '>>';
|
||||
|
||||
return $outStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
if (isset($this->_items['Type'])) {
|
||||
if ($this->_items['Type']->value == 'Pages') {
|
||||
// It's a page tree node
|
||||
// skip it and its children
|
||||
return new Zend_Pdf_Element_Null();
|
||||
}
|
||||
|
||||
if ($this->_items['Type']->value == 'Page' &&
|
||||
$mode == Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES
|
||||
) {
|
||||
// It's a page node, skip it
|
||||
return new Zend_Pdf_Element_Null();
|
||||
}
|
||||
}
|
||||
|
||||
$newDictionary = new self();
|
||||
foreach ($this->_items as $key => $value) {
|
||||
$newDictionary->_items[$key] = $value->makeClone($factory, $processed, $mode);
|
||||
}
|
||||
|
||||
return $newDictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set top level parent indirect object.
|
||||
*
|
||||
* @param Zend_Pdf_Element_Object $parent
|
||||
*/
|
||||
public function setParentObject(Zend_Pdf_Element_Object $parent)
|
||||
{
|
||||
parent::setParentObject($parent);
|
||||
|
||||
foreach ($this->_items as $item) {
|
||||
$item->setParentObject($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PDF element to PHP type.
|
||||
*
|
||||
* Dictionary is returned as an associative array
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function toPhp()
|
||||
{
|
||||
$phpArray = array();
|
||||
|
||||
foreach ($this->_items as $itemName => $item) {
|
||||
$phpArray[$itemName] = $item->toPhp();
|
||||
}
|
||||
|
||||
return $phpArray;
|
||||
}
|
||||
}
|
||||
161
Zend/Pdf/Element/Name.php
Normal file
161
Zend/Pdf/Element/Name.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Name.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'name' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Name extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $val
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val)
|
||||
{
|
||||
settype($val, 'string');
|
||||
if (strpos($val,"\x00") !== false) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Null character is not allowed in PDF Names');
|
||||
}
|
||||
$this->value = (string)$val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_NAME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Escape string according to the PDF rules
|
||||
*
|
||||
* @param string $inStr
|
||||
* @return string
|
||||
*/
|
||||
public static function escape($inStr)
|
||||
{
|
||||
$outStr = '';
|
||||
|
||||
for ($count = 0; $count < strlen($inStr); $count++) {
|
||||
$nextCode = ord($inStr[$count]);
|
||||
|
||||
switch ($inStr[$count]) {
|
||||
case '(':
|
||||
// fall through to next case
|
||||
case ')':
|
||||
// fall through to next case
|
||||
case '<':
|
||||
// fall through to next case
|
||||
case '>':
|
||||
// fall through to next case
|
||||
case '[':
|
||||
// fall through to next case
|
||||
case ']':
|
||||
// fall through to next case
|
||||
case '{':
|
||||
// fall through to next case
|
||||
case '}':
|
||||
// fall through to next case
|
||||
case '/':
|
||||
// fall through to next case
|
||||
case '%':
|
||||
// fall through to next case
|
||||
case '\\':
|
||||
// fall through to next case
|
||||
case '#':
|
||||
$outStr .= sprintf('#%02X', $nextCode);
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($nextCode >= 33 && $nextCode <= 126 ) {
|
||||
// Visible ASCII symbol
|
||||
$outStr .= $inStr[$count];
|
||||
} else {
|
||||
$outStr .= sprintf('#%02X', $nextCode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $outStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unescape string according to the PDF rules
|
||||
*
|
||||
* @param string $inStr
|
||||
* @return string
|
||||
*/
|
||||
public static function unescape($inStr)
|
||||
{
|
||||
$outStr = '';
|
||||
|
||||
for ($count = 0; $count < strlen($inStr); $count++) {
|
||||
if ($inStr[$count] != '#' ) {
|
||||
$outStr .= $inStr[$count];
|
||||
} else {
|
||||
// Escape sequence
|
||||
$outStr .= chr(base_convert(substr($inStr, $count+1, 2), 16, 10 ));
|
||||
$count +=2;
|
||||
}
|
||||
}
|
||||
return $outStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
return '/' . self::escape((string)$this->value);
|
||||
}
|
||||
}
|
||||
75
Zend/Pdf/Element/Null.php
Normal file
75
Zend/Pdf/Element/Null.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Null.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'null' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Null extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value. Always null.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $value;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->value = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
}
|
||||
95
Zend/Pdf/Element/Numeric.php
Normal file
95
Zend/Pdf/Element/Numeric.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Numeric.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'numeric' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Numeric extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value
|
||||
*
|
||||
* @var numeric
|
||||
*/
|
||||
public $value;
|
||||
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param numeric $val
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val)
|
||||
{
|
||||
if ( !is_numeric($val) ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Argument must be numeric');
|
||||
}
|
||||
|
||||
$this->value = $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return Zend_Pdf_Element::TYPE_NUMERIC;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return object as string
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
if (is_integer($this->value)) {
|
||||
return (string)$this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* PDF doesn't support exponental format.
|
||||
* Fixed point format must be used instead
|
||||
*/
|
||||
$prec = 0; $v = $this->value;
|
||||
while (abs( floor($v) - $v ) > 1e-10) {
|
||||
$prec++; $v *= 10;
|
||||
}
|
||||
return sprintf("%.{$prec}F", $this->value);
|
||||
}
|
||||
}
|
||||
284
Zend/Pdf/Element/Object.php
Normal file
284
Zend/Pdf/Element/Object.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Object.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
|
||||
/**
|
||||
* PDF file 'indirect object' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Object extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value
|
||||
*
|
||||
* @var Zend_Pdf_Element
|
||||
*/
|
||||
protected $_value;
|
||||
|
||||
/**
|
||||
* Object number within PDF file
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_objNum;
|
||||
|
||||
/**
|
||||
* Generation number
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_genNum;
|
||||
|
||||
/**
|
||||
* Reference to the factory.
|
||||
*
|
||||
* @var Zend_Pdf_ElementFactory
|
||||
*/
|
||||
protected $_factory;
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param Zend_Pdf_Element $val
|
||||
* @param integer $objNum
|
||||
* @param integer $genNum
|
||||
* @param Zend_Pdf_ElementFactory $factory
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory)
|
||||
{
|
||||
if ($val instanceof self) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.');
|
||||
}
|
||||
|
||||
if ( !(is_integer($objNum) && $objNum > 0) ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Object number must be positive integer.');
|
||||
}
|
||||
|
||||
if ( !(is_integer($genNum) && $genNum >= 0) ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
|
||||
}
|
||||
|
||||
$this->_value = $val;
|
||||
$this->_objNum = $objNum;
|
||||
$this->_genNum = $genNum;
|
||||
$this->_factory = $factory;
|
||||
|
||||
$this->setParentObject($this);
|
||||
|
||||
$factory->registerObject($this, $objNum . ' ' . $genNum);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check, that object is generated by specified factory
|
||||
*
|
||||
* @return Zend_Pdf_ElementFactory
|
||||
*/
|
||||
public function getFactory()
|
||||
{
|
||||
return $this->_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_value->getType();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get object number
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getObjNum()
|
||||
{
|
||||
return $this->_objNum;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get generation number
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getGenNum()
|
||||
{
|
||||
return $this->_genNum;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return reference to the object
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
if ($factory === null) {
|
||||
$shift = 0;
|
||||
} else {
|
||||
$shift = $factory->getEnumerationShift($this->_factory);
|
||||
}
|
||||
|
||||
return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dump object to a string to save within PDF file.
|
||||
*
|
||||
* $factory parameter defines operation context.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function dump(Zend_Pdf_ElementFactory $factory)
|
||||
{
|
||||
$shift = $factory->getEnumerationShift($this->_factory);
|
||||
|
||||
return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
|
||||
. $this->_value->toString($factory) . "\n"
|
||||
. "endobj\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* @param string $property
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
return $this->_value->$property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($property, $value)
|
||||
{
|
||||
$this->_value->$property = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call handler
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->_value, $method), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
$id = spl_object_hash($this);
|
||||
if (isset($processed[$id])) {
|
||||
// Do nothing if object is already processed
|
||||
// return it
|
||||
return $processed[$id];
|
||||
}
|
||||
|
||||
// Create obect with null value and register it in $processed container
|
||||
$processed[$id] = $clonedObject = $factory->newObject(new Zend_Pdf_Element_Null());
|
||||
|
||||
// Pecursively process actual data
|
||||
$clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
|
||||
|
||||
if ($clonedObject->_value instanceof Zend_Pdf_Element_Null) {
|
||||
// Do not store null objects within $processed container since it may be filtered
|
||||
// by $mode parameter but used in some future pass
|
||||
unset($processed[$id]);
|
||||
|
||||
// Return direct null object
|
||||
return $clonedObject->_value;
|
||||
}
|
||||
|
||||
return $clonedObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark object as modified, to include it into new PDF file segment
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$this->_factory->markAsModified($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return object, which can be used to identify object and its references identity
|
||||
*
|
||||
* @return Zend_Pdf_Element_Object
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources, used by object
|
||||
*/
|
||||
public function cleanUp()
|
||||
{
|
||||
$this->_value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PDF element to PHP type.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function toPhp()
|
||||
{
|
||||
return $this->_value->toPhp();
|
||||
}
|
||||
}
|
||||
453
Zend/Pdf/Element/Object/Stream.php
Normal file
453
Zend/Pdf/Element/Object/Stream.php
Normal file
@@ -0,0 +1,453 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Stream.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Stream.php';
|
||||
require_once 'Zend/Pdf/Element/Dictionary.php';
|
||||
require_once 'Zend/Pdf/Element/Numeric.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Element_Object */
|
||||
require_once 'Zend/Pdf/Element/Object.php';
|
||||
|
||||
/**
|
||||
* PDF file 'stream object' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Object_Stream extends Zend_Pdf_Element_Object
|
||||
{
|
||||
/**
|
||||
* StreamObject dictionary
|
||||
* Required enries:
|
||||
* Length
|
||||
*
|
||||
* @var Zend_Pdf_Element_Dictionary
|
||||
*/
|
||||
private $_dictionary;
|
||||
|
||||
/**
|
||||
* Flag which signals, that stream is decoded
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_streamDecoded;
|
||||
|
||||
/**
|
||||
* Stored original stream object dictionary.
|
||||
* Used to decode stream at access time.
|
||||
*
|
||||
* The only properties affecting decoding are sored here.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
private $_initialDictionaryData = null;
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param mixed $val
|
||||
* @param integer $objNum
|
||||
* @param integer $genNum
|
||||
* @param Zend_Pdf_ElementFactory $factory
|
||||
* @param Zend_Pdf_Element_Dictionary|null $dictionary
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory, $dictionary = null)
|
||||
{
|
||||
parent::__construct(new Zend_Pdf_Element_Stream($val), $objNum, $genNum, $factory);
|
||||
|
||||
if ($dictionary === null) {
|
||||
$this->_dictionary = new Zend_Pdf_Element_Dictionary();
|
||||
$this->_dictionary->Length = new Zend_Pdf_Element_Numeric(strlen( $val ));
|
||||
$this->_streamDecoded = true;
|
||||
} else {
|
||||
$this->_dictionary = $dictionary;
|
||||
$this->_streamDecoded = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract dictionary data which are used to store information and to normalize filters
|
||||
* information before defiltering.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _extractDictionaryData()
|
||||
{
|
||||
$dictionaryArray = array();
|
||||
|
||||
$dictionaryArray['Filter'] = array();
|
||||
$dictionaryArray['DecodeParms'] = array();
|
||||
if ($this->_dictionary->Filter === null) {
|
||||
// Do nothing.
|
||||
} else if ($this->_dictionary->Filter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
|
||||
foreach ($this->_dictionary->Filter->items as $id => $filter) {
|
||||
$dictionaryArray['Filter'][$id] = $filter->value;
|
||||
$dictionaryArray['DecodeParms'][$id] = array();
|
||||
|
||||
if ($this->_dictionary->DecodeParms !== null ) {
|
||||
if ($this->_dictionary->DecodeParms->items[$id] !== null &&
|
||||
$this->_dictionary->DecodeParms->items[$id]->value !== null ) {
|
||||
foreach ($this->_dictionary->DecodeParms->items[$id]->getKeys() as $paramKey) {
|
||||
$dictionaryArray['DecodeParms'][$id][$paramKey] =
|
||||
$this->_dictionary->DecodeParms->items[$id]->$paramKey->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($this->_dictionary->Filter->getType() != Zend_Pdf_Element::TYPE_NULL) {
|
||||
$dictionaryArray['Filter'][0] = $this->_dictionary->Filter->value;
|
||||
$dictionaryArray['DecodeParms'][0] = array();
|
||||
if ($this->_dictionary->DecodeParms !== null ) {
|
||||
foreach ($this->_dictionary->DecodeParms->getKeys() as $paramKey) {
|
||||
$dictionaryArray['DecodeParms'][0][$paramKey] =
|
||||
$this->_dictionary->DecodeParms->$paramKey->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_dictionary->F !== null) {
|
||||
$dictionaryArray['F'] = $this->_dictionary->F->value;
|
||||
}
|
||||
|
||||
$dictionaryArray['FFilter'] = array();
|
||||
$dictionaryArray['FDecodeParms'] = array();
|
||||
if ($this->_dictionary->FFilter === null) {
|
||||
// Do nothing.
|
||||
} else if ($this->_dictionary->FFilter->getType() == Zend_Pdf_Element::TYPE_ARRAY) {
|
||||
foreach ($this->_dictionary->FFilter->items as $id => $filter) {
|
||||
$dictionaryArray['FFilter'][$id] = $filter->value;
|
||||
$dictionaryArray['FDecodeParms'][$id] = array();
|
||||
|
||||
if ($this->_dictionary->FDecodeParms !== null ) {
|
||||
if ($this->_dictionary->FDecodeParms->items[$id] !== null &&
|
||||
$this->_dictionary->FDecodeParms->items[$id]->value !== null) {
|
||||
foreach ($this->_dictionary->FDecodeParms->items[$id]->getKeys() as $paramKey) {
|
||||
$dictionaryArray['FDecodeParms'][$id][$paramKey] =
|
||||
$this->_dictionary->FDecodeParms->items[$id]->items[$paramKey]->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$dictionaryArray['FFilter'][0] = $this->_dictionary->FFilter->value;
|
||||
$dictionaryArray['FDecodeParms'][0] = array();
|
||||
if ($this->_dictionary->FDecodeParms !== null ) {
|
||||
foreach ($this->_dictionary->FDecodeParms->getKeys() as $paramKey) {
|
||||
$dictionaryArray['FDecodeParms'][0][$paramKey] =
|
||||
$this->_dictionary->FDecodeParms->items[$paramKey]->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $dictionaryArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode stream
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
private function _decodeStream()
|
||||
{
|
||||
if ($this->_initialDictionaryData === null) {
|
||||
$this->_initialDictionaryData = $this->_extractDictionaryData();
|
||||
}
|
||||
|
||||
/**
|
||||
* All applied stream filters must be processed to decode stream.
|
||||
* If we don't recognize any of applied filetrs an exception should be thrown here
|
||||
*/
|
||||
if (isset($this->_initialDictionaryData['F'])) {
|
||||
/** @todo Check, how external files can be processed. */
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('External filters are not supported now.');
|
||||
}
|
||||
|
||||
foreach ($this->_initialDictionaryData['Filter'] as $id => $filterName ) {
|
||||
$valueRef = &$this->_value->value->getRef();
|
||||
$this->_value->value->touch();
|
||||
switch ($filterName) {
|
||||
case 'ASCIIHexDecode':
|
||||
require_once 'Zend/Pdf/Filter/AsciiHex.php';
|
||||
$valueRef = Zend_Pdf_Filter_AsciiHex::decode($valueRef);
|
||||
break;
|
||||
|
||||
case 'ASCII85Decode':
|
||||
require_once 'Zend/Pdf/Filter/Ascii85.php';
|
||||
$valueRef = Zend_Pdf_Filter_Ascii85::decode($valueRef);
|
||||
break;
|
||||
|
||||
case 'FlateDecode':
|
||||
require_once 'Zend/Pdf/Filter/Compression/Flate.php';
|
||||
$valueRef = Zend_Pdf_Filter_Compression_Flate::decode($valueRef,
|
||||
$this->_initialDictionaryData['DecodeParms'][$id]);
|
||||
break;
|
||||
|
||||
case 'LZWDecode':
|
||||
require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
|
||||
$valueRef = Zend_Pdf_Filter_Compression_Lzw::decode($valueRef,
|
||||
$this->_initialDictionaryData['DecodeParms'][$id]);
|
||||
break;
|
||||
|
||||
case 'RunLengthDecode':
|
||||
require_once 'Zend/Pdf/Filter/RunLength.php';
|
||||
$valueRef = Zend_Pdf_Filter_RunLength::decode($valueRef);
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unknown stream filter: \'' . $filterName . '\'.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_streamDecoded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode stream
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
private function _encodeStream()
|
||||
{
|
||||
/**
|
||||
* All applied stream filters must be processed to encode stream.
|
||||
* If we don't recognize any of applied filetrs an exception should be thrown here
|
||||
*/
|
||||
if (isset($this->_initialDictionaryData['F'])) {
|
||||
/** @todo Check, how external files can be processed. */
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('External filters are not supported now.');
|
||||
}
|
||||
|
||||
$filters = array_reverse($this->_initialDictionaryData['Filter'], true);
|
||||
|
||||
foreach ($filters as $id => $filterName ) {
|
||||
$valueRef = &$this->_value->value->getRef();
|
||||
$this->_value->value->touch();
|
||||
switch ($filterName) {
|
||||
case 'ASCIIHexDecode':
|
||||
require_once 'Zend/Pdf/Filter/AsciiHex.php';
|
||||
$valueRef = Zend_Pdf_Filter_AsciiHex::encode($valueRef);
|
||||
break;
|
||||
|
||||
case 'ASCII85Decode':
|
||||
require_once 'Zend/Pdf/Filter/Ascii85.php';
|
||||
$valueRef = Zend_Pdf_Filter_Ascii85::encode($valueRef);
|
||||
break;
|
||||
|
||||
case 'FlateDecode':
|
||||
require_once 'Zend/Pdf/Filter/Compression/Flate.php';
|
||||
$valueRef = Zend_Pdf_Filter_Compression_Flate::encode($valueRef,
|
||||
$this->_initialDictionaryData['DecodeParms'][$id]);
|
||||
break;
|
||||
|
||||
case 'LZWDecode':
|
||||
require_once 'Zend/Pdf/Filter/Compression/Lzw.php';
|
||||
$valueRef = Zend_Pdf_Filter_Compression_Lzw::encode($valueRef,
|
||||
$this->_initialDictionaryData['DecodeParms'][$id]);
|
||||
break;
|
||||
|
||||
case 'RunLengthDecode':
|
||||
require_once 'Zend/Pdf/Filter/RunLength.php';
|
||||
$valueRef = Zend_Pdf_Filter_RunLength::encode($valueRef);
|
||||
break;
|
||||
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unknown stream filter: \'' . $filterName . '\'.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_streamDecoded = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* @param string $property
|
||||
* @return mixed
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
if ($property == 'dictionary') {
|
||||
/**
|
||||
* If stream is not decoded yet, then store original decoding options (do it only once).
|
||||
*/
|
||||
if (( !$this->_streamDecoded ) && ($this->_initialDictionaryData === null)) {
|
||||
$this->_initialDictionaryData = $this->_extractDictionaryData();
|
||||
}
|
||||
|
||||
return $this->_dictionary;
|
||||
}
|
||||
|
||||
if ($property == 'value') {
|
||||
if (!$this->_streamDecoded) {
|
||||
$this->_decodeStream();
|
||||
}
|
||||
|
||||
return $this->_value->value->getRef();
|
||||
}
|
||||
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unknown stream object property requested.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($property, $value)
|
||||
{
|
||||
if ($property == 'value') {
|
||||
$valueRef = &$this->_value->value->getRef();
|
||||
$valueRef = $value;
|
||||
$this->_value->value->touch();
|
||||
|
||||
$this->_streamDecoded = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unknown stream object property: \'' . $property . '\'.');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Treat stream data as already encoded
|
||||
*/
|
||||
public function skipFilters()
|
||||
{
|
||||
$this->_streamDecoded = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call handler
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (!$this->_streamDecoded) {
|
||||
$this->_decodeStream();
|
||||
}
|
||||
|
||||
switch (count($args)) {
|
||||
case 0:
|
||||
return $this->_value->$method();
|
||||
case 1:
|
||||
return $this->_value->$method($args[0]);
|
||||
default:
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Unsupported number of arguments');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
$id = spl_object_hash($this);
|
||||
if (isset($processed[$id])) {
|
||||
// Do nothing if object is already processed
|
||||
// return it
|
||||
return $processed[$id];
|
||||
}
|
||||
|
||||
$streamValue = $this->_value;
|
||||
$streamDictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
|
||||
|
||||
// Make new empty instance of stream object and register it in $processed container
|
||||
$processed[$id] = $clonedObject = $factory->newStreamObject('');
|
||||
|
||||
// Copy current object data and state
|
||||
$clonedObject->_dictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
|
||||
$clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
|
||||
$clonedObject->_initialDictionaryData = $this->_initialDictionaryData;
|
||||
$clonedObject->_streamDecoded = $this->_streamDecoded;
|
||||
|
||||
return $clonedObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump object to a string to save within PDF file
|
||||
*
|
||||
* $factory parameter defines operation context.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function dump(Zend_Pdf_ElementFactory $factory)
|
||||
{
|
||||
$shift = $factory->getEnumerationShift($this->_factory);
|
||||
|
||||
if ($this->_streamDecoded) {
|
||||
$this->_initialDictionaryData = $this->_extractDictionaryData();
|
||||
$this->_encodeStream();
|
||||
} else if ($this->_initialDictionaryData != null) {
|
||||
$newDictionary = $this->_extractDictionaryData();
|
||||
|
||||
if ($this->_initialDictionaryData !== $newDictionary) {
|
||||
$this->_decodeStream();
|
||||
$this->_initialDictionaryData = $newDictionary;
|
||||
$this->_encodeStream();
|
||||
}
|
||||
}
|
||||
|
||||
// Update stream length
|
||||
$this->dictionary->Length->value = $this->_value->length();
|
||||
|
||||
return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
|
||||
. $this->dictionary->toString($factory) . "\n"
|
||||
. $this->_value->toString($factory) . "\n"
|
||||
. "endobj\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources, used by object
|
||||
*/
|
||||
public function cleanUp()
|
||||
{
|
||||
$this->_dictionary = null;
|
||||
$this->_value = null;
|
||||
}
|
||||
}
|
||||
303
Zend/Pdf/Element/Reference.php
Normal file
303
Zend/Pdf/Element/Reference.php
Normal file
@@ -0,0 +1,303 @@
|
||||
<?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 license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Reference.php 23775 2011-03-01 17:25:24Z ralph $
|
||||
*/
|
||||
|
||||
|
||||
/** Internally used classes */
|
||||
require_once 'Zend/Pdf/Element/Null.php';
|
||||
|
||||
|
||||
/** Zend_Pdf_Element */
|
||||
require_once 'Zend/Pdf/Element.php';
|
||||
|
||||
/**
|
||||
* PDF file 'reference' element implementation
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Pdf
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Pdf_Element_Reference extends Zend_Pdf_Element
|
||||
{
|
||||
/**
|
||||
* Object value
|
||||
* The reference to the object
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_ref;
|
||||
|
||||
/**
|
||||
* Object number within PDF file
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_objNum;
|
||||
|
||||
/**
|
||||
* Generation number
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_genNum;
|
||||
|
||||
/**
|
||||
* Reference context
|
||||
*
|
||||
* @var Zend_Pdf_Element_Reference_Context
|
||||
*/
|
||||
private $_context;
|
||||
|
||||
|
||||
/**
|
||||
* Reference to the factory.
|
||||
*
|
||||
* It's the same as referenced object factory, but we save it here to avoid
|
||||
* unnecessary dereferencing, whech can produce cascade dereferencing and parsing.
|
||||
* The same for duplication of getFactory() function. It can be processed by __call()
|
||||
* method, but we catch it here.
|
||||
*
|
||||
* @var Zend_Pdf_ElementFactory
|
||||
*/
|
||||
private $_factory;
|
||||
|
||||
/**
|
||||
* Object constructor:
|
||||
*
|
||||
* @param integer $objNum
|
||||
* @param integer $genNum
|
||||
* @param Zend_Pdf_Element_Reference_Context $context
|
||||
* @param Zend_Pdf_ElementFactory $factory
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
public function __construct($objNum, $genNum = 0, Zend_Pdf_Element_Reference_Context $context, Zend_Pdf_ElementFactory $factory)
|
||||
{
|
||||
if ( !(is_integer($objNum) && $objNum > 0) ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Object number must be positive integer');
|
||||
}
|
||||
if ( !(is_integer($genNum) && $genNum >= 0) ) {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Generation number must be non-negative integer');
|
||||
}
|
||||
|
||||
$this->_objNum = $objNum;
|
||||
$this->_genNum = $genNum;
|
||||
$this->_ref = null;
|
||||
$this->_context = $context;
|
||||
$this->_factory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check, that object is generated by specified factory
|
||||
*
|
||||
* @return Zend_Pdf_ElementFactory
|
||||
*/
|
||||
public function getFactory()
|
||||
{
|
||||
return $this->_factory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return type of the element.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
return $this->_ref->getType();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return reference to the object
|
||||
*
|
||||
* @param Zend_Pdf_Factory $factory
|
||||
* @return string
|
||||
*/
|
||||
public function toString($factory = null)
|
||||
{
|
||||
if ($factory === null) {
|
||||
$shift = 0;
|
||||
} else {
|
||||
$shift = $factory->getEnumerationShift($this->_factory);
|
||||
}
|
||||
|
||||
return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dereference.
|
||||
* Take inderect object, take $value member of this object (must be Zend_Pdf_Element),
|
||||
* take reference to the $value member of this object and assign it to
|
||||
* $value member of current PDF Reference object
|
||||
* $obj can be null
|
||||
*
|
||||
* @throws Zend_Pdf_Exception
|
||||
*/
|
||||
private function _dereference()
|
||||
{
|
||||
if (($obj = $this->_factory->fetchObject($this->_objNum . ' ' . $this->_genNum)) === null) {
|
||||
$obj = $this->_context->getParser()->getObject(
|
||||
$this->_context->getRefTable()->getOffset($this->_objNum . ' ' . $this->_genNum . ' R'),
|
||||
$this->_context
|
||||
);
|
||||
}
|
||||
|
||||
if ($obj === null ) {
|
||||
$this->_ref = new Zend_Pdf_Element_Null();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($obj->toString() != $this->_objNum . ' ' . $this->_genNum . ' R') {
|
||||
require_once 'Zend/Pdf/Exception.php';
|
||||
throw new Zend_Pdf_Exception('Incorrect reference to the object');
|
||||
}
|
||||
|
||||
$this->_ref = $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach PDF object from the factory (if applicable), clone it and attach to new factory.
|
||||
*
|
||||
* @param Zend_Pdf_ElementFactory $factory The factory to attach
|
||||
* @param array &$processed List of already processed indirect objects, used to avoid objects duplication
|
||||
* @param integer $mode Cloning mode (defines filter for objects cloning)
|
||||
* @returns Zend_Pdf_Element
|
||||
*/
|
||||
public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
// This code duplicates code in Zend_Pdf_Element_Object class,
|
||||
// but allows to avoid unnecessary method call in most cases
|
||||
$id = spl_object_hash($this->_ref);
|
||||
if (isset($processed[$id])) {
|
||||
// Do nothing if object is already processed
|
||||
// return it
|
||||
return $processed[$id];
|
||||
}
|
||||
|
||||
return $this->_ref->makeClone($factory, $processed, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark object as modified, to include it into new PDF file segment.
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
$this->_ref->touch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return object, which can be used to identify object and its references identity
|
||||
*
|
||||
* @return Zend_Pdf_Element_Object
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
return $this->_ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get handler
|
||||
*
|
||||
* @param string $property
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
return $this->_ref->$property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set handler
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($property, $value)
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
$this->_ref->$property = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call handler
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
return call_user_func_array(array($this->_ref, $method), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources
|
||||
*/
|
||||
public function cleanUp()
|
||||
{
|
||||
$this->_ref = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PDF element to PHP type.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function toPhp()
|
||||
{
|
||||
if ($this->_ref === null) {
|
||||
$this->_dereference();
|
||||
}
|
||||
|
||||
return $this->_ref->toPhp();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user