Initial commit with Symfony 2.1+Vendors
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
42
vendor/jms/metadata/src/Metadata/Driver/AbstractFileDriver.php
vendored
Normal file
42
vendor/jms/metadata/src/Metadata/Driver/AbstractFileDriver.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
/**
|
||||
* Base file driver implementation.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class AbstractFileDriver implements DriverInterface
|
||||
{
|
||||
private $locator;
|
||||
|
||||
public function __construct(FileLocatorInterface $locator)
|
||||
{
|
||||
$this->locator = $locator;
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(\ReflectionClass $class)
|
||||
{
|
||||
if (null === $path = $this->locator->findFileForClass($class, $this->getExtension())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->loadMetadataFromFile($class, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the content of the file, and converts it to the desired metadata.
|
||||
*
|
||||
* @param string $file
|
||||
* @return ClassMetadata|null
|
||||
*/
|
||||
abstract protected function loadMetadataFromFile(\ReflectionClass $class, $file);
|
||||
|
||||
/**
|
||||
* Returns the extension of the file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getExtension();
|
||||
}
|
40
vendor/jms/metadata/src/Metadata/Driver/DriverChain.php
vendored
Normal file
40
vendor/jms/metadata/src/Metadata/Driver/DriverChain.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
final class DriverChain implements DriverInterface
|
||||
{
|
||||
private $drivers;
|
||||
|
||||
public function __construct(array $drivers)
|
||||
{
|
||||
$this->drivers = $drivers;
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(\ReflectionClass $class)
|
||||
{
|
||||
foreach ($this->drivers as $driver) {
|
||||
if (null !== $metadata = $driver->loadMetadataForClass($class)) {
|
||||
return $metadata;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
24
vendor/jms/metadata/src/Metadata/Driver/DriverInterface.php
vendored
Normal file
24
vendor/jms/metadata/src/Metadata/Driver/DriverInterface.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
interface DriverInterface
|
||||
{
|
||||
function loadMetadataForClass(\ReflectionClass $class);
|
||||
}
|
29
vendor/jms/metadata/src/Metadata/Driver/FileLocator.php
vendored
Normal file
29
vendor/jms/metadata/src/Metadata/Driver/FileLocator.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
class FileLocator implements FileLocatorInterface
|
||||
{
|
||||
private $dirs;
|
||||
|
||||
public function __construct(array $dirs)
|
||||
{
|
||||
$this->dirs = $dirs;
|
||||
}
|
||||
|
||||
public function findFileForClass(\ReflectionClass $class, $extension)
|
||||
{
|
||||
foreach ($this->dirs as $prefix => $dir) {
|
||||
if (0 !== strpos($class->getNamespaceName(), $prefix)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $dir.'/'.str_replace('\\', '.', substr($class->getName(), strlen($prefix)+1)).'.'.$extension;
|
||||
if (file_exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
8
vendor/jms/metadata/src/Metadata/Driver/FileLocatorInterface.php
vendored
Normal file
8
vendor/jms/metadata/src/Metadata/Driver/FileLocatorInterface.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
interface FileLocatorInterface
|
||||
{
|
||||
function findFileForClass(\ReflectionClass $class, $extension);
|
||||
}
|
22
vendor/jms/metadata/src/Metadata/Driver/LazyLoadingDriver.php
vendored
Normal file
22
vendor/jms/metadata/src/Metadata/Driver/LazyLoadingDriver.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Metadata\Driver;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class LazyLoadingDriver implements DriverInterface
|
||||
{
|
||||
private $container;
|
||||
private $realDriverId;
|
||||
|
||||
public function __construct(ContainerInterface $container, $realDriverId)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->realDriverId = $realDriverId;
|
||||
}
|
||||
|
||||
public function loadMetadataForClass(\ReflectionClass $class)
|
||||
{
|
||||
return $this->container->get($this->realDriverId)->loadMetadataForClass($class);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user