Replace Zend w/ icingaweb2-vendor-zf1

refs #13461
This commit is contained in:
Eric Lippmann 2016-12-08 14:16:04 +01:00
parent 1b6e7177a3
commit a4513ba5cf
1039 changed files with 581 additions and 174437 deletions

View File

@ -19,13 +19,11 @@ Packager: Icinga Team <info@icinga.org>
%define php_cli php-cli
%define wwwconfigdir %{_sysconfdir}/httpd/conf.d
%define wwwuser apache
%define zend php-ZendFramework
%endif
%if 0%{?suse_version}
%define wwwconfigdir %{_sysconfdir}/apache2/conf.d
%define wwwuser wwwrun
%define zend %{name}-vendor-Zend
%if 0%{?suse_version} == 1110
%define php php53
Requires: apache2-mod_php53
@ -78,14 +76,11 @@ Summary: Icinga Web 2 PHP library
Group: Development/Libraries
Requires: %{php} >= 5.3.0
Requires: %{php}-gd %{php}-intl
Requires: %{name}-vendor-zf1 = 1.12.20-1%{?dist}
%{?amzn:Requires: %{php}-pecl-imagick}
%{?fedora:Requires: php-pecl-imagick}
%{?rhel:Requires: php-pecl-imagick}
%{?suse_version:Requires: %{php}-gettext %{php}-json %{php}-openssl %{php}-posix}
Requires: %{zend}
%{?amzn:Requires: %{zend}-Db-Adapter-Pdo-Mysql %{zend}-Db-Adapter-Pdo-Pgsql}
%{?fedora:Requires: %{zend}-Db-Adapter-Pdo-Mysql %{zend}-Db-Adapter-Pdo-Pgsql}
%{?rhel:Requires: %{zend}-Db-Adapter-Pdo-Mysql %{zend}-Db-Adapter-Pdo-Pgsql}
%description -n php-Icinga
Icinga Web 2 PHP library
@ -165,16 +160,17 @@ Requires: %{php} >= 5.3.0
Icinga Web 2 vendor library Parsedown
%package vendor-Zend
Version: 1.12.15
%package vendor-zf1
Version: 1.12.20
Release: 1%{?dist}
Summary: Icinga Web 2 vendor library Zend Framework
Summary: Icinga Web 2's fork of Zend Framework 1
Group: Development/Libraries
License: BSD
Requires: %{php} >= 5.3.0
Obsoletes: %{name}-vendor-Zend
%description vendor-Zend
Icinga Web 2 vendor library Zend
%description vendor-zf1
Icinga Web 2's fork of Zend Framework 1
%prep
@ -281,6 +277,6 @@ exit 0
%{basedir}/library/vendor/Parsedown
%files vendor-Zend
%files vendor-zf1
%defattr(-,root,root)
%{basedir}/library/vendor/Zend

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Acl
*/
/**
* @see Zend_Acl_Role_Interface
*/
/**
* @see Zend_Acl_Resource_Interface
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Acl_Assert_Interface
{
/**
* Returns true if and only if the assertion conditions are met
*
* This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
* $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
* privileges, respectively.
*
* @param Zend_Acl $acl
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Resource_Interface $resource
* @param string $privilege
* @return boolean
*/
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null,
$privilege = null);
}

View File

@ -1,35 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Exception
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Acl_Exception extends Zend_Exception
{}

View File

@ -1,73 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Acl_Resource_Interface
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Acl_Resource implements Zend_Acl_Resource_Interface
{
/**
* Unique id of Resource
*
* @var string
*/
protected $_resourceId;
/**
* Sets the Resource identifier
*
* @param string $resourceId
*/
public function __construct($resourceId)
{
$this->_resourceId = (string) $resourceId;
}
/**
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
*
* @return string
*/
public function getResourceId()
{
return $this->_resourceId;
}
/**
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
* Proxies to getResourceId()
*
* @return string
*/
public function __toString()
{
return $this->getResourceId();
}
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Acl_Resource_Interface
{
/**
* Returns the string identifier of the Resource
*
* @return string
*/
public function getResourceId();
}

View File

@ -1,73 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Acl_Role_Interface
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Acl_Role implements Zend_Acl_Role_Interface
{
/**
* Unique id of Role
*
* @var string
*/
protected $_roleId;
/**
* Sets the Role identifier
*
* @param string $roleId
*/
public function __construct($roleId)
{
$this->_roleId = (string) $roleId;
}
/**
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
*
* @return string
*/
public function getRoleId()
{
return $this->_roleId;
}
/**
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
* Proxies to getRoleId()
*
* @return string
*/
public function __toString()
{
return $this->getRoleId();
}
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Acl_Role_Interface
{
/**
* Returns the string identifier of the Role
*
* @return string
*/
public function getRoleId();
}

View File

@ -1,265 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Acl_Role_Interface
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Acl_Role_Registry
{
/**
* Internal Role registry data storage
*
* @var array
*/
protected $_roles = array();
/**
* Adds a Role having an identifier unique to the registry
*
* The $parents parameter may be a reference to, or the string identifier for,
* a Role existing in the registry, or $parents may be passed as an array of
* these - mixing string identifiers and objects is ok - to indicate the Roles
* from which the newly added Role will directly inherit.
*
* In order to resolve potential ambiguities with conflicting rules inherited
* from different parents, the most recently added parent takes precedence over
* parents that were previously added. In other words, the first parent added
* will have the least priority, and the last parent added will have the
* highest priority.
*
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Role_Interface|string|array $parents
* @throws Zend_Acl_Role_Registry_Exception
* @return Zend_Acl_Role_Registry Provides a fluent interface
*/
public function add(Zend_Acl_Role_Interface $role, $parents = null)
{
$roleId = $role->getRoleId();
if ($this->has($roleId)) {
/**
* @see Zend_Acl_Role_Registry_Exception
*/
throw new Zend_Acl_Role_Registry_Exception("Role id '$roleId' already exists in the registry");
}
$roleParents = array();
if (null !== $parents) {
if (!is_array($parents)) {
$parents = array($parents);
}
/**
* @see Zend_Acl_Role_Registry_Exception
*/
foreach ($parents as $parent) {
try {
if ($parent instanceof Zend_Acl_Role_Interface) {
$roleParentId = $parent->getRoleId();
} else {
$roleParentId = $parent;
}
$roleParent = $this->get($roleParentId);
} catch (Zend_Acl_Role_Registry_Exception $e) {
throw new Zend_Acl_Role_Registry_Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
}
$roleParents[$roleParentId] = $roleParent;
$this->_roles[$roleParentId]['children'][$roleId] = $role;
}
}
$this->_roles[$roleId] = array(
'instance' => $role,
'parents' => $roleParents,
'children' => array()
);
return $this;
}
/**
* Returns the identified Role
*
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend_Acl_Role_Interface|string $role
* @throws Zend_Acl_Role_Registry_Exception
* @return Zend_Acl_Role_Interface
*/
public function get($role)
{
if ($role instanceof Zend_Acl_Role_Interface) {
$roleId = $role->getRoleId();
} else {
$roleId = (string) $role;
}
if (!$this->has($role)) {
/**
* @see Zend_Acl_Role_Registry_Exception
*/
throw new Zend_Acl_Role_Registry_Exception("Role '$roleId' not found");
}
return $this->_roles[$roleId]['instance'];
}
/**
* Returns true if and only if the Role exists in the registry
*
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend_Acl_Role_Interface|string $role
* @return boolean
*/
public function has($role)
{
if ($role instanceof Zend_Acl_Role_Interface) {
$roleId = $role->getRoleId();
} else {
$roleId = (string) $role;
}
return isset($this->_roles[$roleId]);
}
/**
* Returns an array of an existing Role's parents
*
* The array keys are the identifiers of the parent Roles, and the values are
* the parent Role instances. The parent Roles are ordered in this array by
* ascending priority. The highest priority parent Role, last in the array,
* corresponds with the parent Role most recently added.
*
* If the Role does not have any parents, then an empty array is returned.
*
* @param Zend_Acl_Role_Interface|string $role
* @uses Zend_Acl_Role_Registry::get()
* @return array
*/
public function getParents($role)
{
$roleId = $this->get($role)->getRoleId();
return $this->_roles[$roleId]['parents'];
}
/**
* Returns true if and only if $role inherits from $inherit
*
* Both parameters may be either a Role or a Role identifier. If
* $onlyParents is true, then $role must inherit directly from
* $inherit in order to return true. By default, this method looks
* through the entire inheritance DAG to determine whether $role
* inherits from $inherit through its ancestor Roles.
*
* @param Zend_Acl_Role_Interface|string $role
* @param Zend_Acl_Role_Interface|string $inherit
* @param boolean $onlyParents
* @throws Zend_Acl_Role_Registry_Exception
* @return boolean
*/
public function inherits($role, $inherit, $onlyParents = false)
{
/**
* @see Zend_Acl_Role_Registry_Exception
*/
try {
$roleId = $this->get($role)->getRoleId();
$inheritId = $this->get($inherit)->getRoleId();
} catch (Zend_Acl_Role_Registry_Exception $e) {
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
}
$inherits = isset($this->_roles[$roleId]['parents'][$inheritId]);
if ($inherits || $onlyParents) {
return $inherits;
}
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
if ($this->inherits($parentId, $inheritId)) {
return true;
}
}
return false;
}
/**
* Removes the Role from the registry
*
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend_Acl_Role_Interface|string $role
* @throws Zend_Acl_Role_Registry_Exception
* @return Zend_Acl_Role_Registry Provides a fluent interface
*/
public function remove($role)
{
/**
* @see Zend_Acl_Role_Registry_Exception
*/
try {
$roleId = $this->get($role)->getRoleId();
} catch (Zend_Acl_Role_Registry_Exception $e) {
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
}
foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
unset($this->_roles[$childId]['parents'][$roleId]);
}
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
unset($this->_roles[$parentId]['children'][$roleId]);
}
unset($this->_roles[$roleId]);
return $this;
}
/**
* Removes all Roles from the registry
*
* @return Zend_Acl_Role_Registry Provides a fluent interface
*/
public function removeAll()
{
$this->_roles = array();
return $this;
}
public function getRoles()
{
return $this->_roles;
}
}

View File

@ -1,35 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Acl_Exception
*/
/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Acl_Role_Registry_Exception extends Zend_Acl_Exception
{}

View File

@ -1,438 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Application
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application
{
/**
* Autoloader to use
*
* @var Zend_Loader_Autoloader
*/
protected $_autoloader;
/**
* Bootstrap
*
* @var Zend_Application_Bootstrap_BootstrapAbstract
*/
protected $_bootstrap;
/**
* Application environment
*
* @var string
*/
protected $_environment;
/**
* Flattened (lowercase) option keys
*
* @var array
*/
protected $_optionKeys = array();
/**
* Options for Zend_Application
*
* @var array
*/
protected $_options = array();
/**
* Constructor
*
* Initialize application. Potentially initializes include_paths, PHP
* settings, and bootstrap class.
*
* @param string $environment
* @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
* @param bool $suppressNotFoundWarnings Should warnings be suppressed when a file is not found during autoloading?
* @throws Zend_Application_Exception When invalid options are provided
* @return void
*/
public function __construct($environment, $options = null, $suppressNotFoundWarnings = null)
{
$this->_environment = (string) $environment;
$this->_autoloader = Zend_Loader_Autoloader::getInstance();
$this->_autoloader->suppressNotFoundWarnings($suppressNotFoundWarnings);
if (null !== $options) {
if (is_string($options)) {
$options = $this->_loadConfig($options);
} elseif ($options instanceof Zend_Config) {
$options = $options->toArray();
} elseif (!is_array($options)) {
throw new Zend_Application_Exception(
'Invalid options provided; must be location of config file,'
. ' a config object, or an array'
);
}
$this->setOptions($options);
}
}
/**
* Retrieve current environment
*
* @return string
*/
public function getEnvironment()
{
return $this->_environment;
}
/**
* Retrieve autoloader instance
*
* @return Zend_Loader_Autoloader
*/
public function getAutoloader()
{
return $this->_autoloader;
}
/**
* Set application options
*
* @param array $options
* @throws Zend_Application_Exception When no bootstrap path is provided
* @throws Zend_Application_Exception When invalid bootstrap information are provided
* @return Zend_Application
*/
public function setOptions(array $options)
{
if (!empty($options['config'])) {
if (is_array($options['config'])) {
$_options = array();
foreach ($options['config'] as $tmp) {
$_options = $this->mergeOptions(
$_options, $this->_loadConfig($tmp)
);
}
$options = $this->mergeOptions($_options, $options);
} else {
$options = $this->mergeOptions(
$this->_loadConfig($options['config']), $options
);
}
}
$this->_options = $options;
$options = array_change_key_case($options, CASE_LOWER);
$this->_optionKeys = array_keys($options);
if (!empty($options['phpsettings'])) {
$this->setPhpSettings($options['phpsettings']);
}
if (!empty($options['includepaths'])) {
$this->setIncludePaths($options['includepaths']);
}
if (!empty($options['autoloadernamespaces'])) {
$this->setAutoloaderNamespaces($options['autoloadernamespaces']);
}
if (!empty($options['autoloaderzfpath'])) {
$autoloader = $this->getAutoloader();
if (method_exists($autoloader, 'setZfPath')) {
$zfPath = $options['autoloaderzfpath'];
$zfVersion = !empty($options['autoloaderzfversion'])
? $options['autoloaderzfversion']
: 'latest';
$autoloader->setZfPath($zfPath, $zfVersion);
}
}
if (!empty($options['bootstrap'])) {
$bootstrap = $options['bootstrap'];
if (is_string($bootstrap)) {
$this->setBootstrap($bootstrap);
} elseif (is_array($bootstrap)) {
if (empty($bootstrap['path'])) {
throw new Zend_Application_Exception(
'No bootstrap path provided'
);
}
$path = $bootstrap['path'];
$class = null;
if (!empty($bootstrap['class'])) {
$class = $bootstrap['class'];
}
$this->setBootstrap($path, $class);
} else {
throw new Zend_Application_Exception(
'Invalid bootstrap information provided'
);
}
}
return $this;
}
/**
* Retrieve application options (for caching)
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Is an option present?
*
* @param string $key
* @return bool
*/
public function hasOption($key)
{
return in_array(strtolower($key), $this->_optionKeys);
}
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
if ($this->hasOption($key)) {
$options = $this->getOptions();
$options = array_change_key_case($options, CASE_LOWER);
return $options[strtolower($key)];
}
return null;
}
/**
* Merge options recursively
*
* @param array $array1
* @param mixed $array2
* @return array
*/
public function mergeOptions(array $array1, $array2 = null)
{
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
? $this->mergeOptions($array1[$key], $array2[$key])
: $array2[$key];
} else {
$array1[$key] = $val;
}
}
}
return $array1;
}
/**
* Set PHP configuration settings
*
* @param array $settings
* @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
* @return Zend_Application
*/
public function setPhpSettings(array $settings, $prefix = '')
{
foreach ($settings as $key => $value) {
$key = empty($prefix) ? $key : $prefix . $key;
if (is_scalar($value)) {
ini_set($key, $value);
} elseif (is_array($value)) {
$this->setPhpSettings($value, $key . '.');
}
}
return $this;
}
/**
* Set include path
*
* @param array $paths
* @return Zend_Application
*/
public function setIncludePaths(array $paths)
{
$path = implode(PATH_SEPARATOR, $paths);
set_include_path($path . PATH_SEPARATOR . get_include_path());
return $this;
}
/**
* Set autoloader namespaces
*
* @param array $namespaces
* @return Zend_Application
*/
public function setAutoloaderNamespaces(array $namespaces)
{
$autoloader = $this->getAutoloader();
foreach ($namespaces as $namespace) {
$autoloader->registerNamespace($namespace);
}
return $this;
}
/**
* Set bootstrap path/class
*
* @param string $path
* @param string $class
* @return Zend_Application
*/
public function setBootstrap($path, $class = null)
{
// setOptions() can potentially send a null value; specify default
// here
if (null === $class) {
$class = 'Bootstrap';
}
if (!class_exists($class, false)) {
if (!class_exists($class, false)) {
throw new Zend_Application_Exception(
'Bootstrap class not found'
);
}
}
$this->_bootstrap = new $class($this);
if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {
throw new Zend_Application_Exception(
'Bootstrap class does not implement'
. ' Zend_Application_Bootstrap_Bootstrapper'
);
}
return $this;
}
/**
* Get bootstrap object
*
* @return Zend_Application_Bootstrap_BootstrapAbstract
*/
public function getBootstrap()
{
if (null === $this->_bootstrap) {
$this->_bootstrap = new Zend_Application_Bootstrap_Bootstrap($this);
}
return $this->_bootstrap;
}
/**
* Bootstrap application
*
* @param null|string|array $resource
* @return Zend_Application
*/
public function bootstrap($resource = null)
{
$this->getBootstrap()->bootstrap($resource);
return $this;
}
/**
* Run the application
*
* @return void
*/
public function run()
{
$this->getBootstrap()->run();
}
/**
* Load configuration file of options
*
* @param string $file
* @throws Zend_Application_Exception When invalid configuration file is provided
* @return array
*/
protected function _loadConfig($file)
{
$environment = $this->getEnvironment();
$suffix = pathinfo($file, PATHINFO_EXTENSION);
$suffix = ($suffix === 'dist')
? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
: $suffix;
switch (strtolower($suffix)) {
case 'ini':
$config = new Zend_Config_Ini($file, $environment);
break;
case 'xml':
$config = new Zend_Config_Xml($file, $environment);
break;
case 'json':
$config = new Zend_Config_Json($file, $environment);
break;
case 'yaml':
case 'yml':
$config = new Zend_Config_Yaml($file, $environment);
break;
case 'php':
case 'inc':
$config = include $file;
if (!is_array($config)) {
throw new Zend_Application_Exception(
'Invalid configuration file provided; PHP file does not'
. ' return array value'
);
}
return $config;
break;
default:
throw new Zend_Application_Exception(
'Invalid configuration file provided; unknown config type'
);
}
return $config->toArray();
}
}

View File

@ -1,167 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Bootstrap_BootstrapAbstract
*/
/**
* Concrete base class for bootstrap classes
*
* Registers and utilizes Zend_Controller_Front by default.
*
* @uses Zend_Application_Bootstrap_Bootstrap
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Bootstrap_Bootstrap
extends Zend_Application_Bootstrap_BootstrapAbstract
{
/**
* Application resource namespace
* @var false|string
*/
protected $_appNamespace = false;
/**
* Application resource autoloader
* @var Zend_Loader_Autoloader_Resource
*/
protected $_resourceLoader;
/**
* Constructor
*
* Ensure FrontController resource is registered
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
*/
public function __construct($application)
{
parent::__construct($application);
if ($application->hasOption('resourceloader')) {
$this->setOptions(
array(
'resourceloader' => $application->getOption(
'resourceloader'
)
)
);
}
$this->getResourceLoader();
if (!$this->hasPluginResource('FrontController')) {
$this->registerPluginResource('FrontController');
}
}
/**
* Run the application
*
* Checks to see that we have a default controller directory. If not, an
* exception is thrown.
*
* If so, it registers the bootstrap with the 'bootstrap' parameter of
* the front controller, and dispatches the front controller.
*
* @return mixed
* @throws Zend_Application_Bootstrap_Exception
*/
public function run()
{
$front = $this->getResource('FrontController');
$default = $front->getDefaultModule();
if (null === $front->getControllerDirectory($default)) {
throw new Zend_Application_Bootstrap_Exception(
'No default controller directory registered with front controller'
);
}
$front->setParam('bootstrap', $this);
$response = $front->dispatch();
if ($front->returnResponse()) {
return $response;
}
}
/**
* Set module resource loader
*
* @param Zend_Loader_Autoloader_Resource $loader
* @return Zend_Application_Module_Bootstrap
*/
public function setResourceLoader(Zend_Loader_Autoloader_Resource $loader)
{
$this->_resourceLoader = $loader;
return $this;
}
/**
* Retrieve module resource loader
*
* @return Zend_Loader_Autoloader_Resource
*/
public function getResourceLoader()
{
if ((null === $this->_resourceLoader)
&& (false !== ($namespace = $this->getAppNamespace()))
) {
$r = new ReflectionClass($this);
$path = $r->getFileName();
$this->setResourceLoader(
new Zend_Application_Module_Autoloader(
array(
'namespace' => $namespace,
'basePath' => dirname($path),
)
)
);
}
return $this->_resourceLoader;
}
/**
* Get application namespace (used for module autoloading)
*
* @return string
*/
public function getAppNamespace()
{
return $this->_appNamespace;
}
/**
* Set application namespace (for module autoloading)
*
* @param string
* @return Zend_Application_Bootstrap_Bootstrap
*/
public function setAppNamespace($value)
{
$this->_appNamespace = (string) $value;
return $this;
}
}

View File

@ -1,782 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Bootstrap_Bootstrapper
*/
/**
* @see Zend_Application_Bootstrap_ResourceBootstrapper
*/
/**
* Abstract base class for bootstrap classes
*
* @uses Zend_Application_Bootstrap_Bootstrapper
* @uses Zend_Application_Bootstrap_ResourceBootstrapper
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Application_Bootstrap_BootstrapAbstract
implements Zend_Application_Bootstrap_Bootstrapper,
Zend_Application_Bootstrap_ResourceBootstrapper
{
/**
* @var Zend_Application|Zend_Application_Bootstrap_Bootstrapper
*/
protected $_application;
/**
* @var array Internal resource methods (resource/method pairs)
*/
protected $_classResources;
/**
* @var object Resource container
*/
protected $_container;
/**
* @var string
*/
protected $_environment;
/**
* Flattened (lowercase) option keys used for lookups
*
* @var array
*/
protected $_optionKeys = array();
/**
* @var array
*/
protected $_options = array();
/**
* @var Zend_Loader_PluginLoader_Interface
*/
protected $_pluginLoader;
/**
* @var array Class-based resource plugins
*/
protected $_pluginResources = array();
/**
* @var array Initializers that have been run
*/
protected $_run = array();
/**
* @var array Initializers that have been started but not yet completed (circular dependency detection)
*/
protected $_started = array();
/**
* Constructor
*
* Sets application object, initializes options, and prepares list of
* initializer methods.
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
* @throws Zend_Application_Bootstrap_Exception When invalid application is provided
*/
public function __construct($application)
{
$this->setApplication($application);
$options = $application->getOptions();
$this->setOptions($options);
}
/**
* Set class state
*
* @param array $options
* @return Zend_Application_Bootstrap_BootstrapAbstract
*/
public function setOptions(array $options)
{
$this->_options = $this->mergeOptions($this->_options, $options);
$options = array_change_key_case($options, CASE_LOWER);
$this->_optionKeys = array_merge($this->_optionKeys, array_keys($options));
$methods = get_class_methods($this);
foreach ($methods as $key => $method) {
$methods[$key] = strtolower($method);
}
if (array_key_exists('pluginpaths', $options)) {
$pluginLoader = $this->getPluginLoader();
foreach ($options['pluginpaths'] as $prefix => $path) {
$pluginLoader->addPrefixPath($prefix, $path);
}
unset($options['pluginpaths']);
}
foreach ($options as $key => $value) {
$method = 'set' . strtolower($key);
if (in_array($method, $methods)) {
$this->$method($value);
} elseif ('resources' == $key) {
foreach ($value as $resource => $resourceOptions) {
$this->registerPluginResource($resource, $resourceOptions);
}
}
}
return $this;
}
/**
* Get current options from bootstrap
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Is an option present?
*
* @param string $key
* @return bool
*/
public function hasOption($key)
{
return in_array(strtolower($key), $this->_optionKeys);
}
/**
* Retrieve a single option
*
* @param string $key
* @return mixed
*/
public function getOption($key)
{
if ($this->hasOption($key)) {
$options = $this->getOptions();
$options = array_change_key_case($options, CASE_LOWER);
return $options[strtolower($key)];
}
return null;
}
/**
* Merge options recursively
*
* @param array $array1
* @param mixed $array2
* @return array
*/
public function mergeOptions(array $array1, $array2 = null)
{
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
? $this->mergeOptions($array1[$key], $array2[$key])
: $array2[$key];
} else {
$array1[$key] = $val;
}
}
}
return $array1;
}
/**
* Get class resources (as resource/method pairs)
*
* Uses get_class_methods() by default, reflection on prior to 5.2.6,
* as a bug prevents the usage of get_class_methods() there.
*
* @return array
*/
public function getClassResources()
{
if (null === $this->_classResources) {
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
$class = new ReflectionObject($this);
$classMethods = $class->getMethods();
$methodNames = array();
foreach ($classMethods as $method) {
$methodNames[] = $method->getName();
}
} else {
$methodNames = get_class_methods($this);
}
$this->_classResources = array();
foreach ($methodNames as $method) {
if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
$this->_classResources[strtolower(substr($method, 5))] = $method;
}
}
}
return $this->_classResources;
}
/**
* Get class resource names
*
* @return array
*/
public function getClassResourceNames()
{
$resources = $this->getClassResources();
return array_keys($resources);
}
/**
* Register a new resource plugin
*
* @param string|Zend_Application_Resource_Resource $resource
* @param mixed $options
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception When invalid resource is provided
*/
public function registerPluginResource($resource, $options = null)
{
if ($resource instanceof Zend_Application_Resource_Resource) {
$resource->setBootstrap($this);
$pluginName = $this->_resolvePluginResourceName($resource);
$this->_pluginResources[$pluginName] = $resource;
return $this;
}
if (!is_string($resource)) {
throw new Zend_Application_Bootstrap_Exception('Invalid resource provided to ' . __METHOD__);
}
$this->_pluginResources[$resource] = $options;
return $this;
}
/**
* Unregister a resource from the bootstrap
*
* @param string|Zend_Application_Resource_Resource $resource
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception When unknown resource type is provided
*/
public function unregisterPluginResource($resource)
{
if ($resource instanceof Zend_Application_Resource_Resource) {
if ($index = array_search($resource, $this->_pluginResources, true)) {
unset($this->_pluginResources[$index]);
}
return $this;
}
if (!is_string($resource)) {
throw new Zend_Application_Bootstrap_Exception('Unknown resource type provided to ' . __METHOD__);
}
$resource = strtolower($resource);
if (array_key_exists($resource, $this->_pluginResources)) {
unset($this->_pluginResources[$resource]);
}
return $this;
}
/**
* Is the requested plugin resource registered?
*
* @param string $resource
* @return bool
*/
public function hasPluginResource($resource)
{
return (null !== $this->getPluginResource($resource));
}
/**
* Get a registered plugin resource
*
* @param string $resource
* @return Zend_Application_Resource_Resource
* @throws Zend_Application_Bootstrap_Exception
*/
public function getPluginResource($resource)
{
if (array_key_exists(strtolower($resource), $this->_pluginResources)) {
$resource = strtolower($resource);
if (!$this->_pluginResources[$resource] instanceof Zend_Application_Resource_Resource) {
$resourceName = $this->_loadPluginResource($resource, $this->_pluginResources[$resource]);
if (!$resourceName) {
throw new Zend_Application_Bootstrap_Exception(sprintf('Unable to resolve plugin "%s"; no corresponding plugin with that name', $resource));
}
$resource = $resourceName;
}
return $this->_pluginResources[$resource];
}
foreach ($this->_pluginResources as $plugin => $spec) {
if ($spec instanceof Zend_Application_Resource_Resource) {
$pluginName = $this->_resolvePluginResourceName($spec);
if (0 === strcasecmp($resource, $pluginName)) {
unset($this->_pluginResources[$plugin]);
$this->_pluginResources[$pluginName] = $spec;
return $spec;
}
continue;
}
if (false !== $pluginName = $this->_loadPluginResource($plugin, $spec)) {
if (0 === strcasecmp($resource, $pluginName)) {
return $this->_pluginResources[$pluginName];
}
continue;
}
if (class_exists($plugin)
&& is_subclass_of($plugin, 'Zend_Application_Resource_Resource')
) { //@SEE ZF-7550
$spec = (array) $spec;
$spec['bootstrap'] = $this;
$instance = new $plugin($spec);
$pluginName = $this->_resolvePluginResourceName($instance);
unset($this->_pluginResources[$plugin]);
$this->_pluginResources[$pluginName] = $instance;
if (0 === strcasecmp($resource, $pluginName)) {
return $instance;
}
}
}
return null;
}
/**
* Retrieve all plugin resources
*
* @return array
*/
public function getPluginResources()
{
foreach (array_keys($this->_pluginResources) as $resource) {
$this->getPluginResource($resource);
}
return $this->_pluginResources;
}
/**
* Retrieve plugin resource names
*
* @return array
*/
public function getPluginResourceNames()
{
$this->getPluginResources();
return array_keys($this->_pluginResources);
}
/**
* Set plugin loader for loading resources
*
* @param Zend_Loader_PluginLoader_Interface $loader
* @return Zend_Application_Bootstrap_BootstrapAbstract
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
{
$this->_pluginLoader = $loader;
return $this;
}
/**
* Get the plugin loader for resources
*
* @return Zend_Loader_PluginLoader_Interface
*/
public function getPluginLoader()
{
if ($this->_pluginLoader === null) {
$options = array(
'Zend_Application_Resource' => 'Zend/Application/Resource',
'ZendX_Application_Resource' => 'ZendX/Application/Resource'
);
$this->_pluginLoader = new Zend_Loader_PluginLoader($options);
}
return $this->_pluginLoader;
}
/**
* Set application/parent bootstrap
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception
*/
public function setApplication($application)
{
if (($application instanceof Zend_Application)
|| ($application instanceof Zend_Application_Bootstrap_Bootstrapper)
) {
if ($application === $this) {
throw new Zend_Application_Bootstrap_Exception('Cannot set application to same object; creates recursion');
}
$this->_application = $application;
} else {
throw new Zend_Application_Bootstrap_Exception('Invalid application provided to bootstrap constructor (received "' . get_class($application) . '" instance)');
}
return $this;
}
/**
* Retrieve parent application instance
*
* @return Zend_Application|Zend_Application_Bootstrap_Bootstrapper
*/
public function getApplication()
{
return $this->_application;
}
/**
* Retrieve application environment
*
* @return string
*/
public function getEnvironment()
{
if (null === $this->_environment) {
$this->_environment = $this->getApplication()->getEnvironment();
}
return $this->_environment;
}
/**
* Set resource container
*
* By default, if a resource callback has a non-null return value, this
* value will be stored in a container using the resource name as the
* key.
*
* Containers must be objects, and must allow setting public properties.
*
* @param object $container
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception
*/
public function setContainer($container)
{
if (!is_object($container)) {
throw new Zend_Application_Bootstrap_Exception('Resource containers must be objects');
}
$this->_container = $container;
return $this;
}
/**
* Retrieve resource container
*
* @return object
*/
public function getContainer()
{
if (null === $this->_container) {
$this->setContainer(new Zend_Registry());
}
return $this->_container;
}
/**
* Determine if a resource has been stored in the container
*
* During bootstrap resource initialization, you may return a value. If
* you do, it will be stored in the {@link setContainer() container}.
* You can use this method to determine if a value was stored.
*
* @param string $name
* @return bool
*/
public function hasResource($name)
{
$resource = strtolower($name);
$container = $this->getContainer();
return isset($container->{$resource});
}
/**
* Retrieve a resource from the container
*
* During bootstrap resource initialization, you may return a value. If
* you do, it will be stored in the {@link setContainer() container}.
* You can use this method to retrieve that value.
*
* If no value was returned, this will return a null value.
*
* @param string $name
* @return null|mixed
*/
public function getResource($name)
{
$resource = strtolower($name);
$container = $this->getContainer();
if ($this->hasResource($resource)) {
return $container->{$resource};
}
return null;
}
/**
* Implement PHP's magic to retrieve a resource
* in the bootstrap
*
* @param string $prop
* @return null|mixed
*/
public function __get($prop)
{
return $this->getResource($prop);
}
/**
* Implement PHP's magic to ask for the
* existence of a resource in the bootstrap
*
* @param string $prop
* @return bool
*/
public function __isset($prop)
{
return $this->hasResource($prop);
}
/**
* Bootstrap individual, all, or multiple resources
*
* Marked as final to prevent issues when subclassing and naming the
* child class 'Bootstrap' (in which case, overriding this method
* would result in it being treated as a constructor).
*
* If you need to override this functionality, override the
* {@link _bootstrap()} method.
*
* @param null|string|array $resource
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
*/
final public function bootstrap($resource = null)
{
$this->_bootstrap($resource);
return $this;
}
/**
* Overloading: intercept calls to bootstrap<resourcename>() methods
*
* @param string $method
* @param array $args
* @return Zend_Application_Bootstrap_BootstrapAbstract
* @throws Zend_Application_Bootstrap_Exception On invalid method name
*/
public function __call($method, $args)
{
if (9 < strlen($method) && 'bootstrap' === substr($method, 0, 9)) {
$resource = substr($method, 9);
return $this->bootstrap($resource);
}
throw new Zend_Application_Bootstrap_Exception('Invalid method "' . $method . '"');
}
/**
* Bootstrap implementation
*
* This method may be overridden to provide custom bootstrapping logic.
* It is the sole method called by {@link bootstrap()}.
*
* @param null|string|array $resource
* @return void
* @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
*/
protected function _bootstrap($resource = null)
{
if (null === $resource) {
foreach ($this->getClassResourceNames() as $resource) {
$this->_executeResource($resource);
}
foreach ($this->getPluginResourceNames() as $resource) {
$this->_executeResource($resource);
}
} elseif (is_string($resource)) {
$this->_executeResource($resource);
} elseif (is_array($resource)) {
foreach ($resource as $r) {
$this->_executeResource($r);
}
} else {
throw new Zend_Application_Bootstrap_Exception('Invalid argument passed to ' . __METHOD__);
}
}
/**
* Execute a resource
*
* Checks to see if the resource has already been run. If not, it searches
* first to see if a local method matches the resource, and executes that.
* If not, it checks to see if a plugin resource matches, and executes that
* if found.
*
* Finally, if not found, it throws an exception.
*
* @param string $resource
* @return void
* @throws Zend_Application_Bootstrap_Exception When resource not found
*/
protected function _executeResource($resource)
{
$resourceName = strtolower($resource);
if (in_array($resourceName, $this->_run)) {
return;
}
if (isset($this->_started[$resourceName]) && $this->_started[$resourceName]) {
throw new Zend_Application_Bootstrap_Exception('Circular resource dependency detected');
}
$classResources = $this->getClassResources();
if (array_key_exists($resourceName, $classResources)) {
$this->_started[$resourceName] = true;
$method = $classResources[$resourceName];
$return = $this->$method();
unset($this->_started[$resourceName]);
$this->_markRun($resourceName);
if (null !== $return) {
$this->getContainer()->{$resourceName} = $return;
}
return;
}
if ($this->hasPluginResource($resource)) {
$this->_started[$resourceName] = true;
$plugin = $this->getPluginResource($resource);
$return = $plugin->init();
unset($this->_started[$resourceName]);
$this->_markRun($resourceName);
if (null !== $return) {
$this->getContainer()->{$resourceName} = $return;
}
return;
}
throw new Zend_Application_Bootstrap_Exception('Resource matching "' . $resource . '" not found');
}
/**
* Load a plugin resource
*
* @param string $resource
* @param array|object|null $options
* @return string|false
*/
protected function _loadPluginResource($resource, $options)
{
$options = (array) $options;
$options['bootstrap'] = $this;
$className = $this->getPluginLoader()->load(strtolower($resource), false);
if (!$className) {
return false;
}
$instance = new $className($options);
unset($this->_pluginResources[$resource]);
if (isset($instance->_explicitType)) {
$resource = $instance->_explicitType;
}
$resource = strtolower($resource);
$this->_pluginResources[$resource] = $instance;
return $resource;
}
/**
* Mark a resource as having run
*
* @param string $resource
* @return void
*/
protected function _markRun($resource)
{
if (!in_array($resource, $this->_run)) {
$this->_run[] = $resource;
}
}
/**
* Resolve a plugin resource name
*
* Uses, in order of preference
* - $_explicitType property of resource
* - Short name of resource (if a matching prefix path is found)
* - class name (if none of the above are true)
*
* The name is then cast to lowercase.
*
* @param Zend_Application_Resource_Resource $resource
* @return string
*/
protected function _resolvePluginResourceName($resource)
{
if (isset($resource->_explicitType)) {
$pluginName = $resource->_explicitType;
} else {
$className = get_class($resource);
$pluginName = $className;
$loader = $this->getPluginLoader();
foreach ($loader->getPaths() as $prefix => $paths) {
if (0 === strpos($className, $prefix)) {
$pluginName = substr($className, strlen($prefix));
$pluginName = trim($pluginName, '_');
break;
}
}
}
$pluginName = strtolower($pluginName);
return $pluginName;
}
}

