CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,156 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Bootstrap.php 20886 2010-02-03 19:36:06Z matthew $
*/
/**
* 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-2010 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
* @return void
*/
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

@ -0,0 +1,768 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: BootstrapAbstract.php 20988 2010-02-08 16:44:44Z matthew $
*/
/**
* 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-2010 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
* @return void
* @throws Zend_Application_Bootstrap_Exception When invalid applicaiton 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($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 $resourceName
* @return Zend_Application_Resource_Resource
*/
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];
}
}
if (class_exists($plugin)) { //@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'
);
$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
*/
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
*/
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 ressource
* 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 ressource 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 void
* @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

@ -0,0 +1,94 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Bootstrapper.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Interface for bootstrap classes
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2010 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
* @return void
*/
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

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

View file

@ -0,0 +1,95 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ResourceBootstrapper.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Interface for bootstrap classes that utilize resource plugins
*
* @category Zend
* @package Zend_Application
* @subpackage Bootstrap
* @copyright Copyright (c) 2005-2010 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

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

View file

@ -0,0 +1,94 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Autoloader.php 20250 2010-01-12 22:15:20Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** @see Zend_Loader_Autoloader_Resource */
require_once 'Zend/Loader/Autoloader/Resource.php';
/**
* Resource loader for application module classes
*
* @uses Zend_Loader_Autoloader_Resource
* @category Zend
* @package Zend_Application
* @subpackage Module
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Module_Autoloader extends Zend_Loader_Autoloader_Resource
{
/**
* Constructor
*
* @param array|Zend_Config $options
* @return void
*/
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

@ -0,0 +1,128 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Bootstrap.php 20096 2010-01-06 02:05:09Z bkarwin $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Application_Bootstrap_Bootstrap
*/
require_once 'Zend/Application/Bootstrap/Bootstrap.php';
/**
* 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-2010 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
* @return void
*/
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

@ -0,0 +1,73 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Cache Manager resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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) {
if ($this->_manager->hasCacheTemplate($key)) {
$this->_manager->setTemplateOptions($key, $value);
} else {
$this->_manager->setCacheTemplate($key, $value);
}
}
}
return $this->_manager;
}
}

View file

@ -0,0 +1,161 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Db.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for creating database adapter
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbstract
{
/**
* Adapter to use
*
* @var string
*/
protected $_adapter = null;
/**
* @var Zend_Db_Adapter_Interface
*/
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 $adapter string
* @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 $adapter string
* @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 boolean $defaultTableAdapter
* @return Zend_Application_Resource_Db
*/
public function setIsDefaultTableAdapter($isDefaultTableAdapter)
{
$this->_isDefaultTableAdapter = $isDefaultTableAdapter;
return $this;
}
/**
* Is this adapter the default table adapter?
*
* @return void
*/
public function isDefaultTableAdapter()
{
return $this->_isDefaultTableAdapter;
}
/**
* Retrieve initialized DB connection
*
* @return null|Zend_Db_Adapter_Interface
*/
public function getDbAdapter()
{
if ((null === $this->_db)
&& (null !== ($adapter = $this->getAdapter()))
) {
$this->_db = Zend_Db::factory($adapter, $this->getParams());
}
return $this->_db;
}
/**
* Defined by Zend_Application_Resource_Resource
*
* @return Zend_Db_Adapter_Abstract|null
*/
public function init()
{
if (null !== ($db = $this->getDbAdapter())) {
if ($this->isDefaultTableAdapter()) {
Zend_Db_Table::setDefaultAdapter($db);
}
return $db;
}
}
}

View file

@ -0,0 +1,76 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Layout.php 17687 2009-08-20 12:55:34Z thomas $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for settings Dojo options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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

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

View file

@ -0,0 +1,157 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Frontcontroller.php 20886 2010-02-03 19:36:06Z matthew $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Front Controller resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var Zend_Controller_Front
*/
protected $_front;
/**
* Initialize Front Controller
*
* @return Zend_Controller_Front
*/
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':
$front->addModuleDirectory($value);
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;
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

@ -0,0 +1,70 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Layout.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for settings layout options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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

