Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'prolic/phpdoc-di' into prolic-zen-52
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 101 deletions.
19 changes: 13 additions & 6 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

class Configuration
{
protected $data = array();

/**
* @var Zend\Di\DependencyInjector
* @var array
*/
protected $di = null;

protected $data = array();
/**
* Constructor
*
* @param array|Traversable $options
* @throws Exception\InvalidArgumentException
*/
public function __construct($options)
{
Expand All @@ -30,7 +31,13 @@ public function __construct($options)
}
$this->data = $options;
}


/**
* Configure
*
* @param Di $di
* @return void
*/
public function configure(Di $di)
{
if (isset($this->data['definition'])) {
Expand Down
32 changes: 27 additions & 5 deletions src/Definition/Builder/PhpClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ class PhpClass
protected $instantiator = '__construct';
protected $injectionMethods = array();
protected $superTypes = array();


/**
* Set name
*
* @param string $name
* @return PhpClass
*/
public function setName($name)
{
$this->name = $name;
return $this;
}


/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
Expand All @@ -31,18 +42,29 @@ public function getInstantiator()
{
return $this->instantiator;
}

public function addSuperType($superType)
{
$this->superTypes[] = $superType;
return $this;
}


/**
* Get super types
*
* @return array
*/
public function getSuperTypes()
{
return $this->superTypes;
}


/**
* Add injection method
*
* @param InjectionMethod $injectionMethod
* @return PhpClass
*/
public function addInjectionMethod(InjectionMethod $injectionMethod)
{
$this->injectionMethods[] = $injectionMethod;
Expand Down
88 changes: 75 additions & 13 deletions src/Definition/BuilderDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@

class BuilderDefinition implements DefinitionInterface
{
/**
* @var string
*/
protected $defaultClassBuilder = 'Zend\Di\Definition\Builder\PhpClass';

/**
* @var array
*/
protected $classes = array();

/**
* Create classes from array
*
* @param array $builderData
* @return void
*/
public function createClassesFromArray(array $builderData)
{
foreach ($builderData as $className => $classInfo) {
Expand Down Expand Up @@ -42,7 +55,13 @@ public function createClassesFromArray(array $builderData)
$this->addClass($class);
}
}


/**
* Add class
*
* @param Builder\PhpClass $phpClass
* @return BuilderDefinition
*/
public function addClass(Builder\PhpClass $phpClass)
{
$this->classes[] = $phpClass;
Expand Down Expand Up @@ -93,7 +112,10 @@ public function getClassBuilder()
{
return $this->defaultClassBuilder;
}


/**
* @return array
*/
public function getClasses()
{
$classNames = array();
Expand All @@ -102,7 +124,11 @@ public function getClasses()
}
return $classNames;
}


/**
* @param string $class
* @return bool
*/
public function hasClass($class)
{
foreach ($this->classes as $classObj) {
Expand All @@ -112,7 +138,11 @@ public function hasClass($class)
}
return false;
}


/**
* @param string $name
* @return bool
*/
protected function getClass($name)
{
foreach ($this->classes as $classObj) {
Expand All @@ -122,7 +152,12 @@ protected function getClass($name)
}
return false;
}


/**
* @param string $class
* @return array
* @throws Exception\RuntimeException
*/
public function getClassSupertypes($class)
{
$class = $this->getClass($class);
Expand All @@ -131,7 +166,12 @@ public function getClassSupertypes($class)
}
return $class->getSuperTypes();
}


/**
* @param string $class
* @return array|string
* @throws Exception\RuntimeException
*/
public function getInstantiator($class)
{
$class = $this->getClass($class);
Expand All @@ -140,17 +180,27 @@ public function getInstantiator($class)
}
return $class->getInstantiator();
}


/**
* @param string $class
* @return bool
* @throws Exception\RuntimeException
*/
public function hasMethods($class)
{
/* @var $class Zend\Di\Definition\Builder\PhpClass */
/* @var $class \Zend\Di\Definition\Builder\PhpClass */
$class = $this->getClass($class);
if ($class === false) {
throw new Exception\RuntimeException('Cannot find class object in this builder definition.');
}
return (count($class->getInjectionMethods()) > 0);
}


/**
* @param string $class
* @return array
* @throws Exception\RuntimeException
*/
public function getMethods($class)
{
$class = $this->getClass($class);
Expand All @@ -164,7 +214,13 @@ public function getMethods($class)
}
return $methodNames;
}


/**
* @param string $class
* @param string $method
* @return bool
* @throws Exception\RuntimeException
*/
public function hasMethod($class, $method)
{
$class = $this->getClass($class);
Expand All @@ -181,8 +237,8 @@ public function hasMethod($class, $method)
}

/**
* @param $class
* @param $method
* @param string $class
* @param string $method
* @return bool
*/
public function hasMethodParameters($class, $method)
Expand All @@ -202,7 +258,13 @@ public function hasMethodParameters($class, $method)
}
return (count($method->getParameters()) > 0);
}