View File

@ -1,93 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Interface for bootstrap classes
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Application_Bootstrap_Bootstrapper
{
/**
* Constructor
*
* @param Zend_Application $application
*/
public function __construct($application);
/**
* Set bootstrap options
*
* @param array $options
* @return Zend_Application_Bootstrap_Bootstrapper
*/
public function setOptions(array $options);
/**
* Retrieve application object
*
* @return Zend_Application|Zend_Application_Bootstrap_Bootstrapper
*/
public function getApplication();
/**
* Retrieve application environment
*
* @return string
*/
public function getEnvironment();
/**
* Retrieve list of class resource initializers (_init* methods). Returns
* as resource/method pairs.
*
* @return array
*/
public function getClassResources();
/**
* Retrieve list of class resource initializer names (resource names only,
* no method names)
*
* @return array
*/
public function getClassResourceNames();
/**
* Bootstrap application or individual resource
*
* @param null|string $resource
* @return mixed
*/
public function bootstrap($resource = null);
/**
* Run the application
*
* @return void
*/
public function run();
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Exception
*/
/**
* Exception class for Zend_Application
*
* @category Zend
* @package Zend_Application
* @uses Zend_Application_Exception
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Bootstrap_Exception extends Zend_Application_Exception
{
}

View File

@ -1,95 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Interface for bootstrap classes that utilize resource plugins
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Application_Bootstrap_ResourceBootstrapper
{
/**
* Register a resource with the bootstrap
*
* @param string|Zend_Application_Resource_Resource $resource
* @param null|array|Zend_Config $options
* @return Zend_Application_Bootstrap_ResourceBootstrapper
*/
public function registerPluginResource($resource, $options = null);
/**
* Unregister a resource from the bootstrap
*
* @param string|Zend_Application_Resource_Resource $resource
* @return Zend_Application_Bootstrap_ResourceBootstrapper
*/
public function unregisterPluginResource($resource);
/**
* Is the requested resource registered?
*
* @param string $resource
* @return bool
*/
public function hasPluginResource($resource);
/**
* Retrieve resource
*
* @param string $resource
* @return Zend_Application_Resource_Resource
*/
public function getPluginResource($resource);
/**
* Get all resources
*
* @return array
*/
public function getPluginResources();
/**
* Get just resource names
*
* @return array
*/
public function getPluginResourceNames();
/**
* Set plugin loader to use to fetch resources
*
* @param Zend_Loader_PluginLoader_Interface Zend_Loader_PluginLoader
* @return Zend_Application_Bootstrap_ResourceBootstrapper
*/
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader);
/**
* Retrieve plugin loader for resources
*
* @return Zend_Loader_PluginLoader
*/
public function getPluginLoader();
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Exception
*/
/**
* Exception class for Zend_Application
*
* @uses Zend_Exception
* @category Zend
* @package Zend_Application
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Exception extends Zend_Exception
{
}

View File

@ -1,94 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Module
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Loader_Autoloader_Resource */
/**
* Resource loader for application module classes
*
* @uses Zend_Loader_Autoloader_Resource
* @category Zend
* @package Zend_Application
* @subpackage Module
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Module_Autoloader extends Zend_Loader_Autoloader_Resource
{
/**
* Constructor
*
* @param array|Zend_Config $options
*/
public function __construct($options)
{
parent::__construct($options);
$this->initDefaultResourceTypes();
}
/**
* Initialize default resource types for module resource classes
*
* @return void
*/
public function initDefaultResourceTypes()
{
$basePath = $this->getBasePath();
$this->addResourceTypes(
array(
'dbtable' => array(
'namespace' => 'Model_DbTable',
'path' => 'models/DbTable',
),
'mappers' => array(
'namespace' => 'Model_Mapper',
'path' => 'models/mappers',
),
'form' => array(
'namespace' => 'Form',
'path' => 'forms',
),
'model' => array(
'namespace' => 'Model',
'path' => 'models',
),
'plugin' => array(
'namespace' => 'Plugin',
'path' => 'plugins',
),
'service' => array(
'namespace' => 'Service',
'path' => 'services',
),
'viewhelper' => array(
'namespace' => 'View_Helper',
'path' => 'views/helpers',
),
'viewfilter' => array(
'namespace' => 'View_Filter',
'path' => 'views/filters',
),
)
);
$this->setDefaultResourceType('model');
}
}

View File

@ -1,126 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Module
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Application_Bootstrap_Bootstrap
*/
/**
* Base bootstrap class for modules
*
* @uses Zend_Loader_Autoloader_Resource
* @uses Zend_Application_Bootstrap_Bootstrap
* @category Zend
* @package Zend_Application
* @subpackage Module
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Application_Module_Bootstrap
extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Set this explicitly to reduce impact of determining module name
* @var string
*/
protected $_moduleName;
/**
* Constructor
*
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
*/
public function __construct($application)
{
$this->setApplication($application);
// Use same plugin loader as parent bootstrap
if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) {
$this->setPluginLoader($application->getPluginLoader());
}
$key = strtolower($this->getModuleName());
if ($application->hasOption($key)) {
// Don't run via setOptions() to prevent duplicate initialization
$this->setOptions($application->getOption($key));
}
if ($application->hasOption('resourceloader')) {
$this->setOptions(array(
'resourceloader' => $application->getOption('resourceloader')
));
}
$this->initResourceLoader();
// ZF-6545: ensure front controller resource is loaded
if (!$this->hasPluginResource('FrontController')) {
$this->registerPluginResource('FrontController');
}
// ZF-6545: prevent recursive registration of modules
if ($this->hasPluginResource('modules')) {
$this->unregisterPluginResource('modules');
}
}
/**
* Ensure resource loader is loaded
*
* @return void
*/
public function initResourceLoader()
{
$this->getResourceLoader();
}
/**
* Get default application namespace
*
* Proxies to {@link getModuleName()}, and returns the current module
* name
*
* @return string
*/
public function getAppNamespace()
{
return $this->getModuleName();
}
/**
* Retrieve module name
*
* @return string
*/
public function getModuleName()
{
if (empty($this->_moduleName)) {
$class = get_class($this);
if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) {
$prefix = $matches[1];
} else {
$prefix = $class;
}
$this->_moduleName = $prefix;
}
return $this->_moduleName;
}
}

View File

@ -1,81 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Cache Manager resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Cachemanager extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Cache_Manager
*/
protected $_manager = null;
/**
* Initialize Cache_Manager
*
* @return Zend_Cache_Manager
*/
public function init()
{
return $this->getCacheManager();
}
/**
* Retrieve Zend_Cache_Manager instance
*
* @return Zend_Cache_Manager
*/
public function getCacheManager()
{
if (null === $this->_manager) {
$this->_manager = new Zend_Cache_Manager;
$options = $this->getOptions();
foreach ($options as $key => $value) {
// Logger
if (isset($value['frontend']['options']['logger'])) {
$logger = $value['frontend']['options']['logger'];
if (is_array($logger)) {
$value['frontend']['options']['logger'] = Zend_Log::factory($logger);
}
}
// Cache templates
if ($this->_manager->hasCacheTemplate($key)) {
$this->_manager->setTemplateOptions($key, $value);
} else {
$this->_manager->setCacheTemplate($key, $value);
}
}
}
return $this->_manager;
}
}

View File

@ -1,197 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for creating database adapter
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbstract
{
/**
* Adapter to use
*
* @var string
*/
protected $_adapter = null;
/**
* @var Zend_Db_Adapter_Abstract
*/
protected $_db;
/**
* Parameters to use
*
* @var array
*/
protected $_params = array();
/**
* Wether to register the created adapter as default table adapter
*
* @var boolean
*/
protected $_isDefaultTableAdapter = true;
/**
* Set the adapter
*
* @param string $adapter
* @return Zend_Application_Resource_Db
*/
public function setAdapter($adapter)
{
$this->_adapter = $adapter;
return $this;
}
/**
* Adapter type to use
*
* @return string
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
* Set the adapter params
*
* @param array $params
* @return Zend_Application_Resource_Db
*/
public function setParams(array $params)
{
$this->_params = $params;
return $this;
}
/**
* Adapter parameters
*
* @return array
*/
public function getParams()
{
return $this->_params;
}
/**
* Set whether to use this as default table adapter
*
* @param bool $isDefaultTableAdapter
* @return Zend_Application_Resource_Db
*/
public function setIsDefaultTableAdapter($isDefaultTableAdapter)
{
$this->_isDefaultTableAdapter = $isDefaultTableAdapter;
return $this;
}
/**
* Is this adapter the default table adapter?
*
* @return bool
*/
public function isDefaultTableAdapter()
{
return $this->_isDefaultTableAdapter;
}
/**
* Retrieve initialized DB connection
*
* @return null|Zend_Db_Adapter_Abstract
*/
public function getDbAdapter()
{
if ((null === $this->_db)
&& (null !== ($adapter = $this->getAdapter()))
) {
$this->_db = Zend_Db::factory($adapter, $this->getParams());
if ($this->_db instanceof Zend_Db_Adapter_Abstract
&& $this->isDefaultTableAdapter()
) {
Zend_Db_Table::setDefaultAdapter($this->_db);
}
}
return $this->_db;
}
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Db_Adapter_Abstract|null
*/
public function init()
{
if (null !== ($db = $this->getDbAdapter())) {
return $db;
}
return null;
}
/**
* Set the default metadata cache
*
* @param string|Zend_Cache_Core $cache
* @return Zend_Application_Resource_Db
*/
public function setDefaultMetadataCache($cache)
{
$metadataCache = null;
if (is_string($cache)) {
$bootstrap = $this->getBootstrap();
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
&& $bootstrap->hasPluginResource('CacheManager')
) {
$cacheManager = $bootstrap->bootstrap('CacheManager')
->getResource('CacheManager');
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
$metadataCache = $cacheManager->getCache($cache);
}
}
} else if ($cache instanceof Zend_Cache_Core) {
$metadataCache = $cache;
}
if ($metadataCache instanceof Zend_Cache_Core) {
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
}
return $this;
}
}

View File

@ -1,75 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for settings Dojo options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Dojo
extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Dojo_View_Helper_Dojo_Container
*/
protected $_dojo;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Dojo_View_Helper_Dojo_Container
*/
public function init()
{
return $this->getDojo();
}
/**
* Retrieve Dojo View Helper
*
* @return Zend_Dojo_View_Dojo_Container
*/
public function getDojo()
{
if (null === $this->_dojo) {
$this->getBootstrap()->bootstrap('view');
$view = $this->getBootstrap()->view;
Zend_Dojo::enableView($view);
$view->dojo()->setOptions($this->getOptions());
$this->_dojo = $view->dojo();
}
return $this->_dojo;
}
}

View File

@ -1,39 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Exception
*/
/**
* Exception class for Zend_Application
*
* @uses Zend_Application_Exception
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Exception extends Zend_Application_Exception
{
}

View File

@ -1,176 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Front Controller resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Controller_Front
*/
protected $_front;
/**
* Initialize Front Controller
*
* @return Zend_Controller_Front
* @throws Zend_Application_Exception
*/
public function init()
{
$front = $this->getFrontController();
foreach ($this->getOptions() as $key => $value) {
switch (strtolower($key)) {
case 'controllerdirectory':
if (is_string($value)) {
$front->setControllerDirectory($value);
} elseif (is_array($value)) {
foreach ($value as $module => $directory) {
$front->addControllerDirectory($directory, $module);
}
}
break;
case 'modulecontrollerdirectoryname':
$front->setModuleControllerDirectoryName($value);
break;
case 'moduledirectory':
if (is_string($value)) {
$front->addModuleDirectory($value);
} elseif (is_array($value)) {
foreach ($value as $moduleDir) {
$front->addModuleDirectory($moduleDir);
}
}
break;
case 'defaultcontrollername':
$front->setDefaultControllerName($value);
break;
case 'defaultaction':
$front->setDefaultAction($value);
break;
case 'defaultmodule':
$front->setDefaultModule($value);
break;
case 'baseurl':
if (!empty($value)) {
$front->setBaseUrl($value);
}
break;
case 'params':
$front->setParams($value);
break;
case 'plugins':
foreach ((array) $value as $pluginClass) {
$stackIndex = null;
if (is_array($pluginClass)) {
$pluginClass = array_change_key_case($pluginClass, CASE_LOWER);
if (isset($pluginClass['class'])) {
if (isset($pluginClass['stackindex'])) {
$stackIndex = $pluginClass['stackindex'];
}
$pluginClass = $pluginClass['class'];
}
}
$plugin = new $pluginClass();
$front->registerPlugin($plugin, $stackIndex);
}
break;
case 'returnresponse':
$front->returnResponse((bool) $value);
break;
case 'throwexceptions':
$front->throwExceptions((bool) $value);
break;
case 'actionhelperpaths':
if (is_array($value)) {
foreach ($value as $helperPrefix => $helperPath) {
Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
}
}
break;
case 'dispatcher':
if (!isset($value['class'])) {
throw new Zend_Application_Exception('You must specify both ');
}
if (!isset($value['params'])) {
$value['params'] = array();
}
$dispatchClass = $value['class'];
if (!class_exists($dispatchClass)) {
throw new Zend_Application_Exception('Dispatcher class not found!');
}
$front->setDispatcher(new $dispatchClass((array)$value['params']));
break;
default:
$front->setParam($key, $value);
break;
}
}
if (null !== ($bootstrap = $this->getBootstrap())) {
$this->getBootstrap()->frontController = $front;
}
return $front;
}
/**
* Retrieve front controller instance
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
if (null === $this->_front) {
$this->_front = Zend_Controller_Front::getInstance();
}
return $this->_front;
}
}

View File

@ -1,69 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for settings layout options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Layout
extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Layout
*/
protected $_layout;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Layout
*/
public function init()
{
$this->getBootstrap()->bootstrap('FrontController');
return $this->getLayout();
}
/**
* Retrieve layout object
*
* @return Zend_Layout
*/
public function getLayout()
{
if (null === $this->_layout) {
$this->_layout = Zend_Layout::startMvc($this->getOptions());
}
return $this->_layout;
}
}

View File

@ -1,116 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for initializing the locale
*
* @uses Zend_Application_Resource_Base
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Locale
extends Zend_Application_Resource_ResourceAbstract
{
const DEFAULT_REGISTRY_KEY = 'Zend_Locale';
/**
* @var Zend_Locale
*/
protected $_locale;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Locale
*/
public function init()
{
return $this->getLocale();
}
/**
* Retrieve locale object
*
* @return Zend_Locale
*/
public function getLocale()
{
if (null === $this->_locale) {
$options = $this->getOptions();
if (!isset($options['default'])) {
$this->_locale = new Zend_Locale();
} elseif (!isset($options['force'])
|| (bool)$options['force'] == false
) {
// Don't force any locale, just go for auto detection
Zend_Locale::setDefault($options['default']);
$this->_locale = new Zend_Locale();
} else {
$this->_locale = new Zend_Locale($options['default']);
}
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
? $options['registry_key']
: self::DEFAULT_REGISTRY_KEY;
Zend_Registry::set($key, $this->_locale);
}
return $this->_locale;
}
/**
* Set the cache
*
* @param string|Zend_Cache_Core $cache
* @return Zend_Application_Resource_Locale
*/
public function setCache($cache)
{
if (is_string($cache)) {
$bootstrap = $this->getBootstrap();
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
&& $bootstrap->hasPluginResource('CacheManager')
) {
$cacheManager = $bootstrap->bootstrap('CacheManager')
->getResource('CacheManager');
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
$cache = $cacheManager->getCache($cache);
}
}
}
if ($cache instanceof Zend_Cache_Core) {
Zend_Locale::setCache($cache);
}
return $this;
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for initializing logger
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Log
extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Log
*/
protected $_log;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Log
*/
public function init()
{
return $this->getLog();
}
/**
* Attach logger
*
* @param Zend_Log $log
* @return Zend_Application_Resource_Log
*/
public function setLog(Zend_Log $log)
{
$this->_log = $log;
return $this;
}
/**
* Retrieve logger object
*
* @return Zend_Log
*/
public function getLog()
{
if (null === $this->_log) {
$options = $this->getOptions();
$log = Zend_Log::factory($options);
$this->setLog($log);
}
return $this->_log;
}
}

View File

@ -1,150 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for setting up Mail Transport and default From & ReplyTo addresses
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Mail extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Mail_Transport_Abstract
*/
protected $_transport;
public function init()
{
return $this->getMail();
}
/**
*
* @return Zend_Mail_Transport_Abstract|null
*/
public function getMail()
{
if (null === $this->_transport) {
$options = $this->getOptions();
foreach ($options as $key => $option) {
$options[strtolower($key)] = $option;
}
$this->setOptions($options);
if (isset($options['transport'])
&& !is_numeric($options['transport'])
) {
$this->_transport = $this->_setupTransport($options['transport']);
if (!isset($options['transport']['register'])
|| $options['transport']['register'] == '1'
|| (isset($options['transport']['register'])
&& !is_numeric($options['transport']['register'])
&& (bool)$options['transport']['register'] == true)
) {
Zend_Mail::setDefaultTransport($this->_transport);
}
}
$this->_setDefaults('from');
$this->_setDefaults('replyTo');
}
return $this->_transport;
}
protected function _setDefaults($type)
{
$key = strtolower('default' . $type);
$options = $this->getOptions();
if (isset($options[$key]['email'])
&& !is_numeric($options[$key]['email'])
) {
$method = array('Zend_Mail', 'setDefault' . ucfirst($type));
if (isset($options[$key]['name'])
&& !is_numeric(
$options[$key]['name']
)
) {
call_user_func(
$method, $options[$key]['email'], $options[$key]['name']
);
} else {
call_user_func($method, $options[$key]['email']);
}
}
}
protected function _setupTransport($options)
{
if (!isset($options['type'])) {
$options['type'] = 'sendmail';
}
$transportName = $options['type'];
if (!Zend_Loader_Autoloader::autoload($transportName)) {
$transportName = ucfirst(strtolower($transportName));
if (!Zend_Loader_Autoloader::autoload($transportName)) {
$transportName = 'Zend_Mail_Transport_' . $transportName;
if (!Zend_Loader_Autoloader::autoload($transportName)) {
throw new Zend_Application_Resource_Exception(
"Specified Mail Transport '{$transportName}'"
. 'could not be found'
);
}
}
}
unset($options['type']);
unset($options['register']); //@see ZF-11022
switch($transportName) {
case 'Zend_Mail_Transport_Smtp':
if (!isset($options['host'])) {
throw new Zend_Application_Resource_Exception(
'A host is necessary for smtp transport,'
. ' but none was given'
);
}
$transport = new $transportName($options['host'], $options);
break;
case 'Zend_Mail_Transport_Sendmail':
default:
$transport = new $transportName($options);
break;
}
return $transport;
}
}

View File

@ -1,157 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Module bootstrapping resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Modules extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var ArrayObject
*/
protected $_bootstraps;
/**
* Constructor
*
* @param mixed $options
*/
public function __construct($options = null)
{
$this->_bootstraps = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
parent::__construct($options);
}
/**
* Initialize modules
*
* @return array
* @throws Zend_Application_Resource_Exception When bootstrap class was not found
*/
public function init()
{
$bootstraps = array();
$bootstrap = $this->getBootstrap();
$bootstrap->bootstrap('FrontController');
$front = $bootstrap->getResource('FrontController');
$modules = $front->getControllerDirectory();
$default = $front->getDefaultModule();
$curBootstrapClass = get_class($bootstrap);
foreach ($modules as $module => $moduleDirectory) {
$bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
if (!class_exists($bootstrapClass, false)) {
$bootstrapPath = dirname($moduleDirectory) . '/Bootstrap.php';
if (file_exists($bootstrapPath)) {
$eMsgTpl = 'Bootstrap file found for module "%s" but bootstrap class "%s" not found';
include_once $bootstrapPath;
if (($default != $module)
&& !class_exists($bootstrapClass, false)
) {
throw new Zend_Application_Resource_Exception(
sprintf(
$eMsgTpl, $module, $bootstrapClass
)
);
} elseif ($default == $module) {
if (!class_exists($bootstrapClass, false)) {
$bootstrapClass = 'Bootstrap';
if (!class_exists($bootstrapClass, false)) {
throw new Zend_Application_Resource_Exception(
sprintf(
$eMsgTpl, $module, $bootstrapClass
)
);
}
}
}
} else {
continue;
}
}
if ($bootstrapClass == $curBootstrapClass) {
// If the found bootstrap class matches the one calling this
// resource, don't re-execute.
continue;
}
$bootstraps[$module] = $bootstrapClass;
}
return $this->_bootstraps = $this->bootstrapBootstraps($bootstraps);
}
/*
* Bootstraps the bootstraps found. Allows for easy extension.
* @param array $bootstraps Array containing the bootstraps to instantiate
*/
protected function bootstrapBootstraps($bootstraps)
{
$bootstrap = $this->getBootstrap();
$out = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
foreach ($bootstraps as $module => $bootstrapClass) {
$moduleBootstrap = new $bootstrapClass($bootstrap);
$moduleBootstrap->bootstrap();
$out[$module] = $moduleBootstrap;
}
return $out;
}
/**
* Get bootstraps that have been run
*
* @return ArrayObject
*/
public function getExecutedBootstraps()
{
return $this->_bootstraps;
}
/**
* Format a module name to the module class prefix
*
* @param string $name
* @return string
*/
protected function _formatModuleName($name)
{
$name = strtolower($name);
$name = str_replace(array('-', '.'), ' ', $name);
$name = ucwords($name);
$name = str_replace(' ', '', $name);
return $name;
}
}

View File

@ -1,208 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
*/
/**
* Cache Manager resource
*
* Example configuration:
* <pre>
* resources.multidb.defaultMetadataCache = "database"
*
* resources.multidb.db1.adapter = "pdo_mysql"
* resources.multidb.db1.host = "localhost"
* resources.multidb.db1.username = "webuser"
* resources.multidb.db1.password = "XXXX"
* resources.multidb.db1.dbname = "db1"
* resources.multidb.db1.default = true
*
* resources.multidb.db2.adapter = "pdo_pgsql"
* resources.multidb.db2.host = "example.com"
* resources.multidb.db2.username = "dba"
* resources.multidb.db2.password = "notthatpublic"
* resources.multidb.db2.dbname = "db2"
* </pre>
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Multidb extends Zend_Application_Resource_ResourceAbstract
{
/**
* Associative array containing all configured db's
*
* @var array
*/
protected $_dbs = array();
/**
* An instance of the default db, if set
*
* @var null|Zend_Db_Adapter_Abstract
*/
protected $_defaultDb;
/**
* Initialize the Database Connections (instances of Zend_Db_Table_Abstract)
*
* @return Zend_Application_Resource_Multidb
*/
public function init()
{
$options = $this->getOptions();
if (isset($options['defaultMetadataCache'])) {
$this->_setDefaultMetadataCache($options['defaultMetadataCache']);
unset($options['defaultMetadataCache']);
}
foreach ($options as $id => $params) {
$adapter = $params['adapter'];
$default = (int) (
isset($params['isDefaultTableAdapter']) && $params['isDefaultTableAdapter']
|| isset($params['default']) && $params['default']
);
unset(
$params['adapter'],
$params['default'],
$params['isDefaultTableAdapter']
);
$this->_dbs[$id] = Zend_Db::factory($adapter, $params);
if ($default) {
$this->_setDefault($this->_dbs[$id]);
}
}
return $this;
}
/**
* Determine if the given db(identifier) is the default db.
*
* @param string|Zend_Db_Adapter_Abstract $db The db to determine whether it's set as default
* @return boolean True if the given parameter is configured as default. False otherwise
*/
public function isDefault($db)
{
if (!$db instanceof Zend_Db_Adapter_Abstract) {
$db = $this->getDb($db);
}
return $db === $this->_defaultDb;
}
/**
* Retrieve the specified database connection
*
* @param null|string|Zend_Db_Adapter_Abstract $db The adapter to retrieve.
* Null to retrieve the default connection
* @return Zend_Db_Adapter_Abstract
* @throws Zend_Application_Resource_Exception if the given parameter could not be found
*/
public function getDb($db = null)
{
if ($db === null) {
return $this->getDefaultDb();
}
if (isset($this->_dbs[$db])) {
return $this->_dbs[$db];
}
throw new Zend_Application_Resource_Exception(
'A DB adapter was tried to retrieve, but was not configured'
);
}
/**
* Get the default db connection
*
* @param boolean $justPickOne If true, a random (the first one in the stack)
* connection is returned if no default was set.
* If false, null is returned if no default was set.
* @return null|Zend_Db_Adapter_Abstract
*/
public function getDefaultDb($justPickOne = true)
{
if ($this->_defaultDb !== null) {
return $this->_defaultDb;
}
if ($justPickOne) {
return reset($this->_dbs); // Return first db in db pool
}
return null;
}
/**
* Set the default db adapter
*
* @var Zend_Db_Adapter_Abstract $adapter Adapter to set as default
*/
protected function _setDefault(Zend_Db_Adapter_Abstract $adapter)
{
Zend_Db_Table::setDefaultAdapter($adapter);
$this->_defaultDb = $adapter;
}
/**
* Set the default metadata cache
*
* @param string|Zend_Cache_Core $cache
* @return Zend_Application_Resource_Multidb
*/
protected function _setDefaultMetadataCache($cache)
{
$metadataCache = null;
if (is_string($cache)) {
$bootstrap = $this->getBootstrap();
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
$bootstrap->hasPluginResource('CacheManager')
) {
$cacheManager = $bootstrap->bootstrap('CacheManager')
->getResource('CacheManager');
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
$metadataCache = $cacheManager->getCache($cache);
}
}
} else if ($cache instanceof Zend_Cache_Core) {
$metadataCache = $cache;
}
if ($metadataCache instanceof Zend_Cache_Core) {
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
}
return $this;
}
}

View File

@ -1,130 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for setting navigation structure
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @author Dolf Schimmel
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Navigation
extends Zend_Application_Resource_ResourceAbstract
{
const DEFAULT_REGISTRY_KEY = 'Zend_Navigation';
/**
* @var Zend_Navigation
*/
protected $_container;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Navigation
*/
public function init()
{
if (!$this->_container) {
$options = $this->getOptions();
if (isset($options['defaultPageType'])) {
Zend_Navigation_Page::setDefaultPageType(
$options['defaultPageType']
);
}
$pages = isset($options['pages']) ? $options['pages'] : array();
$this->_container = new Zend_Navigation($pages);
}
$this->store();
return $this->_container;
}
/**
* Stores navigation container in registry or Navigation view helper
*
* @return void
*/
public function store()
{
$options = $this->getOptions();
if (isset($options['storage']['registry']) &&
$options['storage']['registry'] == true) {
$this->_storeRegistry();
} else {
$this->_storeHelper();
}
}
/**
* Stores navigation container in the registry
*
* @return void
*/
protected function _storeRegistry()
{
$options = $this->getOptions();
// see ZF-7461
if (isset($options['storage']['registry']['key'])
&& !is_numeric($options['storage']['registry']['key'])
) {
$key = $options['storage']['registry']['key'];
} else {
$key = self::DEFAULT_REGISTRY_KEY;
}
Zend_Registry::set($key, $this->getContainer());
}
/**
* Stores navigation container in the Navigation helper
*
* @return void
*/
protected function _storeHelper()
{
$this->getBootstrap()->bootstrap('view');
$view = $this->getBootstrap()->view;
$view->getHelper('navigation')->navigation($this->getContainer());
}
/**
* Returns navigation container
*
* @return Zend_Navigation
*/
public function getContainer()
{
return $this->_container;
}
}

View File

@ -1,79 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Interface for bootstrap resources
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Application_Resource_Resource
{
/**
* Constructor
*
* Must take an optional single argument, $options.
*
* @param mixed $options
*/
public function __construct($options = null);
/**
* Set the bootstrap to which the resource is attached
*
* @param Zend_Application_Bootstrap_Bootstrapper $bootstrap
* @return Zend_Application_Resource_Resource
*/
public function setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap);
/**
* Retrieve the bootstrap to which the resource is attached
*
* @return Zend_Application_Bootstrap_Bootstrapper
*/
public function getBootstrap();
/**
* Set resource options
*
* @param array $options
* @return Zend_Application_Resource_Resource
*/
public function setOptions(array $options);
/**
* Retrieve resource options
*
* @return array
*/
public function getOptions();
/**
* Strategy pattern: initialize resource
*
* @return mixed
*/
public function init();
}

View File

@ -1,160 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_Resource
*/
/**
* Abstract class for bootstrap resources
*
* @uses Zend_Application_Resource_Resource
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Application_Resource_Resource
{
/**
* Parent bootstrap
*
* @var Zend_Application_Bootstrap_Bootstrapper
*/
protected $_bootstrap;
/**
* Options for the resource
*
* @var array
*/
protected $_options = array();
/**
* Option keys to skip when calling setOptions()
*
* @var array
*/
protected $_skipOptions = array(
'options',
'config',
);
/**
* Create a instance with options
*
* @param mixed $options
*/
public function __construct($options = null)
{
if (is_array($options)) {
$this->setOptions($options);
} else if ($options instanceof Zend_Config) {
$this->setOptions($options->toArray());
}
}
/**
* Set options from array
*
* @param array $options Configuration for resource
* @return Zend_Application_Resource_ResourceAbstract
*/
public function setOptions(array $options)
{
if (array_key_exists('bootstrap', $options)) {
$this->setBootstrap($options['bootstrap']);
unset($options['bootstrap']);
}
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->_skipOptions)) {
continue;
}
$method = 'set' . strtolower($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
$this->_options = $this->mergeOptions($this->_options, $options);
return $this;
}
/**
* Retrieve resource options
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Merge options recursively
*
* @param array $array1
* @param mixed $array2
* @return array
*/
public function mergeOptions(array $array1, $array2 = null)
{
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
? $this->mergeOptions($array1[$key], $array2[$key])
: $array2[$key];
} else {
$array1[$key] = $val;
}
}
}
return $array1;
}
/**
* Set the bootstrap to which the resource is attached
*
* @param Zend_Application_Bootstrap_Bootstrapper $bootstrap
* @return Zend_Application_Resource_Resource
*/
public function setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap)
{
$this->_bootstrap = $bootstrap;
return $this;
}
/**
* Retrieve the bootstrap to which the resource is attached
*
* @return null|Zend_Application_Bootstrap_Bootstrapper
*/
public function getBootstrap()
{
return $this->_bootstrap;
}
}

View File

@ -1,86 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for initializing the locale
*
* @uses Zend_Application_Resource_Base
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Router
extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Controller_Router_Rewrite
*/
protected $_router;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Controller_Router_Rewrite
*/
public function init()
{
return $this->getRouter();
}
/**
* Retrieve router object
*
* @return Zend_Controller_Router_Rewrite
*/
public function getRouter()
{
if (null === $this->_router) {
$bootstrap = $this->getBootstrap();
$bootstrap->bootstrap('FrontController');
$this->_router = $bootstrap->getContainer()->frontcontroller->getRouter();
$options = $this->getOptions();
if (!isset($options['routes'])) {
$options['routes'] = array();
}
if (isset($options['chainNameSeparator'])) {
$this->_router->setChainNameSeparator($options['chainNameSeparator']);
}
if (isset($options['useRequestParametersAsGlobal'])) {
$this->_router->useRequestParametersAsGlobal($options['useRequestParametersAsGlobal']);
}
$this->_router->addConfig(new Zend_Config($options['routes']));
}
return $this->_router;
}
}

View File

@ -1,118 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for setting session options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Session extends Zend_Application_Resource_ResourceAbstract
{
/**
* Save handler to use
*
* @var Zend_Session_SaveHandler_Interface
*/
protected $_saveHandler = null;
/**
* Set session save handler
*
* @param array|string|Zend_Session_SaveHandler_Interface $saveHandler
* @return Zend_Application_Resource_Session
* @throws Zend_Application_Resource_Exception When $saveHandler is not a valid save handler
*/
public function setSaveHandler($saveHandler)
{
$this->_saveHandler = $saveHandler;
return $this;
}
/**
* Get session save handler
*
* @return Zend_Session_SaveHandler_Interface
* @throws Zend_Application_Resource_Exception
*/
public function getSaveHandler()
{
if (!$this->_saveHandler instanceof Zend_Session_SaveHandler_Interface) {
if (is_array($this->_saveHandler)) {
if (!array_key_exists('class', $this->_saveHandler)) {
throw new Zend_Application_Resource_Exception('Session save handler class not provided in options');
}
$options = array();
if (array_key_exists('options', $this->_saveHandler)) {
$options = $this->_saveHandler['options'];
}
$this->_saveHandler = $this->_saveHandler['class'];
$this->_saveHandler = new $this->_saveHandler($options);
} elseif (is_string($this->_saveHandler)) {
$this->_saveHandler = new $this->_saveHandler();
}
if (!$this->_saveHandler instanceof Zend_Session_SaveHandler_Interface) {
throw new Zend_Application_Resource_Exception('Invalid session save handler');
}
}
return $this->_saveHandler;
}
/**
* @return bool
*/
protected function _hasSaveHandler()
{
return ($this->_saveHandler !== null);
}
/**
* Defined by Zend_Application_Resource_Resource
*
* @return void
*/
public function init()
{
$options = array_change_key_case($this->getOptions(), CASE_LOWER);
if (isset($options['savehandler'])) {
unset($options['savehandler']);
}
if (count($options) > 0) {
Zend_Session::setOptions($options);
}
if ($this->_hasSaveHandler()) {
Zend_Session::setSaveHandler($this->getSaveHandler());
}
}
}

View File

@ -1,138 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for setting translation options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Translate extends Zend_Application_Resource_ResourceAbstract
{
const DEFAULT_REGISTRY_KEY = 'Zend_Translate';
/**
* @var Zend_Translate
*/
protected $_translate;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Translate
*/
public function init()
{
return $this->getTranslate();
}
/**
* Retrieve translate object
*
* @return Zend_Translate
* @throws Zend_Application_Resource_Exception if registry key was used
* already but is no instance of Zend_Translate
*/
public function getTranslate()
{
if (null === $this->_translate) {
$options = $this->getOptions();
if (!isset($options['content']) && !isset($options['data'])) {
throw new Zend_Application_Resource_Exception('No translation source data provided.');
} else if (array_key_exists('content', $options) && array_key_exists('data', $options)) {
throw new Zend_Application_Resource_Exception(
'Conflict on translation source data: choose only one key between content and data.'
);
}
if (empty($options['adapter'])) {
$options['adapter'] = Zend_Translate::AN_ARRAY;
}
if (!empty($options['data'])) {
$options['content'] = $options['data'];
unset($options['data']);
}
if (isset($options['log'])) {
if (is_array($options['log'])) {
$options['log'] = Zend_Log::factory($options['log']);
}
}
if (isset($options['options'])) {
foreach ($options['options'] as $key => $value) {
$options[$key] = $value;
}
}
if (!empty($options['cache']) && is_string($options['cache'])) {
$bootstrap = $this->getBootstrap();
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
$bootstrap->hasPluginResource('CacheManager')
) {
$cacheManager = $bootstrap->bootstrap('CacheManager')
->getResource('CacheManager');
if (null !== $cacheManager &&
$cacheManager->hasCache($options['cache'])
) {
$options['cache'] = $cacheManager->getCache($options['cache']);
}
}
}
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
? $options['registry_key']
: self::DEFAULT_REGISTRY_KEY;
unset($options['registry_key']);
if (Zend_Registry::isRegistered($key)) {
$translate = Zend_Registry::get($key);
if (!$translate instanceof Zend_Translate) {
throw new Zend_Application_Resource_Exception(
$key
. ' already registered in registry but is '
. 'no instance of Zend_Translate'
);
}
$translate->addTranslation($options);
$this->_translate = $translate;
} else {
$this->_translate = new Zend_Translate($options);
Zend_Registry::set($key, $this->_translate);
}
}
return $this->_translate;
}
}

