/**
  * Class constructor.
  * @param \Brickoo\Component\Common\Collection $definitionsCollection
  * @throws InvalidTypeException
  */
 public function __construct(Collection $definitionsCollection)
 {
     if ($definitionsCollection->getType() !== "Brickoo\\Component\\Annotation\\Definition\\AnnotationDefinition") {
         throw new InvalidTypeException($definitionsCollection->getType());
     }
     $this->definitionsCollection = $definitionsCollection;
 }
 /** {@inheritDoc} */
 public function collect()
 {
     $collection = new Collection();
     if (($routeCollections = call_user_func($this->callback)) && is_array($routeCollections) && (new ContainsInstancesOfConstraint("\\Brickoo\\Component\\Routing\\Route\\RouteCollection"))->matches($routeCollections)) {
         $collection->fromArray($routeCollections);
     }
     return $collection;
 }
 /**
  * Extracts collected route collections from the message response.
  * @param \Brickoo\Component\Common\ArrayList $messageResponseList
  * @return \Brickoo\Component\Common\Collection
  */
 private function extractRouteCollections(ArrayList $messageResponseList)
 {
     $collection = new Collection();
     foreach ($messageResponseList as $item) {
         if ($item instanceof RouteCollection) {
             $collection->add($item);
         }
     }
     return $collection;
 }
 /** {@inheritDoc} */
 public function collect()
 {
     $filePaths = $this->collectRouteCollectionsFilePaths();
     $collection = new Collection();
     foreach ($filePaths as $filePath) {
         if (($routeCollection = $this->getRouteCollectionFromFilePath($filePath)) && $routeCollection instanceof RouteCollection) {
             $collection->add($routeCollection);
         }
     }
     return $collection;
 }
<?php

use Brickoo\Component\Annotation\Annotation;
use Brickoo\Component\Annotation\Definition\AnnotationDefinition;
use Brickoo\Component\Annotation\Definition\AnnotationParameterDefinition;
use Brickoo\Component\Common\Collection;
/**
 * Definition annotations:
 * @Controller (path = "/")
 * @Route (path = "/list")
 * @Assert (maxlength = 30)
 */
$collection = new Collection();
$annotation = new AnnotationDefinition("Controller", Annotation::TARGET_CLASS);
$annotation->addParameter(new AnnotationParameterDefinition("path", "string"));
$collection->add($annotation);
$annotation = new AnnotationDefinition("Route", Annotation::TARGET_METHOD);
$annotation->addParameter(new AnnotationParameterDefinition("path", "string"));
$collection->add($annotation);
$annotation = new AnnotationDefinition("Assert", Annotation::TARGET_PROPERTY);
$annotation->addParameter(new AnnotationParameterDefinition("maxlength", "integer"));
$collection->add($annotation);
return $collection;
Example #6
0
 /**
  * @covers Brickoo\Component\Common\Collection::toArray
  * @covers Brickoo\Component\Common\Collection::getIterator
  */
 public function testCollectionItemsCanBeExported()
 {
     $collection = new Collection(["a", "b", "c"]);
     $this->assertEquals(["a", "b", "c"], $collection->toArray());
     $iterator = $collection->getIterator();
     $this->assertEquals(["a", "b", "c"], $iterator->getArrayCopy());
 }