/**
* @param string $class
* @param string $method
* @return array
* @throws Exception\RuntimeException
*/
public function getMethodParameters($class, $method)
{
$class = $this->getClass($class);
Expand Down
6 changes: 6 additions & 0 deletions src/Definition/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function setSupertypes(array $supertypes)
return $this;
}

/**
* @param string $method
* @param bool|null $isRequired
* @return ClassDefinition
*/
public function addMethod($method, $isRequired = null)
{
if ($isRequired === null) {
Expand All @@ -43,6 +48,7 @@ public function addMethod($method, $isRequired = null)
* @param $method
* @param $parameterName
* @param array $parameterInfo (keys: required, type)
* @return ClassDefinition
*/
public function addMethodParameter($method, $parameterName, array $parameterInfo)
{
Expand Down
54 changes: 42 additions & 12 deletions src/Definition/CompilerDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Zend\Di\Definition;

use Zend\Code\Scanner\DerivedClassScanner,
Zend\Code\Scanner\AggregateDirectoryScanner,
Zend\Code\Scanner\DirectoryScanner,
Zend\Code\Scanner\FileScanner,

Zend\Di\Definition\Annotation,
Zend\Code\Annotation\AnnotationManager,
Zend\Code\Reflection,
Zend\Code\Annotation\AnnotationCollection;
use Zend\Code\Annotation\AnnotationCollection;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Scanner\AggregateDirectoryScanner;
use Zend\Code\Scanner\DirectoryScanner;
use Zend\Code\Scanner\DerivedClassScanner;
use Zend\Code\Scanner\FileScanner;
use Zend\Code\Reflection;
use Zend\Di\Definition\Annotation;

class CompilerDefinition implements DefinitionInterface
{
Expand All @@ -25,36 +24,62 @@ class CompilerDefinition implements DefinitionInterface

protected $classes = array();

/**
* Constructor
*
* @param null|IntrospectionStrategy $introspectionStrategy
*/
public function __construct(IntrospectionStrategy $introspectionStrategy = null)
{
$this->introspectionStrategy = ($introspectionStrategy) ?: new IntrospectionStrategy();
$this->directoryScanner = new AggregateDirectoryScanner();
}

/**
* Set introspection strategy
*
* @param IntrospectionStrategy $introspectionStrategy
*/
public function setIntrospectionStrategy(IntrospectionStrategy $introspectionStrategy)
{
$this->introspectionStrategy = $introspectionStrategy;
}

/**
*
* Get introspection strategy
*
* @return IntrospectionStrategy
*/
public function getIntrospectionStrategy()
{
return $this->introspectionStrategy;
}

/**
* Add directory
*
* @param string $directory
*/
public function addDirectory($directory)
{
$this->addDirectoryScanner(new DirectoryScanner($directory));
}

/**
* Add directory scanner
*
* @param DirectoryScanner $directoryScanner
*/
public function addDirectoryScanner(DirectoryScanner $directoryScanner)
{
$this->directoryScanner->addDirectoryScanner($directoryScanner);
}


/**
* Add code scanner file
*
* @param FileScanner $fileScanner
*/
public function addCodeScannerFile(FileScanner $fileScanner)
{
if ($this->directoryScanner == null) {
Expand All @@ -63,7 +88,12 @@ public function addCodeScannerFile(FileScanner $fileScanner)

$this->directoryScanner->addFileScanner($fileScanner);
}


/**
* Compile
*
* @return void
*/
public function compile()
{
/* @var $classScanner \Zend\Code\Scanner\DerivedClassScanner */
Expand Down
Loading

0 comments on commit 761379e

Please sign in to comment.