View File

@ -1,72 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_UserAgent extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Http_UserAgent
*/
protected $_userAgent;
/**
* Intialize resource
*
* @return Zend_Http_UserAgent
*/
public function init()
{
$userAgent = $this->getUserAgent();
// Optionally seed the UserAgent view helper
$bootstrap = $this->getBootstrap();
if ($bootstrap->hasResource('view') || $bootstrap->hasPluginResource('view')) {
$bootstrap->bootstrap('view');
$view = $bootstrap->getResource('view');
if (null !== $view) {
$view->userAgent($userAgent);
}
}
return $userAgent;
}
/**
* Get UserAgent instance
*
* @return Zend_Http_UserAgent
*/
public function getUserAgent()
{
if (null === $this->_userAgent) {
$options = $this->getOptions();
$this->_userAgent = new Zend_Http_UserAgent($options);
}
return $this->_userAgent;
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
/**
* Resource for settings view options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_View_Interface
*/
protected $_view;
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_View
*/
public function init()
{
$view = $this->getView();
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view);
return $view;
}
/**
* Retrieve view object
*
* @return Zend_View
*/
public function getView()
{
if (null === $this->_view) {
$options = $this->getOptions();
$this->_view = new Zend_View($options);
if (isset($options['doctype'])) {
$this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
$this->_view->headMeta()->setCharset($options['charset']);
}
}
if (isset($options['contentType'])) {
$this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
}
if (isset($options['assign']) && is_array($options['assign'])) {
$this->_view->assign($options['assign']);
}
}
return $this->_view;
}
}

View File

@ -1,168 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth
{
/**
* Singleton instance
*
* @var Zend_Auth
*/
protected static $_instance = null;
/**
* Persistent storage handler
*
* @var Zend_Auth_Storage_Interface
*/
protected $_storage = null;
/**
* Singleton pattern implementation makes "new" unavailable
*
* @return void
*/
protected function __construct()
{}
/**
* Singleton pattern implementation makes "clone" unavailable
*
* @return void
*/
protected function __clone()
{}
/**
* Returns an instance of Zend_Auth
*
* Singleton pattern implementation
*
* @return Zend_Auth Provides a fluent interface
*/
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Returns the persistent storage handler
*
* Session storage is used by default unless a different storage adapter has been set.
*
* @return Zend_Auth_Storage_Interface
*/
public function getStorage()
{
if (null === $this->_storage) {
/**
* @see Zend_Auth_Storage_Session
*/
$this->setStorage(new Zend_Auth_Storage_Session());
}
return $this->_storage;
}
/**
* Sets the persistent storage handler
*
* @param Zend_Auth_Storage_Interface $storage
* @return Zend_Auth Provides a fluent interface
*/
public function setStorage(Zend_Auth_Storage_Interface $storage)
{
$this->_storage = $storage;
return $this;
}
/**
* Authenticates against the supplied adapter
*
* @param Zend_Auth_Adapter_Interface $adapter
* @return Zend_Auth_Result
*/
public function authenticate(Zend_Auth_Adapter_Interface $adapter)
{
$result = $adapter->authenticate();
/**
* ZF-7546 - prevent multiple succesive calls from storing inconsistent results
* Ensure storage has clean state
*/
if ($this->hasIdentity()) {
$this->clearIdentity();
}
if ($result->isValid()) {
$this->getStorage()->write($result->getIdentity());
}
return $result;
}
/**
* Returns true if and only if an identity is available from storage
*
* @return boolean
*/
public function hasIdentity()
{
return !$this->getStorage()->isEmpty();
}
/**
* Returns the identity from storage or null if no identity is available
*
* @return mixed|null
*/
public function getIdentity()
{
$storage = $this->getStorage();
if ($storage->isEmpty()) {
return null;
}
return $storage->read();
}
/**
* Clears the identity from persistent storage
*
* @return void
*/
public function clearIdentity()
{
$this->getStorage()->clear();
}
}

View File

@ -1,553 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
/**
* @see Zend_Auth_Result
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface
{
/**
* Database Connection
*
* @var Zend_Db_Adapter_Abstract
*/
protected $_zendDb = null;
/**
* @var Zend_Db_Select
*/
protected $_dbSelect = null;
/**
* $_tableName - the table name to check
*
* @var string
*/
protected $_tableName = null;
/**
* $_identityColumn - the column to use as the identity
*
* @var string
*/
protected $_identityColumn = null;
/**
* $_credentialColumns - columns to be used as the credentials
*
* @var string
*/
protected $_credentialColumn = null;
/**
* $_identity - Identity value
*
* @var string
*/
protected $_identity = null;
/**
* $_credential - Credential values
*
* @var string
*/
protected $_credential = null;
/**
* $_credentialTreatment - Treatment applied to the credential, such as MD5() or PASSWORD()
*
* @var string
*/
protected $_credentialTreatment = null;
/**
* $_authenticateResultInfo
*
* @var array
*/
protected $_authenticateResultInfo = null;
/**
* $_resultRow - Results of database authentication query
*
* @var array
*/
protected $_resultRow = null;
/**
* $_ambiguityIdentity - Flag to indicate same Identity can be used with
* different credentials. Default is FALSE and need to be set to true to
* allow ambiguity usage.
*
* @var boolean
*/
protected $_ambiguityIdentity = false;
/**
* __construct() - Sets configuration options
*
* @param Zend_Db_Adapter_Abstract $zendDb If null, default database adapter assumed
* @param string $tableName
* @param string $identityColumn
* @param string $credentialColumn
* @param string $credentialTreatment
*/
public function __construct(Zend_Db_Adapter_Abstract $zendDb = null, $tableName = null, $identityColumn = null,
$credentialColumn = null, $credentialTreatment = null)
{
$this->_setDbAdapter($zendDb);
if (null !== $tableName) {
$this->setTableName($tableName);
}
if (null !== $identityColumn) {
$this->setIdentityColumn($identityColumn);
}
if (null !== $credentialColumn) {
$this->setCredentialColumn($credentialColumn);
}
if (null !== $credentialTreatment) {
$this->setCredentialTreatment($credentialTreatment);
}
}
/**
* _setDbAdapter() - set the database adapter to be used for quering
*
* @param Zend_Db_Adapter_Abstract
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Adapter_DbTable
*/
protected function _setDbAdapter(Zend_Db_Adapter_Abstract $zendDb = null)
{
$this->_zendDb = $zendDb;
/**
* If no adapter is specified, fetch default database adapter.
*/
if(null === $this->_zendDb) {
$this->_zendDb = Zend_Db_Table_Abstract::getDefaultAdapter();
if (null === $this->_zendDb) {
throw new Zend_Auth_Adapter_Exception('No database adapter present');
}
}
return $this;
}
/**
* setTableName() - set the table name to be used in the select query
*
* @param string $tableName
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setTableName($tableName)
{
$this->_tableName = $tableName;
return $this;
}
/**
* setIdentityColumn() - set the column name to be used as the identity column
*
* @param string $identityColumn
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setIdentityColumn($identityColumn)
{
$this->_identityColumn = $identityColumn;
return $this;
}
/**
* setCredentialColumn() - set the column name to be used as the credential column
*
* @param string $credentialColumn
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setCredentialColumn($credentialColumn)
{
$this->_credentialColumn = $credentialColumn;
return $this;
}
/**
* setCredentialTreatment() - allows the developer to pass a parameterized string that is
* used to transform or treat the input credential data.
*
* In many cases, passwords and other sensitive data are encrypted, hashed, encoded,
* obscured, or otherwise treated through some function or algorithm. By specifying a
* parameterized treatment string with this method, a developer may apply arbitrary SQL
* upon input credential data.
*
* Examples:
*
* 'PASSWORD(?)'
* 'MD5(?)'
*
* @param string $treatment
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setCredentialTreatment($treatment)
{
$this->_credentialTreatment = $treatment;
return $this;
}
/**
* setIdentity() - set the value to be used as the identity
*
* @param string $value
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setIdentity($value)
{
$this->_identity = $value;
return $this;
}
/**
* setCredential() - set the credential value to be used, optionally can specify a treatment
* to be used, should be supplied in parameterized form, such as 'MD5(?)' or 'PASSWORD(?)'
*
* @param string $credential
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
*/
public function setCredential($credential)
{
$this->_credential = $credential;
return $this;
}
/**
* setAmbiguityIdentity() - sets a flag for usage of identical identities
* with unique credentials. It accepts integers (0, 1) or boolean (true,
* false) parameters. Default is false.
*
* @param int|bool $flag
* @return Zend_Auth_Adapter_DbTable
*/
public function setAmbiguityIdentity($flag)
{
if (is_integer($flag)) {
$this->_ambiguityIdentity = (1 === $flag ? true : false);
} elseif (is_bool($flag)) {
$this->_ambiguityIdentity = $flag;
}
return $this;
}
/**
* getAmbiguityIdentity() - returns TRUE for usage of multiple identical
* identies with different credentials, FALSE if not used.
*
* @return bool
*/
public function getAmbiguityIdentity()
{
return $this->_ambiguityIdentity;
}
/**
* getDbSelect() - Return the preauthentication Db Select object for userland select query modification
*
* @return Zend_Db_Select
*/
public function getDbSelect()
{
if ($this->_dbSelect == null) {
$this->_dbSelect = $this->_zendDb->select();
}
return $this->_dbSelect;
}
/**
* getResultRowObject() - Returns the result row as a stdClass object
*
* @param string|array $returnColumns
* @param string|array $omitColumns
* @return stdClass|boolean
*/
public function getResultRowObject($returnColumns = null, $omitColumns = null)
{
if (!$this->_resultRow) {
return false;
}
$returnObject = new stdClass();
if (null !== $returnColumns) {
$availableColumns = array_keys($this->_resultRow);
foreach ( (array) $returnColumns as $returnColumn) {
if (in_array($returnColumn, $availableColumns)) {
$returnObject->{$returnColumn} = $this->_resultRow[$returnColumn];
}
}
return $returnObject;
} elseif (null !== $omitColumns) {
$omitColumns = (array) $omitColumns;
foreach ($this->_resultRow as $resultColumn => $resultValue) {
if (!in_array($resultColumn, $omitColumns)) {
$returnObject->{$resultColumn} = $resultValue;
}
}
return $returnObject;
} else {
foreach ($this->_resultRow as $resultColumn => $resultValue) {
$returnObject->{$resultColumn} = $resultValue;
}
return $returnObject;
}
}
/**
* authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to
* attempt an authentication. Previous to this call, this adapter would have already
* been configured with all necessary information to successfully connect to a database
* table and attempt to find a record matching the provided identity.
*
* @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
* @return Zend_Auth_Result
*/
public function authenticate()
{
$this->_authenticateSetup();
$dbSelect = $this->_authenticateCreateSelect();
$resultIdentities = $this->_authenticateQuerySelect($dbSelect);
if ( ($authResult = $this->_authenticateValidateResultSet($resultIdentities)) instanceof Zend_Auth_Result) {
return $authResult;
}
if (true === $this->getAmbiguityIdentity()) {
$validIdentities = array ();
$zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
foreach ($resultIdentities as $identity) {
if (1 === (int) $identity[$zendAuthCredentialMatchColumn]) {
$validIdentities[] = $identity;
}
}
$resultIdentities = $validIdentities;
}
$authResult = $this->_authenticateValidateResult(array_shift($resultIdentities));
return $authResult;
}
/**
* _authenticateSetup() - This method abstracts the steps involved with
* making sure that this adapter was indeed setup properly with all
* required pieces of information.
*
* @throws Zend_Auth_Adapter_Exception - in the event that setup was not done properly
* @return true
*/
protected function _authenticateSetup()
{
$exception = null;
if ($this->_tableName == '') {
$exception = 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
} elseif ($this->_identityColumn == '') {
$exception = 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
} elseif ($this->_credentialColumn == '') {
$exception = 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
} elseif ($this->_identity == '') {
$exception = 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.';
} elseif ($this->_credential === null) {
$exception = 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.';
}
if (null !== $exception) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception($exception);
}
$this->_authenticateResultInfo = array(
'code' => Zend_Auth_Result::FAILURE,
'identity' => $this->_identity,
'messages' => array()
);
return true;
}
/**
* _authenticateCreateSelect() - This method creates a Zend_Db_Select object that
* is completely configured to be queried against the database.
*
* @return Zend_Db_Select
*/
protected function _authenticateCreateSelect()
{
// build credential expression
if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) {
$this->_credentialTreatment = '?';
}
$credentialExpression = new Zend_Db_Expr(
'(CASE WHEN ' .
$this->_zendDb->quoteInto(
$this->_zendDb->quoteIdentifier($this->_credentialColumn, true)
. ' = ' . $this->_credentialTreatment, $this->_credential
)
. ' THEN 1 ELSE 0 END) AS '
. $this->_zendDb->quoteIdentifier(
$this->_zendDb->foldCase('zend_auth_credential_match')
)
);
// get select
$dbSelect = clone $this->getDbSelect();
$dbSelect->from($this->_tableName, array('*', $credentialExpression))
->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity);
return $dbSelect;
}
/**
* _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and
* performs a query against the database with that object.
*
* @param Zend_Db_Select $dbSelect
* @throws Zend_Auth_Adapter_Exception - when an invalid select
* object is encountered
* @return array
*/
protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect)
{
try {
if ($this->_zendDb->getFetchMode() != Zend_DB::FETCH_ASSOC) {
$origDbFetchMode = $this->_zendDb->getFetchMode();
$this->_zendDb->setFetchMode(Zend_DB::FETCH_ASSOC);
}
$resultIdentities = $this->_zendDb->fetchAll($dbSelect);
if (isset($origDbFetchMode)) {
$this->_zendDb->setFetchMode($origDbFetchMode);
unset($origDbFetchMode);
}
} catch (Exception $e) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to '
. 'produce a valid sql statement, please check table and column names '
. 'for validity.', 0, $e);
}
return $resultIdentities;
}
/**
* _authenticateValidateResultSet() - This method attempts to make
* certain that only one record was returned in the resultset
*
* @param array $resultIdentities
* @return true|Zend_Auth_Result
*/
protected function _authenticateValidateResultSet(array $resultIdentities)
{
if (count($resultIdentities) < 1) {
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
$this->_authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.';
return $this->_authenticateCreateAuthResult();
} elseif (count($resultIdentities) > 1 && false === $this->getAmbiguityIdentity()) {
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS;
$this->_authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.';
return $this->_authenticateCreateAuthResult();
}
return true;
}
/**
* _authenticateValidateResult() - This method attempts to validate that
* the record in the resultset is indeed a record that matched the
* identity provided to this adapter.
*
* @param array $resultIdentity
* @return Zend_Auth_Result
*/
protected function _authenticateValidateResult($resultIdentity)
{
$zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') {
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
$this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
return $this->_authenticateCreateAuthResult();
}
unset($resultIdentity[$zendAuthCredentialMatchColumn]);
$this->_resultRow = $resultIdentity;
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::SUCCESS;
$this->_authenticateResultInfo['messages'][] = 'Authentication successful.';
return $this->_authenticateCreateAuthResult();
}
/**
* _authenticateCreateAuthResult() - Creates a Zend_Auth_Result object from
* the information that has been collected during the authenticate() attempt.
*
* @return Zend_Auth_Result
*/
protected function _authenticateCreateAuthResult()
{
return new Zend_Auth_Result(
$this->_authenticateResultInfo['code'],
$this->_authenticateResultInfo['identity'],
$this->_authenticateResultInfo['messages']
);
}
}

View File

@ -1,248 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface
{
/**
* Filename against which authentication queries are performed
*
* @var string
*/
protected $_filename;
/**
* Digest authentication realm
*
* @var string
*/
protected $_realm;
/**
* Digest authentication user
*
* @var string
*/
protected $_username;
/**
* Password for the user of the realm
*
* @var string
*/
protected $_password;
/**
* Sets adapter options
*
* @param mixed $filename
* @param mixed $realm
* @param mixed $username
* @param mixed $password
*/
public function __construct($filename = null, $realm = null, $username = null, $password = null)
{
$options = array('filename', 'realm', 'username', 'password');
foreach ($options as $option) {
if (null !== $$option) {
$methodName = 'set' . ucfirst($option);
$this->$methodName($$option);
}
}
}
/**
* Returns the filename option value or null if it has not yet been set
*
* @return string|null
*/
public function getFilename()
{
return $this->_filename;
}
/**
* Sets the filename option value
*
* @param mixed $filename
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
*/
public function setFilename($filename)
{
$this->_filename = (string) $filename;
return $this;
}
/**
* Returns the realm option value or null if it has not yet been set
*
* @return string|null
*/
public function getRealm()
{
return $this->_realm;
}
/**
* Sets the realm option value
*
* @param mixed $realm
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
*/
public function setRealm($realm)
{
$this->_realm = (string) $realm;
return $this;
}
/**
* Returns the username option value or null if it has not yet been set
*
* @return string|null
*/
public function getUsername()
{
return $this->_username;
}
/**
* Sets the username option value
*
* @param mixed $username
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
*/
public function setUsername($username)
{
$this->_username = (string) $username;
return $this;
}
/**
* Returns the password option value or null if it has not yet been set
*
* @return string|null
*/
public function getPassword()
{
return $this->_password;
}
/**
* Sets the password option value
*
* @param mixed $password
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
*/
public function setPassword($password)
{
$this->_password = (string) $password;
return $this;
}
/**
* Defined by Zend_Auth_Adapter_Interface
*
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result
*/
public function authenticate()
{
$optionsRequired = array('filename', 'realm', 'username', 'password');
foreach ($optionsRequired as $optionRequired) {
if (null === $this->{"_$optionRequired"}) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception("Option '$optionRequired' must be set before authentication");
}
}
if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception("Cannot open '$this->_filename' for reading");
}
$id = "$this->_username:$this->_realm";
$idLength = strlen($id);
$result = array(
'code' => Zend_Auth_Result::FAILURE,
'identity' => array(
'realm' => $this->_realm,
'username' => $this->_username,
),
'messages' => array()
);
while ($line = trim(fgets($fileHandle))) {
if (substr($line, 0, $idLength) === $id) {
if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) {
$result['code'] = Zend_Auth_Result::SUCCESS;
} else {
$result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
$result['messages'][] = 'Password incorrect';
}
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
}
}
$result['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
$result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found";
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
}
/**
* Securely compare two strings for equality while avoided C level memcmp()
* optimisations capable of leaking timing information useful to an attacker
* attempting to iteratively guess the unknown string (e.g. password) being
* compared against.
*
* @param string $a
* @param string $b
* @return bool
*/
protected function _secureStringCompare($a, $b)
{
if (strlen($a) !== strlen($b)) {
return false;
}
$result = 0;
for ($i = 0; $i < strlen($a); $i++) {
$result |= ord($a[$i]) ^ ord($b[$i]);
}
return $result == 0;
}
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Zend_Auth_Exception
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_Exception extends Zend_Auth_Exception
{}

View File

@ -1,853 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
/**
* HTTP Authentication Adapter
*
* Implements a pretty good chunk of RFC 2617.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @todo Support auth-int
* @todo Track nonces, nonce-count, opaque for replay protection and stale support
* @todo Support Authentication-Info header
*/
class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
{
/**
* Reference to the HTTP Request object
*
* @var Zend_Controller_Request_Http
*/
protected $_request;
/**
* Reference to the HTTP Response object
*
* @var Zend_Controller_Response_Http
*/
protected $_response;
/**
* Object that looks up user credentials for the Basic scheme
*
* @var Zend_Auth_Adapter_Http_Resolver_Interface
*/
protected $_basicResolver;
/**
* Object that looks up user credentials for the Digest scheme
*
* @var Zend_Auth_Adapter_Http_Resolver_Interface
*/
protected $_digestResolver;
/**
* List of authentication schemes supported by this class
*
* @var array
*/
protected $_supportedSchemes = array('basic', 'digest');
/**
* List of schemes this class will accept from the client
*
* @var array
*/
protected $_acceptSchemes;
/**
* Space-delimited list of protected domains for Digest Auth
*
* @var string
*/
protected $_domains;
/**
* The protection realm to use
*
* @var string
*/
protected $_realm;
/**
* Nonce timeout period
*
* @var integer
*/
protected $_nonceTimeout;
/**
* Whether to send the opaque value in the header. True by default
*
* @var boolean
*/
protected $_useOpaque;
/**
* List of the supported digest algorithms. I want to support both MD5 and
* MD5-sess, but MD5-sess won't make it into the first version.
*
* @var array
*/
protected $_supportedAlgos = array('MD5');
/**
* The actual algorithm to use. Defaults to MD5
*
* @var string
*/
protected $_algo;
/**
* List of supported qop options. My intetion is to support both 'auth' and
* 'auth-int', but 'auth-int' won't make it into the first version.
*
* @var array
*/
protected $_supportedQops = array('auth');
/**
* Whether or not to do Proxy Authentication instead of origin server
* authentication (send 407's instead of 401's). Off by default.
*
* @var boolean
*/
protected $_imaProxy;
/**
* Flag indicating the client is IE and didn't bother to return the opaque string
*
* @var boolean
*/
protected $_ieNoOpaque;
/**
* Constructor
*
* @param array $config Configuration settings:
* 'accept_schemes' => 'basic'|'digest'|'basic digest'
* 'realm' => <string>
* 'digest_domains' => <string> Space-delimited list of URIs
* 'nonce_timeout' => <int>
* 'use_opaque' => <bool> Whether to send the opaque value in the header
* 'alogrithm' => <string> See $_supportedAlgos. Default: MD5
* 'proxy_auth' => <bool> Whether to do authentication as a Proxy
* @throws Zend_Auth_Adapter_Exception
*/
public function __construct(array $config)
{
if (!extension_loaded('hash')) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception(__CLASS__ . ' requires the \'hash\' extension');
}
$this->_request = null;
$this->_response = null;
$this->_ieNoOpaque = false;
if (empty($config['accept_schemes'])) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Config key \'accept_schemes\' is required');
}
$schemes = explode(' ', $config['accept_schemes']);
$this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes);
if (empty($this->_acceptSchemes)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('No supported schemes given in \'accept_schemes\'. Valid values: '
. implode(', ', $this->_supportedSchemes));
}
// Double-quotes are used to delimit the realm string in the HTTP header,
// and colons are field delimiters in the password file.
if (empty($config['realm']) ||
!ctype_print($config['realm']) ||
strpos($config['realm'], ':') !== false ||
strpos($config['realm'], '"') !== false) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Config key \'realm\' is required, and must contain only printable '
. 'characters, excluding quotation marks and colons');
} else {
$this->_realm = $config['realm'];
}
if (in_array('digest', $this->_acceptSchemes)) {
if (empty($config['digest_domains']) ||
!ctype_print($config['digest_domains']) ||
strpos($config['digest_domains'], '"') !== false) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Config key \'digest_domains\' is required, and must contain '
. 'only printable characters, excluding quotation marks');
} else {
$this->_domains = $config['digest_domains'];
}
if (empty($config['nonce_timeout']) ||
!is_numeric($config['nonce_timeout'])) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Config key \'nonce_timeout\' is required, and must be an '
. 'integer');
} else {
$this->_nonceTimeout = (int) $config['nonce_timeout'];
}
// We use the opaque value unless explicitly told not to
if (isset($config['use_opaque']) && false == (bool) $config['use_opaque']) {
$this->_useOpaque = false;
} else {
$this->_useOpaque = true;
}
if (isset($config['algorithm']) && in_array($config['algorithm'], $this->_supportedAlgos)) {
$this->_algo = $config['algorithm'];
} else {
$this->_algo = 'MD5';
}
}
// Don't be a proxy unless explicitly told to do so
if (isset($config['proxy_auth']) && true == (bool) $config['proxy_auth']) {
$this->_imaProxy = true; // I'm a Proxy
} else {
$this->_imaProxy = false;
}
}
/**
* Setter for the _basicResolver property
*
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
* @return Zend_Auth_Adapter_Http Provides a fluent interface
*/
public function setBasicResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
{
$this->_basicResolver = $resolver;
return $this;
}
/**
* Getter for the _basicResolver property
*
* @return Zend_Auth_Adapter_Http_Resolver_Interface
*/
public function getBasicResolver()
{
return $this->_basicResolver;
}
/**
* Setter for the _digestResolver property
*
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
* @return Zend_Auth_Adapter_Http Provides a fluent interface
*/
public function setDigestResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
{
$this->_digestResolver = $resolver;
return $this;
}
/**
* Getter for the _digestResolver property
*
* @return Zend_Auth_Adapter_Http_Resolver_Interface
*/
public function getDigestResolver()
{
return $this->_digestResolver;
}
/**
* Setter for the Request object
*
* @param Zend_Controller_Request_Http $request
* @return Zend_Auth_Adapter_Http Provides a fluent interface
*/
public function setRequest(Zend_Controller_Request_Http $request)
{
$this->_request = $request;
return $this;
}
/**
* Getter for the Request object
*
* @return Zend_Controller_Request_Http
*/
public function getRequest()
{
return $this->_request;
}
/**
* Setter for the Response object
*
* @param Zend_Controller_Response_Http $response
* @return Zend_Auth_Adapter_Http Provides a fluent interface
*/
public function setResponse(Zend_Controller_Response_Http $response)
{
$this->_response = $response;
return $this;
}
/**
* Getter for the Response object
*
* @return Zend_Controller_Response_Http
*/
public function getResponse()
{
return $this->_response;
}
/**
* Authenticate
*
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result
*/
public function authenticate()
{
if (empty($this->_request) ||
empty($this->_response)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling '
. 'authenticate()');
}
if ($this->_imaProxy) {
$getHeader = 'Proxy-Authorization';
} else {
$getHeader = 'Authorization';
}
$authHeader = $this->_request->getHeader($getHeader);
if (!$authHeader) {
return $this->_challengeClient();
}
list($clientScheme) = explode(' ', $authHeader);
$clientScheme = strtolower($clientScheme);
// The server can issue multiple challenges, but the client should
// answer with only the selected auth scheme.
if (!in_array($clientScheme, $this->_supportedSchemes)) {
$this->_response->setHttpResponseCode(400);
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
array(),
array('Client requested an incorrect or unsupported authentication scheme')
);
}
// client sent a scheme that is not the one required
if (!in_array($clientScheme, $this->_acceptSchemes)) {
// challenge again the client
return $this->_challengeClient();
}
switch ($clientScheme) {
case 'basic':
$result = $this->_basicAuth($authHeader);
break;
case 'digest':
$result = $this->_digestAuth($authHeader);
break;
default:
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Unsupported authentication scheme');
}
return $result;
}
/**
* Challenge Client
*
* Sets a 401 or 407 Unauthorized response code, and creates the
* appropriate Authenticate header(s) to prompt for credentials.
*
* @return Zend_Auth_Result Always returns a non-identity Auth result
*/
protected function _challengeClient()
{
if ($this->_imaProxy) {
$statusCode = 407;
$headerName = 'Proxy-Authenticate';
} else {
$statusCode = 401;
$headerName = 'WWW-Authenticate';
}
$this->_response->setHttpResponseCode($statusCode);
// Send a challenge in each acceptable authentication scheme
if (in_array('basic', $this->_acceptSchemes)) {
$this->_response->setHeader($headerName, $this->_basicHeader());
}
if (in_array('digest', $this->_acceptSchemes)) {
$this->_response->setHeader($headerName, $this->_digestHeader());
}
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
array(),
array('Invalid or absent credentials; challenging client')
);
}
/**
* Basic Header
*
* Generates a Proxy- or WWW-Authenticate header value in the Basic
* authentication scheme.
*
* @return string Authenticate header value
*/
protected function _basicHeader()
{
return 'Basic realm="' . $this->_realm . '"';
}
/**
* Digest Header
*
* Generates a Proxy- or WWW-Authenticate header value in the Digest
* authentication scheme.
*
* @return string Authenticate header value
*/
protected function _digestHeader()
{
$wwwauth = 'Digest realm="' . $this->_realm . '", '
. 'domain="' . $this->_domains . '", '
. 'nonce="' . $this->_calcNonce() . '", '
. ($this->_useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '')
. 'algorithm="' . $this->_algo . '", '
. 'qop="' . implode(',', $this->_supportedQops) . '"';
return $wwwauth;
}
/**
* Basic Authentication
*
* @param string $header Client's Authorization header
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result
*/
protected function _basicAuth($header)
{
if (empty($header)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
}
if (empty($this->_basicResolver)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('A basicResolver object must be set before doing Basic '
. 'authentication');
}
// Decode the Authorization header
$auth = substr($header, strlen('Basic '));
$auth = base64_decode($auth);
if (!$auth) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Unable to base64_decode Authorization header value');
}
// See ZF-1253. Validate the credentials the same way the digest
// implementation does. If invalid credentials are detected,
// re-challenge the client.
if (!ctype_print($auth)) {
return $this->_challengeClient();
}
// Fix for ZF-1515: Now re-challenges on empty username or password
$creds = array_filter(explode(':', $auth));
if (count($creds) != 2) {
return $this->_challengeClient();
}
$password = $this->_basicResolver->resolve($creds[0], $this->_realm);
if ($password && $this->_secureStringCompare($password, $creds[1])) {
$identity = array('username'=>$creds[0], 'realm'=>$this->_realm);
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
} else {
return $this->_challengeClient();
}
}
/**
* Digest Authentication
*
* @param string $header Client's Authorization header
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result Valid auth result only on successful auth
*/
protected function _digestAuth($header)
{
if (empty($header)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
}
if (empty($this->_digestResolver)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('A digestResolver object must be set before doing Digest authentication');
}
$data = $this->_parseDigestAuth($header);
if ($data === false) {
$this->_response->setHttpResponseCode(400);
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
array(),
array('Invalid Authorization header format')
);
}
// See ZF-1052. This code was a bit too unforgiving of invalid
// usernames. Now, if the username is bad, we re-challenge the client.
if ('::invalid::' == $data['username']) {
return $this->_challengeClient();
}
// Verify that the client sent back the same nonce
if ($this->_calcNonce() != $data['nonce']) {
return $this->_challengeClient();
}
// The opaque value is also required to match, but of course IE doesn't
// play ball.
if (!$this->_ieNoOpaque && $this->_calcOpaque() != $data['opaque']) {
return $this->_challengeClient();
}
// Look up the user's password hash. If not found, deny access.
// This makes no assumptions about how the password hash was
// constructed beyond that it must have been built in such a way as
// to be recreatable with the current settings of this object.
$ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']);
if ($ha1 === false) {
return $this->_challengeClient();
}
// If MD5-sess is used, a1 value is made of the user's password
// hash with the server and client nonce appended, separated by
// colons.
if ($this->_algo == 'MD5-sess') {
$ha1 = hash('md5', $ha1 . ':' . $data['nonce'] . ':' . $data['cnonce']);
}
// Calculate h(a2). The value of this hash depends on the qop
// option selected by the client and the supported hash functions
switch ($data['qop']) {
case 'auth':
$a2 = $this->_request->getMethod() . ':' . $data['uri'];
break;
case 'auth-int':
// Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body),
// but this isn't supported yet, so fall through to default case
default:
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Client requested an unsupported qop option');
}
// Using hash() should make parameterizing the hash algorithm
// easier
$ha2 = hash('md5', $a2);
// Calculate the server's version of the request-digest. This must
// match $data['response']. See RFC 2617, section 3.2.2.1
$message = $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $ha2;
$digest = hash('md5', $ha1 . ':' . $message);
// If our digest matches the client's let them in, otherwise return
// a 401 code and exit to prevent access to the protected resource.
if ($this->_secureStringCompare($digest, $data['response'])) {
$identity = array('username'=>$data['username'], 'realm'=>$data['realm']);
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
} else {
return $this->_challengeClient();
}
}
/**
* Calculate Nonce
*
* @return string The nonce value
*/
protected function _calcNonce()
{
// Once subtle consequence of this timeout calculation is that it
// actually divides all of time into _nonceTimeout-sized sections, such
// that the value of timeout is the point in time of the next
// approaching "boundary" of a section. This allows the server to
// consistently generate the same timeout (and hence the same nonce
// value) across requests, but only as long as one of those
// "boundaries" is not crossed between requests. If that happens, the
// nonce will change on its own, and effectively log the user out. This
// would be surprising if the user just logged in.
$timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout;
$nonce = hash('md5', $timeout . ':' . $this->_request->getServer('HTTP_USER_AGENT') . ':' . __CLASS__);
return $nonce;
}
/**
* Calculate Opaque
*
* The opaque string can be anything; the client must return it exactly as
* it was sent. It may be useful to store data in this string in some
* applications. Ideally, a new value for this would be generated each time
* a WWW-Authenticate header is sent (in order to reduce predictability),
* but we would have to be able to create the same exact value across at
* least two separate requests from the same client.
*
* @return string The opaque value
*/
protected function _calcOpaque()
{
return hash('md5', 'Opaque Data:' . __CLASS__);
}
/**
* Parse Digest Authorization header
*
* @param string $header Client's Authorization: HTTP header
* @return array|false Data elements from header, or false if any part of
* the header is invalid
*/
protected function _parseDigestAuth($header)
{
$temp = null;
$data = array();
// See ZF-1052. Detect invalid usernames instead of just returning a
// 400 code.
$ret = preg_match('/username="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])
|| !ctype_print($temp[1])
|| strpos($temp[1], ':') !== false) {
$data['username'] = '::invalid::';
} else {
$data['username'] = $temp[1];
}
$temp = null;
$ret = preg_match('/realm="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!ctype_print($temp[1]) || strpos($temp[1], ':') !== false) {
return false;
} else {
$data['realm'] = $temp[1];
}
$temp = null;
$ret = preg_match('/nonce="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!ctype_xdigit($temp[1])) {
return false;
} else {
$data['nonce'] = $temp[1];
}
$temp = null;
$ret = preg_match('/uri="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
// Section 3.2.2.5 in RFC 2617 says the authenticating server must
// verify that the URI field in the Authorization header is for the
// same resource requested in the Request Line.
$rUri = @parse_url($this->_request->getRequestUri());
$cUri = @parse_url($temp[1]);
if (false === $rUri || false === $cUri) {
return false;
} else {
// Make sure the path portion of both URIs is the same
if ($rUri['path'] != $cUri['path']) {
return false;
}
// Section 3.2.2.5 seems to suggest that the value of the URI
// Authorization field should be made into an absolute URI if the
// Request URI is absolute, but it's vague, and that's a bunch of
// code I don't want to write right now.
$data['uri'] = $temp[1];
}
$temp = null;
$ret = preg_match('/response="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (32 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
return false;
} else {
$data['response'] = $temp[1];
}
$temp = null;
// The spec says this should default to MD5 if omitted. OK, so how does
// that square with the algo we send out in the WWW-Authenticate header,
// if it can easily be overridden by the client?
$ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp);
if ($ret && !empty($temp[1])
&& in_array($temp[1], $this->_supportedAlgos)) {
$data['algorithm'] = $temp[1];
} else {
$data['algorithm'] = 'MD5'; // = $this->_algo; ?
}
$temp = null;
// Not optional in this implementation
$ret = preg_match('/cnonce="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!ctype_print($temp[1])) {
return false;
} else {
$data['cnonce'] = $temp[1];
}
$temp = null;
// If the server sent an opaque value, the client must send it back
if ($this->_useOpaque) {
$ret = preg_match('/opaque="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
// Big surprise: IE isn't RFC 2617-compliant.
if (false !== strpos($this->_request->getHeader('User-Agent'), 'MSIE')) {
$temp[1] = '';
$this->_ieNoOpaque = true;
} else {
return false;
}
}
// This implementation only sends MD5 hex strings in the opaque value
if (!$this->_ieNoOpaque &&
(32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) {
return false;
} else {
$data['opaque'] = $temp[1];
}
$temp = null;
}
// Not optional in this implementation, but must be one of the supported
// qop types
$ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!in_array($temp[1], $this->_supportedQops)) {
return false;
} else {
$data['qop'] = $temp[1];
}
$temp = null;
// Not optional in this implementation. The spec says this value
// shouldn't be a quoted string, but apparently some implementations
// quote it anyway. See ZF-1544.
$ret = preg_match('/nc="?([0-9A-Fa-f]{8})"?/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (8 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
return false;
} else {
$data['nc'] = $temp[1];
}
$temp = null;
return $data;
}
/**
* Securely compare two strings for equality while avoided C level memcmp()
* optimisations capable of leaking timing information useful to an attacker
* attempting to iteratively guess the unknown string (e.g. password) being
* compared against.
*
* @param string $a
* @param string $b
* @return bool
*/
protected function _secureStringCompare($a, $b)
{
if (strlen($a) !== strlen($b)) {
return false;
}
$result = 0;
for ($i = 0; $i < strlen($a); $i++) {
$result |= ord($a[$i]) ^ ord($b[$i]);
}
return $result == 0;
}
}

