Augmentation vers version 3.3.0
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Zend\Code\Annotation;
|
||||
|
||||
use ArrayObject;
|
||||
|
||||
use function get_class;
|
||||
|
||||
class AnnotationCollection extends ArrayObject
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,9 @@ use Zend\EventManager\EventManager;
|
||||
use Zend\EventManager\EventManagerAwareInterface;
|
||||
use Zend\EventManager\EventManagerInterface;
|
||||
|
||||
use function get_class;
|
||||
use function is_object;
|
||||
|
||||
/**
|
||||
* Pluggable annotation manager
|
||||
*
|
||||
@@ -41,10 +44,10 @@ class AnnotationManager implements EventManagerAwareInterface
|
||||
*/
|
||||
public function setEventManager(EventManagerInterface $events)
|
||||
{
|
||||
$events->setIdentifiers(array(
|
||||
$events->setIdentifiers([
|
||||
__CLASS__,
|
||||
get_class($this),
|
||||
));
|
||||
]);
|
||||
$this->events = $events;
|
||||
|
||||
return $this;
|
||||
@@ -75,7 +78,7 @@ class AnnotationManager implements EventManagerAwareInterface
|
||||
public function attach(ParserInterface $parser)
|
||||
{
|
||||
$this->getEventManager()
|
||||
->attach(self::EVENT_CREATE_ANNOTATION, array($parser, 'onCreateAnnotation'));
|
||||
->attach(self::EVENT_CREATE_ANNOTATION, [$parser, 'onCreateAnnotation']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -91,19 +94,19 @@ class AnnotationManager implements EventManagerAwareInterface
|
||||
$event = new Event();
|
||||
$event->setName(self::EVENT_CREATE_ANNOTATION);
|
||||
$event->setTarget($this);
|
||||
$event->setParams(array(
|
||||
$event->setParams([
|
||||
'class' => $annotationData[0],
|
||||
'content' => $annotationData[1],
|
||||
'raw' => $annotationData[2],
|
||||
));
|
||||
]);
|
||||
|
||||
$eventManager = $this->getEventManager();
|
||||
$results = $eventManager->trigger($event, function ($r) {
|
||||
return (is_object($r));
|
||||
});
|
||||
$results = $eventManager->triggerEventUntil(function ($r) {
|
||||
return is_object($r);
|
||||
}, $event);
|
||||
|
||||
$annotation = $results->last();
|
||||
|
||||
return (is_object($annotation) ? $annotation : false);
|
||||
return is_object($annotation) ? $annotation : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,15 @@ use Traversable;
|
||||
use Zend\Code\Exception;
|
||||
use Zend\EventManager\EventInterface;
|
||||
|
||||
use function array_shift;
|
||||
use function class_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function preg_replace;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* A parser for docblock annotations that utilizes the annotation parser from
|
||||
* Doctrine\Common.
|
||||
@@ -29,7 +38,7 @@ class DoctrineAnnotationParser implements ParserInterface
|
||||
/**
|
||||
* @var array Annotation classes we support on this iteration
|
||||
*/
|
||||
protected $allowedAnnotations = array();
|
||||
protected $allowedAnnotations = [];
|
||||
|
||||
/**
|
||||
* @var DocParser
|
||||
@@ -65,7 +74,7 @@ class DoctrineAnnotationParser implements ParserInterface
|
||||
*/
|
||||
public function getDocParser()
|
||||
{
|
||||
if (!$this->docParser instanceof DocParser) {
|
||||
if (! $this->docParser instanceof DocParser) {
|
||||
$this->setDocParser(new DocParser());
|
||||
}
|
||||
|
||||
@@ -81,16 +90,16 @@ class DoctrineAnnotationParser implements ParserInterface
|
||||
public function onCreateAnnotation(EventInterface $e)
|
||||
{
|
||||
$annotationClass = $e->getParam('class', false);
|
||||
if (!$annotationClass) {
|
||||
if (! $annotationClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->allowedAnnotations[$annotationClass])) {
|
||||
if (! isset($this->allowedAnnotations[$annotationClass])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$annotationString = $e->getParam('raw', false);
|
||||
if (!$annotationString) {
|
||||
if (! $annotationString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,7 +116,7 @@ class DoctrineAnnotationParser implements ParserInterface
|
||||
}
|
||||
|
||||
$annotation = array_shift($annotations);
|
||||
if (!is_object($annotation)) {
|
||||
if (! is_object($annotation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,11 +145,11 @@ class DoctrineAnnotationParser implements ParserInterface
|
||||
*/
|
||||
public function registerAnnotations($annotations)
|
||||
{
|
||||
if (!is_array($annotations) && !$annotations instanceof Traversable) {
|
||||
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'%s: expects an array or Traversable; received "%s"',
|
||||
__METHOD__,
|
||||
(is_object($annotations) ? get_class($annotations) : gettype($annotations))
|
||||
is_object($annotations) ? get_class($annotations) : gettype($annotations)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,19 @@ use Zend\Code\Annotation\AnnotationInterface;
|
||||
use Zend\Code\Exception;
|
||||
use Zend\EventManager\EventInterface;
|
||||
|
||||
use function array_search;
|
||||
use function class_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strtolower;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Generic annotation parser
|
||||
*
|
||||
@@ -26,17 +39,17 @@ class GenericAnnotationParser implements ParserInterface
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $aliases = array();
|
||||
protected $aliases = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $annotationNames = array();
|
||||
protected $annotationNames = [];
|
||||
|
||||
/**
|
||||
* @var AnnotationInterface[]
|
||||
*/
|
||||
protected $annotations = array();
|
||||
protected $annotations = [];
|
||||
|
||||
/**
|
||||
* Listen to onCreateAnnotation, and attempt to return an annotation object
|
||||
@@ -53,7 +66,7 @@ class GenericAnnotationParser implements ParserInterface
|
||||
public function onCreateAnnotation(EventInterface $e)
|
||||
{
|
||||
$class = $e->getParam('class', false);
|
||||
if (!$class || !$this->hasAnnotation($class)) {
|
||||
if (! $class || ! $this->hasAnnotation($class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -80,7 +93,7 @@ class GenericAnnotationParser implements ParserInterface
|
||||
*
|
||||
* @param string|AnnotationInterface $annotation String class name of an
|
||||
* AnnotationInterface implementation, or actual instance
|
||||
* @return GenericAnnotationParser
|
||||
* @return void
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
public function registerAnnotation($annotation)
|
||||
@@ -91,12 +104,12 @@ class GenericAnnotationParser implements ParserInterface
|
||||
$annotation = new $annotation();
|
||||
}
|
||||
|
||||
if (!$annotation instanceof AnnotationInterface) {
|
||||
if (! $annotation instanceof AnnotationInterface) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'%s: expects an instance of %s\AnnotationInterface; received "%s"',
|
||||
__METHOD__,
|
||||
__NAMESPACE__,
|
||||
(is_object($annotation) ? get_class($annotation) : gettype($annotation))
|
||||
is_object($annotation) ? get_class($annotation) : gettype($annotation)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -122,11 +135,11 @@ class GenericAnnotationParser implements ParserInterface
|
||||
*/
|
||||
public function registerAnnotations($annotations)
|
||||
{
|
||||
if (!is_array($annotations) && !$annotations instanceof Traversable) {
|
||||
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'%s: expects an array or Traversable; received "%s"',
|
||||
__METHOD__,
|
||||
(is_object($annotations) ? get_class($annotations) : gettype($annotations))
|
||||
is_object($annotations) ? get_class($annotations) : gettype($annotations)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -166,7 +179,7 @@ class GenericAnnotationParser implements ParserInterface
|
||||
*/
|
||||
public function setAlias($alias, $class)
|
||||
{
|
||||
if (!in_array($class, $this->annotationNames) && !$this->hasAlias($class)) {
|
||||
if (! in_array($class, $this->annotationNames) && ! $this->hasAlias($class)) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'%s: Cannot alias "%s" to "%s", as class "%s" is not currently a registered annotation or alias',
|
||||
__METHOD__,
|
||||
@@ -190,7 +203,7 @@ class GenericAnnotationParser implements ParserInterface
|
||||
*/
|
||||
protected function normalizeAlias($alias)
|
||||
{
|
||||
return strtolower(str_replace(array('-', '_', ' ', '\\', '/'), '', $alias));
|
||||
return strtolower(str_replace(['-', '_', ' ', '\\', '/'], '', $alias));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +216,7 @@ class GenericAnnotationParser implements ParserInterface
|
||||
{
|
||||
$alias = $this->normalizeAlias($alias);
|
||||
|
||||
return (isset($this->aliases[$alias]));
|
||||
return isset($this->aliases[$alias]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user