@ -0,0 +1,89 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Locale.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for initializing the locale
*
* @uses Zend_Application_Resource_Base
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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;
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 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
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for initializing the locale
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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;
}
public function getLog()
{
if (null === $this->_log) {
$options = $this->getOptions();
$log = Zend_Log::factory($options);
$this->setLog($log);
}
return $this->_log;
}
}

View file

@ -0,0 +1,146 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Db.php 17687 2009-08-20 12:55:34Z thomas $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* 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-2010 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']);
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

@ -0,0 +1,138 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Modules.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Module bootstrapping resource
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Application_Resource_Modules extends Zend_Application_Resource_ResourceAbstract
{
/**
* @var ArrayObject
*/
protected $_bootstraps;
/**
* Constructor
*
* @param mixed $options
* @return void
*/
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()
{
$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;
}
$moduleBootstrap = new $bootstrapClass($bootstrap);
$moduleBootstrap->bootstrap();
$this->_bootstraps[$module] = $moduleBootstrap;
}
return $this->_bootstraps;
}
/**
* 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

@ -0,0 +1,168 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
require_once 'Zend/Db/Table.php';
/**
*/
/**
* Cache Manager resource
*
* Example configuration:
* <pre>
* 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-2010 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();
foreach ($options as $id => $params) {
$adapter = $params['adapter'];
$default = isset($params['default'])?(int)$params['default']:false;
unset($params['adapter'], $params['default']);
$this->_dbs[$id] = Zend_Db::factory($adapter, $params);
if ($default
// For consistency with the Db Resource Plugin
|| (isset($params['isDefaultTableAdapter'])
&& $params['isDefaultTableAdapter'] == true)
) {
$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;
}
}

View file

@ -0,0 +1,123 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Navigation.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for setting navigation structure
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 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();
$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();
if(isset($options['storage']['registry']['key']) &&
!is_numeric($options['storage']['registry']['key'])) // see ZF-7461
{
$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

@ -0,0 +1,80 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Resource.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Interface for bootstrap resources
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 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
* @return void
*/
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

@ -0,0 +1,159 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ResourceAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Application_Resource_Resource
*/
require_once 'Zend/Application/Resource/Resource.php';
/**
* Abstract class for bootstrap resources
*
* @uses Zend_Application_Resource_Resource
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 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)
{
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);
}
if ('bootstrap' === $key) {
unset($options[$key]);
}
}
$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

@ -0,0 +1,87 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Router.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for initializing the locale
*
* @uses Zend_Application_Resource_Base
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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

@ -0,0 +1,118 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Session.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for setting session options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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 no valid save handler
*/
public function setSaveHandler($saveHandler)
{
$this->_saveHandler = $saveHandler;
return $this;
}
/**
* Get session save handler
*
* @return Zend_Session_SaveHandler_Interface
*/
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

@ -0,0 +1,105 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Translate.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for setting translation options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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['data'])) {
require_once 'Zend/Application/Resource/Exception.php';
throw new Zend_Application_Resource_Exception('No translation source data provided.');
}
$adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY;
$locale = isset($options['locale']) ? $options['locale'] : null;
$translateOptions = isset($options['options']) ? $options['options'] : array();
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
? $options['registry_key']
: self::DEFAULT_REGISTRY_KEY;
if(Zend_Registry::isRegistered($key)) {
$translate = Zend_Registry::get($key);
if(!$translate instanceof Zend_Translate) {
require_once 'Zend/Application/Resource/Exception.php';
throw new Zend_Application_Resource_Exception($key
. ' already registered in registry but is '
. 'no instance of Zend_Translate');
}
$translate->addTranslation($options['data'], $locale, $options);
$this->_translate = $translate;
} else {
$this->_translate = new Zend_Translate(
$adapter, $options['data'], $locale, $translateOptions
);
Zend_Registry::set($key, $this->_translate);
}
}
return $this->_translate;
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: View.php 20816 2010-02-01 21:13:54Z freak $
*/
/**
* @see Zend_Application_Resource_ResourceAbstract
*/
require_once 'Zend/Application/Resource/ResourceAbstract.php';
/**
* Resource for settings view options
*
* @uses Zend_Application_Resource_ResourceAbstract
* @category Zend
* @package Zend_Application
* @subpackage Resource
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_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 = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
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']));
}
}
return $this->_view;
}
}