View File

@ -1,39 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Exception
*/
/**
* HTTP Auth Resolver Exception
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_Http_Resolver_Exception extends Zend_Auth_Exception
{}

View File

@ -1,159 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Http_Resolver_Interface
*/
/**
* HTTP Authentication File Resolver
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_Http_Resolver_File implements Zend_Auth_Adapter_Http_Resolver_Interface
{
/**
* Path to credentials file
*
* @var string
*/
protected $_file;
/**
* Constructor
*
* @param string $path Complete filename where the credentials are stored
*/
public function __construct($path = '')
{
if (!empty($path)) {
$this->setFile($path);
}
}
/**
* Set the path to the credentials file
*
* @param string $path
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
* @return Zend_Auth_Adapter_Http_Resolver_File Provides a fluent interface
*/
public function setFile($path)
{
if (empty($path) || !is_readable($path)) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Path not readable: ' . $path);
}
$this->_file = $path;
return $this;
}
/**
* Returns the path to the credentials file
*
* @return string
*/
public function getFile()
{
return $this->_file;
}
/**
* Resolve credentials
*
* Only the first matching username/realm combination in the file is
* returned. If the file contains credentials for Digest authentication,
* the returned string is the password hash, or h(a1) from RFC 2617. The
* returned string is the plain-text password for Basic authentication.
*
* The expected format of the file is:
* username:realm:sharedSecret
*
* That is, each line consists of the user's username, the applicable
* authentication realm, and the password or hash, each delimited by
* colons.
*
* @param string $username Username
* @param string $realm Authentication Realm
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
* @return string|false User's shared secret, if the user is found in the
* realm, false otherwise.
*/
public function resolve($username, $realm)
{
if (empty($username)) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username is required');
} else if (!ctype_print($username) || strpos($username, ':') !== false) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username must consist only of printable characters, '
. 'excluding the colon');
}
if (empty($realm)) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm is required');
} else if (!ctype_print($realm) || strpos($realm, ':') !== false) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm must consist only of printable characters, '
. 'excluding the colon.');
}
// Open file, read through looking for matching credentials
$fp = @fopen($this->_file, 'r');
if (!$fp) {
/**
* @see Zend_Auth_Adapter_Http_Resolver_Exception
*/
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Unable to open password file: ' . $this->_file);
}
// No real validation is done on the contents of the password file. The
// assumption is that we trust the administrators to keep it secure.
while (($line = fgetcsv($fp, 512, ':')) !== false) {
if ($line[0] == $username && $line[1] == $realm) {
$password = $line[2];
fclose($fp);
return $password;
}
}
fclose($fp);
return false;
}
}

View File

@ -1,47 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Auth HTTP Resolver Interface
*
* Defines an interace to resolve a username/realm combination into a shared
* secret usable by HTTP Authentication.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter_Http
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Auth_Adapter_Http_Resolver_Interface
{
/**
* Resolve username/realm to password/hash/etc.
*
* @param string $username Username
* @param string $realm Authentication Realm
* @return string|false User's shared secret, if the user is found in the
* realm, false otherwise.
*/
public function resolve($username, $realm);
}

View File

@ -1,45 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Result
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Auth_Adapter_Interface
{
/**
* Performs an authentication attempt
*
* @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
* @return Zend_Auth_Result
*/
public function authenticate();
}

View File

@ -1,526 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_Ldap implements Zend_Auth_Adapter_Interface
{
/**
* The Zend_Ldap context.
*
* @var Zend_Ldap
*/
protected $_ldap = null;
/**
* The array of arrays of Zend_Ldap options passed to the constructor.
*
* @var array
*/
protected $_options = null;
/**
* The username of the account being authenticated.
*
* @var string
*/
protected $_username = null;
/**
* The password of the account being authenticated.
*
* @var string
*/
protected $_password = null;
/**
* The DN of the authenticated account. Used to retrieve the account entry on request.
*
* @var string
*/
protected $_authenticatedDn = null;
/**
* Constructor
*
* @param array $options An array of arrays of Zend_Ldap options
* @param string $username The username of the account being authenticated
* @param string $password The password of the account being authenticated
*/
public function __construct(array $options = array(), $username = null, $password = null)
{
$this->setOptions($options);
if ($username !== null) {
$this->setUsername($username);
}
if ($password !== null) {
$this->setPassword($password);
}
}
/**
* Returns the array of arrays of Zend_Ldap options of this adapter.
*
* @return array|null
*/
public function getOptions()
{
return $this->_options;
}
/**
* Sets the array of arrays of Zend_Ldap options to be used by
* this adapter.
*
* @param array $options The array of arrays of Zend_Ldap options
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setOptions($options)
{
$this->_options = is_array($options) ? $options : array();
return $this;
}
/**
* Returns the username of the account being authenticated, or
* NULL if none is set.
*
* @return string|null
*/
public function getUsername()
{
return $this->_username;
}
/**
* Sets the username for binding
*
* @param string $username The username for binding
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setUsername($username)
{
$this->_username = (string) $username;
return $this;
}
/**
* Returns the password of the account being authenticated, or
* NULL if none is set.
*
* @return string|null
*/
public function getPassword()
{
return $this->_password;
}
/**
* Sets the passwort for the account
*
* @param string $password The password of the account being authenticated
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setPassword($password)
{
$this->_password = (string) $password;
return $this;
}
/**
* setIdentity() - set the identity (username) to be used
*
* Proxies to {@see setUsername()}
*
* Closes ZF-6813
*
* @param string $identity
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setIdentity($identity)
{
return $this->setUsername($identity);
}
/**
* setCredential() - set the credential (password) value to be used
*
* Proxies to {@see setPassword()}
*
* Closes ZF-6813
*
* @param string $credential
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setCredential($credential)
{
return $this->setPassword($credential);
}
/**
* Returns the LDAP Object
*
* @return Zend_Ldap The Zend_Ldap object used to authenticate the credentials
*/
public function getLdap()
{
if ($this->_ldap === null) {
/**
* @see Zend_Ldap
*/
$this->_ldap = new Zend_Ldap();
}
return $this->_ldap;
}
/**
* Set an Ldap connection
*
* @param Zend_Ldap $ldap An existing Ldap object
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
*/
public function setLdap(Zend_Ldap $ldap)
{
$this->_ldap = $ldap;
$this->setOptions(array($ldap->getOptions()));
return $this;
}
/**
* Returns a domain name for the current LDAP options. This is used
* for skipping redundant operations (e.g. authentications).
*
* @return string
*/
protected function _getAuthorityName()
{
$options = $this->getLdap()->getOptions();
$name = $options['accountDomainName'];
if (!$name)
$name = $options['accountDomainNameShort'];
return $name ? $name : '';
}
/**
* Authenticate the user
*
* @throws Zend_Auth_Adapter_Exception
* @return Zend_Auth_Result
*/
public function authenticate()
{
/**
* @see Zend_Ldap_Exception
*/
$messages = array();
$messages[0] = ''; // reserved
$messages[1] = ''; // reserved
$username = $this->_username;
$password = $this->_password;
if (!$username) {
$code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
$messages[0] = 'A username is required';
return new Zend_Auth_Result($code, '', $messages);
}
if (!$password) {
/* A password is required because some servers will
* treat an empty password as an anonymous bind.
*/
$code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
$messages[0] = 'A password is required';
return new Zend_Auth_Result($code, '', $messages);
}
$ldap = $this->getLdap();
$code = Zend_Auth_Result::FAILURE;
$messages[0] = "Authority not found: $username";
$failedAuthorities = array();
/* Iterate through each server and try to authenticate the supplied
* credentials against it.
*/
foreach ($this->_options as $name => $options) {
if (!is_array($options)) {
/**
* @see Zend_Auth_Adapter_Exception
*/
throw new Zend_Auth_Adapter_Exception('Adapter options array not an array');
}
$adapterOptions = $this->_prepareOptions($ldap, $options);
$dname = '';
try {
if ($messages[1])
$messages[] = $messages[1];
$messages[1] = '';
$messages[] = $this->_optionsToString($options);
$dname = $this->_getAuthorityName();
if (isset($failedAuthorities[$dname])) {
/* If multiple sets of server options for the same domain
* are supplied, we want to skip redundant authentications
* where the identity or credentials where found to be
* invalid with another server for the same domain. The
* $failedAuthorities array tracks this condition (and also
* serves to supply the original error message).
* This fixes issue ZF-4093.
*/
$messages[1] = $failedAuthorities[$dname];
$messages[] = "Skipping previously failed authority: $dname";
continue;
}
$canonicalName = $ldap->getCanonicalAccountName($username);
$ldap->bind($canonicalName, $password);
/*
* Fixes problem when authenticated user is not allowed to retrieve
* group-membership information or own account.
* This requires that the user specified with "username" and optionally
* "password" in the Zend_Ldap options is able to retrieve the required
* information.
*/
$requireRebind = false;
if (isset($options['username'])) {
$ldap->bind();
$requireRebind = true;
}
$dn = $ldap->getCanonicalAccountName($canonicalName, Zend_Ldap::ACCTNAME_FORM_DN);
$groupResult = $this->_checkGroupMembership($ldap, $canonicalName, $dn, $adapterOptions);
if ($groupResult === true) {
$this->_authenticatedDn = $dn;
$messages[0] = '';
$messages[1] = '';
$messages[] = "$canonicalName authentication successful";
if ($requireRebind === true) {
// rebinding with authenticated user
$ldap->bind($dn, $password);
}
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $canonicalName, $messages);
} else {
$messages[0] = 'Account is not a member of the specified group';
$messages[1] = $groupResult;
$failedAuthorities[$dname] = $groupResult;
}
} catch (Zend_Ldap_Exception $zle) {
/* LDAP based authentication is notoriously difficult to diagnose. Therefore
* we bend over backwards to capture and record every possible bit of
* information when something goes wrong.
*/
$err = $zle->getCode();
if ($err == Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH) {
/* This error indicates that the domain supplied in the
* username did not match the domains in the server options
* and therefore we should just skip to the next set of
* server options.
*/
continue;
} else if ($err == Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT) {
$code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
$messages[0] = "Account not found: $username";
$failedAuthorities[$dname] = $zle->getMessage();
} else if ($err == Zend_Ldap_Exception::LDAP_INVALID_CREDENTIALS) {
$code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
$messages[0] = 'Invalid credentials';
$failedAuthorities[$dname] = $zle->getMessage();
} else {
$line = $zle->getLine();
$messages[] = $zle->getFile() . "($line): " . $zle->getMessage();
$messages[] = preg_replace(
'/\b'.preg_quote(substr($password, 0, 15), '/').'\b/',
'*****',
$zle->getTraceAsString()
);
$messages[0] = 'An unexpected failure occurred';
}
$messages[1] = $zle->getMessage();
}
}
$msg = isset($messages[1]) ? $messages[1] : $messages[0];
$messages[] = "$username authentication failed: $msg";
return new Zend_Auth_Result($code, $username, $messages);
}
/**
* Sets the LDAP specific options on the Zend_Ldap instance
*
* @param Zend_Ldap $ldap
* @param array $options
* @return array of auth-adapter specific options
*/
protected function _prepareOptions(Zend_Ldap $ldap, array $options)
{
$adapterOptions = array(
'group' => null,
'groupDn' => $ldap->getBaseDn(),
'groupScope' => Zend_Ldap::SEARCH_SCOPE_SUB,
'groupAttr' => 'cn',
'groupFilter' => 'objectClass=groupOfUniqueNames',
'memberAttr' => 'uniqueMember',
'memberIsDn' => true
);
foreach ($adapterOptions as $key => $value) {
if (array_key_exists($key, $options)) {
$value = $options[$key];
unset($options[$key]);
switch ($key) {
case 'groupScope':
$value = (int)$value;
if (in_array($value, array(Zend_Ldap::SEARCH_SCOPE_BASE,
Zend_Ldap::SEARCH_SCOPE_ONE, Zend_Ldap::SEARCH_SCOPE_SUB), true)) {
$adapterOptions[$key] = $value;
}
break;
case 'memberIsDn':
$adapterOptions[$key] = ($value === true ||
$value === '1' || strcasecmp($value, 'true') == 0);
break;
default:
$adapterOptions[$key] = trim($value);
break;
}
}
}
$ldap->setOptions($options);
return $adapterOptions;
}
/**
* Checks the group membership of the bound user
*
* @param Zend_Ldap $ldap
* @param string $canonicalName
* @param string $dn
* @param array $adapterOptions
* @return string|true
*/
protected function _checkGroupMembership(Zend_Ldap $ldap, $canonicalName, $dn, array $adapterOptions)
{
if ($adapterOptions['group'] === null) {
return true;
}
if ($adapterOptions['memberIsDn'] === false) {
$user = $canonicalName;
} else {
$user = $dn;
}
/**
* @see Zend_Ldap_Filter
*/
$groupName = Zend_Ldap_Filter::equals($adapterOptions['groupAttr'], $adapterOptions['group']);
$membership = Zend_Ldap_Filter::equals($adapterOptions['memberAttr'], $user);
$group = Zend_Ldap_Filter::andFilter($groupName, $membership);
$groupFilter = $adapterOptions['groupFilter'];
if (!empty($groupFilter)) {
$group = $group->addAnd($groupFilter);
}
$result = $ldap->count($group, $adapterOptions['groupDn'], $adapterOptions['groupScope']);
if ($result === 1) {
return true;
} else {
return 'Failed to verify group membership with ' . $group->toString();
}
}
/**
* getAccountObject() - Returns the result entry as a stdClass object
*
* This resembles the feature {@see Zend_Auth_Adapter_DbTable::getResultRowObject()}.
* Closes ZF-6813
*
* @param array $returnAttribs
* @param array $omitAttribs
* @return stdClass|boolean
*/
public function getAccountObject(array $returnAttribs = array(), array $omitAttribs = array())
{
if (!$this->_authenticatedDn) {
return false;
}
$returnObject = new stdClass();
$returnAttribs = array_map('strtolower', $returnAttribs);
$omitAttribs = array_map('strtolower', $omitAttribs);
$returnAttribs = array_diff($returnAttribs, $omitAttribs);
$entry = $this->getLdap()->getEntry($this->_authenticatedDn, $returnAttribs, true);
foreach ($entry as $attr => $value) {
if (in_array($attr, $omitAttribs)) {
// skip attributes marked to be omitted
continue;
}
if (is_array($value)) {
$returnObject->$attr = (count($value) > 1) ? $value : $value[0];
} else {
$returnObject->$attr = $value;
}
}
return $returnObject;
}
/**
* Converts options to string
*
* @param array $options
* @return string
*/
private function _optionsToString(array $options)
{
$str = '';
foreach ($options as $key => $val) {
if ($key === 'password')
$val = '*****';
if ($str)
$str .= ',';
$str .= $key . '=' . $val;
}
return $str;
}
}

View File

@ -1,281 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Adapter_Interface
*/
/**
* @see Zend_OpenId_Consumer
*/
/**
* A Zend_Auth Authentication Adapter allowing the use of OpenID protocol as an
* authentication mechanism
*
* @category Zend
* @package Zend_Auth
* @subpackage Zend_Auth_Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Adapter_OpenId implements Zend_Auth_Adapter_Interface
{
/**
* The identity value being authenticated
*
* @var string
*/
private $_id = null;
/**
* Reference to an implementation of a storage object
*
* @var Zend_OpenId_Consumer_Storage
*/
private $_storage = null;
/**
* The URL to redirect response from server to
*
* @var string
*/
private $_returnTo = null;
/**
* The HTTP URL to identify consumer on server
*
* @var string
*/
private $_root = null;
/**
* Extension object or array of extensions objects
*
* @var string
*/
private $_extensions = null;
/**
* The response object to perform HTTP or HTML form redirection
*
* @var Zend_Controller_Response_Abstract
*/
private $_response = null;
/**
* Enables or disables interaction with user during authentication on
* OpenID provider.
*
* @var bool
*/
private $_check_immediate = false;
/**
* HTTP client to make HTTP requests
*
* @var Zend_Http_Client $_httpClient
*/
private $_httpClient = null;
/**
* Constructor
*
* @param string $id the identity value
* @param Zend_OpenId_Consumer_Storage $storage an optional implementation
* of a storage object
* @param string $returnTo HTTP URL to redirect response from server to
* @param string $root HTTP URL to identify consumer on server
* @param mixed $extensions extension object or array of extensions objects
* @param Zend_Controller_Response_Abstract $response an optional response
* object to perform HTTP or HTML form redirection
*/
public function __construct($id = null,
Zend_OpenId_Consumer_Storage $storage = null,
$returnTo = null,
$root = null,
$extensions = null,
Zend_Controller_Response_Abstract $response = null) {
$this->_id = $id;
$this->_storage = $storage;
$this->_returnTo = $returnTo;
$this->_root = $root;
$this->_extensions = $extensions;
$this->_response = $response;
}
/**
* Sets the value to be used as the identity
*
* @param string $id the identity value
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setIdentity($id)
{
$this->_id = $id;
return $this;
}
/**
* Sets the storage implementation which will be use by OpenId
*
* @param Zend_OpenId_Consumer_Storage $storage
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setStorage(Zend_OpenId_Consumer_Storage $storage)
{
$this->_storage = $storage;
return $this;
}
/**
* Sets the HTTP URL to redirect response from server to
*
* @param string $returnTo
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setReturnTo($returnTo)
{
$this->_returnTo = $returnTo;
return $this;
}
/**
* Sets HTTP URL to identify consumer on server
*
* @param string $root
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setRoot($root)
{
$this->_root = $root;
return $this;
}
/**
* Sets OpenID extension(s)
*
* @param mixed $extensions
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setExtensions($extensions)
{
$this->_extensions = $extensions;
return $this;
}
/**
* Sets an optional response object to perform HTTP or HTML form redirection
*
* @param string $response
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setResponse($response)
{
$this->_response = $response;
return $this;
}
/**
* Enables or disables interaction with user during authentication on
* OpenID provider.
*
* @param bool $check_immediate
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
*/
public function setCheckImmediate($check_immediate)
{
$this->_check_immediate = $check_immediate;
return $this;
}
/**
* Sets HTTP client object to make HTTP requests
*
* @param Zend_Http_Client $client HTTP client object to be used
*/
public function setHttpClient($client) {
$this->_httpClient = $client;
}
/**
* Authenticates the given OpenId identity.
* Defined by Zend_Auth_Adapter_Interface.
*
* @throws Zend_Auth_Adapter_Exception If answering the authentication query is impossible
* @return Zend_Auth_Result
*/
public function authenticate() {
$id = $this->_id;
if (!empty($id)) {
$consumer = new Zend_OpenId_Consumer($this->_storage);
$consumer->setHttpClient($this->_httpClient);
/* login() is never returns on success */
if (!$this->_check_immediate) {
if (!$consumer->login($id,
$this->_returnTo,
$this->_root,
$this->_extensions,
$this->_response)) {
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE,
$id,
array("Authentication failed", $consumer->getError()));
}
} else {
if (!$consumer->check($id,
$this->_returnTo,
$this->_root,
$this->_extensions,
$this->_response)) {
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE,
$id,
array("Authentication failed", $consumer->getError()));
}
}
} else {
$params = (isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD']=='POST') ? $_POST: $_GET;
$consumer = new Zend_OpenId_Consumer($this->_storage);
$consumer->setHttpClient($this->_httpClient);
if ($consumer->verify(
$params,
$id,
$this->_extensions)) {
return new Zend_Auth_Result(
Zend_Auth_Result::SUCCESS,
$id,
array("Authentication successful"));
} else {
return new Zend_Auth_Result(
Zend_Auth_Result::FAILURE,
$id,
array("Authentication failed", $consumer->getError()));
}
}
}
}

View File

@ -1,35 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Exception
*/
/**
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Exception extends Zend_Exception
{}

View File

@ -1,147 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Auth
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Result
{
/**
* General Failure
*/
const FAILURE = 0;
/**
* Failure due to identity not being found.
*/
const FAILURE_IDENTITY_NOT_FOUND = -1;
/**
* Failure due to identity being ambiguous.
*/
const FAILURE_IDENTITY_AMBIGUOUS = -2;
/**
* Failure due to invalid credential being supplied.
*/
const FAILURE_CREDENTIAL_INVALID = -3;
/**
* Failure due to uncategorized reasons.
*/
const FAILURE_UNCATEGORIZED = -4;
/**
* Authentication success.
*/
const SUCCESS = 1;
/**
* Authentication result code
*
* @var int
*/
protected $_code;
/**
* The identity used in the authentication attempt
*
* @var mixed
*/
protected $_identity;
/**
* An array of string reasons why the authentication attempt was unsuccessful
*
* If authentication was successful, this should be an empty array.
*
* @var array
*/
protected $_messages;
/**
* Sets the result code, identity, and failure messages
*
* @param int $code
* @param mixed $identity
* @param array $messages
*/
public function __construct($code, $identity, array $messages = array())
{
$code = (int) $code;
if ($code < self::FAILURE_UNCATEGORIZED) {
$code = self::FAILURE;
} elseif ($code > self::SUCCESS ) {
$code = 1;
}
$this->_code = $code;
$this->_identity = $identity;
$this->_messages = $messages;
}
/**
* Returns whether the result represents a successful authentication attempt
*
* @return boolean
*/
public function isValid()
{
return ($this->_code > 0) ? true : false;
}
/**
* getCode() - Get the result code for this authentication attempt
*
* @return int
*/
public function getCode()
{
return $this->_code;
}
/**
* Returns the identity used in the authentication attempt
*
* @return mixed
*/
public function getIdentity()
{
return $this->_identity;
}
/**
* Returns an array of string reasons why the authentication attempt was unsuccessful
*
* If authentication was successful, this method returns an empty array.
*
* @return array
*/
public function getMessages()
{
return $this->_messages;
}
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Exception
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Storage_Exception extends Zend_Auth_Exception
{}

View File

@ -1,66 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Auth_Storage_Interface
{
/**
* Returns true if and only if storage is empty
*
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
* @return boolean
*/
public function isEmpty();
/**
* Returns the contents of storage
*
* Behavior is undefined when storage is empty.
*
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
* @return mixed
*/
public function read();
/**
* Writes $contents to storage
*
* @param mixed $contents
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
* @return void
*/
public function write($contents);
/**
* Clears contents from storage
*
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
* @return void
*/
public function clear();
}

View File

@ -1,94 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Storage_Interface
*/
/**
* Non-Persistent Auth Storage
*
* Since HTTP Authentication happens again on each request, this will always be
* re-populated. So there's no need to use sessions, this simple value class
* will hold the data for rest of the current request.
*
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Storage_NonPersistent implements Zend_Auth_Storage_Interface
{
/**
* Holds the actual auth data
*/
protected $_data;
/**
* Returns true if and only if storage is empty
*
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
* @return boolean
*/
public function isEmpty()
{
return empty($this->_data);
}
/**
* Returns the contents of storage
* Behavior is undefined when storage is empty.
*
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
* @return mixed
*/
public function read()
{
return $this->_data;
}
/**
* Writes $contents to storage
*
* @param mixed $contents
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
* @return void
*/
public function write($contents)
{
$this->_data = $contents;
}
/**
* Clears contents from storage
*
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
* @return void
*/
public function clear()
{
$this->_data = null;
}
}

View File

@ -1,147 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Auth_Storage_Interface
*/
/**
* @see Zend_Session
*/
/**
* @category Zend
* @package Zend_Auth
* @subpackage Storage
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
{
/**
* Default session namespace
*/
const NAMESPACE_DEFAULT = 'Zend_Auth';
/**
* Default session object member name
*/
const MEMBER_DEFAULT = 'storage';
/**
* Object to proxy $_SESSION storage
*
* @var Zend_Session_Namespace
*/
protected $_session;
/**
* Session namespace
*
* @var mixed
*/
protected $_namespace;
/**
* Session object member
*
* @var mixed
*/
protected $_member;
/**
* Sets session storage options and initializes session namespace object
*
* @param mixed $namespace
* @param mixed $member
*/
public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
{
$this->_namespace = $namespace;
$this->_member = $member;
$this->_session = new Zend_Session_Namespace($this->_namespace);
}
/**
* Returns the session namespace
*
* @return string
*/
public function getNamespace()
{
return $this->_namespace;
}
/**
* Returns the name of the session object member
*
* @return string
*/
public function getMember()
{
return $this->_member;
}
/**
* Defined by Zend_Auth_Storage_Interface
*
* @return boolean
*/
public function isEmpty()
{
return !isset($this->_session->{$this->_member});
}
/**
* Defined by Zend_Auth_Storage_Interface
*
* @return mixed
*/
public function read()
{
return $this->_session->{$this->_member};
}
/**
* Defined by Zend_Auth_Storage_Interface
*
* @param mixed $contents
* @return void
*/
public function write($contents)
{
$this->_session->{$this->_member} = $contents;
}
/**
* Defined by Zend_Auth_Storage_Interface
*
* @return void
*/
public function clear()
{
unset($this->_session->{$this->_member});
}
}

View File

@ -1,343 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Class for generate Barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode
{
/**
* Factory for Zend_Barcode classes.
*
* First argument may be a string containing the base of the adapter class
* name, e.g. 'int25' corresponds to class Zend_Barcode_Object_Int25. This
* is case-insensitive.
*
* First argument may alternatively be an object of type Zend_Config.
* The barcode class base name is read from the 'barcode' property.
* The barcode config parameters are read from the 'params' property.
*
* Second argument is optional and may be an associative array of key-value
* pairs. This is used as the argument to the barcode constructor.
*
* If the first argument is of type Zend_Config, it is assumed to contain
* all parameters, and the second argument is ignored.
*
* @param mixed $barcode String name of barcode class, or Zend_Config object.
* @param mixed $renderer String name of renderer class
* @param mixed $barcodeConfig OPTIONAL; an array or Zend_Config object with barcode parameters.
* @param mixed $rendererConfig OPTIONAL; an array or Zend_Config object with renderer parameters.
* @param boolean $automaticRenderError OPTIONAL; set the automatic rendering of exception
* @return Zend_Barcode
* @throws Zend_Barcode_Exception
*/
public static function factory(
$barcode,
$renderer = 'image',
$barcodeConfig = array(),
$rendererConfig = array(),
$automaticRenderError = true
) {
/*
* Convert Zend_Config argument to plain string
* barcode name and separate config object.
*/
if ($barcode instanceof Zend_Config) {
if (isset($barcode->rendererParams)) {
$rendererConfig = $barcode->rendererParams->toArray();
}
if (isset($barcode->renderer)) {
$renderer = (string) $barcode->renderer;
}
if (isset($barcode->barcodeParams)) {
$barcodeConfig = $barcode->barcodeParams->toArray();
}
if (isset($barcode->barcode)) {
$barcode = (string) $barcode->barcode;
} else {
$barcode = null;
}
}
try {
$barcode = self::makeBarcode($barcode, $barcodeConfig);
$renderer = self::makeRenderer($renderer, $rendererConfig);
} catch (Zend_Exception $e) {
$renderable = ($e instanceof Zend_Barcode_Exception) ? $e->isRenderable() : false;
if ($automaticRenderError && $renderable) {
$barcode = self::makeBarcode('error', array(
'text' => $e->getMessage()
));
$renderer = self::makeRenderer($renderer, array());
} else {
throw $e;
}
}
$renderer->setAutomaticRenderError($automaticRenderError);
return $renderer->setBarcode($barcode);
}
/**
* Barcode Constructor
*
* @param mixed $barcode String name of barcode class, or Zend_Config object.
* @param mixed $barcodeConfig OPTIONAL; an array or Zend_Config object with barcode parameters.
* @return Zend_Barcode_Object
*/
public static function makeBarcode($barcode, $barcodeConfig = array())
{
if ($barcode instanceof Zend_Barcode_Object_ObjectAbstract) {
return $barcode;
}
/*
* Convert Zend_Config argument to plain string
* barcode name and separate config object.
*/
if ($barcode instanceof Zend_Config) {
if (isset($barcode->barcodeParams) && $barcode->barcodeParams instanceof Zend_Config) {
$barcodeConfig = $barcode->barcodeParams->toArray();
}
if (isset($barcode->barcode)) {
$barcode = (string) $barcode->barcode;
} else {
$barcode = null;
}
}
if ($barcodeConfig instanceof Zend_Config) {
$barcodeConfig = $barcodeConfig->toArray();
}
/*
* Verify that barcode parameters are in an array.
*/
if (!is_array($barcodeConfig)) {
/**
* @see Zend_Barcode_Exception
*/
throw new Zend_Barcode_Exception(
'Barcode parameters must be in an array or a Zend_Config object'
);
}
/*
* Verify that an barcode name has been specified.
*/
if (!is_string($barcode) || empty($barcode)) {
/**
* @see Zend_Barcode_Exception
*/
throw new Zend_Barcode_Exception(
'Barcode name must be specified in a string'
);
}
/*
* Form full barcode class name
*/
$barcodeNamespace = 'Zend_Barcode_Object';
if (isset($barcodeConfig['barcodeNamespace'])) {
$barcodeNamespace = $barcodeConfig['barcodeNamespace'];
}
$barcodeName = strtolower($barcodeNamespace . '_' . $barcode);
$barcodeName = str_replace(' ', '_', ucwords(
str_replace( '_', ' ', $barcodeName)
));
/*
* Load the barcode class. This throws an exception
* if the specified class cannot be loaded.
*/
if (!class_exists($barcodeName)) {
Zend_Loader::loadClass($barcodeName);
}
/*
* Create an instance of the barcode class.
* Pass the config to the barcode class constructor.
*/
$bcAdapter = new $barcodeName($barcodeConfig);
/*
* Verify that the object created is a descendent of the abstract barcode type.
*/
if (!$bcAdapter instanceof Zend_Barcode_Object_ObjectAbstract) {
/**
* @see Zend_Barcode_Exception
*/
throw new Zend_Barcode_Exception(
"Barcode class '$barcodeName' does not extend Zend_Barcode_Object_ObjectAbstract"
);
}
return $bcAdapter;
}
/**
* Renderer Constructor
*
* @param mixed $renderer String name of renderer class, or Zend_Config object.
* @param mixed $rendererConfig OPTIONAL; an array or Zend_Config object with renderer parameters.
* @return Zend_Barcode_Renderer
*/
public static function makeRenderer($renderer = 'image', $rendererConfig = array())
{
if ($renderer instanceof Zend_Barcode_Renderer_RendererAbstract) {
return $renderer;
}
/*
* Convert Zend_Config argument to plain string
* barcode name and separate config object.
*/
if ($renderer instanceof Zend_Config) {
if (isset($renderer->rendererParams)) {
$rendererConfig = $renderer->rendererParams->toArray();
}
if (isset($renderer->renderer)) {
$renderer = (string) $renderer->renderer;
}
}
if ($rendererConfig instanceof Zend_Config) {
$rendererConfig = $rendererConfig->toArray();
}
/*
* Verify that barcode parameters are in an array.
*/
if (!is_array($rendererConfig)) {
/**
* @see Zend_Barcode_Exception
*/
$e = new Zend_Barcode_Exception(
'Barcode parameters must be in an array or a Zend_Config object'
);
$e->setIsRenderable(false);
throw $e;
}
/*
* Verify that an barcode name has been specified.
*/
if (!is_string($renderer) || empty($renderer)) {
/**
* @see Zend_Barcode_Exception
*/
$e = new Zend_Barcode_Exception(
'Renderer name must be specified in a string'
);
$e->setIsRenderable(false);
throw $e;
}
/*
* Form full barcode class name
*/
$rendererNamespace = 'Zend_Barcode_Renderer';
if (isset($rendererConfig['rendererNamespace'])) {
$rendererNamespace = $rendererConfig['rendererNamespace'];
}
$rendererName = strtolower($rendererNamespace . '_' . $renderer);
$rendererName = str_replace(' ', '_', ucwords(
str_replace( '_', ' ', $rendererName)
));
/*
* Load the barcode class. This throws an exception
* if the specified class cannot be loaded.
*/
if (!class_exists($rendererName)) {
Zend_Loader::loadClass($rendererName);
}
/*
* Create an instance of the barcode class.
* Pass the config to the barcode class constructor.
*/
$rdrAdapter = new $rendererName($rendererConfig);
/*
* Verify that the object created is a descendent of the abstract barcode type.
*/
if (!$rdrAdapter instanceof Zend_Barcode_Renderer_RendererAbstract) {
/**
* @see Zend_Barcode_Exception
*/
$e = new Zend_Barcode_Exception(
"Renderer class '$rendererName' does not extend Zend_Barcode_Renderer_RendererAbstract"
);
$e->setIsRenderable(false);
throw $e;
}
return $rdrAdapter;
}
/**
* Proxy to renderer render() method
*
* @param string | Zend_Barcode_Object | array | Zend_Config $barcode
* @param string | Zend_Barcode_Renderer $renderer
* @param array | Zend_Config $barcodeConfig
* @param array | Zend_Config $rendererConfig
*/
public static function render(
$barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array()
) {
self::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->render();
}
/**
* Proxy to renderer draw() method
*
* @param string | Zend_Barcode_Object | array | Zend_Config $barcode
* @param string | Zend_Barcode_Renderer $renderer
* @param array | Zend_Config $barcodeConfig
* @param array | Zend_Config $rendererConfig
* @return mixed
*/
public static function draw(
$barcode,
$renderer,
$barcodeConfig = array(),
$rendererConfig = array()
) {
return self::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->draw();
}
/**
* Proxy for setBarcodeFont of Zend_Barcode_Object
* @param string $font
* @eturn void
*/
public static function setBarcodeFont($font)
{
Zend_Barcode_Object_ObjectAbstract::setBarcodeFont($font);
}
}

View File

@ -1,62 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE.txt, and
* is available through the world-wide-web at the following URL:
* http://framework.zend.com/license/new-bsd. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Zend_Exception
*/
/**
* Zend_Barcode_Exception
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Exception extends Zend_Exception
{
/**
* Is this exception renderable?
* @var bool
*/
protected $_isRenderable = true;
/**
* Set renderable flag
*
* @param bool $flag
* @return Zend_Barcode_Exception
*/
public function setIsRenderable($flag)
{
$this->_isRenderable = (bool) $flag;
return $this;
}
/**
* Retrieve renderable flag
*
* @return bool
*/
public function isRenderable()
{
return $this->_isRenderable;
}
}

View File

