/**
  * @inheritdoc
  */
 public function supports(Resource $resource, Resource $parentResource)
 {
     if ($resource->hasMetadata('file') && 0 === strpos(parse_url($resource->getMetadata('file'), PHP_URL_PATH), '/')) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function supports(Resource $resource)
 {
     if (!$resource->hasMetadata('data')) {
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function open(Resource $resource)
 {
     $this->data = $resource->getMetadata('data');
     if (!is_array($this->data)) {
         throw new \InvalidArgumentException('Resource "data" metadata is not an array');
     }
 }
 /**
  * @inheritdoc
  */
 public function supports($data, Resource $resource)
 {
     if ($resource->hasType('type') && 'annotation' == $resource->getType()) {
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function read(Resource $resource)
 {
     $file = $resource->getMetadata('file');
     if (!is_file($file)) {
         throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file));
     }
     return file_get_contents($file);
 }
 /**
  * @inheritdoc
  */
 public function supports($data, Resource $resource)
 {
     if ($resource->hasType('type')) {
         if ('ini' == $resource->getType()) {
             return true;
         }
         return false;
     }
     if ($resource->hasMetadata('file') && in_array(pathinfo($resource->getMetadata('file'), PATHINFO_EXTENSION), array('ini'))) {
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function open(Resource $resource)
 {
     $file = $resource->getMetadata('file');
     if (!is_file($file)) {
         throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file));
     }
     try {
         $data = (array) Yaml::parse($file);
     } catch (\Exception $e) {
         throw new \InvalidArgumentException($e->getMessage(), 0, $e);
     }
     $this->inMemoryReader = new InMemoryReader();
     $this->inMemoryReader->open(new Resource(array('data' => $data), 'in_memory'));
 }
Exemplo n.º 8
0
 /**
  * @covers Yosmanyga\Resource\Resource::setMetadata
  * @covers Yosmanyga\Resource\Resource::getMetadata
  * @covers Yosmanyga\Resource\Resource::hasMetadata
  * @covers Yosmanyga\Resource\Resource::setType
  * @covers Yosmanyga\Resource\Resource::getType
  * @covers Yosmanyga\Resource\Resource::hasType
  */
 public function testAccessors()
 {
     $resource = new Resource();
     $resource->setMetadata('foo1', 'bar1');
     $resource->setMetadata('foo2', 'bar2');
     $resource->setType('foo');
     $this->assertTrue($resource->hasMetadata('foo1'));
     $this->assertEquals('bar1', $resource->getMetadata('foo1'));
     $this->assertEquals(array('foo1' => 'bar1', 'foo2' => 'bar2'), $resource->getMetadata());
     $this->assertFalse($resource->hasMetadata('foo3'));
     $this->assertEquals('foo', $resource->getType());
     $this->assertTrue($resource->hasType());
     $resource = new Resource();
     $this->assertFalse($resource->hasType());
 }
Exemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function open(Resource $resource)
 {
     $file = $resource->getMetadata('file');
     if (!is_file($file)) {
         throw new \InvalidArgumentException(sprintf('File "%s" not found.', $file));
     }
     $this->xmlReader = new \XmlReader();
     $this->xmlReader->open($file);
     // Try to move pointer to first node inside root tag
     try {
         while ($this->xmlReader->read()) {
             $name = $this->xmlReader->name;
             $depth = $this->xmlReader->depth;
             if (1 == $depth && !in_array($name, array("", "#text"))) {
                 break;
             }
         }
     } catch (\Exception $e) {
         throw new \InvalidArgumentException($e->getMessage(), 0, $e);
     }
 }
Exemplo n.º 10
0
 private function calculateDirVersion(Resource $resource)
 {
     // Adjust finder
     $dir = $resource->getMetadata('dir');
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException(sprintf('Directory "%s" not found.', $dir));
     }
     $this->finder->files()->in($dir);
     if ($resource->hasMetadata('filter')) {
         $this->finder->name($resource->getMetadata('filter'));
     }
     if ($resource->hasMetadata('depth')) {
         $this->finder->depth($resource->getMetadata('depth'));
     } else {
         $this->finder->depth('>= 0');
     }
     $version = array();
     /** @var \SplFileInfo $file */
     foreach ($this->finder->getIterator() as $file) {
         $version[md5($file->getRealPath())] = filemtime($file);
     }
     return $version;
 }
 /**
  * @inheritdoc
  */
 public function transform(Resource $resource, Resource $parentResource)
 {
     list($vendor, $path) = $this->parseFile($resource->getMetadata('file'));
     $file = sprintf("%s/%s/%s%s", dirname(dirname($this->file)), $vendor, $this->resolveSrc($vendor), $path);
     return new Resource(array('file' => $file));
 }
Exemplo n.º 12
0
 /**
  * @param  \Yosmanyga\Resource\Resource $resource
  * @param  \SplFileInfo                 $file
  * @return \Yosmanyga\Resource\Resource
  */
 private function convertResource(Resource $resource, \SplFileInfo $file)
 {
     return new Resource(array_merge($resource->getMetadata(), array('file' => $file->getRealpath())), $resource->getMetadata('type'));
 }
 /**
  * @inheritdoc
  */
 public function transform(Resource $resource, Resource $parentResource)
 {
     $file = sprintf("%s/%s", dirname($parentResource->getMetadata('file')), $resource->getMetadata('dir'));
     return new Resource(array('file' => $file));
 }
Exemplo n.º 14
0
 /**
  * @param  \Yosmanyga\Resource\Resource $resource
  * @return \Yosmanyga\Resource\Resource
  */
 private function convertResource(Resource $resource)
 {
     return new Resource($resource->getMetadata(), $resource->getMetadata('type'));
 }