Source of file ClassDefinition.php
Size: 5,172 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Di/Definition/ClassDefinition.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Di\Definition; use Zend\Di\Definition\Builder\InjectionMethod; use Zend\Di\Di; /** * Class definitions for a single class */ class ClassDefinition implements DefinitionInterface, PartialMarker { /** * @var null|string */ protected $class = null; /** * @var string[] */ protected $supertypes = array(); /** * @var null|\Callable|array|string */ protected $instantiator = null; /** * @var bool[] */ protected $methods = array(); /** * @var array */ protected $methodParameters = array(); /** * @param string $class */ public function __construct($class) { $this->class = $class; } /** * @param null|\Callable|array|string $instantiator * @return self */ public function setInstantiator($instantiator) { $this->instantiator = $instantiator; return $this; } /** * @param string[] $supertypes * @return self */ public function setSupertypes(array $supertypes) { $this->supertypes = $supertypes; return $this; } /** * @param string $method * @param mixed|bool|null $isRequired * @return self */ public function addMethod($method, $isRequired = null) { if ($isRequired === null) { if ($method === '__construct') { $methodRequirementType = Di::METHOD_IS_CONSTRUCTOR; } $methodRequirementType = Di::METHOD_IS_OPTIONAL; } else { $methodRequirementType = InjectionMethod::detectMethodRequirement($isRequired); } $this->methods[$method] = $methodRequirementType; return $this; } /** * @param $method * @param $parameterName * @param array $parameterInfo (keys: required, type) * @return ClassDefinition */ public function addMethodParameter($method, $parameterName, array $parameterInfo) { if (!array_key_exists($method, $this->methods)) { if ($method === '__construct') { $this->methods[$method] = Di::METHOD_IS_CONSTRUCTOR; } else { $this->methods[$method] = Di::METHOD_IS_OPTIONAL; } } if (!array_key_exists($method, $this->methodParameters)) { $this->methodParameters[$method] = array(); } $type = (isset($parameterInfo['type'])) ? $parameterInfo['type'] : null; $required = (isset($parameterInfo['required'])) ? (bool) $parameterInfo['required'] : false; $default = (isset($parameterInfo['default'])) ? $parameterInfo['default'] : null; $fqName = $this->class . '::' . $method . ':' . $parameterName; $this->methodParameters[$method][$fqName] = array( $parameterName, $type, $required, $default ); return $this; } /** * {@inheritDoc} */ public function getClasses() { return array($this->class); } /** * {@inheritDoc} */ public function hasClass($class) { return ($class === $this->class); } /** * {@inheritDoc} */ public function getClassSupertypes($class) { if ($this->class !== $class) { return array(); } return $this->supertypes; } /** * {@inheritDoc} */ public function getInstantiator($class) { if ($this->class !== $class) { return null; } return $this->instantiator; } /** * {@inheritDoc} */ public function hasMethods($class) { return (count($this->methods) > 0); } /** * {@inheritDoc} */ public function getMethods($class) { if ($this->class !== $class) { return array(); } return $this->methods; } /** * {@inheritDoc} */ public function hasMethod($class, $method) { if ($this->class !== $class) { return null; } if (is_array($this->methods)) { return array_key_exists($method, $this->methods); } return null; } /** * {@inheritDoc} */ public function hasMethodParameters($class, $method) { if ($this->class !== $class) { return false; } return (array_key_exists($method, $this->methodParameters)); } /** * {@inheritDoc} */ public function getMethodParameters($class, $method) { if ($this->class !== $class) { return null; } if (array_key_exists($method, $this->methodParameters)) { return $this->methodParameters[$method]; } return null; } } |