@ -1,393 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Code25.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Code128 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code128 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Drawing of checksum
* (even if it's sometime optional, most of time it's required)
* @var boolean
*/
protected $_withChecksum = true;
/**
* @var array
*/
protected $_convertedText = array();
protected $_codingMap = array(
0 => "11011001100", 1 => "11001101100", 2 => "11001100110",
3 => "10010011000", 4 => "10010001100", 5 => "10001001100",
6 => "10011001000", 7 => "10011000100", 8 => "10001100100",
9 => "11001001000", 10 => "11001000100", 11 => "11000100100",
12 => "10110011100", 13 => "10011011100", 14 => "10011001110",
15 => "10111001100", 16 => "10011101100", 17 => "10011100110",
18 => "11001110010", 19 => "11001011100", 20 => "11001001110",
21 => "11011100100", 22 => "11001110100", 23 => "11101101110",
24 => "11101001100", 25 => "11100101100", 26 => "11100100110",
27 => "11101100100", 28 => "11100110100", 29 => "11100110010",
30 => "11011011000", 31 => "11011000110", 32 => "11000110110",
33 => "10100011000", 34 => "10001011000", 35 => "10001000110",
36 => "10110001000", 37 => "10001101000", 38 => "10001100010",
39 => "11010001000", 40 => "11000101000", 41 => "11000100010",
42 => "10110111000", 43 => "10110001110", 44 => "10001101110",
45 => "10111011000", 46 => "10111000110", 47 => "10001110110",
48 => "11101110110", 49 => "11010001110", 50 => "11000101110",
51 => "11011101000", 52 => "11011100010", 53 => "11011101110",
54 => "11101011000", 55 => "11101000110", 56 => "11100010110",
57 => "11101101000", 58 => "11101100010", 59 => "11100011010",
60 => "11101111010", 61 => "11001000010", 62 => "11110001010",
63 => "10100110000", 64 => "10100001100", 65 => "10010110000",
66 => "10010000110", 67 => "10000101100", 68 => "10000100110",
69 => "10110010000", 70 => "10110000100", 71 => "10011010000",
72 => "10011000010", 73 => "10000110100", 74 => "10000110010",
75 => "11000010010", 76 => "11001010000", 77 => "11110111010",
78 => "11000010100", 79 => "10001111010", 80 => "10100111100",
81 => "10010111100", 82 => "10010011110", 83 => "10111100100",
84 => "10011110100", 85 => "10011110010", 86 => "11110100100",
87 => "11110010100", 88 => "11110010010", 89 => "11011011110",
90 => "11011110110", 91 => "11110110110", 92 => "10101111000",
93 => "10100011110", 94 => "10001011110", 95 => "10111101000",
96 => "10111100010", 97 => "11110101000", 98 => "11110100010",
99 => "10111011110", 100 => "10111101110", 101 => "11101011110",
102 => "11110101110",
103 => "11010000100", 104 => "11010010000", 105 => "11010011100",
106 => "1100011101011");
/**
* Character sets ABC
* @var array
*/
protected $_charSets = array(
'A' => array(
' ', '!', '"', '#', '$', '%', '&', "'",
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
'FNC3', 'FNC2', 'SHIFT', 'Code C', 'Code B', 'FNC4', 'FNC1',
'START A', 'START B', 'START C', 'STOP'),
'B' => array(
' ', '!', '"', '#', '$', '%', '&', "'",
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', 0x7F,
'FNC3', 'FNC2', 'SHIFT', 'Code C', 'FNC4', 'Code A', 'FNC1',
'START A', 'START B', 'START C', 'STOP',),
'C' => array(
'00', '01', '02', '03', '04', '05', '06', '07', '08', '09',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
'20', '21', '22', '23', '24', '25', '26', '27', '28', '29',
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39',
'40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
'50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
'60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
'70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
'80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
'90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
'Code B', 'Code A', 'FNC1', 'START A', 'START B', 'START C', 'STOP'));
/*'A' => array(
' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
'('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
'0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
'8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
'@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
0x00=>64, 0x01=>65, 0x02=>66, 0x03=>67, 0x04=>68, 0x05=>69, 0x06=>70, 0x07=>71,
0x08=>72, 0x09=>73, 0x0A=>74, 0x0B=>75, 0x0C=>76, 0x0D=>77, 0x0E=>78, 0x0F=>79,
0x10=>80, 0x11=>81, 0x12=>82, 0x13=>83, 0x14=>84, 0x15=>85, 0x16=>86, 0x17=>87,
0x18=>88, 0x19=>89, 0x1A=>90, 0x1B=>91, 0x1C=>92, 0x1D=>93, 0x1E=>94, 0x1F=>95,
'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'Code B'=>100, 'FNC4'=>101, 'FNC1'=>102, 'START A'=>103,
'START B'=>104, 'START C'=>105, 'STOP'=>106),
'B' => array(
' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
'('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
'0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
'8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
'@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
'`' =>64, 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71,
'h'=>72, 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79,
'p'=>80, 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87,
'x'=>88, 'y'=>89, 'z'=>90, '{'=>91, '|'=>92, '}'=>93, '~'=>94, 0x7F=>95,
'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'FNC4'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103,
'START B'=>104, 'START C'=>105, 'STOP'=>106,),
'C' => array(
'00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, '06'=>6, '07'=>7, '08'=>8, '09'=>9,
'10'=>10, '11'=>11, '12'=>12, '13'=>13, '14'=>14, '15'=>15, '16'=>16, '17'=>17, '18'=>18, '19'=>19,
'20'=>20, '21'=>21, '22'=>22, '23'=>23, '24'=>24, '25'=>25, '26'=>26, '27'=>27, '28'=>28, '29'=>29,
'30'=>30, '31'=>31, '32'=>32, '33'=>33, '34'=>34, '35'=>35, '36'=>36, '37'=>37, '38'=>38, '39'=>39,
'40'=>40, '41'=>41, '42'=>42, '43'=>43, '44'=>44, '45'=>45, '46'=>46, '47'=>47, '48'=>48, '49'=>49,
'50'=>50, '51'=>51, '52'=>52, '53'=>53, '54'=>54, '55'=>55, '56'=>56, '57'=>57, '58'=>58, '59'=>59,
'60'=>60, '61'=>61, '62'=>62, '63'=>63, '64'=>64, '65'=>65, '66'=>66, '67'=>67, '68'=>68, '69'=>69,
'70'=>70, '71'=>71, '72'=>72, '73'=>73, '74'=>74, '75'=>75, '76'=>76, '77'=>77, '78'=>78, '79'=>79,
'80'=>80, '81'=>81, '82'=>82, '83'=>83, '84'=>84, '85'=>85, '86'=>86, '87'=>87, '88'=>88, '89'=>89,
'90'=>90, '91'=>91, '92'=>92, '93'=>93, '94'=>94, '95'=>95, '96'=>96, '97'=>97, '98'=>98, '99'=>99,
'Code B'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103, 'START B'=>104, 'START C'=>105, 'STOP'=>106));*/
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
// Each characters contain 11 bars...
$characterLength = 11 * $this->_barThinWidth * $this->_factor;
$convertedChars = count($this->_convertToBarcodeChars($this->getText()));
if ($this->_withChecksum) {
$convertedChars++;
}
$encodedData = $convertedChars * $characterLength;
// ...except the STOP character (13)
$encodedData += $characterLength + 2 * $this->_barThinWidth * $this->_factor;
$width = $quietZone + $encodedData + $quietZone;
return $width;
}
/**
* Partial check of code128 barcode
* @return void
*/
protected function _checkParams()
{
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$convertedChars = $this->_convertToBarcodeChars($this->getText());
if ($this->_withChecksum) {
$convertedChars[] = $this->getChecksum($this->getText());
}
// STOP CHARACTER
$convertedChars[] = 106;
foreach ($convertedChars as $barcodeChar) {
$barcodePattern = $this->_codingMap[$barcodeChar];
foreach (str_split($barcodePattern) as $c) {
$barcodeTable[] = array($c, $this->_barThinWidth, 0, 1);
}
}
return $barcodeTable;
}
/**
* Checks if the next $length chars of $string starting at $pos are numeric.
* Returns false if the end of the string is reached.
* @param string $string String to search
* @param int $pos Starting position
* @param int $length Length to search
* @return bool
*/
protected static function _isDigit($string, $pos, $length = 2)
{
if ($pos + $length > strlen($string)) {
return false;
}
for ($i = $pos; $i < $pos + $length; $i++) {
if (!is_numeric($string[$i])) {
return false;
}
}
return true;
}
/**
* Convert string to barcode string
*
* @param $string
* @return array
*/
protected function _convertToBarcodeChars($string)
{
$string = (string) $string;
if (!strlen($string)) {
return array();
}
if (isset($this->_convertedText[md5($string)])) {
return $this->_convertedText[md5($string)];
}
$currentCharset = null;
$sum = 0;
$fak = 0;
$result = array();
for ($pos = 0; $pos < strlen($string); $pos++) {
$char = $string[$pos];
$code = null;
if (self::_isDigit($string, $pos, 4) && $currentCharset != 'C'
|| self::_isDigit($string, $pos, 2) && $currentCharset == 'C') {
/**
* Switch to C if the next 4 chars are numeric or stay C if the next 2
* chars are numeric
*/
if ($currentCharset != 'C') {
if ($pos == 0) {
$code = array_search("START C", $this->_charSets['C']);
} else {
$code = array_search("Code C", $this->_charSets[$currentCharset]);
}
$result[] = $code;
$currentCharset = 'C';
}
} else if (in_array($char, $this->_charSets['B']) && $currentCharset != 'B'
&& !(in_array($char, $this->_charSets['A']) && $currentCharset == 'A')) {
/**
* Switch to B as B contains the char and B is not the current charset.
*/
if ($pos == 0) {
$code = array_search("START B", $this->_charSets['B']);
} else {
$code = array_search("Code B", $this->_charSets[$currentCharset]);
}
$result[] = $code;
$currentCharset = 'B';
} else if (array_key_exists($char, $this->_charSets['A']) && $currentCharset != 'A'
&& !(array_key_exists($char, $this->_charSets['B']) && $currentCharset == 'B')) {
/**
* Switch to C as C contains the char and C is not the current charset.
*/
if ($pos == 0) {
$code = array_search("START A", $this->_charSets['A']);
} else {
$code =array_search("Code A", $this->_charSets[$currentCharset]);
}
$result[] = $code;
$currentCharset = 'A';
}
if ($currentCharset == 'C') {
$code = array_search(substr($string, $pos, 2), $this->_charSets['C']);
$pos++; //Two chars from input
} else {
$code = array_search($string[$pos], $this->_charSets[$currentCharset]);
}
$result[] = $code;
}
$this->_convertedText[md5($string)] = $result;
return $result;
}
/**
* Set text to encode
* @param string $value
* @return Zend_Barcode_Object
*/
public function setText($value)
{
$this->_text = $value;
return $this;
}
/**
* Retrieve text to encode
* @return string
*/
public function getText()
{
return $this->_text;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$tableOfChars = $this->_convertToBarcodeChars($text);
$sum = $tableOfChars[0];
unset($tableOfChars[0]);
$k = 1;
foreach ($tableOfChars as $char) {
$sum += ($k++) * $char;
}
$checksum = $sum % 103;
return $checksum;
}
/**
* Standard validation for most of barcode objects
*
* @param string $value
* @param array $options
* @return bool
*/
protected function _validateText($value, $options = array())
{
// @TODO: add code128 validator
return true;
}
}

View File

@ -1,141 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Interleaved 2 of 5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code25 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = narrow bar
* - 1 = wide bar
* @var array
*/
protected $_codingMap = array(
'0' => '00110',
'1' => '10001',
'2' => '01001',
'3' => '11000',
'4' => '00101',
'5' => '10100',
'6' => '01100',
'7' => '00011',
'8' => '10010',
'9' => '01010',
);
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth + 5 * $this->_barThinWidth)
* $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength;
$stopCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved 2 of 5 barcode
* @return void
*/
protected function _checkParams()
{
$this->_checkRatio();
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (30301)
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth);
$text = str_split($this->getText());
foreach ($text as $char) {
$barcodeChar = str_split($this->_codingMap[$char]);
foreach ($barcodeChar as $c) {
/* visible, width, top, length */
$width = $c ? $this->_barThickWidth : $this->_barThinWidth;
$barcodeTable[] = array(1 , $width , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth);
}
}
// Stop character (30103)
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$factor = 3;
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * $factor;
$factor = 4 - $factor;
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
}

View File

@ -1,177 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Object_Code25 */
/** @see Zend_Validate_Barcode */
/**
* Class for generate Interleaved 2 of 5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code25interleaved extends Zend_Barcode_Object_Code25
{
/**
* Drawing of bearer bars
* @var boolean
*/
private $_withBearerBars = false;
/**
* Default options for Code25interleaved barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 'even';
}
/**
* Activate/deactivate drawing of bearer bars
* @param boolean $value
* @return Zend_Barcode_Object_Int25
*/
public function setWithBearerBars($value)
{
$this->_withBearerBars = (bool) $value;
return $this;
}
/**
* Retrieve if bearer bars are enabled
* @return boolean
*/
public function getWithBearerBars()
{
return $this->_withBearerBars;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (4 * $this->_barThinWidth) * $this->_factor;
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth) * $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength;
$stopCharacter = ($this->_barThickWidth + 2 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
if ($this->_withBearerBars) {
$this->_withBorder = false;
}
// Start character (0000)
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
// Encoded $text
$text = $this->getText();
for ($i = 0; $i < strlen($text); $i += 2) { // Draw 2 chars at a time
$char1 = substr($text, $i, 1);
$char2 = substr($text, $i + 1, 1);
// Interleave
for ($ibar = 0; $ibar < 5; $ibar ++) {
// Draws char1 bar (fore color)
$barWidth = (substr($this->_codingMap[$char1], $ibar, 1))
? $this->_barThickWidth
: $this->_barThinWidth;
$barcodeTable[] = array(1, $barWidth, 0, 1);
// Left space corresponding to char2 (background color)
$barWidth = (substr($this->_codingMap[$char2], $ibar, 1))
? $this->_barThickWidth
: $this->_barThinWidth;
$barcodeTable[] = array(0, $barWidth, 0 , 1);
}
}
// Stop character (100)
$barcodeTable[] = array(1 , $this->_barThickWidth, 0, 1);
$barcodeTable[] = array(0 , $this->_barThinWidth, 0, 1);
$barcodeTable[] = array(1 , $this->_barThinWidth, 0, 1);
return $barcodeTable;
}
/**
* Drawing of bearer bars (if enabled)
*
* @return void
*/
protected function _postDrawBarcode()
{
if (!$this->_withBearerBars) {
return;
}
$width = $this->_barThickWidth * $this->_factor;
$point1 = $this->_rotate(-1, -1);
$point2 = $this->_rotate($this->_calculateWidth() - 1, -1);
$point3 = $this->_rotate($this->_calculateWidth() - 1, $width - 1);
$point4 = $this->_rotate(-1, $width - 1);
$this->_addPolygon(array(
$point1,
$point2,
$point3,
$point4,
));
$point1 = $this->_rotate(
0,
0 + $this->_barHeight * $this->_factor - 1
);
$point2 = $this->_rotate(
$this->_calculateWidth() - 1,
0 + $this->_barHeight * $this->_factor - 1
);
$point3 = $this->_rotate(
$this->_calculateWidth() - 1,
0 + $this->_barHeight * $this->_factor - $width
);
$point4 = $this->_rotate(
0,
0 + $this->_barHeight * $this->_factor - $width
);
$this->_addPolygon(array(
$point1,
$point2,
$point3,
$point4,
));
}
}

View File

@ -1,186 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see 'Zend_Validate_Barcode'
*/
/**
* Class for generate Code39 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Code39 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* @var array
*/
protected $_codingMap = array(
'0' => '000110100',
'1' => '100100001',
'2' => '001100001',
'3' => '101100000',
'4' => '000110001',
'5' => '100110000',
'6' => '001110000',
'7' => '000100101',
'8' => '100100100',
'9' => '001100100',
'A' => '100001001',
'B' => '001001001',
'C' => '101001000',
'D' => '000011001',
'E' => '100011000',
'F' => '001011000',
'G' => '000001101',
'H' => '100001100',
'I' => '001001100',
'J' => '000011100',
'K' => '100000011',
'L' => '001000011',
'M' => '101000010',
'N' => '000010011',
'O' => '100010010',
'P' => '001010010',
'Q' => '000000111',
'R' => '100000110',
'S' => '001000110',
'T' => '000010110',
'U' => '110000001',
'V' => '011000001',
'W' => '111000000',
'X' => '010010001',
'Y' => '110010000',
'Z' => '011010000',
'-' => '010000101',
'.' => '110000100',
' ' => '011000100',
'$' => '010101000',
'/' => '010100010',
'+' => '010001010',
'%' => '000101010',
'*' => '010010100',
);
/**
* Partial check of Code39 barcode
* @return void
*/
protected function _checkParams()
{
$this->_checkRatio();
}
/**
* Width of the barcode (in pixels)
* @return int
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$characterLength = (6 * $this->_barThinWidth + 3 * $this->_barThickWidth + 1) * $this->_factor;
$encodedData = strlen($this->getText()) * $characterLength - $this->_factor;
return $quietZone + $encodedData + $quietZone;
}
/**
* Set text to encode
* @param string $value
* @return Zend_Barcode_Object
*/
public function setText($value)
{
$this->_text = $value;
return $this;
}
/**
* Retrieve text to display
* @return string
*/
public function getText()
{
return '*' . parent::getText() . '*';
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
$text = parent::getTextToDisplay();
if (substr($text, 0, 1) != '*' && substr($text, -1) != '*') {
return '*' . $text . '*';
} else {
return $text;
}
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$text = str_split($this->getText());
$barcodeTable = array();
foreach ($text as $char) {
$barcodeChar = str_split($this->_codingMap[$char]);
$visible = true;
foreach ($barcodeChar as $c) {
/* visible, width, top, length */
$width = $c ? $this->_barThickWidth : $this->_barThinWidth;
$barcodeTable[] = array((int) $visible, $width, 0, 1);
$visible = ! $visible;
}
$barcodeTable[] = array(0 , $this->_barThinWidth);
}
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$text = str_split($text);
$charset = array_flip(array_keys($this->_codingMap));
$checksum = 0;
foreach ($text as $character) {
$checksum += $charset[$character];
}
return array_search(($checksum % 43), $charset);
}
}

View File

