v7‰PNG  IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ± üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0A­ºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT PK\ksfServiceDefinition.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceDefinition represents a service definition. * * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id: sfServiceDefinition.php 269 2009-03-26 20:39:16Z fabien $ */ class sfServiceDefinition { protected $class = null, $file = null, $constructor = null, $shared = true, $arguments = array(), $calls = array(), $configurator = null; /** * Constructor. * * @param string $class The service class * @param array $arguments An array of arguments to pass to the service constructor */ public function __construct($class, array $arguments = array()) { $this->class = $class; $this->arguments = $arguments; } /** * Sets the constructor method. * * @param string $method The method name * * @return sfServiceDefinition The current instance */ public function setConstructor($method) { $this->constructor = $method; return $this; } /** * Gets the constructor method. * * @return sfServiceDefinition The constructor method name */ public function getConstructor() { return $this->constructor; } /** * Sets the service class. * * @param string $class The service class * * @return sfServiceDefinition The current instance */ public function setClass($class) { $this->class = $class; return $this; } /** * Sets the constructor method. * * @return string The service class */ public function getClass() { return $this->class; } /** * Sets the constructor arguments to pass to the service constructor. * * @param array $arguments An array of arguments * * @return sfServiceDefinition The current instance */ public function setArguments(array $arguments) { $this->arguments = $arguments; return $this; } /** * Adds a constructor argument to pass to the service constructor. * * @param mixed $argument An argument * * @return sfServiceDefinition The current instance */ public function addArgument($argument) { $this->arguments[] = $argument; return $this; } /** * Gets the constructor arguments to pass to the service constructor. * * @return array The array of arguments */ public function getArguments() { return $this->arguments; } /** * Sets the methods to call after service initialization. * * @param array $calls An array of method calls * * @return sfServiceDefinition The current instance */ public function setMethodCalls(array $calls = array()) { $this->calls = array(); foreach ($calls as $call) { $this->addMethodCall($call[0], $call[1]); } return $this; } /** * Adds a method to call after service initialization. * * @param string $method The method name to call * @param array $arguments An array of arguments to pass to the method call * * @return sfServiceDefinition The current instance */ public function addMethodCall($method, array $arguments = array()) { $this->calls[] = array($method, $arguments); return $this; } /** * Gets the methods to call after service initialization. * * @return array An array of method calls */ public function getMethodCalls() { return $this->calls; } /** * Sets a file to require before creating the service. * * @param string $file A full pathname to include * * @return sfServiceDefinition The current instance */ public function setFile($file) { $this->file = $file; return $this; } /** * Gets the file to require before creating the service. * * @return string The full pathname to include */ public function getFile() { return $this->file; } /** * Sets if the service must be shared or not. * * @param Boolean $shared Whether the service must be shared or not * * @return sfServiceDefinition The current instance */ public function setShared($shared) { $this->shared = (Boolean) $shared; return $this; } /** * Returns true if the service must be shared. * * @return Boolean true if the service is shared, false otherwise */ public function isShared() { return $this->shared; } /** * Sets a configurator to call after the service is fully initialized. * * @param mixed $callable A PHP callable * * @return sfServiceDefinition The current instance */ public function setConfigurator($callable) { $this->configurator = $callable; return $this; } /** * Gets the configurator to call after the service is fully initialized. * * @return mixed The PHP callable to call */ public function getConfigurator() { return $this->configurator; } } PK\%?__sfServiceParameter.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceParameter represents a parameter reference. * * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id: sfServiceReference.php 267 2009-03-26 19:56:18Z fabien $ */ class sfServiceParameter { protected $id = null; /** * Constructor. * * @param string $id The parameter key */ public function __construct($id) { $this->id = $id; } /** * __toString. * * @return string The parameter key */ public function __toString() { return (string) $this->id; } } PK\e8ggsfServiceReference.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceReference represents a service reference. * * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id: sfServiceReference.php 267 2009-03-26 19:56:18Z fabien $ */ class sfServiceReference { protected $id = null; /** * Constructor. * * @param string $id The service identifier */ public function __construct($id) { $this->id = $id; } /** * __toString. * * @return string The service identifier */ public function __toString() { return (string) $this->id; } } PK\:sfServiceContainerInterface.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceContainerInterface is the interface implemented by service container classes. * * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id$ */ interface sfServiceContainerInterface { public function setParameters(array $parameters); public function addParameters(array $parameters); public function getParameters(); public function getParameter($name); public function setParameter($name, $value); public function hasParameter($name); public function setService($id, $service); public function getService($id); public function hasService($name); } PK\i!Asa$a$sfServiceContainerBuilder.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceContainerBuilder is a DI container that provides an interface to build the services. * * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id: sfServiceContainerBuilder.php 269 2009-03-26 20:39:16Z fabien $ */ class sfServiceContainerBuilder extends sfServiceContainer { protected $definitions = array(), $aliases = array(), $loading = array(); /** * Sets a service. * * @param string $id The service identifier * @param object $service The service instance */ public function setService($id, $service) { unset($this->aliases[$id]); parent::setService($id, $service); } /** * Returns true if the given service is defined. * * @param string $id The service identifier * * @return Boolean true if the service is defined, false otherwise */ public function hasService($id) { return isset($this->definitions[$id]) || isset($this->aliases[$id]) || parent::hasService($id); } /** * Gets a service. * * @param string $id The service identifier * * @return object The associated service * * @throw InvalidArgumentException if the service is not defined * @throw LogicException if the service has a circular reference to itself */ public function getService($id) { try { return parent::getService($id); } catch (InvalidArgumentException $e) { if (isset($this->loading[$id])) { throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id)); } if (!$this->hasServiceDefinition($id) && isset($this->aliases[$id])) { return $this->getService($this->aliases[$id]); } $definition = $this->getServiceDefinition($id); $this->loading[$id] = true; if ($definition->isShared()) { $service = $this->services[$id] = $this->createService($definition); } else { $service = $this->createService($definition); } unset($this->loading[$id]); return $service; } } /** * Gets all service ids. * * @return array An array of all defined service ids */ public function getServiceIds() { return array_unique(array_merge(array_keys($this->getServiceDefinitions()), array_keys($this->aliases), parent::getServiceIds())); } /** * Sets an alias for an existing service. * * @param string $alias The alias to create * @param string $id The service to alias */ public function setAlias($alias, $id) { $this->aliases[$alias] = $id; } /** * Gets all defined aliases. * * @return array An array of aliases */ public function getAliases() { return $this->aliases; } /** * Registers a service definition. * * This methods allows for simple registration of service definition * with a fluid interface. * * @param string $id The service identifier * @param string $class The service class * * @return sfServiceDefinition A sfServiceDefinition instance */ public function register($id, $class) { return $this->setServiceDefinition($id, new sfServiceDefinition($class)); } /** * Adds the service definitions. * * @param array $definitions An array of service definitions */ public function addServiceDefinitions(array $definitions) { foreach ($definitions as $id => $definition) { $this->setServiceDefinition($id, $definition); } } /** * Sets the service definitions. * * @param array $definitions An array of service definitions */ public function setServiceDefinitions(array $definitions) { $this->definitions = array(); $this->addServiceDefinitions($definitions); } /** * Gets all service definitions. * * @return array An array of sfServiceDefinition instances */ public function getServiceDefinitions() { return $this->definitions; } /** * Sets a service definition. * * @param string $id The service identifier * @param sfServiceDefinition $definition A sfServiceDefinition instance */ public function setServiceDefinition($id, sfServiceDefinition $definition) { unset($this->aliases[$id]); return $this->definitions[$id] = $definition; } /** * Returns true if a service definition exists under the given identifier. * * @param string $id The service identifier * * @return Boolean true if the service definition exists, false otherwise */ public function hasServiceDefinition($id) { return array_key_exists($id, $this->definitions); } /** * Gets a service definition. * * @param string $id The service identifier * * @return sfServiceDefinition A sfServiceDefinition instance * * @throw InvalidArgumentException if the service definition does not exist */ public function getServiceDefinition($id) { if (!$this->hasServiceDefinition($id)) { //print_rr(array_keys($this->services)); //print_rr($this->definitions); //print_rre($this); //print_rre($id); throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id)); } return $this->definitions[$id]; } /** * Creates a service for a service definition. * * @param sfServiceDefinition $definition A service definition instance * * @return object The service described by the service definition */ protected function createService(sfServiceDefinition $definition) { if (null !== $definition->getFile()) { require_once $this->resolveValue($definition->getFile()); } $r = new ReflectionClass($this->resolveValue($definition->getClass())); $arguments = $this->resolveServices($this->resolveValue($definition->getArguments())); if (null !== $definition->getConstructor()) { $service = call_user_func_array(array($this->resolveValue($definition->getClass()), $definition->getConstructor()), $arguments); } else { $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); } foreach ($definition->getMethodCalls() as $call) { call_user_func_array(array($service, $call[0]), $this->resolveServices($this->resolveValue($call[1]))); } if ($callable = $definition->getConfigurator()) { if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof sfServiceReference) { $callable[0] = $this->getService((string) $callable[0]); } elseif (is_array($callable)) { $callable[0] = $this->resolveValue($callable[0]); } if (!is_callable($callable)) { throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service))); } call_user_func($callable, $service); } return $service; } /** * Replaces parameter placeholders (%name%) by their values. * * @param mixed $value A value * * @return mixed The same value with all placeholders replaced by their values * * @throw RuntimeException if a placeholder references a parameter that does not exist */ public function resolveValue($value) { if (is_array($value)) { $args = array(); foreach ($value as $k => $v) { $args[$this->resolveValue($k)] = $this->resolveValue($v); } $value = $args; } else if (is_string($value)) { if (preg_match('/^%([^%]+)%$/', $value, $match)) { // we do this to deal with non string values (boolean, integer, ...) // the preg_replace_callback converts them to strings if (!$this->hasParameter($name = strtolower($match[1]))) { throw new RuntimeException(sprintf('The parameter "%s" must be defined.', $name)); } $value = $this->getParameter($name); } else { $value = str_replace('%%', '%', preg_replace_callback('/(?getService((string) $value); } return $value; } protected function replaceParameter($match) { if (!$this->hasParameter($name = strtolower($match[2]))) { throw new RuntimeException(sprintf('The parameter "%s" must be defined.', $name)); } return $this->getParameter($name); } } PK\<))LICENSEnu[Copyright (c) 2008-2009 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK\:xxsfServiceSimpleXMLElement.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ class sfServiceSimpleXMLElement extends SimpleXMLElement { public function getAttributeAsPhp($name) { return self::phpize($this[$name]); } public function getArgumentsAsPhp($name) { $arguments = array(); foreach ($this->$name as $arg) { $key = isset($arg['key']) ? (string) $arg['key'] : (!$arguments ? 0 : max(array_keys($arguments)) + 1); // parameter keys are case insensitive if ('parameter' == $name) { $key = strtolower($key); } switch ($arg['type']) { case 'service': $arguments[$key] = new sfServiceReference((string) $arg['id']); break; case 'collection': $arguments[$key] = $arg->getArgumentsAsPhp($name); break; case 'string': $arguments[$key] = (string) $arg; break; default: $arguments[$key] = self::phpize($arg); } } return $arguments; } static public function phpize($value) { $value = (string) $value; switch (true) { case 'null' == strtolower($value): return null; case ctype_digit($value): return '0' == $value[0] ? octdec($value) : intval($value); case in_array(strtolower($value), array('true', 'on')): return true; case in_array(strtolower($value), array('false', 'off')): return false; case is_numeric($value): return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value); case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value): return floatval(str_replace(',', '', $value)); default: return (string) $value; } } } PK\U""sfServiceContainer.phpnu[ * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * sfServiceContainer is a dependency injection container. * * It gives access to object instances (services), and parameters. * * Services and parameters are simple key/pair stores. * * Parameters keys are case insensitive. * * A service id can contain lowercased letters, digits, underscores, and dots. * Underscores are used to separate words, and dots to group services * under namespaces: * *
    *
  • request
  • *
  • mysql_session_storage
  • *
  • symfony.mysql_session_storage
  • *
* * A service can also be defined by creating a method named * getXXXService(), where XXX is the camelized version of the id: * *
    *
  • request -> getRequestService()
  • *
  • mysql_session_storage -> getMysqlSessionStorageService()
  • *
  • symfony.mysql_session_storage -> getSymfony_MysqlSessionStorageService()
  • *
* * @package symfony * @subpackage dependency_injection * @author Fabien Potencier * @version SVN: $Id$ */ class sfServiceContainer implements sfServiceContainerInterface, ArrayAccess, Iterator { protected $serviceIds = array(), $parameters = array(), $services = array(), $count = 0; /** * Constructor. * * @param array $parameters An array of parameters */ public function __construct(array $parameters = array()) { $this->setParameters($parameters); $this->setService('service_container', $this); } /** * Sets the service container parameters. * * @param array $parameters An array of parameters */ public function setParameters(array $parameters) { $this->parameters = array(); foreach ($parameters as $key => $value) { $this->parameters[strtolower($key)] = $value; } } /** * Adds parameters to the service container parameters. * * @param array $parameters An array of parameters */ public function addParameters(array $parameters) { $this->setParameters(array_merge($this->parameters, $parameters)); } /** * Gets the service container parameters. * * @return array An array of parameters */ public function getParameters() { return $this->parameters; } /** * Gets a service container parameter. * * @param string $name The parameter name * * @return mixed The parameter value * * @throw InvalidArgumentException if the parameter is not defined */ public function getParameter($name) { if (!$this->hasParameter($name)) { throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); } return $this->parameters[strtolower($name)]; } /** * Sets a service container parameter. * * @param string $name The parameter name * @param mixed $parameters The parameter value */ public function setParameter($name, $value) { $this->parameters[strtolower($name)] = $value; } /** * Returns true if a parameter name is defined. * * @param string $name The parameter name * * @return Boolean true if the parameter name is defined, false otherwise */ public function hasParameter($name) { return array_key_exists(strtolower($name), $this->parameters); } /** * Sets a service. * * @param string $id The service identifier * @param object $service The service instance */ public function setService($id, $service) { $this->services[$id] = $service; } /** * Returns true if the given service is defined. * * @param string $id The service identifier * * @return Boolean true if the service is defined, false otherwise */ public function hasService($id) { return isset($this->services[$id]) || method_exists($this, 'get'.self::camelize($id).'Service'); } /** * Gets a service. * * If a service is both defined through a setService() method and * with a set*Service() method, the former has always precedence. * * @param string $id The service identifier * * @return object The associated service * * @throw InvalidArgumentException if the service is not defined */ public function getService($id) { if (isset($this->services[$id])) { return $this->services[$id]; } if (method_exists($this, $method = 'get'.self::camelize($id).'Service')) { return $this->$method(); } throw new InvalidArgumentException(sprintf('The service "%s" does not exist.', $id)); } /** * Gets all service ids. * * @return array An array of all defined service ids */ public function getServiceIds() { $ids = array(); $r = new ReflectionClass($this); foreach ($r->getMethods() as $method) { if (preg_match('/^get(.+)Service$/', $name = $method->getName(), $match)) { $ids[] = self::underscore($match[1]); } } return array_merge($ids, array_keys($this->services)); } /** * Returns true if the parameter name is defined (implements the ArrayAccess interface). * * @param string The parameter name * * @return Boolean true if the parameter name is defined, false otherwise */ public function offsetExists($name) { return $this->hasParameter($name); } /** * Gets a service container parameter (implements the ArrayAccess interface). * * @param string The parameter name * * @return mixed The parameter value */ public function offsetGet($name) { return $this->getParameter($name); } /** * Sets a parameter (implements the ArrayAccess interface). * * @param string The parameter name * @param mixed The parameter value */ public function offsetSet($name, $value) { $this->setParameter($name, $value); } /** * Removes a parameter (implements the ArrayAccess interface). * * @param string The parameter name */ public function offsetUnset($name) { unset($this->parameters[$name]); } /** * Returns true if the container has a service with the given identifier. * * @param string The service identifier * * @return Boolean true if the container has a service with the given identifier, false otherwise */ public function __isset($id) { return $this->hasService($id); } /** * Gets the service associated with the given identifier. * * @param string The service identifier * * @return mixed The service instance associated with the given identifier */ public function __get($id) { return $this->getService($id); } /** * Sets a service. * * @param string The service identifier * @param mixed A service instance */ public function __set($id, $service) { $this->setService($id, $service); } /** * Removes a service by identifier. * * @param string The service identifier */ public function __unset($id) { throw new LogicException('You can\'t unset a service.'); } /** * Resets the service identifiers array to the beginning (implements the Iterator interface). */ public function rewind() { $this->serviceIds = $this->getServiceIds(); $this->count = count($this->serviceIds); } /** * Gets the key associated with the current service (implements the Iterator interface). * * @return string The service identifier */ public function key() { return current($this->serviceIds); } /** * Returns the current service (implements the Iterator interface). * * @return mixed The service */ public function current() { return $this->getService(current($this->serviceIds)); } /** * Moves to the next service (implements the Iterator interface). */ public function next() { next($this->serviceIds); --$this->count; } /** * Returns true if the current service is valid (implements the Iterator interface). * * @return boolean The validity of the current service; true if it is valid */ public function valid() { return $this->count > 0; } static public function camelize($id) { return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ '))), array(' ' => '')); } static function _camelizeCallback($regs) { } static public function underscore($id) { return strtolower(preg_replace(array('/_/', '/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('.', '\\1_\\2', '\\1_\\2'), $id)); } } PK\ksfServiceDefinition.phpnu[PK\%?__sfServiceParameter.phpnu[PK\e8ggsfServiceReference.phpnu[PK\:RsfServiceContainerInterface.phpnu[PK\i!Asa$a$C sfServiceContainerBuilder.phpnu[PK\<))DLICENSEnu[PK\:xxQIsfServiceSimpleXMLElement.phpnu[PK\U""QsfServiceContainer.phpnu[PKzs