Initial commit with Symfony 2.1+Vendors

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Polonkai Gergely
2012-07-01 09:52:20 +02:00
commit 082a0130c2
5381 changed files with 416709 additions and 0 deletions

View 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();
}

View 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;
}
}

View 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);
}

View 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;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Metadata\Driver;
interface FileLocatorInterface
{
function findFileForClass(\ReflectionClass $class, $extension);
}

View 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);
}
}