@ -1,223 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Ean13 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean13 extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = narrow bar
* - 1 = wide bar
* @var array
*/
protected $_codingMap = array(
'A' => array(
0 => "0001101", 1 => "0011001", 2 => "0010011", 3 => "0111101", 4 => "0100011",
5 => "0110001", 6 => "0101111", 7 => "0111011", 8 => "0110111", 9 => "0001011"
),
'B' => array(
0 => "0100111", 1 => "0110011", 2 => "0011011", 3 => "0100001", 4 => "0011101",
5 => "0111001", 6 => "0000101", 7 => "0010001", 8 => "0001001", 9 => "0010111"
),
'C' => array(
0 => "1110010", 1 => "1100110", 2 => "1101100", 3 => "1000010", 4 => "1011100",
5 => "1001110", 6 => "1010000", 7 => "1000100", 8 => "1001000", 9 => "1110100"
));
protected $_parities = array(
0 => array('A','A','A','A','A','A'),
1 => array('A','A','B','A','B','B'),
2 => array('A','A','B','B','A','B'),
3 => array('A','A','B','B','B','A'),
4 => array('A','B','A','A','B','B'),
5 => array('A','B','B','A','A','B'),
6 => array('A','B','B','B','A','A'),
7 => array('A','B','A','B','A','B'),
8 => array('A','B','A','B','B','A'),
9 => array('A','B','B','A','B','A')
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 13;
$this->_mandatoryChecksum = true;
$this->_mandatoryQuietZones = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 12;
return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved EAN/UPC barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
$parity = $this->_parities[$textTable[0]];
// First part
for ($i = 1; $i < 7; $i++) {
$bars = str_split($this->_codingMap[$parity[$i - 1]][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 7; $i < 13; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$factor = 3;
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * $factor;
$factor = 4 - $factor;
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if (get_class($this) == 'Zend_Barcode_Object_Ean13') {
$this->_drawEan13Text();
} else {
parent::_drawText();
}
}
protected function _drawEan13Text()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$this->_addText(
$text{$i},
$this->_fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $this->_fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 3;
break;
case 6:
$factor = 4;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
}

View File

@ -1,63 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Ean5
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Ean2 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean2 extends Zend_Barcode_Object_Ean5
{
protected $_parities = array(
0 => array('A','A'),
1 => array('A','B'),
2 => array('B','A'),
3 => array('B','B')
);
/**
* Default options for Ean2 barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 2;
}
protected function _getParity($i)
{
$modulo = $this->getText() % 4;
return $this->_parities[$modulo][$i];
}
}

View File

@ -1,145 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Ean5 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean5 extends Zend_Barcode_Object_Ean13
{
protected $_parities = array(
0 => array('B','B','A','A','A'),
1 => array('B','A','B','A','A'),
2 => array('B','A','A','B','A'),
3 => array('B','A','A','A','B'),
4 => array('A','B','B','A','A'),
5 => array('A','A','B','B','A'),
6 => array('A','A','A','B','B'),
7 => array('A','B','A','B','A'),
8 => array('A','B','A','A','B'),
9 => array('A','A','B','A','B')
);
/**
* Default options for Ean5 barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 5;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor;
return $quietZone + $startCharacter + ($this->_barcodeLength - 1) * $middleCharacter + $this->_barcodeLength * $encodedData + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (01011)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$firstCharacter = true;
$textTable = str_split($this->getText());
// Characters
for ($i = 0; $i < $this->_barcodeLength; $i++) {
if ($firstCharacter) {
$firstCharacter = false;
} else {
// Intermediate character (01)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
}
$bars = str_split($this->_codingMap[$this->_getParity($i)][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$checksum = 0;
for ($i = 0 ; $i < $this->_barcodeLength; $i ++) {
$checksum += intval($text{$i}) * ($i % 2 ? 9 : 3);
}
return ($checksum % 10);
}
protected function _getParity($i)
{
$checksum = $this->getChecksum($this->getText());
return $this->_parities[$checksum][$i];
}
/**
* Retrieve text to encode
* @return string
*/
public function getText()
{
return $this->_addLeadingZeros($this->_text);
}
}

View File

@ -1,174 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Ean8 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Ean8 extends Zend_Barcode_Object_Ean13
{
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 8;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 8;
return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
// First part
for ($i = 0; $i < 4; $i++) {
$bars = str_split($this->_codingMap['A'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 4; $i < 8; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() + (3 * $this->_barThinWidth) * $this->_factor;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$this->_addText(
$text{$i},
$this->_fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $this->_fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 3:
$factor = 4;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
/**
* Particular validation for Ean8 barcode objects
* (to suppress checksum character substitution)
*
* @param string $value
* @param array $options
* @throws Zend_Barcode_Object_Exception
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array(
'adapter' => 'ean8',
'checksum' => false,
));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
throw new Zend_Barcode_Object_Exception($message);
}
}
}

View File

@ -1,103 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Object_ObjectAbstract */
/**
* Class for generate Barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Error extends Zend_Barcode_Object_ObjectAbstract
{
/**
* All texts are accepted
* @param string $value
* @return boolean
*/
public function validateText($value)
{
return true;
}
/**
* Height is forced
*
* @param bool $recalculate
* @return integer
*/
public function getHeight($recalculate = false)
{
return 40;
}
/**
* Width is forced
*
* @param bool $recalculate
* @return integer
*/
public function getWidth($recalculate = false)
{
return 400;
}
/**
* Reset precedent instructions
* and draw the error message
* @return array
*/
public function draw()
{
$this->_instructions = array();
$this->_addText('ERROR:', 10, array(5 , 18), $this->_font, 0, 'left');
$this->_addText($this->_text, 10, array(5 , 32), $this->_font, 0, 'left');
return $this->_instructions;
}
/**
* For compatibility reason
* @return void
*/
protected function _prepareBarcode()
{
}
/**
* For compatibility reason
* @return void
*/
protected function _checkParams()
{
}
/**
* For compatibility reason
* @return void
*/
protected function _calculateBarcodeWidth()
{
}
}

View File

@ -1,34 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE.txt, and
* is available through the world-wide-web at the following URL:
* http://framework.zend.com/license/new-bsd. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Exception */
/**
* Zend_Barcode_Renderer_Exception
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Exception extends Zend_Barcode_Exception
{
}

View File

@ -1,93 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Code25interleaved
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Identcode barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Identcode extends Zend_Barcode_Object_Code25interleaved
{
/**
* Default options for Identcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 12;
$this->_mandatoryChecksum = true;
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{3})([0-9])/',
'$1.$2 $3.$4 $5',
$this->getText());
}
/**
* Check allowed characters
* @param string $value
* @return string
* @throws Zend_Barcode_Object_Exception
*/
public function validateText($value)
{
$this->_validateText($value, array('validator' => $this->getType()));
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$checksum = 0;
for ($i = strlen($text); $i > 0; $i --) {
$checksum += intval($text{$i - 1}) * (($i % 2) ? 4 : 9);
}
$checksum = (10 - ($checksum % 10)) % 10;
return $checksum;
}
}

View File

@ -1,47 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Object_Code25interleaved */
/** @see Zend_Validate_Barcode */
/**
* Class for generate Itf14 barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Itf14 extends Zend_Barcode_Object_Code25interleaved
{
/**
* Default options for Identcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 14;
$this->_mandatoryChecksum = true;
}
}

View File

@ -1,62 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Identcode
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Identcode barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Leitcode extends Zend_Barcode_Object_Identcode
{
/**
* Default options for Leitcode barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 14;
$this->_mandatoryChecksum = true;
}
/**
* Retrieve text to display
* @return string
*/
public function getTextToDisplay()
{
return preg_replace('/([0-9]{5})([0-9]{3})([0-9]{3})([0-9]{2})([0-9])/',
'$1.$2.$3.$4 $5',
$this->getText());
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,60 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Postnet
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Planet barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Planet extends Zend_Barcode_Object_Postnet
{
/**
* Coding map
* - 0 = half bar
* - 1 = complete bar
* @var array
*/
protected $_codingMap = array(
0 => "00111",
1 => "11100",
2 => "11010",
3 => "11001",
4 => "10110",
5 => "10101",
6 => "10011",
7 => "01110",
8 => "01101",
9 => "01011"
);
}

View File

@ -1,134 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Postnet barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Postnet extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = half bar
* - 1 = complete bar
* @var array
*/
protected $_codingMap = array(
0 => "11000",
1 => "00011",
2 => "00101",
3 => "00110",
4 => "01001",
5 => "01010",
6 => "01100",
7 => "10001",
8 => "10010",
9 => "10100"
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barThinWidth = 2;
$this->_barHeight = 20;
$this->_drawText = false;
$this->_stretchText = true;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (1 * $this->_barThinWidth) * $this->_factor;
$encodedData = (10 * $this->_barThinWidth) * $this->_factor * strlen($this->getText());
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved Postnet barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
// Text to encode
$textTable = str_split($this->getText());
foreach ($textTable as $char) {
$bars = str_split($this->_codingMap[$char]);
foreach ($bars as $b) {
$barcodeTable[] = array(1 , $this->_barThinWidth , 0.5 - $b * 0.5 , 1);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$sum = array_sum(str_split($text));
$checksum = (10 - ($sum % 10)) % 10;
return $checksum;
}
}

View File

@ -1,161 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_ObjectAbstract
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate Royal maim barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Royalmail extends Zend_Barcode_Object_ObjectAbstract
{
/**
* Coding map
* - 0 = Tracker, Ascender and Descender
* - 1 = Tracker and Ascender
* - 2 = Tracker and Descender
* - 3 = Tracker
* @var array
*/
protected $_codingMap = array(
'0' => '3300', '1' => '3210', '2' => '3201', '3' => '2310', '4' => '2301', '5' => '2211',
'6' => '3120', '7' => '3030', '8' => '3021', '9' => '2130', 'A' => '2121', 'B' => '2031',
'C' => '3102', 'D' => '3012', 'E' => '3003', 'F' => '2112', 'G' => '2103', 'H' => '2013',
'I' => '1320', 'J' => '1230', 'K' => '1221', 'L' => '0330', 'M' => '0321', 'N' => '0231',
'O' => '1302', 'P' => '1212', 'Q' => '1203', 'R' => '0312', 'S' => '0303', 'T' => '0213',
'U' => '1122', 'V' => '1032', 'W' => '1023', 'X' => '0132', 'Y' => '0123', 'Z' => '0033'
);
protected $_rows = array(
'0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
'6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
);
protected $_columns = array(
'0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
'6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barThinWidth = 2;
$this->_barHeight = 20;
$this->_drawText = false;
$this->_stretchText = true;
$this->_mandatoryChecksum = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (2 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (1 * $this->_barThinWidth) * $this->_factor;
$encodedData = (8 * $this->_barThinWidth) * $this->_factor * strlen($this->getText());
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Partial check of interleaved Postnet barcode
* @return void
*/
protected function _checkParams()
{}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
// Start character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 5/8);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
// Text to encode
$textTable = str_split($this->getText());
foreach ($textTable as $char) {
$bars = str_split($this->_codingMap[$char]);
foreach ($bars as $b) {
$barcodeTable[] = array(1 , $this->_barThinWidth , ($b > 1 ? 3/8 : 0) , ($b % 2 ? 5/8 : 1));
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (1)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
return $barcodeTable;
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$this->_checkText($text);
$values = str_split($text);
$rowvalue = 0;
$colvalue = 0;
foreach($values as $row) {
$rowvalue += $this->_rows[$row];
$colvalue += $this->_columns[$row];
}
$rowvalue %= 6;
$colvalue %= 6;
$rowchkvalue = array_keys($this->_rows, $rowvalue);
$colchkvalue = array_keys($this->_columns, $colvalue);
return current(array_intersect($rowchkvalue, $colchkvalue));
}
}

View File

@ -1,170 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate UpcA barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Upca extends Zend_Barcode_Object_Ean13
{
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 12;
$this->_mandatoryChecksum = true;
$this->_mandatoryQuietZones = true;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$middleCharacter = (5 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 12;
return $quietZone + $startCharacter + $middleCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
// First character
$bars = str_split($this->_codingMap['A'][$textTable[0]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , $height);
}
// First part
for ($i = 1; $i < 6; $i++) {
$bars = str_split($this->_codingMap['A'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
// Second part
for ($i = 6; $i < 11; $i++) {
$bars = str_split($this->_codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Last character
$bars = str_split($this->_codingMap['C'][$textTable[11]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , $height);
}
// Stop character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$fontSize = $this->_fontSize;
if ($i == 0 || $i == 11) {
$fontSize *= 0.8;
}
$this->_addText(
$text{$i},
$fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 10;
break;
case 5:
$factor = 4;
break;
case 10:
$factor = 11;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
}

View File

@ -1,227 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Object
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Barcode_Object_Ean13
*/
/**
* @see Zend_Validate_Barcode
*/
/**
* Class for generate UpcA barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Object_Upce extends Zend_Barcode_Object_Ean13
{
protected $_parities = array(
0 => array(
0 => array('B','B','B','A','A','A'),
1 => array('B','B','A','B','A','A'),
2 => array('B','B','A','A','B','A'),
3 => array('B','B','A','A','A','B'),
4 => array('B','A','B','B','A','A'),
5 => array('B','A','A','B','B','A'),
6 => array('B','A','A','A','B','B'),
7 => array('B','A','B','A','B','A'),
8 => array('B','A','B','A','A','B'),
9 => array('B','A','A','B','A','B')),
1 => array(
0 => array('A','A','A','B','B','B'),
1 => array('A','A','B','A','B','B'),
2 => array('A','A','B','B','A','B'),
3 => array('A','A','B','B','B','A'),
4 => array('A','B','A','A','B','B'),
5 => array('A','B','B','A','A','B'),
6 => array('A','B','B','B','A','A'),
7 => array('A','B','A','B','A','B'),
8 => array('A','B','A','B','B','A'),
9 => array('A','B','B','A','B','A'))
);
/**
* Default options for Postnet barcode
* @return void
*/
protected function _getDefaultOptions()
{
$this->_barcodeLength = 8;
$this->_mandatoryChecksum = true;
$this->_mandatoryQuietZones = true;
}
/**
* Retrieve text to encode
* @return string
*/
public function getText()
{
$text = parent::getText();
if ($text{0} != 1) {
$text{0} = 0;
}
return $text;
}
/**
* Width of the barcode (in pixels)
* @return integer
*/
protected function _calculateBarcodeWidth()
{
$quietZone = $this->getQuietZone();
$startCharacter = (3 * $this->_barThinWidth) * $this->_factor;
$stopCharacter = (6 * $this->_barThinWidth) * $this->_factor;
$encodedData = (7 * $this->_barThinWidth) * $this->_factor * 6;
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
}
/**
* Prepare array to draw barcode
* @return array
*/
protected function _prepareBarcode()
{
$barcodeTable = array();
$height = ($this->_drawText) ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$textTable = str_split($this->getText());
$system = 0;
if ($textTable[0] == 1) {
$system = 1;
}
$checksum = $textTable[7];
$parity = $this->_parities[$system][$checksum];
for ($i = 1; $i < 7; $i++) {
$bars = str_split($this->_codingMap[$parity[$i - 1]][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b , $this->_barThinWidth , 0 , 1);
}
}
// Stop character (10101)
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , $height);
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , $height);
return $barcodeTable;
}
/**
* Partial function to draw text
* @return void
*/
protected function _drawText()
{
if ($this->_drawText) {
$text = $this->getTextToDisplay();
$characterWidth = (7 * $this->_barThinWidth) * $this->_factor;
$leftPosition = $this->getQuietZone() - $characterWidth;
for ($i = 0; $i < $this->_barcodeLength; $i ++) {
$fontSize = $this->_fontSize;
if ($i == 0 || $i == 7) {
$fontSize *= 0.8;
}
$this->_addText(
$text{$i},
$fontSize * $this->_factor,
$this->_rotate(
$leftPosition,
(int) $this->_withBorder * 2
+ $this->_factor * ($this->_barHeight + $fontSize) + 1
),
$this->_font,
$this->_foreColor,
'left',
- $this->_orientation
);
switch ($i) {
case 0:
$factor = 3;
break;
case 6:
$factor = 5;
break;
default:
$factor = 0;
}
$leftPosition = $leftPosition + $characterWidth + ($factor * $this->_barThinWidth * $this->_factor);
}
}
}
/**
* Particular validation for Upce barcode objects
* (to suppress checksum character substitution)
*
* @param string $value
* @param array $options
* @throws Zend_Barcode_Object_Exception
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array(
'adapter' => 'upce',
'checksum' => false,
));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
throw new Zend_Barcode_Object_Exception($message);
}
}
/**
* Get barcode checksum
*
* @param string $text
* @return int
*/
public function getChecksum($text)
{
$text = $this->_addLeadingZeros($text, true);
if ($text{0} != 1) {
$text{0} = 0;
}
return parent::getChecksum($text);
}
}

View File

@ -1,34 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE.txt, and
* is available through the world-wide-web at the following URL:
* http://framework.zend.com/license/new-bsd. If you did not receive
* a copy of the Zend Framework license and are unable to obtain it
* through the world-wide-web, please send a note to license@zend.com
* so we can mail you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Exception */
/**
* Zend_Barcode_Renderer_Exception
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Renderer_Exception extends Zend_Barcode_Exception
{
}

View File

@ -1,462 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Renderer
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Renderer_RendererAbstract*/
/**
* Class for rendering the barcode as image
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Renderer_Image extends Zend_Barcode_Renderer_RendererAbstract
{
/**
* List of authorized output format
* @var array
*/
protected $_allowedImageType = array(
'png',
'jpeg',
'gif',
);
/**
* Image format
* @var string
*/
protected $_imageType = 'png';
/**
* Resource for the image
* @var resource
*/
protected $_resource = null;
/**
* Resource for the font and bars color of the image
* @var integer
*/
protected $_imageForeColor = null;
/**
* Resource for the background color of the image
* @var integer
*/
protected $_imageBackgroundColor = null;
/**
* Height of the rendered image wanted by user
* @var integer
*/
protected $_userHeight = 0;
/**
* Width of the rendered image wanted by user
* @var integer
*/
protected $_userWidth = 0;
public function __construct($options = null)
{
if (!function_exists('gd_info')) {
throw new Zend_Barcode_Renderer_Exception('Zend_Barcode_Renderer_Image requires the GD extension');
}
parent::__construct($options);
}
/**
* Set height of the result image
*
* @param null|integer $value
* @return Zend_Image_Barcode_Abstract
* @throws Zend_Barcode_Renderer_Exception
*/
public function setHeight($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Image height must be greater than or equals 0'
);
}
$this->_userHeight = intval($value);
return $this;
}
/**
* Get barcode height
*
* @return int
*/
public function getHeight()
{
return $this->_userHeight;
}
/**
* Set barcode width
*
* @param mixed $value
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setWidth($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Image width must be greater than or equals 0'
);
}
$this->_userWidth = intval($value);
return $this;
}
/**
* Get barcode width
*
* @return int
*/
public function getWidth()
{
return $this->_userWidth;
}
/**
* Set an image resource to draw the barcode inside
*
* @param $image
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setResource($image)
{
if (gettype($image) != 'resource' || get_resource_type($image) != 'gd') {
throw new Zend_Barcode_Renderer_Exception(
'Invalid image resource provided to setResource()'
);
}
$this->_resource = $image;
return $this;
}
/**
* Set the image type to produce (png, jpeg, gif)
*
* @param string $value
* @return Zend_Barcode_RendererAbstract
* @throws Zend_Barcode_Renderer_Exception
*/
public function setImageType($value)
{
if ($value == 'jpg') {
$value = 'jpeg';
}
if (!in_array($value, $this->_allowedImageType)) {
throw new Zend_Barcode_Renderer_Exception(sprintf(
'Invalid type "%s" provided to setImageType()',
$value
));
}
$this->_imageType = $value;
return $this;
}
/**
* Retrieve the image type to produce
*
* @return string
*/
public function getImageType()
{
return $this->_imageType;
}
/**
* Initialize the image resource
*
* @return void
* @throws Zend_Barcode_Exception
*/
protected function _initRenderer()
{
if (!extension_loaded('gd')) {
$e = new Zend_Barcode_Exception(
'Gd extension must be loaded to render barcode as image'
);
$e->setIsRenderable(false);
throw $e;
}
$barcodeWidth = $this->_barcode->getWidth(true);
$barcodeHeight = $this->_barcode->getHeight(true);
if ($this->_resource !== null) {
$foreColor = $this->_barcode->getForeColor();
$backgroundColor = $this->_barcode->getBackgroundColor();
$this->_imageBackgroundColor = imagecolorallocate(
$this->_resource,
($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
$backgroundColor & 0x0000FF
);
$this->_imageForeColor = imagecolorallocate(
$this->_resource,
($foreColor & 0xFF0000) >> 16,
($foreColor & 0x00FF00) >> 8,
$foreColor & 0x0000FF
);
} else {
$width = $barcodeWidth;
$height = $barcodeHeight;
if ($this->_userWidth && $this->_barcode->getType() != 'error') {
$width = $this->_userWidth;
}
if ($this->_userHeight && $this->_barcode->getType() != 'error') {
$height = $this->_userHeight;
}
$foreColor = $this->_barcode->getForeColor();
$backgroundColor = $this->_barcode->getBackgroundColor();
$this->_resource = imagecreatetruecolor($width, $height);
$this->_imageBackgroundColor = imagecolorallocate(
$this->_resource,
($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
$backgroundColor & 0x0000FF
);
$this->_imageForeColor = imagecolorallocate(
$this->_resource,
($foreColor & 0xFF0000) >> 16,
($foreColor & 0x00FF00) >> 8,
$foreColor & 0x0000FF
);
$white = imagecolorallocate($this->_resource, 255, 255, 255);
imagefilledrectangle($this->_resource, 0, 0, $width - 1, $height - 1, $white);
}
$this->_adjustPosition(imagesy($this->_resource), imagesx($this->_resource));
imagefilledrectangle(
$this->_resource,
$this->_leftOffset,
$this->_topOffset,
$this->_leftOffset + $barcodeWidth - 1,
$this->_topOffset + $barcodeHeight - 1,
$this->_imageBackgroundColor
);
}
/**
* Check barcode parameters
*
* @return void
*/
protected function _checkParams()
{
$this->_checkDimensions();
}
/**
* Check barcode dimensions
*
* @return void
* @throws Zend_Barcode_Renderer_Exception
*/
protected function _checkDimensions()
{
if ($this->_resource !== null) {
if (imagesy($this->_resource) < $this->_barcode->getHeight(true)) {
throw new Zend_Barcode_Renderer_Exception(
'Barcode is define outside the image (height)'
);
}
} else {
if ($this->_userHeight) {
$height = $this->_barcode->getHeight(true);
if ($this->_userHeight < $height) {
throw new Zend_Barcode_Renderer_Exception(sprintf(
"Barcode is define outside the image (calculated: '%d', provided: '%d')",
$height,
$this->_userHeight
));
}
}
}
if ($this->_resource !== null) {
if (imagesx($this->_resource) < $this->_barcode->getWidth(true)) {
throw new Zend_Barcode_Renderer_Exception(
'Barcode is define outside the image (width)'
);
}
} else {
if ($this->_userWidth) {
$width = $this->_barcode->getWidth(true);
if ($this->_userWidth < $width) {
throw new Zend_Barcode_Renderer_Exception(sprintf(
"Barcode is define outside the image (calculated: '%d', provided: '%d')",
$width,
$this->_userWidth
));
}
}
}
}
/**
* Draw and render the barcode with correct headers
*
* @return mixed
*/
public function render()
{
$this->draw();
header("Content-Type: image/" . $this->_imageType);
$functionName = 'image' . $this->_imageType;
call_user_func($functionName, $this->_resource);
@imagedestroy($this->_resource);
}
/**
* Draw a polygon in the image resource
*
* @param array $points
* @param integer $color
* @param boolean $filled
*/
protected function _drawPolygon($points, $color, $filled = true)
{
$newPoints = array(
$points[0][0] + $this->_leftOffset,
$points[0][1] + $this->_topOffset,
$points[1][0] + $this->_leftOffset,
$points[1][1] + $this->_topOffset,
$points[2][0] + $this->_leftOffset,
$points[2][1] + $this->_topOffset,
$points[3][0] + $this->_leftOffset,
$points[3][1] + $this->_topOffset,
);
$allocatedColor = imagecolorallocate(
$this->_resource,
($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
$color & 0x0000FF
);
if ($filled) {
imagefilledpolygon($this->_resource, $newPoints, 4, $allocatedColor);
} else {
imagepolygon($this->_resource, $newPoints, 4, $allocatedColor);
}
}
/**
* Draw a polygon in the image resource
*
* @param string $text
* @param float $size
* @param array $position
* @param string $font
* @param integer $color
* @param string $alignment
* @param float|int $orientation
* @throws Zend_Barcode_Renderer_Exception
*/
protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
{
$allocatedColor = imagecolorallocate(
$this->_resource,
($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
$color & 0x0000FF
);
if ($font == null) {
$font = 3;
}
$position[0] += $this->_leftOffset;
$position[1] += $this->_topOffset;
if (is_numeric($font)) {
if ($orientation) {
/**
* imagestring() doesn't allow orientation, if orientation
* needed: a TTF font is required.
* Throwing an exception here, allow to use automaticRenderError
* to informe user of the problem instead of simply not drawing
* the text
*/
throw new Zend_Barcode_Renderer_Exception(
'No orientation possible with GD internal font'
);
}
$fontWidth = imagefontwidth($font);
$positionY = $position[1] - imagefontheight($font) + 1;
switch ($alignment) {
case 'left':
$positionX = $position[0];
break;
case 'center':
$positionX = $position[0] - ceil(($fontWidth * strlen($text)) / 2);
break;
case 'right':
$positionX = $position[0] - ($fontWidth * strlen($text));
break;
}
imagestring($this->_resource, $font, $positionX, $positionY, $text, $color);
} else {
if (!function_exists('imagettfbbox')) {
throw new Zend_Barcode_Renderer_Exception(
'A font was provided, but this instance of PHP does not have TTF (FreeType) support'
);
}
$box = imagettfbbox($size, 0, $font, $text);
switch ($alignment) {
case 'left':
$width = 0;
break;
case 'center':
$width = ($box[2] - $box[0]) / 2;
break;
case 'right':
$width = ($box[2] - $box[0]);
break;
}
imagettftext(
$this->_resource,
$size,
$orientation,
$position[0] - ($width * cos(pi() * $orientation / 180)),
$position[1] + ($width * sin(pi() * $orientation / 180)),
$allocatedColor,
$font,
$text
);
}
}
}

View File

@ -1,240 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Renderer
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Barcode_Renderer_RendererAbstract */
/** @see Zend_Pdf */
/** @see Zend_Pdf_Page */
/** @see Zend_Pdf_Color_Rgb */
/**
* Class for rendering the barcode in PDF resource
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Renderer_Pdf extends Zend_Barcode_Renderer_RendererAbstract
{
/**
* PDF resource
* @var Zend_Pdf
*/
protected $_resource = null;
/**
* Page number in PDF resource
* @var integer
*/
protected $_page = 0;
/**
* Module size rendering
* @var float
*/
protected $_moduleSize = 0.5;
/**
* Set an image resource to draw the barcode inside
*
* @param Zend_Pdf $pdf
* @param int $page
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setResource($pdf, $page = 0)
{
if (!$pdf instanceof Zend_Pdf) {
throw new Zend_Barcode_Renderer_Exception(
'Invalid Zend_Pdf resource provided to setResource()'
);
}
$this->_resource = $pdf;
$this->_page = intval($page);
if (!count($this->_resource->pages)) {
$this->_page = 0;
$this->_resource->pages[] = new Zend_Pdf_Page(
Zend_Pdf_Page::SIZE_A4
);
}
return $this;
}
/**
* Check renderer parameters
*
* @return void
*/
protected function _checkParams()
{
}
/**
* Draw the barcode in the PDF, send headers and the PDF
* @return mixed
*/
public function render()
{
$this->draw();
header("Content-Type: application/pdf");
echo $this->_resource->render();
}
/**
* Initialize the PDF resource
* @return void
*/
protected function _initRenderer()
{
if ($this->_resource === null) {
$this->_resource = new Zend_Pdf();
$this->_resource->pages[] = new Zend_Pdf_Page(
Zend_Pdf_Page::SIZE_A4
);
}
$pdfPage = $this->_resource->pages[$this->_page];
$this->_adjustPosition($pdfPage->getHeight(), $pdfPage->getWidth());
}
/**
* Draw a polygon in the rendering resource
* @param array $points
* @param integer $color
* @param boolean $filled
*/
protected function _drawPolygon($points, $color, $filled = true)
{
$page = $this->_resource->pages[$this->_page];
foreach ($points as $point) {
$x[] = $point[0] * $this->_moduleSize + $this->_leftOffset;
$y[] = $page->getHeight() - $point[1] * $this->_moduleSize - $this->_topOffset;
}
if (count($y) == 4) {
if ($x[0] != $x[3] && $y[0] == $y[3]) {
$y[0] -= ($this->_moduleSize / 2);
$y[3] -= ($this->_moduleSize / 2);
}
if ($x[1] != $x[2] && $y[1] == $y[2]) {
$y[1] += ($this->_moduleSize / 2);
$y[2] += ($this->_moduleSize / 2);
}
}
$color = new Zend_Pdf_Color_Rgb(
(($color & 0xFF0000) >> 16) / 255.0,
(($color & 0x00FF00) >> 8) / 255.0,
($color & 0x0000FF) / 255.0
);
$page->setLineColor($color);
$page->setFillColor($color);
$page->setLineWidth($this->_moduleSize);
$fillType = ($filled)
? Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE
: Zend_Pdf_Page::SHAPE_DRAW_STROKE;
$page->drawPolygon($x, $y, $fillType);
}
/**
* Draw a text in the rendering resource
*
* @param string $text
* @param float $size
* @param array $position
* @param string $font
* @param integer $color
* @param string $alignment
* @param float|int $orientation
*/
protected function _drawText(
$text,
$size,
$position,
$font,
$color,
$alignment = 'center',
$orientation = 0
) {
$page = $this->_resource->pages[$this->_page];
$color = new Zend_Pdf_Color_Rgb(
(($color & 0xFF0000) >> 16) / 255.0,
(($color & 0x00FF00) >> 8) / 255.0,
($color & 0x0000FF) / 255.0
);
$page->setLineColor($color);
$page->setFillColor($color);
$page->setFont(Zend_Pdf_Font::fontWithPath($font), $size * $this->_moduleSize * 1.2);
$width = $this->widthForStringUsingFontSize(
$text,
Zend_Pdf_Font::fontWithPath($font),
$size * $this->_moduleSize
);
$angle = pi() * $orientation / 180;
$left = $position[0] * $this->_moduleSize + $this->_leftOffset;
$top = $page->getHeight() - $position[1] * $this->_moduleSize - $this->_topOffset;
switch ($alignment) {
case 'center':
$left -= ($width / 2) * cos($angle);
$top -= ($width / 2) * sin($angle);
break;
case 'right':
$left -= $width;
break;
}
$page->rotate($left, $top, $angle);
$page->drawText($text, $left, $top);
$page->rotate($left, $top, - $angle);
}
/**
* Calculate the width of a string:
* in case of using alignment parameter in drawText
* @param string $text
* @param Zend_Pdf_Font $font
* @param float $fontSize
* @return float
*/
public function widthForStringUsingFontSize($text, $font, $fontSize)
{
$drawingString = iconv('UTF-8', 'UTF-16BE//IGNORE', $text);
$characters = array();
for ($i = 0; $i < strlen($drawingString); $i ++) {
$characters[] = (ord($drawingString[$i ++]) << 8) | ord($drawingString[$i]);
}
$glyphs = $font->glyphNumbersForCharacters($characters);
$widths = $font->widthsForGlyphs($glyphs);
$stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
return $stringWidth;
}
}

View File

@ -1,543 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Renderer
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Class for rendering the barcode
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Barcode_Renderer_RendererAbstract
{
/**
* Namespace of the renderer for autoloading
* @var string
*/
protected $_rendererNamespace = 'Zend_Barcode_Renderer';
/**
* Renderer type
* @var string
*/
protected $_type = null;
/**
* Activate/Deactivate the automatic rendering of exception
* @var boolean
*/
protected $_automaticRenderError = false;
/**
* Offset of the barcode from the top of the rendering resource
* @var integer
*/
protected $_topOffset = 0;
/**
* Offset of the barcode from the left of the rendering resource
* @var integer
*/
protected $_leftOffset = 0;
/**
* Horizontal position of the barcode in the rendering resource
* @var integer
*/
protected $_horizontalPosition = 'left';
/**
* Vertical position of the barcode in the rendering resource
* @var integer
*/
protected $_verticalPosition = 'top';
/**
* Module size rendering
* @var float
*/
protected $_moduleSize = 1;
/**
* Barcode object
* @var Zend_Barcode_Object_ObjectAbstract
*/
protected $_barcode;
/**
* Drawing resource
*/
protected $_resource;
/**
* Constructor
*
* @param array|Zend_Config $options
* @return Zend_Barcode_Renderer_RendererAbstract
*/
public function __construct($options = null)
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (is_array($options)) {
$this->setOptions($options);
}
$this->_type = strtolower(substr(
get_class($this),
strlen($this->_rendererNamespace) + 1
));
}
/**
* Set renderer state from options array
* @param array $options
* @return Zend_Renderer_Object
*/
public function setOptions($options)
{
foreach ($options as $key => $value) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set renderer state from config object
* @param Zend_Config $config
* @return Zend_Renderer_Object
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Set renderer namespace for autoloading
*
* @param string $namespace
* @return Zend_Renderer_Object
*/
public function setRendererNamespace($namespace)
{
$this->_rendererNamespace = $namespace;
return $this;
}
/**
* Retrieve renderer namespace
*
* @return string
*/
public function getRendererNamespace()
{
return $this->_rendererNamespace;
}
/**
* Retrieve renderer type
* @return string
*/
public function getType()
{
return $this->_type;
}
/**
* Manually adjust top position
* @param integer $value
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setTopOffset($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Vertical position must be greater than or equals 0'
);
}
$this->_topOffset = intval($value);
return $this;
}
/**
* Retrieve vertical adjustment
* @return integer
*/
public function getTopOffset()
{
return $this->_topOffset;
}
/**
* Manually adjust left position
* @param integer $value
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setLeftOffset($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Horizontal position must be greater than or equals 0'
);
}
$this->_leftOffset = intval($value);
return $this;
}
/**
* Retrieve vertical adjustment
* @return integer
*/
public function getLeftOffset()
{
return $this->_leftOffset;
}
/**
* Activate/Deactivate the automatic rendering of exception
*
* @param boolean $value
* @return $this
*/
public function setAutomaticRenderError($value)
{
$this->_automaticRenderError = (bool) $value;
return $this;
}
/**
* Horizontal position of the barcode in the rendering resource
*
* @param string $value
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setHorizontalPosition($value)
{
if (!in_array($value, array('left' , 'center' , 'right'))) {
throw new Zend_Barcode_Renderer_Exception(
"Invalid barcode position provided must be 'left', 'center' or 'right'"
);
}
$this->_horizontalPosition = $value;
return $this;
}
/**
* Horizontal position of the barcode in the rendering resource
* @return string
*/
public function getHorizontalPosition()
{
return $this->_horizontalPosition;
}
/**
* Vertical position of the barcode in the rendering resource
*
* @param string $value
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setVerticalPosition($value)
{
if (!in_array($value, array('top' , 'middle' , 'bottom'))) {
throw new Zend_Barcode_Renderer_Exception(
"Invalid barcode position provided must be 'top', 'middle' or 'bottom'"
);
}
$this->_verticalPosition = $value;
return $this;
}
/**
* Vertical position of the barcode in the rendering resource
* @return string
*/
public function getVerticalPosition()
{
return $this->_verticalPosition;
}
/**
* Set the size of a module
* @param float $value
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setModuleSize($value)
{
if (!is_numeric($value) || floatval($value) <= 0) {
throw new Zend_Barcode_Renderer_Exception(
'Float size must be greater than 0'
);
}
$this->_moduleSize = floatval($value);
return $this;
}
/**
* Set the size of a module
* @return float
*/
public function getModuleSize()
{
return $this->_moduleSize;
}
/**
* Retrieve the automatic rendering of exception
* @return boolean
*/
public function getAutomaticRenderError()
{
return $this->_automaticRenderError;
}
/**
* Set the barcode object
*
* @param Zend_Barcode_Object $barcode
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setBarcode($barcode)
{
if (!$barcode instanceof Zend_Barcode_Object_ObjectAbstract) {
throw new Zend_Barcode_Renderer_Exception(
'Invalid barcode object provided to setBarcode()'
);
}
$this->_barcode = $barcode;
return $this;
}
/**
* Retrieve the barcode object
* @return Zend_Barcode_Object
*/
public function getBarcode()
{
return $this->_barcode;
}
/**
* Checking of parameters after all settings
* @return boolean
*/
public function checkParams()
{
$this->_checkBarcodeObject();
$this->_checkParams();
return true;
}
/**
* Check if a barcode object is correctly provided
* @return void
* @throws Zend_Barcode_Renderer_Exception
*/
protected function _checkBarcodeObject()
{
if ($this->_barcode === null) {
/**
* @see Zend_Barcode_Renderer_Exception
*/
throw new Zend_Barcode_Renderer_Exception(
'No barcode object provided'
);
}
}
/**
* Calculate the left and top offset of the barcode in the
* rendering support
*
* @param float $supportHeight
* @param float $supportWidth
* @return void
*/
protected function _adjustPosition($supportHeight, $supportWidth)
{
$barcodeHeight = $this->_barcode->getHeight(true) * $this->_moduleSize;
if ($barcodeHeight != $supportHeight && $this->_topOffset == 0) {
switch ($this->_verticalPosition) {
case 'middle':
$this->_topOffset = floor(
($supportHeight - $barcodeHeight) / 2);
break;
case 'bottom':
$this->_topOffset = $supportHeight - $barcodeHeight;
break;
case 'top':
default:
$this->_topOffset = 0;
break;
}
}
$barcodeWidth = $this->_barcode->getWidth(true) * $this->_moduleSize;
if ($barcodeWidth != $supportWidth && $this->_leftOffset == 0) {
switch ($this->_horizontalPosition) {
case 'center':
$this->_leftOffset = floor(
($supportWidth - $barcodeWidth) / 2);
break;
case 'right':
$this->_leftOffset = $supportWidth - $barcodeWidth;
break;
case 'left':
default:
$this->_leftOffset = 0;
break;
}
}
}
/**
* Draw the barcode in the rendering resource
*
* @return mixed
* @throws Zend_Exception
* @throws Zend_Barcode_Exception
*/
public function draw()
{
try {
$this->checkParams();
$this->_initRenderer();
$this->_drawInstructionList();
} catch (Zend_Exception $e) {
$renderable = false;
if ($e instanceof Zend_Barcode_Exception) {
$renderable = $e->isRenderable();
}
if ($this->_automaticRenderError && $renderable) {
$barcode = Zend_Barcode::makeBarcode(
'error',
array('text' => $e->getMessage())
);
$this->setBarcode($barcode);
$this->_resource = null;
$this->_initRenderer();
$this->_drawInstructionList();
} else {
if ($e instanceof Zend_Barcode_Exception) {
$e->setIsRenderable(false);
}
throw $e;
}
}
return $this->_resource;
}
/**
* Sub process to draw the barcode instructions
* Needed by the automatic error rendering
*/
private function _drawInstructionList()
{
$instructionList = $this->_barcode->draw();
foreach ($instructionList as $instruction) {
switch ($instruction['type']) {
case 'polygon':
$this->_drawPolygon(
$instruction['points'],
$instruction['color'],
$instruction['filled']
);
break;
case 'text': //$text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
$this->_drawText(
$instruction['text'],
$instruction['size'],
$instruction['position'],
$instruction['font'],
$instruction['color'],
$instruction['alignment'],
$instruction['orientation']
);
break;
default:
/**
* @see Zend_Barcode_Renderer_Exception
*/
throw new Zend_Barcode_Renderer_Exception(
'Unknown drawing command'
);
}
}
}
/**
* Checking of parameters after all settings
* @return void
*/
abstract protected function _checkParams();
/**
* Render the resource by sending headers and drawed resource
* @return mixed
*/
abstract public function render();
/**
* Initialize the rendering resource
* @return void
*/
abstract protected function _initRenderer();
/**
* Draw a polygon in the rendering resource
* @param array $points
* @param integer $color
* @param boolean $filled
*/
abstract protected function _drawPolygon($points, $color, $filled = true);
/**
* Draw a polygon in the rendering resource
*
* @param string $text
* @param float $size
* @param array $position
* @param string $font
* @param integer $color
* @param string $alignment
* @param float|int $orientation
*/
abstract protected function _drawText(
$text,
$size,
$position,
$font,
$color,
$alignment = 'center',
$orientation = 0
);
}

View File

@ -1,377 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Barcode
* @subpackage Renderer
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Image.php 20366 2010-01-18 03:56:52Z ralph $
*/
/** @see Zend_Barcode_Renderer_RendererAbstract*/
/**
* Class for rendering the barcode as svg
*
* @category Zend
* @package Zend_Barcode
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Barcode_Renderer_Svg extends Zend_Barcode_Renderer_RendererAbstract
{
/**
* Resource for the image
* @var DOMDocument
*/
protected $_resource = null;
/**
* Root element of the XML structure
* @var DOMElement
*/
protected $_rootElement = null;
/**
* Height of the rendered image wanted by user
* @var integer
*/
protected $_userHeight = 0;
/**
* Width of the rendered image wanted by user
* @var integer
*/
protected $_userWidth = 0;
/**
* Set height of the result image
*
* @param null|integer $value
* @return Zend_Image_Barcode_Abstract
* @throws Zend_Barcode_Renderer_Exception
*/
public function setHeight($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Svg height must be greater than or equals 0'
);
}
$this->_userHeight = intval($value);
return $this;
}
/**
* Get barcode height
*
* @return int
*/
public function getHeight()
{
return $this->_userHeight;
}
/**
* Set barcode width
*
* @param mixed $value
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setWidth($value)
{
if (!is_numeric($value) || intval($value) < 0) {
throw new Zend_Barcode_Renderer_Exception(
'Svg width must be greater than or equals 0'
);
}
$this->_userWidth = intval($value);
return $this;
}
/**
* Get barcode width
*
* @return int
*/
public function getWidth()
{
return $this->_userWidth;
}
/**
* Set an image resource to draw the barcode inside
*
* @param $svg
* @return Zend_Barcode_Renderer
* @throws Zend_Barcode_Renderer_Exception
*/
public function setResource($svg)
{
if (!$svg instanceof DOMDocument) {
throw new Zend_Barcode_Renderer_Exception(
'Invalid DOMDocument resource provided to setResource()'
);
}
$this->_resource = $svg;
return $this;
}
/**
* Initialize the image resource
*
* @return void
*/
protected function _initRenderer()
{
$barcodeWidth = $this->_barcode->getWidth(true);
$barcodeHeight = $this->_barcode->getHeight(true);
$backgroundColor = $this->_barcode->getBackgroundColor();
$imageBackgroundColor = 'rgb(' . implode(', ', array(($backgroundColor & 0xFF0000) >> 16,
($backgroundColor & 0x00FF00) >> 8,
($backgroundColor & 0x0000FF))) . ')';
$width = $barcodeWidth;
$height = $barcodeHeight;
if ($this->_userWidth && $this->_barcode->getType() != 'error') {
$width = $this->_userWidth;
}
if ($this->_userHeight && $this->_barcode->getType() != 'error') {
$height = $this->_userHeight;
}
if ($this->_resource === null) {
$this->_resource = new DOMDocument('1.0', 'utf-8');
$this->_resource->formatOutput = true;
$this->_rootElement = $this->_resource->createElement('svg');
$this->_rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
$this->_rootElement->setAttribute('version', '1.1');
$this->_rootElement->setAttribute('width', $width);
$this->_rootElement->setAttribute('height', $height);
$this->_appendRootElement('title',
array(),
"Barcode " . strtoupper($this->_barcode->getType()) . " " . $this->_barcode->getText());
} else {
$this->_readRootElement();
$width = $this->_rootElement->getAttribute('width');
$height = $this->_rootElement->getAttribute('height');
}
$this->_adjustPosition($height, $width);
$this->_appendRootElement('rect',
array('x' => $this->_leftOffset,
'y' => $this->_topOffset,
'width' => ($this->_leftOffset + $barcodeWidth - 1),
'height' => ($this->_topOffset + $barcodeHeight - 1),
'fill' => $imageBackgroundColor));
}
protected function _readRootElement()
{
if ($this->_resource !== null) {
$this->_rootElement = $this->_resource->documentElement;
}
}
/**
* Append a new DOMElement to the root element
*
* @param string $tagName
* @param array $attributes
* @param string $textContent
*/
protected function _appendRootElement($tagName, $attributes = array(), $textContent = null)
{
$newElement = $this->_createElement($tagName, $attributes, $textContent);
$this->_rootElement->appendChild($newElement);
}
/**
* Create DOMElement
*
* @param string $tagName
* @param array $attributes
* @param string $textContent
* @return DOMElement
*/
protected function _createElement($tagName, $attributes = array(), $textContent = null)
{
$element = $this->_resource->createElement($tagName);
foreach ($attributes as $k =>$v) {
$element->setAttribute($k, $v);
}
if ($textContent !== null) {
$element->appendChild(new DOMText((string) $textContent));
}
return $element;
}
/**
* Check barcode parameters
*
* @return void
*/
protected function _checkParams()
{
$this->_checkDimensions();
}
/**
* Check barcode dimensions
*
* @return void
* @throws Zend_Barcode_Renderer_Exception
*/
protected function _checkDimensions()
{
if ($this->_resource !== null) {
$this->_readRootElement();
$height = (float) $this->_rootElement->getAttribute('height');
if ($height < $this->_barcode->getHeight(true)) {
throw new Zend_Barcode_Renderer_Exception(
'Barcode is define outside the image (height)'
);
}
} else {
if ($this->_userHeight) {
$height = $this->_barcode->getHeight(true);
if ($this->_userHeight < $height) {
throw new Zend_Barcode_Renderer_Exception(sprintf(
"Barcode is define outside the image (calculated: '%d', provided: '%d')",
$height,
$this->_userHeight
));
}
}
}
if ($this->_resource !== null) {
$this->_readRootElement();
$width = $this->_rootElement->getAttribute('width');
if ($width < $this->_barcode->getWidth(true)) {
throw new Zend_Barcode_Renderer_Exception(
'Barcode is define outside the image (width)'
);
}
} else {
if ($this->_userWidth) {
$width = (float) $this->_barcode->getWidth(true);
if ($this->_userWidth < $width) {
throw new Zend_Barcode_Renderer_Exception(sprintf(
"Barcode is define outside the image (calculated: '%d', provided: '%d')",
$width,
$this->_userWidth
));
}
}
}
}
/**
* Draw the barcode in the rendering resource
* @return mixed
*/
public function draw()
{
parent::draw();
$this->_resource->appendChild($this->_rootElement);
return $this->_resource;
}
/**
* Draw and render the barcode with correct headers
*
* @return mixed
*/
public function render()
{
$this->draw();
header("Content-Type: image/svg+xml");
echo $this->_resource->saveXML();
}
/**
* Draw a polygon in the svg resource
*
* @param array $points
* @param integer $color
* @param boolean $filled
*/
protected function _drawPolygon($points, $color, $filled = true)
{
$color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
($color & 0x0000FF))) . ')';
$orientation = $this->getBarcode()->getOrientation();
$newPoints = array(
$points[0][0] + $this->_leftOffset,
$points[0][1] + $this->_topOffset,
$points[1][0] + $this->_leftOffset,
$points[1][1] + $this->_topOffset,
$points[2][0] + $this->_leftOffset + cos(-$orientation),
$points[2][1] + $this->_topOffset - sin($orientation),
$points[3][0] + $this->_leftOffset + cos(-$orientation),
$points[3][1] + $this->_topOffset - sin($orientation),
);
$newPoints = implode(' ', $newPoints);
$attributes['points'] = $newPoints;
$attributes['fill'] = $color;
$this->_appendRootElement('polygon', $attributes);
}
/**
* Draw a polygon in the svg resource
*
* @param string $text
* @param float $size
* @param array $position
* @param string $font
* @param integer $color
* @param string $alignment
* @param float|int $orientation
*/
protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
{
$color = 'rgb(' . implode(', ', array(($color & 0xFF0000) >> 16,
($color & 0x00FF00) >> 8,
($color & 0x0000FF))) . ')';
$attributes['x'] = $position[0] + $this->_leftOffset;
$attributes['y'] = $position[1] + $this->_topOffset;
//$attributes['font-family'] = $font;
$attributes['color'] = $color;
$attributes['font-size'] = $size * 1.2;
switch ($alignment) {
case 'left':
$textAnchor = 'start';
break;
case 'right':
$textAnchor = 'end';
break;
case 'center':
default:
$textAnchor = 'middle';
}
$attributes['style'] = 'text-anchor: ' . $textAnchor;
$attributes['transform'] = 'rotate('
. (- $orientation)
. ', '
. ($position[0] + $this->_leftOffset)
. ', ' . ($position[1] + $this->_topOffset)
. ')';
$this->_appendRootElement('text', $attributes, $text);
}
}

View File

@ -84,6 +84,7 @@ abstract class Zend_Cache
* @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
*/

0
library/vendor/Zend/Cache/Backend/ZendServer.php vendored Normal file → Executable file
View File

0
library/vendor/Zend/Cache/Backend/ZendServer/Disk.php vendored Normal file → Executable file
View File

0
library/vendor/Zend/Cache/Backend/ZendServer/ShMem.php vendored Normal file → Executable file
View File

View File

@ -1,75 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Validate_Interface */
/**
* Generic Captcha adapter interface
*
* Each specific captcha implementation should implement this interface
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
interface Zend_Captcha_Adapter extends Zend_Validate_Interface
{
/**
* Generate a new captcha
*
* @return string new captcha ID
*/
public function generate();
/**
* Display the captcha
*
* @param Zend_View_Interface $view
* @param mixed $element
* @return string
*/
public function render(Zend_View_Interface $view = null, $element = null);
/**
* Set captcha name
*
* @param string $name
* @return Zend_Captcha_Adapter
*/
public function setName($name);
/**
* Get captcha name
*
* @return string
*/
public function getName();
/**
* Get optional private decorator for this captcha type
*
* @return Zend_Form_Decorator_Interface|string
*/
public function getDecorator();
}

View File

@ -1,174 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Captcha_Adapter */
/** @see Zend_Validate_Abstract */
/**
* Base class for Captcha adapters
*
* Provides some utility functionality to build on
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
abstract class Zend_Captcha_Base extends Zend_Validate_Abstract implements Zend_Captcha_Adapter
{
/**
* Element name
*
* Useful to generate/check form fields
*
* @var string
*/
protected $_name;
/**
* Captcha options
*
* @var array
*/
protected $_options = array();
/**
* Options to skip when processing options
* @var array
*/
protected $_skipOptions = array(
'options',
'config',
);
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->_name;
}
/**
* Set name
*
* @param string $name
* @return Zend_Captcha_Adapter
*/
public function setName($name)
{
$this->_name = $name;
return $this;
}
/**
* Constructor
*
* @param array|Zend_Config $options
*/
public function __construct($options = null)
{
// Set options
if (is_array($options)) {
$this->setOptions($options);
} else if ($options instanceof Zend_Config) {
$this->setConfig($options);
}
}
/**
* Set single option for the object
*
* @param string $key
* @param string $value
* @return Zend_Form_Element
*/
public function setOption($key, $value)
{
if (in_array(strtolower($key), $this->_skipOptions)) {
return $this;
}
$method = 'set' . ucfirst ($key);
if (method_exists ($this, $method)) {
// Setter exists; use it
$this->$method ($value);
$this->_options[$key] = $value;
} elseif (property_exists($this, $key)) {
// Assume it's metadata
$this->$key = $value;
$this->_options[$key] = $value;
}
return $this;
}
/**
* Set object state from options array
*
* @param array $options
* @return Zend_Form_Element
*/
public function setOptions($options = null)
{
foreach ($options as $key => $value) {
$this->setOption($key, $value);
}
return $this;
}
/**
* Retrieve options representing object state
*
* @return array
*/
public function getOptions()
{
return $this->_options;
}
/**
* Set object state from config object
*
* @param Zend_Config $config
* @return Zend_Captcha_Base
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Get optional decorator
*
* By default, return null, indicating no extra decorator needed.
*
* @return null
*/
public function getDecorator()
{
return null;
}
}

View File

@ -1,74 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Captcha_Word */
/**
* Example dumb word-based captcha
*
* Note that only rendering is necessary for word-based captcha
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
class Zend_Captcha_Dumb extends Zend_Captcha_Word
{
/**
* CAPTCHA label
* @type string
*/
protected $_label = 'Please type this word backwards';
/**
* Set the label for the CAPTCHA
* @param string $label
*/
public function setLabel($label)
{
$this->_label = $label;
}
/**
* Retrieve the label for the CAPTCHA
* @return string
*/
public function getLabel()
{
return $this->_label;
}
/**
* Render the captcha
*
* @param Zend_View_Interface $view
* @param mixed $element
* @return string
*/
public function render(Zend_View_Interface $view = null, $element = null)
{
return $this->getLabel() . ': <b>'
. strrev($this->getWord())
. '</b>';
}
}

View File

@ -1,36 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Exception
*/
/**
* Exception for Zend_Form component.
*
* @category Zend
* @package Zend_Captcha
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Captcha_Exception extends Zend_Exception
{
}

View File

@ -1,82 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Captcha_Word */
/** @see Zend_Text_Figlet */
/**
* Captcha based on figlet text rendering service
*
* Note that this engine seems not to like numbers
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
class Zend_Captcha_Figlet extends Zend_Captcha_Word
{
/**
* Figlet text renderer
*
* @var Zend_Text_Figlet
*/
protected $_figlet;
/**
* Constructor
*
* @param null|string|array|Zend_Config $options
*/
public function __construct($options = null)
{
parent::__construct($options);
$this->_figlet = new Zend_Text_Figlet($options);
}
/**
* Generate new captcha
*
* @return string
*/
public function generate()
{
$this->_useNumbers = false;
return parent::generate();
}
/**
* Display the captcha
*
* @param Zend_View_Interface $view
* @param mixed $element
* @return string
*/
public function render(Zend_View_Interface $view = null, $element = null)
{
return '<pre>'
. $this->_figlet->render($this->getWord())
. "</pre>\n";
}
}

View File

@ -1,619 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/** @see Zend_Captcha_Word */
/**
* Image-based captcha element
*
* Generates image displaying random word
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Captcha_Image extends Zend_Captcha_Word
{
/**
* Directory for generated images
*
* @var string
*/
protected $_imgDir = "./images/captcha/";
/**
* URL for accessing images
*
* @var string
*/
protected $_imgUrl = "/images/captcha/";
/**
* Image's alt tag content
*
* @var string
*/
protected $_imgAlt = "";
/**
* Image suffix (including dot)
*
* @var string
*/
protected $_suffix = ".png";
/**
* Image width
*
* @var int
*/
protected $_width = 200;
/**
* Image height
*
* @var int
*/
protected $_height = 50;
/**
* Font size
*
* @var int
*/
protected $_fsize = 24;
/**
* Image font file
*
* @var string
*/
protected $_font;
/**
* Image to use as starting point
* Default is blank image. If provided, should be PNG image.
*
* @var string
*/
protected $_startImage;
/**
* How frequently to execute garbage collection
*
* @var int
*/
protected $_gcFreq = 10;
/**
* How long to keep generated images
*
* @var int
*/
protected $_expiration = 600;
/**
* Number of noise dots on image
* Used twice - before and after transform
*
* @var int
*/
protected $_dotNoiseLevel = 100;
/**
* Number of noise lines on image
* Used twice - before and after transform
*
* @var int
*/
protected $_lineNoiseLevel = 5;
/**
* @return string
*/
public function getImgAlt ()
{
return $this->_imgAlt;
}
/**
* @return string
*/
public function getStartImage ()
{
return $this->_startImage;
}
/**
* @return int
*/
public function getDotNoiseLevel ()
{
return $this->_dotNoiseLevel;
}
/**
* @return int
*/
public function getLineNoiseLevel ()
{
return $this->_lineNoiseLevel;
}
/**
* Get captcha expiration
*
* @return int
*/
public function getExpiration()
{
return $this->_expiration;
}
/**
* Get garbage collection frequency
*
* @return int
*/
public function getGcFreq()
{
return $this->_gcFreq;
}
/**
* Get font to use when generating captcha
*
* @return string
*/
public function getFont()
{
return $this->_font;
}
/**
* Get font size
*
* @return int
*/
public function getFontSize()
{
return $this->_fsize;
}
/**
* Get captcha image height
*
* @return int
*/
public function getHeight()
{
return $this->_height;
}
/**
* Get captcha image directory
*
* @return string
*/
public function getImgDir()
{
return $this->_imgDir;
}
/**
* Get captcha image base URL
*
* @return string
*/
public function getImgUrl()
{
return $this->_imgUrl;
}
/**
* Get captcha image file suffix
*
* @return string
*/
public function getSuffix()
{
return $this->_suffix;
}
/**
* Get captcha image width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
/**
* Set start image
*
* @param string $startImage
* @return Zend_Captcha_Image
*/
public function setStartImage ($startImage)
{
$this->_startImage = $startImage;
return $this;
}
/**
* Set dot noise level
*
* @param int $dotNoiseLevel
* @return Zend_Captcha_Image
*/
public function setDotNoiseLevel ($dotNoiseLevel)
{
$this->_dotNoiseLevel = $dotNoiseLevel;
return $this;
}
/**
* Set line noise level
*
* @param int $lineNoiseLevel
* @return Zend_Captcha_Image
*/
public function setLineNoiseLevel ($lineNoiseLevel)
{
$this->_lineNoiseLevel = $lineNoiseLevel;
return $this;
}
/**
* Set captcha expiration
*
* @param int $expiration
* @return Zend_Captcha_Image
*/
public function setExpiration($expiration)
{
$this->_expiration = $expiration;
return $this;
}
/**
* Set garbage collection frequency
*
* @param int $gcFreq
* @return Zend_Captcha_Image
*/
public function setGcFreq($gcFreq)
{
$this->_gcFreq = $gcFreq;
return $this;
}
/**
* Set captcha font
*
* @param string $font
* @return Zend_Captcha_Image
*/
public function setFont($font)
{
$this->_font = $font;
return $this;
}
/**
* Set captcha font size
*
* @param int $fsize
* @return Zend_Captcha_Image
*/
public function setFontSize($fsize)
{
$this->_fsize = $fsize;
return $this;
}
/**
* Set captcha image height
*
* @param int $height
* @return Zend_Captcha_Image
*/
public function setHeight($height)
{
$this->_height = $height;
return $this;
}
/**
* Set captcha image storage directory
*
* @param string $imgDir
* @return Zend_Captcha_Image
*/
public function setImgDir($imgDir)
{
$this->_imgDir = rtrim($imgDir, "/\\") . '/';
return $this;
}
/**
* Set captcha image base URL
*
* @param string $imgUrl
* @return Zend_Captcha_Image
*/
public function setImgUrl($imgUrl)
{
$this->_imgUrl = rtrim($imgUrl, "/\\") . '/';
return $this;
}
/**
* Set image alternative text
*
* @param string $imgAlt
* @return Zend_Captcha_Image
*/
public function setImgAlt ($imgAlt)
{
$this->_imgAlt = $imgAlt;
return $this;
}
/**
* Set captch image filename suffix
*
* @param string $suffix
* @return Zend_Captcha_Image
*/
public function setSuffix($suffix)
{
$this->_suffix = $suffix;
return $this;
}
/**
* Set captcha image width
*
* @param int $width
* @return Zend_Captcha_Image
*/
public function setWidth($width)
{
$this->_width = $width;
return $this;
}
/**
* Generate random frequency
*
* @return float
*/
protected function _randomFreq()
{
return mt_rand(700000, 1000000) / 15000000;
}
/**
* Generate random phase
*
* @return float
*/
protected function _randomPhase()
{
// random phase from 0 to pi
return mt_rand(0, 3141592) / 1000000;
}
/**
* Generate random character size
*
* @return int
*/
protected function _randomSize()
{
return mt_rand(300, 700) / 100;
}
/**
* Generate captcha
*
* @return string captcha ID
*/
public function generate()
{
$id = parent::generate();
$tries = 5;
// If there's already such file, try creating a new ID
while($tries-- && file_exists($this->getImgDir() . $id . $this->getSuffix())) {
$id = $this->_generateRandomId();
$this->_setId($id);
}
$this->_generateImage($id, $this->getWord());
if (mt_rand(1, $this->getGcFreq()) == 1) {
$this->_gc();
}
return $id;
}
/**
* Generate image captcha
*
* Override this function if you want different image generator
* Wave transform from http://www.captcha.ru/captchas/multiwave/
*
* @param string $id Captcha ID
* @param string $word Captcha word
* @throws Zend_Captcha_Exception
*/
protected function _generateImage($id, $word)
{
if (!extension_loaded("gd")) {
throw new Zend_Captcha_Exception("Image CAPTCHA requires GD extension");
}
if (!function_exists("imagepng")) {
throw new Zend_Captcha_Exception("Image CAPTCHA requires PNG support");
}
if (!function_exists("imageftbbox")) {
throw new Zend_Captcha_Exception("Image CAPTCHA requires FT fonts support");
}
$font = $this->getFont();
if (empty($font)) {
throw new Zend_Captcha_Exception("Image CAPTCHA requires font");
}
$w = $this->getWidth();
$h = $this->getHeight();
$fsize = $this->getFontSize();
$img_file = $this->getImgDir() . $id . $this->getSuffix();
if(empty($this->_startImage)) {
$img = imagecreatetruecolor($w, $h);
} else {
$img = imagecreatefrompng($this->_startImage);
if(!$img) {
throw new Zend_Captcha_Exception("Can not load start image");
}
$w = imagesx($img);
$h = imagesy($img);
}
$text_color = imagecolorallocate($img, 0, 0, 0);
$bg_color = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 0, 0, $w-1, $h-1, $bg_color);
$textbox = imageftbbox($fsize, 0, $font, $word);
$x = ($w - ($textbox[2] - $textbox[0])) / 2;
$y = ($h - ($textbox[7] - $textbox[1])) / 2;
imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word);
// generate noise
for ($i=0; $i<$this->_dotNoiseLevel; $i++) {
imagefilledellipse($img, mt_rand(0,$w), mt_rand(0,$h), 2, 2, $text_color);
}
for($i=0; $i<$this->_lineNoiseLevel; $i++) {
imageline($img, mt_rand(0,$w), mt_rand(0,$h), mt_rand(0,$w), mt_rand(0,$h), $text_color);
}
// transformed image
$img2 = imagecreatetruecolor($w, $h);
$bg_color = imagecolorallocate($img2, 255, 255, 255);
imagefilledrectangle($img2, 0, 0, $w-1, $h-1, $bg_color);
// apply wave transforms
$freq1 = $this->_randomFreq();
$freq2 = $this->_randomFreq();
$freq3 = $this->_randomFreq();
$freq4 = $this->_randomFreq();
$ph1 = $this->_randomPhase();
$ph2 = $this->_randomPhase();
$ph3 = $this->_randomPhase();
$ph4 = $this->_randomPhase();
$szx = $this->_randomSize();
$szy = $this->_randomSize();
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$sx = $x + (sin($x*$freq1 + $ph1) + sin($y*$freq3 + $ph3)) * $szx;
$sy = $y + (sin($x*$freq2 + $ph2) + sin($y*$freq4 + $ph4)) * $szy;
if ($sx < 0 || $sy < 0 || $sx >= $w - 1 || $sy >= $h - 1) {
continue;
} else {
$color = (imagecolorat($img, $sx, $sy) >> 16) & 0xFF;
$color_x = (imagecolorat($img, $sx + 1, $sy) >> 16) & 0xFF;
$color_y = (imagecolorat($img, $sx, $sy + 1) >> 16) & 0xFF;
$color_xy = (imagecolorat($img, $sx + 1, $sy + 1) >> 16) & 0xFF;
}
if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) {
// ignore background
continue;
} elseif ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) {
// transfer inside of the image as-is
$newcolor = 0;
} else {
// do antialiasing for border items
$frac_x = $sx-floor($sx);
$frac_y = $sy-floor($sy);
$frac_x1 = 1-$frac_x;
$frac_y1 = 1-$frac_y;
$newcolor = $color * $frac_x1 * $frac_y1
+ $color_x * $frac_x * $frac_y1
+ $color_y * $frac_x1 * $frac_y
+ $color_xy * $frac_x * $frac_y;
}
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newcolor, $newcolor, $newcolor));
}
}
// generate noise
for ($i=0; $i<$this->_dotNoiseLevel; $i++) {
imagefilledellipse($img2, mt_rand(0,$w), mt_rand(0,$h), 2, 2, $text_color);
}
for ($i=0; $i<$this->_lineNoiseLevel; $i++) {
imageline($img2, mt_rand(0,$w), mt_rand(0,$h), mt_rand(0,$w), mt_rand(0,$h), $text_color);
}
imagepng($img2, $img_file);
imagedestroy($img);
imagedestroy($img2);
}
/**
* Remove old files from image directory
*/
protected function _gc()
{
$expire = time() - $this->getExpiration();
$imgdir = $this->getImgDir();
if(!$imgdir || strlen($imgdir) < 2) {
// safety guard
return;
}
$suffixLength = strlen($this->_suffix);
foreach (new DirectoryIterator($imgdir) as $file) {
if (!$file->isDot() && !$file->isDir()) {
if (file_exists($file->getPathname()) && $file->getMTime() < $expire) {
// only deletes files ending with $this->_suffix
if (substr($file->getFilename(), -($suffixLength)) == $this->_suffix) {
unlink($file->getPathname());
}
}
}
}
}
/**
* Display the captcha
*
* @param Zend_View_Interface $view
* @param mixed $element
* @return string
*/
public function render(Zend_View_Interface $view = null, $element = null)
{
$endTag = ' />';
if (($view instanceof Zend_View_Abstract) && !$view->doctype()->isXhtml()) {
$endTag = '>';
}
return '<img width="' . $this->getWidth() . '" height="' . $this->getHeight() . '" alt="' . $this->getImgAlt()
. '" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '"' . $endTag;
}
}

View File

@ -1,278 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Captcha_Base */
/** @see Zend_Service_ReCaptcha */
/**
* ReCaptcha adapter
*
* Allows to insert captchas driven by ReCaptcha service
*
* @see http://recaptcha.net/apidocs/captcha/
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
{
/**@+
* ReCaptcha Field names
* @var string
*/
protected $_CHALLENGE = 'recaptcha_challenge_field';
protected $_RESPONSE = 'recaptcha_response_field';
/**@-*/
/**
* Recaptcha service object
*
* @var Zend_Service_Recaptcha
*/
protected $_service;
/**
* Parameters defined by the service
*
* @var array
*/
protected $_serviceParams = array();
/**
* Options defined by the service
*
* @var array
*/
protected $_serviceOptions = array();
/**#@+
* Error codes
*/
const MISSING_VALUE = 'missingValue';
const ERR_CAPTCHA = 'errCaptcha';
const BAD_CAPTCHA = 'badCaptcha';
/**#@-*/
/**
* Error messages
* @var array
*/
protected $_messageTemplates = array(
self::MISSING_VALUE => 'Missing captcha fields',
self::ERR_CAPTCHA => 'Failed to validate captcha',
self::BAD_CAPTCHA => 'Captcha value is wrong: %value%',
);
/**
* Retrieve ReCaptcha Private key
*
* @return string
*/
public function getPrivkey()
{
return $this->getService()->getPrivateKey();
}
/**
* Retrieve ReCaptcha Public key
*
* @return string
*/
public function getPubkey()
{
return $this->getService()->getPublicKey();
}
/**
* Set ReCaptcha Private key
*
* @param string $privkey
* @return Zend_Captcha_ReCaptcha
*/
public function setPrivkey($privkey)
{
$this->getService()->setPrivateKey($privkey);
return $this;
}
/**
* Set ReCaptcha public key
*
* @param string $pubkey
* @return Zend_Captcha_ReCaptcha
*/
public function setPubkey($pubkey)
{
$this->getService()->setPublicKey($pubkey);
return $this;
}
/**
* Constructor
*
* @param array|Zend_Config $options
*/
public function __construct($options = null)
{
$this->setService(new Zend_Service_ReCaptcha());
$this->_serviceParams = $this->getService()->getParams();
$this->_serviceOptions = $this->getService()->getOptions();
parent::__construct($options);
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
if (!empty($options)) {
$this->setOptions($options);
}
}
/**
* Set service object
*
* @param Zend_Service_ReCaptcha $service
* @return Zend_Captcha_ReCaptcha
*/
public function setService(Zend_Service_ReCaptcha $service)
{
$this->_service = $service;
return $this;
}
/**
* Retrieve ReCaptcha service object
*
* @return Zend_Service_ReCaptcha
*/
public function getService()
{
return $this->_service;
}
/**
* Set option
*
* If option is a service parameter, proxies to the service. The same
* goes for any service options (distinct from service params)
*
* @param string $key
* @param mixed $value
* @return Zend_Captcha_ReCaptcha
*/
public function setOption($key, $value)
{
$service = $this->getService();
if (isset($this->_serviceParams[$key])) {
$service->setParam($key, $value);
return $this;
}
if (isset($this->_serviceOptions[$key])) {
$service->setOption($key, $value);
return $this;
}
return parent::setOption($key, $value);
}
/**
* Generate captcha
*
* @see Zend_Form_Captcha_Adapter::generate()
* @return string
*/
public function generate()
{
return "";
}
/**
* Validate captcha
*
* @see Zend_Validate_Interface::isValid()
* @param mixed $value
* @param array|null $context
* @return boolean
*/
public function isValid($value, $context = null)
{
if (!is_array($value) && !is_array($context)) {
$this->_error(self::MISSING_VALUE);
return false;
}
if (!is_array($value) && is_array($context)) {
$value = $context;
}
if (empty($value[$this->_CHALLENGE]) || empty($value[$this->_RESPONSE])) {
$this->_error(self::MISSING_VALUE);
return false;
}
$service = $this->getService();
$res = $service->verify($value[$this->_CHALLENGE], $value[$this->_RESPONSE]);
if (!$res) {
$this->_error(self::ERR_CAPTCHA);
return false;
}
if (!$res->isValid()) {
$this->_error(self::BAD_CAPTCHA, $res->getErrorCode());
$service->setParam('error', $res->getErrorCode());
return false;
}
return true;
}
/**
* Render captcha
*
* @param Zend_View_Interface $view
* @param mixed $element
* @return string
*/
public function render(Zend_View_Interface $view = null, $element = null)
{
$name = null;
if ($element instanceof Zend_Form_Element) {
$name = $element->getBelongsTo();
}
return $this->getService()->getHTML($name);
}
/**
* Get captcha decorator
*
* @return string
*/
public function getDecorator()
{
return "Captcha_ReCaptcha";
}
}

View File

@ -1,417 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Captcha_Base */
/**
* Word-based captcha adapter
*
* Generates random word which user should recognise
*
* @category Zend
* @package Zend_Captcha
* @subpackage Adapter
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
abstract class Zend_Captcha_Word extends Zend_Captcha_Base
{
/**#@+
* @var array Character sets
*/
static $V = array("a", "e", "i", "o", "u", "y");
static $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
static $C = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
static $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
/**#@-*/
/**
* Random session ID
*
* @var string
*/
protected $_id;
/**
* Generated word
*
* @var string
*/
protected $_word;
/**
* Session
*
* @var Zend_Session_Namespace
*/
protected $_session;
/**
* Class name for sessions
*
* @var string
*/
protected $_sessionClass = 'Zend_Session_Namespace';
/**
* Should the numbers be used or only letters
*
* @var boolean
*/
protected $_useNumbers = true;
/**
* Should both cases be used or only lowercase
*
* @var boolean
*/
// protected $_useCase = false;
/**
* Session lifetime for the captcha data
*
* @var integer
*/
protected $_timeout = 300;
/**
* Should generate() keep session or create a new one?
*
* @var boolean
*/
protected $_keepSession = false;
/**#@+
* Error codes
*/
const MISSING_VALUE = 'missingValue';
const MISSING_ID = 'missingID';
const BAD_CAPTCHA = 'badCaptcha';
/**#@-*/
/**
* Error messages
* @var array
*/
protected $_messageTemplates = array(
self::MISSING_VALUE => 'Empty captcha value',
self::MISSING_ID => 'Captcha ID field is missing',
self::BAD_CAPTCHA => 'Captcha value is wrong',
);
/**
* Length of the word to generate
*
* @var integer
*/
protected $_wordlen = 8;
/**
* Retrieve session class to utilize
*
* @return string
*/
public function getSessionClass()
{
return $this->_sessionClass;
}
/**
* Set session class for persistence
*
* @param string $_sessionClass
* @return Zend_Captcha_Word
*/
public function setSessionClass($_sessionClass)
{
$this->_sessionClass = $_sessionClass;
return $this;
}
/**
* Retrieve word length to use when genrating captcha
*
* @return integer
*/
public function getWordlen()
{
return $this->_wordlen;
}
/**
* Set word length of captcha
*
* @param integer $wordlen
* @return Zend_Captcha_Word
*/
public function setWordlen($wordlen)
{
$this->_wordlen = $wordlen;
return $this;
}
/**
* Retrieve captcha ID
*
* @return string
*/
public function getId ()
{
if (null === $this->_id) {
$this->_setId($this->_generateRandomId());
}
return $this->_id;
}
/**
* Set captcha identifier
*
* @param string $id
* @return Zend_Captcha_Word
*/
protected function _setId ($id)
{
$this->_id = $id;
return $this;
}
/**
* Set timeout for session token
*
* @param int $ttl
* @return Zend_Captcha_Word
*/
public function setTimeout($ttl)
{
$this->_timeout = (int) $ttl;
return $this;
}
/**
* Get session token timeout
*
* @return int
*/
public function getTimeout()
{
return $this->_timeout;
}
/**
* Sets if session should be preserved on generate()
*
* @param bool $keepSession Should session be kept on generate()?
* @return Zend_Captcha_Word
*/
public function setKeepSession($keepSession)
{
$this->_keepSession = $keepSession;
return $this;
}
/**
* Numbers should be included in the pattern?
*
* @return bool
*/
public function getUseNumbers()
{
return $this->_useNumbers;
}
/**
* Set if numbers should be included in the pattern
*
* @param bool $_useNumbers numbers should be included in the pattern?
* @return Zend_Captcha_Word
*/
public function setUseNumbers($_useNumbers)
{
$this->_useNumbers = $_useNumbers;
return $this;
}
/**
* Get session object
*
* @return Zend_Session_Namespace
*/
public function getSession()
{
if (!isset($this->_session) || (null === $this->_session)) {
$id = $this->getId();
if (!class_exists($this->_sessionClass)) {
Zend_Loader::loadClass($this->_sessionClass);
}
$this->_session = new $this->_sessionClass('Zend_Form_Captcha_' . $id);
$this->_session->setExpirationHops(1, null, true);
$this->_session->setExpirationSeconds($this->getTimeout());
}
return $this->_session;
}
/**
* Set session namespace object
*
* @param Zend_Session_Namespace $session
* @return Zend_Captcha_Word
*/
public function setSession(Zend_Session_Namespace $session)
{
$this->_session = $session;
if($session) {
$this->_keepSession = true;
}
return $this;
}
/**
* Get captcha word
*
* @return string
*/
public function getWord()
{
if (empty($this->_word)) {
$session = $this->getSession();
$this->_word = $session->word;
}
return $this->_word;
}
/**
* Set captcha word
*
* @param string $word
* @return Zend_Captcha_Word
*/
protected function _setWord($word)
{
$session = $this->getSession();
$session->word = $word;
$this->_word = $word;
return $this;
}
/**
* Generate new random word
*
* @return string
*/
protected function _generateWord()
{
$word = '';
$wordLen = $this->getWordLen();
$vowels = $this->_useNumbers ? self::$VN : self::$V;
$consonants = $this->_useNumbers ? self::$CN : self::$C;
for ($i=0; $i < $wordLen; $i = $i + 2) {
// generate word with mix of vowels and consonants
$consonant = $consonants[array_rand($consonants)];
$vowel = $vowels[array_rand($vowels)];
$word .= $consonant . $vowel;
}
if (strlen($word) > $wordLen) {
$word = substr($word, 0, $wordLen);
}
return $word;
}
/**
* Generate new session ID and new word
*
* @return string session ID
*/
public function generate()
{
if(!$this->_keepSession) {
$this->_session = null;
}
$id = $this->_generateRandomId();
$this->_setId($id);
$word = $this->_generateWord();
$this->_setWord($word);
return $id;
}
protected function _generateRandomId()
{
return md5(mt_rand(0, 1000) . microtime(true));
}
/**
* Validate the word
*
* @see Zend_Validate_Interface::isValid()
* @param mixed $value
* @param array|null $context
* @return boolean
*/
public function isValid($value, $context = null)
{
if (!is_array($value) && !is_array($context)) {
$this->_error(self::MISSING_VALUE);
return false;
}
if (!is_array($value) && is_array($context)) {
$value = $context;
}
$name = $this->getName();
if (isset($value[$name])) {
$value = $value[$name];
}
if (!isset($value['input'])) {
$this->_error(self::MISSING_VALUE);
return false;
}
$input = strtolower($value['input']);
$this->_setValue($input);
if (!isset($value['id'])) {
$this->_error(self::MISSING_ID);
return false;
}
$this->_id = $value['id'];
if ($input !== $this->getWord()) {
$this->_error(self::BAD_CAPTCHA);
return false;
}
return true;
}
/**
* Get captcha decorator
*
* @return string
*/
public function getDecorator()
{
return "Captcha_Word";
}
}

View File

@ -1,233 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config
*/
/**
* @see Zend_Json
*/
/**
* JSON Adapter for Zend_Config
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Json extends Zend_Config
{
/**
* Name of object key indicating section current section extends
*/
const EXTENDS_NAME = "_extends";
/**
* Whether or not to ignore constants in the JSON string
*
* Note: if you do not have constant names in quotations in your JSON
* string, they may lead to syntax errors when parsing.
*
* @var bool
*/
protected $_ignoreConstants = false;
/**
* Whether to skip extends or not
*
* @var boolean
*/
protected $_skipExtends = false;
/**
* Loads the section $section from the config file encoded as JSON
*
* Sections are defined as properties of the main object
*
* In order to extend another section, a section defines the "_extends"
* property having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "_extends".
*
* @param string $json JSON file or string to process
* @param mixed $section Section to process
* @param boolean $options Whether modifiacations are allowed at runtime
* @throws Zend_Config_Exception When JSON text is not set or cannot be loaded
* @throws Zend_Config_Exception When section $sectionName cannot be found in $json
*/
public function __construct($json, $section = null, $options = false)
{
if (empty($json)) {
throw new Zend_Config_Exception('Filename is not set');
}
$allowModifications = false;
if (is_bool($options)) {
$allowModifications = $options;
} elseif (is_array($options)) {
foreach ($options as $key => $value) {
switch (strtolower($key)) {
case 'allow_modifications':
case 'allowmodifications':
$allowModifications = (bool) $value;
break;
case 'skip_extends':
case 'skipextends':
$this->_skipExtends = (bool) $value;
break;
case 'ignore_constants':
case 'ignoreconstants':
$this->_ignoreConstants = (bool) $value;
break;
default:
break;
}
}
}
set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed
if ($json[0] != '{') {
$json = file_get_contents($json);
}
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
// Replace constants
if (!$this->_ignoreConstants) {
$json = $this->_replaceConstants($json);
}
// Parse/decode
try {
$config = Zend_Json::decode($json);
} catch (Zend_Json_Exception $e) {
// decode failed
throw new Zend_Config_Exception("Error parsing JSON data");
}
if ($section === null) {
$dataArray = array();
foreach ($config as $sectionName => $sectionData) {
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
}
parent::__construct($dataArray, $allowModifications);
} elseif (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($config[$sectionName])) {
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $sectionName));
}
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($config[$section])) {
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
}
$dataArray = $this->_processExtends($config, $section);
if (!is_array($dataArray)) {
// Section in the JSON data contains just one top level string
$dataArray = array($section => $dataArray);
}
parent::__construct($dataArray, $allowModifications);
}
$this->_loadedSection = $section;
}
/**
* Helper function to process each element in the section and handle
* the "_extends" inheritance attribute.
*
* @param array $data Data array to process
* @param string $section Section to process
* @param array $config Configuration which was parsed yet
* @throws Zend_Config_Exception When $section cannot be found
* @return array
*/
protected function _processExtends(array $data, $section, array $config = array())
{
if (!isset($data[$section])) {
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
}
$thisSection = $data[$section];
if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
if (is_array($thisSection[self::EXTENDS_NAME])) {
throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received');
}
$this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
if (!$this->_skipExtends) {
$config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
}
unset($thisSection[self::EXTENDS_NAME]);
}
$config = $this->_arrayMergeRecursive($config, $thisSection);
return $config;
}
/**
* Replace any constants referenced in a string with their values
*
* @param string $value
* @return string
*/
protected function _replaceConstants($value)
{
foreach ($this->_getConstants() as $constant) {
if (strstr($value, $constant)) {
// handle backslashes that may represent windows path names for instance
$replacement = str_replace('\\', '\\\\', constant($constant));
$value = str_replace($constant, $replacement, $value);
}
}
return $value;
}
/**
* Get (reverse) sorted list of defined constant names
*
* @return array
*/
protected function _getConstants()
{
$constants = array_keys(get_defined_constants());
rsort($constants, SORT_STRING);
return $constants;
}
}

View File

@ -1,104 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config_Writer
*/
/**
* @see Zend_Config_Json
*/
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Writer_Json extends Zend_Config_Writer_FileAbstract
{
/**
* If we need to pretty-print JSON data
*
* @var boolean
*/
protected $_prettyPrint = false;
/**
* Get prettyPrint flag
*
* @return the prettyPrint flag
*/
public function prettyPrint()
{
return $this->_prettyPrint;
}
/**
* Set prettyPrint flag
*
* @param bool $prettyPrint PrettyPrint flag
* @return Zend_Config_Writer_Json
*/
public function setPrettyPrint($flag)
{
$this->_prettyPrint = (bool) $flag;
return $this;
}
/**
* Render a Zend_Config into a JSON config string.
*
* @since 1.10
* @return string
*/
public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parentSection) {
$data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
}
// Ensure that each "extends" section actually exists
foreach ($data as $section => $sectionData) {
if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
$sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
if (!isset($data[$sectionExtends])) {
// Remove "extends" declaration if section does not exist
unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
}
}
}
$out = Zend_Json::encode($data);
if ($this->prettyPrint()) {
$out = Zend_Json::prettyPrint($out);
}
return $out;
}
}

View File

@ -1,124 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config_Writer
*/
/**
* @see Zend_Config_Xml
*/
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Writer_Xml extends Zend_Config_Writer_FileAbstract
{
/**
* Render a Zend_Config into a XML config string.
*
* @since 1.10
* @return string
*/
public function render()
{
$xml = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>');
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$child = $xml->addChild($sectionName);
$this->_addBranch($this->_config, $child, $xml);
} else {
foreach ($this->_config as $sectionName => $data) {
if (!($data instanceof Zend_Config)) {
$xml->addChild($sectionName, (string) $data);
} else {
$child = $xml->addChild($sectionName);
if (isset($extends[$sectionName])) {
$child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE);
}
$this->_addBranch($data, $child, $xml);
}
}
}
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
$xmlString = $dom->saveXML();
return $xmlString;
}
/**
* Add a branch to an XML object recursively
*
* @param Zend_Config $config
* @param SimpleXMLElement $xml
* @param SimpleXMLElement $parent
* @return void
*/
protected function _addBranch(Zend_Config $config, SimpleXMLElement $xml, SimpleXMLElement $parent)
{
$branchType = null;
foreach ($config as $key => $value) {
if ($branchType === null) {
if (is_numeric($key)) {
$branchType = 'numeric';
$branchName = $xml->getName();
$xml = $parent;
unset($parent->{$branchName});
} else {
$branchType = 'string';
}
} else if ($branchType !== (is_numeric($key) ? 'numeric' : 'string')) {
throw new Zend_Config_Exception('Mixing of string and numeric keys is not allowed');
}
if ($branchType === 'numeric') {
if ($value instanceof Zend_Config) {
$child = $parent->addChild($branchName);
$this->_addBranch($value, $child, $parent);
} else {
$parent->addChild($branchName, (string) $value);
}
} else {
if ($value instanceof Zend_Config) {
$child = $xml->addChild($key);
$this->_addBranch($value, $child, $xml);
} else {
$xml->addChild($key, (string) $value);
}
}
}
}
}

View File

@ -1,141 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config_Writer
*/
/**
* @see Zend_Config_Yaml
*/
/**
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Writer_Yaml extends Zend_Config_Writer_FileAbstract
{
/**
* What to call when we need to decode some YAML?
*
* @var callable
*/
protected $_yamlEncoder = array('Zend_Config_Writer_Yaml', 'encode');
/**
* Get callback for decoding YAML
*
* @return callable
*/
public function getYamlEncoder()
{
return $this->_yamlEncoder;
}
/**
* Set callback for decoding YAML
*
* @param callable $yamlEncoder the decoder to set
* @return Zend_Config_Yaml
*/
public function setYamlEncoder($yamlEncoder)
{
if (!is_callable($yamlEncoder)) {
throw new Zend_Config_Exception('Invalid parameter to setYamlEncoder - must be callable');
}
$this->_yamlEncoder = $yamlEncoder;
return $this;
}
/**
* Render a Zend_Config into a YAML config string.
*
* @since 1.10
* @return string
*/
public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parentSection) {
$data[$section][Zend_Config_Yaml::EXTENDS_NAME] = $parentSection;
}
// Ensure that each "extends" section actually exists
foreach ($data as $section => $sectionData) {
if (is_array($sectionData) && isset($sectionData[Zend_Config_Yaml::EXTENDS_NAME])) {
$sectionExtends = $sectionData[Zend_Config_Yaml::EXTENDS_NAME];
if (!isset($data[$sectionExtends])) {
// Remove "extends" declaration if section does not exist
unset($data[$section][Zend_Config_Yaml::EXTENDS_NAME]);
}
}
}
return call_user_func($this->getYamlEncoder(), $data);
}
/**
* Very dumb YAML encoder
*
* Until we have Zend_Yaml...
*
* @param array $data YAML data
* @return string
*/
public static function encode($data)
{
return self::_encodeYaml(0, $data);
}
/**
* Service function for encoding YAML
*
* @param int $indent Current indent level
* @param array $data Data to encode
* @return string
*/
protected static function _encodeYaml($indent, $data)
{
reset($data);
$result = "";
$numeric = is_numeric(key($data));
foreach($data as $key => $value) {
if(is_array($value)) {
$encoded = "\n".self::_encodeYaml($indent+1, $value);
} else {
$encoded = (string)$value."\n";
}
$result .= str_repeat(" ", $indent).($numeric?"- ":"$key: ").$encoded;
}
return $result;
}
}

View File

@ -1,300 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config
*/
/** @see Zend_Xml_Security */
/** @see Zend_Xml_Exception */
/**
* XML Adapter for Zend_Config
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Xml extends Zend_Config
{
/**
* XML namespace for ZF-related tags and attributes
*/
const XML_NAMESPACE = 'http://framework.zend.com/xml/zend-config-xml/1.0/';
/**
* Whether to skip extends or not
*
* @var boolean
*/
protected $_skipExtends = false;
/**
* Loads the section $section from the config file (or string $xml for
* access facilitated by nested object properties.
*
* Sections are defined in the XML as children of the root element.
*
* In order to extend another section, a section defines the "extends"
* attribute having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "extends".
*
* The $options parameter may be provided as either a boolean or an array.
* If provided as a boolean, this sets the $allowModifications option of
* Zend_Config. If provided as an array, there are two configuration
* directives that may be set. For example:
*
* $options = array(
* 'allowModifications' => false,
* 'skipExtends' => false
* );
*
* @param string $xml XML file or string to process
* @param mixed $section Section to process
* @param array|boolean $options
* @throws Zend_Config_Exception When xml is not set or cannot be loaded
* @throws Zend_Config_Exception When section $sectionName cannot be found in $xml
*/
public function __construct($xml, $section = null, $options = false)
{
if (empty($xml)) {
throw new Zend_Config_Exception('Filename is not set');
}
$allowModifications = false;
if (is_bool($options)) {
$allowModifications = $options;
} elseif (is_array($options)) {
if (isset($options['allowModifications'])) {
$allowModifications = (bool) $options['allowModifications'];
}
if (isset($options['skipExtends'])) {
$this->_skipExtends = (bool) $options['skipExtends'];
}
}
set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed
if (strstr($xml, '<?xml')) {
$config = Zend_Xml_Security::scan($xml);
} else {
try {
if (!$config = Zend_Xml_Security::scanFile($xml)) {
throw new Zend_Config_Exception(
"Error failed to load $xml file"
);
}
} catch (Zend_Xml_Exception $e) {
throw new Zend_Config_Exception(
$e->getMessage()
);
}
}
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
if ($section === null) {
$dataArray = array();
foreach ($config as $sectionName => $sectionData) {
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
}
parent::__construct($dataArray, $allowModifications);
} else if (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($config->$sectionName)) {
throw new Zend_Config_Exception("Section '$sectionName' cannot be found in $xml");
}
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($config->$section)) {
throw new Zend_Config_Exception("Section '$section' cannot be found in $xml");
}
$dataArray = $this->_processExtends($config, $section);
if (!is_array($dataArray)) {
// Section in the XML file contains just one top level string
$dataArray = array($section => $dataArray);
}
parent::__construct($dataArray, $allowModifications);
}
$this->_loadedSection = $section;
}
/**
* Helper function to process each element in the section and handle
* the "extends" inheritance attribute.
*
* @param SimpleXMLElement $element XML Element to process
* @param string $section Section to process
* @param array $config Configuration which was parsed yet
* @throws Zend_Config_Exception When $section cannot be found
* @return array
*/
protected function _processExtends(SimpleXMLElement $element, $section, array $config = array())
{
if (!isset($element->$section)) {
throw new Zend_Config_Exception("Section '$section' cannot be found");
}
$thisSection = $element->$section;
$nsAttributes = $thisSection->attributes(self::XML_NAMESPACE);
if (isset($thisSection['extends']) || isset($nsAttributes['extends'])) {
$extendedSection = (string) (isset($nsAttributes['extends']) ? $nsAttributes['extends'] : $thisSection['extends']);
$this->_assertValidExtend($section, $extendedSection);
if (!$this->_skipExtends) {
$config = $this->_processExtends($element, $extendedSection, $config);
}
}
$config = $this->_arrayMergeRecursive($config, $this->_toArray($thisSection));
return $config;
}
/**
* Returns a string or an associative and possibly multidimensional array from
* a SimpleXMLElement.
*
* @param SimpleXMLElement $xmlObject Convert a SimpleXMLElement into an array
* @return array|string
*/
protected function _toArray(SimpleXMLElement $xmlObject)
{
$config = array();
$nsAttributes = $xmlObject->attributes(self::XML_NAMESPACE);
// Search for parent node values
if (count($xmlObject->attributes()) > 0) {
foreach ($xmlObject->attributes() as $key => $value) {
if ($key === 'extends') {
continue;
}
$value = (string) $value;
if (array_key_exists($key, $config)) {
if (!is_array($config[$key])) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
}
}
// Search for local 'const' nodes and replace them
if (count($xmlObject->children(self::XML_NAMESPACE)) > 0) {
if (count($xmlObject->children()) > 0) {
throw new Zend_Config_Exception("A node with a 'const' childnode may not have any other children");
}
$dom = dom_import_simplexml($xmlObject);
$namespaceChildNodes = array();
// We have to store them in an array, as replacing nodes will
// confuse the DOMNodeList later
foreach ($dom->childNodes as $node) {
if ($node instanceof DOMElement && $node->namespaceURI === self::XML_NAMESPACE) {
$namespaceChildNodes[] = $node;
}
}
foreach ($namespaceChildNodes as $node) {
switch ($node->localName) {
case 'const':
if (!$node->hasAttributeNS(self::XML_NAMESPACE, 'name')) {
throw new Zend_Config_Exception("Misssing 'name' attribute in 'const' node");
}
$constantName = $node->getAttributeNS(self::XML_NAMESPACE, 'name');
if (!defined($constantName)) {
throw new Zend_Config_Exception("Constant with name '$constantName' was not defined");
}
$constantValue = constant($constantName);
$dom->replaceChild($dom->ownerDocument->createTextNode($constantValue), $node);
break;
default:
throw new Zend_Config_Exception("Unknown node with name '$node->localName' found");
}
}
return (string) simplexml_import_dom($dom);
}
// Search for children
if (count($xmlObject->children()) > 0) {
foreach ($xmlObject->children() as $key => $value) {
if (count($value->children()) > 0 || count($value->children(self::XML_NAMESPACE)) > 0) {
$value = $this->_toArray($value);
} else if (count($value->attributes()) > 0) {
$attributes = $value->attributes();
if (isset($attributes['value'])) {
$value = (string) $attributes['value'];
} else {
$value = $this->_toArray($value);
}
} else {
$value = (string) $value;
}
if (array_key_exists($key, $config)) {
if (!is_array($config[$key]) || !array_key_exists(0, $config[$key])) {
$config[$key] = array($config[$key]);
}
$config[$key][] = $value;
} else {
$config[$key] = $value;
}
}
} else if (!isset($xmlObject['extends']) && !isset($nsAttributes['extends']) && (count($config) === 0)) {
// Object has no children nor attributes and doesn't use the extends
// attribute: it's a string
$config = (string) $xmlObject;
}
return $config;
}
}

View File

@ -1,406 +0,0 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Config
*/
/**
* YAML Adapter for Zend_Config
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Config_Yaml extends Zend_Config
{
/**
* Attribute name that indicates what section a config extends from
*/
const EXTENDS_NAME = "_extends";
/**
* Whether to skip extends or not
*
* @var boolean
*/
protected $_skipExtends = false;
/**
* What to call when we need to decode some YAML?
*
* @var callable
*/
protected $_yamlDecoder = array(__CLASS__, 'decode');
/**
* Whether or not to ignore constants in parsed YAML
* @var bool
*/
protected static $_ignoreConstants = false;
/**
* Indicate whether parser should ignore constants or not
*
* @param bool $flag
* @return void
*/
public static function setIgnoreConstants($flag)
{
self::$_ignoreConstants = (bool) $flag;
}
/**
* Whether parser should ignore constants or not
*
* @return bool
*/
public static function ignoreConstants()
{
return self::$_ignoreConstants;
}
/**
* Get callback for decoding YAML
*
* @return callable
*/
public function getYamlDecoder()
{
return $this->_yamlDecoder;
}
/**
* Set callback for decoding YAML
*
* @param callable $yamlDecoder the decoder to set
* @return Zend_Config_Yaml
*/
public function setYamlDecoder($yamlDecoder)
{
if (!is_callable($yamlDecoder)) {
throw new Zend_Config_Exception('Invalid parameter to setYamlDecoder() - must be callable');
}
$this->_yamlDecoder = $yamlDecoder;
return $this;
}
/**
* Loads the section $section from the config file encoded as YAML
*
* Sections are defined as properties of the main object
*
* In order to extend another section, a section defines the "_extends"
* property having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "_extends".
*
* Options may include:
* - allow_modifications: whether or not the config object is mutable
* - skip_extends: whether or not to skip processing of parent configuration
* - yaml_decoder: a callback to use to decode the Yaml source
*
* @param string $yaml YAML file to process
* @param mixed $section Section to process
* @param array|boolean $options
*/
public function __construct($yaml, $section = null, $options = false)
{
if (empty($yaml)) {
throw new Zend_Config_Exception('Filename is not set');
}
$ignoreConstants = $staticIgnoreConstants = self::ignoreConstants();
$allowModifications = false;
if (is_bool($options)) {
$allowModifications = $options;
} elseif (is_array($options)) {
foreach ($options as $key => $value) {
switch (strtolower($key)) {
case 'allow_modifications':
case 'allowmodifications':
$allowModifications = (bool) $value;
break;
case 'skip_extends':
case 'skipextends':
$this->_skipExtends = (bool) $value;
break;
case 'ignore_constants':
case 'ignoreconstants':
$ignoreConstants = (bool) $value;
break;
case 'yaml_decoder':
case 'yamldecoder':
$this->setYamlDecoder($value);
break;
default:
break;
}
}
}
// Suppress warnings and errors while loading file
set_error_handler(array($this, '_loadFileErrorHandler'));
$yaml = file_get_contents($yaml);
restore_error_handler();
// Check if there was a error while loading file
if ($this->_loadFileErrorStr !== null) {
throw new Zend_Config_Exception($this->_loadFileErrorStr);
}
// Override static value for ignore_constants if provided in $options
self::setIgnoreConstants($ignoreConstants);
// Parse YAML
$config = call_user_func($this->getYamlDecoder(), $yaml);
// Reset original static state of ignore_constants
self::setIgnoreConstants($staticIgnoreConstants);
if (null === $config) {
// decode failed
throw new Zend_Config_Exception("Error parsing YAML data");
}
if (null === $section) {
$dataArray = array();
foreach ($config as $sectionName => $sectionData) {
$dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
}
parent::__construct($dataArray, $allowModifications);
} elseif (is_array($section)) {
$dataArray = array();
foreach ($section as $sectionName) {
if (!isset($config[$sectionName])) {
throw new Zend_Config_Exception(sprintf(
'Section "%s" cannot be found',
implode(' ', (array)$section)
));
}
$dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
}
parent::__construct($dataArray, $allowModifications);
} else {
if (!isset($config[$section])) {
throw new Zend_Config_Exception(sprintf(
'Section "%s" cannot be found',
implode(' ', (array)$section)
));
}
$dataArray = $this->_processExtends($config, $section);
if (!is_array($dataArray)) {
// Section in the yaml data contains just one top level string
$dataArray = array($section => $dataArray);
}
parent::__construct($dataArray, $allowModifications);
}
$this->_loadedSection = $section;
}
/**
* Helper function to process each element in the section and handle
* the "_extends" inheritance attribute.
*
* @param array $data Data array to process
* @param string $section Section to process
* @param array $config Configuration which was parsed yet
* @return array
* @throws Zend_Config_Exception When $section cannot be found
*/
protected function _processExtends(array $data, $section, array $config = array())
{
if (!isset($data[$section])) {
throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section));
}
$thisSection = $data[$section];
if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) {
$this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]);
if (!$this->_skipExtends) {
$config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config);
}
unset($thisSection[self::EXTENDS_NAME]);
}
$config = $this->_arrayMergeRecursive($config, $thisSection);
return $config;
}
/**
* Very dumb YAML parser
*
* Until we have Zend_Yaml...
*
* @param string $yaml YAML source
* @return array Decoded data
*/
public static function decode($yaml)
{
$lines = explode("\n", $yaml);
reset($lines);
return self::_decodeYaml(0, $lines);
}
/**
* Service function to decode YAML
*
* @param int $currentIndent Current indent level
* @param array $lines YAML lines
* @return array|string
*/
protected static function _decodeYaml($currentIndent, &$lines)
{
$config = array();
$inIndent = false;
while (list($n, $line) = each($lines)) {
$lineno = $n + 1;
$line = rtrim(preg_replace("/#.*$/", "", $line));
if (strlen($line) == 0) {
continue;
}
$indent = strspn($line, " ");
// line without the spaces
$line = trim($line);
if (strlen($line) == 0) {
continue;
}
if ($indent < $currentIndent) {
// this level is done
prev($lines);
return $config;
}
if (!$inIndent) {
$currentIndent = $indent;
$inIndent = true;
}
if (preg_match("/(?!-)([\w\-]+):\s*(.*)/", $line, $m)) {
// key: value
if (strlen($m[2])) {
// simple key: value
$value = preg_replace("/#.*$/", "", $m[2]);
$value = self::_parseValue($value);
} else {
// key: and then values on new lines
$value = self::_decodeYaml($currentIndent + 1, $lines);
if (is_array($value) && !count($value)) {
$value = "";
}
}
$config[$m[1]] = $value;
} elseif ($line[0] == "-") {
// item in the list:
// - FOO
if (strlen($line) > 2) {
$value = substr($line, 2);
$config[] = self::_parseValue($value);
} else {
$config[] = self::_decodeYaml($currentIndent + 1, $lines);
}
} else {
throw new Zend_Config_Exception(sprintf(
'Error parsing YAML at line %d - unsupported syntax: "%s"',
$lineno, $line
));
}
}
return $config;
}
/**
* Parse values
*
* @param string $value
* @return string
*/
protected static function _parseValue($value)
{
$value = trim($value);
// remove quotes from string.
if ('"' == $value['0']) {
if ('"' == $value[count($value) -1]) {
$value = substr($value, 1, -1);
}
} elseif ('\'' == $value['0'] && '\'' == $value[count($value) -1]) {
$value = strtr($value, array("''" => "'", "'" => ''));
}
// Check for booleans and constants
if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
$value = true;
} elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) {
$value = false;
} elseif (strcasecmp($value, 'null') === 0) {
$value = null;
} elseif (!self::$_ignoreConstants) {
// test for constants
$value = self::_replaceConstants($value);
}
return $value;
}
/**
* Replace any constants referenced in a string with their values
*
* @param string $value
* @return string
*/
protected static function _replaceConstants($value)
{
foreach (self::_getConstants() as $constant) {
if (strstr($value, $constant)) {
$value = str_replace($constant, constant($constant), $value);
}
}
return $value;
}
/**
* Get (reverse) sorted list of defined constant names
*
* @return array
*/
protected static function _getConstants()
{
$constants = array_keys(get_defined_constants());
rsort($constants, SORT_STRING);
return $constants;
}
}

View File

@ -1,979 +0,0 @@
<?php
/**
* Zend_Console_Getopt is a class to parse options for command-line
* applications.
*
* 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_Console_Getopt
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* Zend_Console_Getopt is a class to parse options for command-line
* applications.
*
* Terminology:
* Argument: an element of the argv array. This may be part of an option,
* or it may be a non-option command-line argument.
* Flag: the letter or word set off by a '-' or '--'. Example: in '--output filename',
* '--output' is the flag.
* Parameter: the additional argument that is associated with the option.
* Example: in '--output filename', the 'filename' is the parameter.
* Option: the combination of a flag and its parameter, if any.
* Example: in '--output filename', the whole thing is the option.
*
* The following features are supported:
*
* - Short flags like '-a'. Short flags are preceded by a single
* dash. Short flags may be clustered e.g. '-abc', which is the
* same as '-a' '-b' '-c'.
* - Long flags like '--verbose'. Long flags are preceded by a
* double dash. Long flags may not be clustered.
* - Options may have a parameter, e.g. '--output filename'.
* - Parameters for long flags may also be set off with an equals sign,
* e.g. '--output=filename'.
* - Parameters for long flags may be checked as string, word, or integer.
* - Automatic generation of a helpful usage message.
* - Signal end of options with '--'; subsequent arguments are treated
* as non-option arguments, even if they begin with '-'.
* - Raise exception Zend_Console_Getopt_Exception in several cases
* when invalid flags or parameters are given. Usage message is
* returned in the exception object.
*
* The format for specifying options uses a PHP associative array.
* The key is has the format of a list of pipe-separated flag names,
* followed by an optional '=' to indicate a required parameter or
* '-' to indicate an optional parameter. Following that, the type
* of parameter may be specified as 's' for string, 'w' for word,
* or 'i' for integer.
*
* Examples:
* - 'user|username|u=s' this means '--user' or '--username' or '-u'
* are synonyms, and the option requires a string parameter.
* - 'p=i' this means '-p' requires an integer parameter. No synonyms.
* - 'verbose|v-i' this means '--verbose' or '-v' are synonyms, and
* they take an optional integer parameter.
* - 'help|h' this means '--help' or '-h' are synonyms, and
* they take no parameter.
*
* The values in the associative array are strings that are used as
* brief descriptions of the options when printing a usage message.
*
* The simpler format for specifying options used by PHP's getopt()
* function is also supported. This is similar to GNU getopt and shell
* getopt format.
*
* Example: 'abc:' means options '-a', '-b', and '-c'
* are legal, and the latter requires a string parameter.
*
* @category Zend
* @package Zend_Console_Getopt
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version Release: @package_version@
* @since Class available since Release 0.6.0
*
* @todo Handle params with multiple values, e.g. --colors=red,green,blue
* Set value of parameter to the array of values. Allow user to specify
* the separator with Zend_Console_Getopt::CONFIG_PARAMETER_SEPARATOR.
* If this config value is null or empty string, do not split values
* into arrays. Default separator is comma (',').
*
* @todo Handle params with multiple values specified with separate options
* e.g. --colors red --colors green --colors blue should give one
* option with an array(red, green, blue).
* Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_PARAMETERS.
* Default is that subsequent options overwrite the parameter value.
*
* @todo Handle flags occurring multiple times, e.g. -v -v -v
* Set value of the option's parameter to the integer count of instances
* instead of a boolean.
* Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_FLAGS.
* Default is that the value is simply boolean true regardless of
* how many instances of the flag appear.
*
* @todo Handle flags that implicitly print usage message, e.g. --help
*
* @todo Handle freeform options, e.g. --set-variable
* Enable with Zend_Console_Getopt::CONFIG_FREEFORM_FLAGS
* All flag-like syntax is recognized, no flag generates an exception.
*
* @todo Handle numeric options, e.g. -1, -2, -3, -1000
* Enable with Zend_Console_Getopt::CONFIG_NUMERIC_FLAGS
* The rule must specify a named flag and the '#' symbol as the
* parameter type. e.g., 'lines=#'
*
* @todo Enable user to specify header and footer content in the help message.
*
* @todo Feature request to handle option interdependencies.
* e.g. if -b is specified, -a must be specified or else the
* usage is invalid.
*
* @todo Feature request to implement callbacks.
* e.g. if -a is specified, run function 'handleOptionA'().
*/
class Zend_Console_Getopt
{
/**
* The options for a given application can be in multiple formats.
* modeGnu is for traditional 'ab:c:' style getopt format.
* modeZend is for a more structured format.
*/
const MODE_ZEND = 'zend';
const MODE_GNU = 'gnu';
/**
* Constant tokens for various symbols used in the mode_zend
* rule format.
*/
const PARAM_REQUIRED = '=';
const PARAM_OPTIONAL = '-';
const TYPE_STRING = 's';
const TYPE_WORD = 'w';
const TYPE_INTEGER = 'i';
/**
* These are constants for optional behavior of this class.
* ruleMode is either 'zend' or 'gnu' or a user-defined mode.
* dashDash is true if '--' signifies the end of command-line options.
* ignoreCase is true if '--opt' and '--OPT' are implicitly synonyms.
* parseAll is true if all options on the command line should be parsed, regardless of
* whether an argument appears before them.
*/
const CONFIG_RULEMODE = 'ruleMode';
const CONFIG_DASHDASH = 'dashDash';
const CONFIG_IGNORECASE = 'ignoreCase';
const CONFIG_PARSEALL = 'parseAll';
/**
* Defaults for getopt configuration are:
* ruleMode is 'zend' format,
* dashDash (--) token is enabled,
* ignoreCase is not enabled,
* parseAll is enabled.
*/
protected $_getoptConfig = array(
self::CONFIG_RULEMODE => self::MODE_ZEND,
self::CONFIG_DASHDASH => true,
self::CONFIG_IGNORECASE => false,
self::CONFIG_PARSEALL => true,
);
/**
* Stores the command-line arguments for the calling applicaion.
*
* @var array
*/
protected $_argv = array();
/**
* Stores the name of the calling applicaion.
*
* @var string
*/
protected $_progname = '';
/**
* Stores the list of legal options for this application.
*
* @var array
*/
protected $_rules = array();
/**
* Stores alternate spellings of legal options.
*
* @var array
*/
protected $_ruleMap = array();
/**
* Stores options given by the user in the current invocation
* of the application, as well as parameters given in options.
*
* @var array
*/
protected $_options = array();
/**
* Stores the command-line arguments other than options.
*
* @var array
*/
protected $_remainingArgs = array();
/**
* State of the options: parsed or not yet parsed?
*
* @var boolean
*/
protected $_parsed = false;
/**
* The constructor takes one to three parameters.
*
* The first parameter is $rules, which may be a string for
* gnu-style format, or a structured array for Zend-style format.
*
* The second parameter is $argv, and it is optional. If not
* specified, $argv is inferred from the global argv.
*
* The third parameter is an array of configuration parameters
* to control the behavior of this instance of Getopt; it is optional.
*
* @param array $rules
* @param array $argv
* @param array $getoptConfig
* @return void
*/
public function __construct($rules, $argv = null, $getoptConfig = array())
{
if (!isset($_SERVER['argv'])) {
if (ini_get('register_argc_argv') == false) {
throw new Zend_Console_Getopt_Exception(
"argv is not available, because ini option 'register_argc_argv' is set Off"
);
} else {
throw new Zend_Console_Getopt_Exception(
'$_SERVER["argv"] is not set, but Zend_Console_Getopt cannot work without this information.'
);
}
}
$this->_progname = $_SERVER['argv'][0];
$this->setOptions($getoptConfig);
$this->addRules($rules);
if (!is_array($argv)) {
$argv = array_slice($_SERVER['argv'], 1);
}
if (isset($argv)) {
$this->addArguments((array)$argv);
}
}
/**
* Return the state of the option seen on the command line of the
* current application invocation. This function returns true, or the
* parameter to the option, if any. If the option was not given,
* this function returns null.
*
* The magic __get method works in the context of naming the option
* as a virtual member of this class.
*
* @param string $key
* @return string
*/
public function __get($key)
{
return $this->getOption($key);
}
/**
* Test whether a given option has been seen.
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
return isset($this->_options[$key]);
}
return false;
}
/**
* Set the value for a given option.
*
* @param string $key
* @param string $value
* @return void
*/
public function __set($key, $value)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
$this->_options[$key] = $value;
}
}
/**
* Return the current set of options and parameters seen as a string.
*
* @return string
*/
public function __toString()
{
return $this->toString();
}
/**
* Unset an option.
*
* @param string $key
* @return void
*/
public function __unset($key)
{
$this->parse();
if (isset($this->_ruleMap[$key])) {
$key = $this->_ruleMap[$key];
unset($this->_options[$key]);
}
}
/**
* Define additional command-line arguments.
* These are appended to those defined when the constructor was called.
*
* @param array $argv
* @throws Zend_Console_Getopt_Exception When not given an array as parameter
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function addArguments($argv)
{
if(!is_array($argv)) {
throw new Zend_Console_Getopt_Exception(
"Parameter #1 to addArguments should be an array");
}
$this->_argv = array_merge($this->_argv, $argv);
$this->_parsed = false;
return $this;
}
/**
* Define full set of command-line arguments.
* These replace any currently defined.
*
* @param array $argv
* @throws Zend_Console_Getopt_Exception When not given an array as parameter
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setArguments($argv)
{
if(!is_array($argv)) {
throw new Zend_Console_Getopt_Exception(
"Parameter #1 to setArguments should be an array");
}
$this->_argv = $argv;
$this->_parsed = false;
return $this;
}
/**
* Define multiple configuration options from an associative array.
* These are not program options, but properties to configure
* the behavior of Zend_Console_Getopt.
*
* @param array $getoptConfig
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setOptions($getoptConfig)
{
if (isset($getoptConfig)) {
foreach ($getoptConfig as $key => $value) {
$this->setOption($key, $value);
}
}
return $this;
}
/**
* Define one configuration option as a key/value pair.
* These are not program options, but properties to configure
* the behavior of Zend_Console_Getopt.
*
* @param string $configKey
* @param string $configValue
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setOption($configKey, $configValue)
{
if ($configKey !== null) {
$this->_getoptConfig[$configKey] = $configValue;
}
return $this;
}
/**
* Define additional option rules.
* These are appended to the rules defined when the constructor was called.
*
* @param array $rules
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function addRules($rules)
{
$ruleMode = $this->_getoptConfig['ruleMode'];
switch ($this->_getoptConfig['ruleMode']) {
case self::MODE_ZEND:
if (is_array($rules)) {
$this->_addRulesModeZend($rules);
break;
}
// intentional fallthrough
case self::MODE_GNU:
$this->_addRulesModeGnu($rules);
break;
default:
/**
* Call addRulesModeFoo() for ruleMode 'foo'.
* The developer should subclass Getopt and
* provide this method.
*/
$method = '_addRulesMode' . ucfirst($ruleMode);
$this->$method($rules);
}
$this->_parsed = false;
return $this;
}
/**
* Return the current set of options and parameters seen as a string.
*
* @return string
*/
public function toString()
{
$this->parse();
$s = array();
foreach ($this->_options as $flag => $value) {
$s[] = $flag . '=' . ($value === true ? 'true' : $value);
}
return implode(' ', $s);
}
/**
* Return the current set of options and parameters seen
* as an array of canonical options and parameters.
*
* Clusters have been expanded, and option aliases
* have been mapped to their primary option names.
*
* @return array
*/
public function toArray()
{
$this->parse();
$s = array();
foreach ($this->_options as $flag => $value) {
$s[] = $flag;
if ($value !== true) {
$s[] = $value;
}
}
return $s;
}
/**
* Return the current set of options and parameters seen in Json format.
*
* @return string
*/
public function toJson()
{
$this->parse();
$j = array();
foreach ($this->_options as $flag => $value) {
$j['options'][] = array(
'option' => array(
'flag' => $flag,
'parameter' => $value
)
);
}
/**
* @see Zend_Json
*/
$json = Zend_Json::encode($j);
return $json;
}
/**
* Return the current set of options and parameters seen in XML format.
*
* @return string
*/
public function toXml()
{
$this->parse();
$doc = new DomDocument('1.0', 'utf-8');
$optionsNode = $doc->createElement('options');
$doc->appendChild($optionsNode);
foreach ($this->_options as $flag => $value) {
$optionNode = $doc->createElement('option');
$optionNode->setAttribute('flag', utf8_encode($flag));
if ($value !== true) {
$optionNode->setAttribute('parameter', utf8_encode($value));
}
$optionsNode->appendChild($optionNode);
}
$xml = $doc->saveXML();
return $xml;
}
/**
* Return a list of options that have been seen in the current argv.
*
* @return array
*/
public function getOptions()
{
$this->parse();
return array_keys($this->_options);
}
/**
* Return the state of the option seen on the command line of the
* current application invocation.
*
* This function returns true, or the parameter value to the option, if any.
* If the option was not given, this function returns false.
*
* @param string $flag
* @return mixed
*/
public function getOption($flag)
{
$this->parse();
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
if (isset($this->_ruleMap[$flag])) {
$flag = $this->_ruleMap[$flag];
if (isset($this->_options[$flag])) {
return $this->_options[$flag];
}
}
return null;
}
/**
* Return the arguments from the command-line following all options found.
*
* @return array
*/
public function getRemainingArgs()
{
$this->parse();
return $this->_remainingArgs;
}
/**
* Return a useful option reference, formatted for display in an
* error message.
*
* Note that this usage information is provided in most Exceptions
* generated by this class.
*
* @return string
*/
public function getUsageMessage()
{
$usage = "Usage: {$this->_progname} [ options ]\n";
$maxLen = 20;
$lines = array();
foreach ($this->_rules as $rule) {
$flags = array();
if (is_array($rule['alias'])) {
foreach ($rule['alias'] as $flag) {
$flags[] = (strlen($flag) == 1 ? '-' : '--') . $flag;
}
}
$linepart['name'] = implode('|', $flags);
if (isset($rule['param']) && $rule['param'] != 'none') {
$linepart['name'] .= ' ';
switch ($rule['param']) {
case 'optional':
$linepart['name'] .= "[ <{$rule['paramType']}> ]";
break;
case 'required':
$linepart['name'] .= "<{$rule['paramType']}>";
break;
}
}
if (strlen($linepart['name']) > $maxLen) {
$maxLen = strlen($linepart['name']);
}
$linepart['help'] = '';
if (isset($rule['help'])) {
$linepart['help'] .= $rule['help'];
}
$lines[] = $linepart;
}
foreach ($lines as $linepart) {
$usage .= sprintf("%s %s\n",
str_pad($linepart['name'], $maxLen),
$linepart['help']);
}
return $usage;
}
/**
* Define aliases for options.
*
* The parameter $aliasMap is an associative array
* mapping option name (short or long) to an alias.
*
* @param array $aliasMap
* @throws Zend_Console_Getopt_Exception
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setAliases($aliasMap)
{
foreach ($aliasMap as $flag => $alias)
{
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
$alias = strtolower($alias);
}
if (!isset($this->_ruleMap[$flag])) {
continue;
}
$flag = $this->_ruleMap[$flag];
if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) {
$o = (strlen($alias) == 1 ? '-' : '--') . $alias;
throw new Zend_Console_Getopt_Exception(
"Option \"$o\" is being defined more than once.");
}
$this->_rules[$flag]['alias'][] = $alias;
$this->_ruleMap[$alias] = $flag;
}
return $this;
}
/**
* Define help messages for options.
*
* The parameter $help_map is an associative array
* mapping option name (short or long) to the help string.
*
* @param array $helpMap
* @return Zend_Console_Getopt Provides a fluent interface
*/
public function setHelp($helpMap)
{
foreach ($helpMap as $flag => $help)
{
if (!isset($this->_ruleMap[$flag])) {
continue;
}
$flag = $this->_ruleMap[$flag];
$this->_rules[$flag]['help'] = $help;
}
return $this;
}
/**
* Parse command-line arguments and find both long and short
* options.
*
* Also find option parameters, and remaining arguments after
* all options have been parsed.
*
* @return Zend_Console_Getopt|null Provides a fluent interface
*/
public function parse()
{
if ($this->_parsed === true) {
return;
}
$argv = $this->_argv;
$this->_options = array();
$this->_remainingArgs = array();
while (count($argv) > 0) {
if ($argv[0] == '--') {
array_shift($argv);
if ($this->_getoptConfig[self::CONFIG_DASHDASH]) {
$this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
break;
}
}
if (substr($argv[0], 0, 2) == '--') {
$this->_parseLongOption($argv);
} else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) {
$this->_parseShortOptionCluster($argv);
} else if($this->_getoptConfig[self::CONFIG_PARSEALL]) {
$this->_remainingArgs[] = array_shift($argv);
} else {
/*
* We should put all other arguments in _remainingArgs and stop parsing
* since CONFIG_PARSEALL is false.
*/
$this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
break;
}
}
$this->_parsed = true;
return $this;
}
/**
* @throws Zend_Console_Getopt_Exception
*/
public function checkRequiredArguments()
{
foreach ($this->_rules as $name => $rule) {
if ($rule['param'] === 'required') {
$defined = false;
foreach ($rule['alias'] as $alias) {
$defined = $defined === true ? true : array_key_exists($alias, $this->_options);
}
if ($defined === false) {
throw new Zend_Console_Getopt_Exception(
'Option "$alias" requires a parameter.',
$this->getUsageMessage()
);
}
}
}
}
/**
* Parse command-line arguments for a single long option.
* A long option is preceded by a double '--' character.
* Long options may not be clustered.
*
* @param mixed &$argv
* @return void
*/
protected function _parseLongOption(&$argv)
{
$optionWithParam = ltrim(array_shift($argv), '-');
$l = explode('=', $optionWithParam, 2);
$flag = array_shift($l);
$param = array_shift($l);
if (isset($param)) {
array_unshift($argv, $param);
}
$this->_parseSingleOption($flag, $argv);
}
/**
* Parse command-line arguments for short options.
* Short options are those preceded by a single '-' character.
* Short options may be clustered.
*
* @param mixed &$argv
* @return void
*/
protected function _parseShortOptionCluster(&$argv)
{
$flagCluster = ltrim(array_shift($argv), '-');
foreach (str_split($flagCluster) as $flag) {
$this->_parseSingleOption($flag, $argv);
}
}
/**
* Parse command-line arguments for a single option.
*
* @param string $flag
* @param mixed $argv
* @throws Zend_Console_Getopt_Exception
* @return void
*/
protected function _parseSingleOption($flag, &$argv)
{
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
if (!isset($this->_ruleMap[$flag])) {
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" is not recognized.",
$this->getUsageMessage());
}
$realFlag = $this->_ruleMap[$flag];
switch ($this->_rules[$realFlag]['param']) {
case 'required':
if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
$param = array_shift($argv);
$this->_checkParameterType($realFlag, $param);
} else {
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires a parameter.",
$this->getUsageMessage());
}
break;
case 'optional':
if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
$param = array_shift($argv);
$this->_checkParameterType($realFlag, $param);
} else {
$param = true;
}
break;
default:
$param = true;
}
$this->_options[$realFlag] = $param;
}
/**
* Return true if the parameter is in a valid format for
* the option $flag.
* Throw an exception in most other cases.
*
* @param string $flag
* @param string $param
* @throws Zend_Console_Getopt_Exception
* @return bool
*/
protected function _checkParameterType($flag, $param)
{
$type = 'string';
if (isset($this->_rules[$flag]['paramType'])) {
$type = $this->_rules[$flag]['paramType'];
}
switch ($type) {
case 'word':
if (preg_match('/\W/', $param)) {
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires a single-word parameter, but was given \"$param\".",
$this->getUsageMessage());
}
break;
case 'integer':
if (preg_match('/\D/', $param)) {
throw new Zend_Console_Getopt_Exception(
"Option \"$flag\" requires an integer parameter, but was given \"$param\".",
$this->getUsageMessage());
}
break;
case 'string':
default:
break;
}
return true;
}
/**
* Define legal options using the gnu-style format.
*
* @param string $rules
* @return void
*/
protected function _addRulesModeGnu($rules)
{
$ruleArray = array();
/**
* Options may be single alphanumeric characters.
* Options may have a ':' which indicates a required string parameter.
* No long options or option aliases are supported in GNU style.
*/
preg_match_all('/([a-zA-Z0-9]:?)/', $rules, $ruleArray);
foreach ($ruleArray[1] as $rule) {
$r = array();
$flag = substr($rule, 0, 1);
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flag = strtolower($flag);
}
$r['alias'][] = $flag;
if (substr($rule, 1, 1) == ':') {
$r['param'] = 'required';
$r['paramType'] = 'string';
} else {
$r['param'] = 'none';
}
$this->_rules[$flag] = $r;
$this->_ruleMap[$flag] = $flag;
}
}
/**
* Define legal options using the Zend-style format.
*
* @param array $rules
* @throws Zend_Console_Getopt_Exception
* @return void
*/
protected function _addRulesModeZend($rules)
{
foreach ($rules as $ruleCode => $helpMessage)
{
// this may have to translate the long parm type if there
// are any complaints that =string will not work (even though that use
// case is not documented)
if (in_array(substr($ruleCode, -2, 1), array('-', '='))) {
$flagList = substr($ruleCode, 0, -2);
$delimiter = substr($ruleCode, -2, 1);
$paramType = substr($ruleCode, -1);
} else {
$flagList = $ruleCode;
$delimiter = $paramType = null;
}
if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
$flagList = strtolower($flagList);
}
$flags = explode('|', $flagList);
$rule = array();
$mainFlag = $flags[0];
foreach ($flags as $flag) {
if (empty($flag)) {
throw new Zend_Console_Getopt_Exception(
"Blank flag not allowed in rule \"$ruleCode\".");
}
if (strlen($flag) == 1) {
if (isset($this->_ruleMap[$flag])) {
throw new Zend_Console_Getopt_Exception(
"Option \"-$flag\" is being defined more than once.");
}
$this->_ruleMap[$flag] = $mainFlag;
$rule['alias'][] = $flag;
} else {
if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) {
throw new Zend_Console_Getopt_Exception(
"Option \"--$flag\" is being defined more than once.");
}
$this->_ruleMap[$flag] = $mainFlag;
$rule['alias'][] = $flag;
}
}
if (isset($delimiter)) {
switch ($delimiter) {
case self::PARAM_REQUIRED:
$rule['param'] = 'required';
break;
case self::PARAM_OPTIONAL:
default:
$rule['param'] = 'optional';
}
switch (substr($paramType, 0, 1)) {
case self::TYPE_WORD:
$rule['paramType'] = 'word';
break;
case self::TYPE_INTEGER:
$rule['paramType'] = 'integer';
break;
case self::TYPE_STRING:
default:
$rule['paramType'] = 'string';
}
} else {
$rule['param'] = 'none';
}
$rule['help'] = $helpMessage;
$this->_rules[$mainFlag] = $rule;
}
}
}

Some files were not shown because too many files have changed in this diff Show More