Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
19
vendor/doctrine/annotations/LICENSE
vendored
19
vendor/doctrine/annotations/LICENSE
vendored
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
19
vendor/doctrine/annotations/README.md
vendored
19
vendor/doctrine/annotations/README.md
vendored
|
@ -1,19 +0,0 @@
|
|||
# Doctrine Annotations
|
||||
|
||||
[](https://travis-ci.org/doctrine/annotations)
|
||||
|
||||
Docblock Annotations Parser library (extracted from [Doctrine Common](https://github.com/doctrine/common)).
|
||||
|
||||
## Changelog
|
||||
|
||||
### v1.2.0
|
||||
|
||||
* HHVM support
|
||||
* Allowing dangling comma in annotations
|
||||
* Excluded annotations are no longer autoloaded
|
||||
* Importing namespaces also in traits
|
||||
* Added support for `::class` 5.5-style constant, works also in 5.3 and 5.4
|
||||
|
||||
### v1.1
|
||||
|
||||
* Add Exception when ZendOptimizer+ or Opcache is configured to drop comments
|
31
vendor/doctrine/annotations/composer.json
vendored
31
vendor/doctrine/annotations/composer.json
vendored
|
@ -1,31 +0,0 @@
|
|||
{
|
||||
"name": "doctrine/annotations",
|
||||
"type": "library",
|
||||
"description": "Docblock Annotations Parser",
|
||||
"keywords": ["annotations", "docblock", "parser"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"doctrine/lexer": "1.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "1.*",
|
||||
"phpunit/phpunit": "4.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\Common\\Annotations\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.3.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Annotations class.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Annotation
|
||||
{
|
||||
/**
|
||||
* Value property. Common among all derived classes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $data Key-value for properties to be defined in this class.
|
||||
*/
|
||||
public final function __construct(array $data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property accessor in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
throw new \BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error handler for unknown property mutator in Annotation class.
|
||||
*
|
||||
* @param string $name Unknown property name.
|
||||
* @param mixed $value Property value.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
throw new \BadMethodCallException(
|
||||
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the attribute type during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attribute
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $required = false;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the types of all declared attributes during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Attributes
|
||||
{
|
||||
/**
|
||||
* @var array<Doctrine\Common\Annotations\Annotation\Attribute>
|
||||
*/
|
||||
public $value;
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the available values during the parsing process.
|
||||
*
|
||||
* @since 2.4
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
* @Attributes({
|
||||
* @Attribute("value", required = true, type = "array"),
|
||||
* @Attribute("literal", required = false, type = "array")
|
||||
* })
|
||||
*/
|
||||
final class Enum
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* Annotation constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if ( ! isset($values['literal'])) {
|
||||
$values['literal'] = array();
|
||||
}
|
||||
|
||||
foreach ($values['value'] as $var) {
|
||||
if( ! is_scalar($var)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'@Enum supports only scalar values "%s" given.',
|
||||
is_object($var) ? get_class($var) : gettype($var)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($values['literal'] as $key => $var) {
|
||||
if( ! in_array($key, $values['value'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Undefined enumerator value "%s" for literal "%s".',
|
||||
$key , $var
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->value = $values['value'];
|
||||
$this->literal = $values['literal'];
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser to ignore specific
|
||||
* annotations during the parsing process.
|
||||
*
|
||||
* @Annotation
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
final class IgnoreAnnotation
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $names;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (is_string($values['value'])) {
|
||||
$values['value'] = array($values['value']);
|
||||
}
|
||||
if (!is_array($values['value'])) {
|
||||
throw new \RuntimeException(sprintf('@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.', json_encode($values['value'])));
|
||||
}
|
||||
|
||||
$this->names = $values['value'];
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check if that attribute is required during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Required
|
||||
{
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* Annotation that can be used to signal to the parser
|
||||
* to check the annotation target during the parsing process.
|
||||
*
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
final class Target
|
||||
{
|
||||
const TARGET_CLASS = 1;
|
||||
const TARGET_METHOD = 2;
|
||||
const TARGET_PROPERTY = 4;
|
||||
const TARGET_ANNOTATION = 8;
|
||||
const TARGET_ALL = 15;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $map = array(
|
||||
'ALL' => self::TARGET_ALL,
|
||||
'CLASS' => self::TARGET_CLASS,
|
||||
'METHOD' => self::TARGET_METHOD,
|
||||
'PROPERTY' => self::TARGET_PROPERTY,
|
||||
'ANNOTATION' => self::TARGET_ANNOTATION,
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Targets as bitmask.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $targets;
|
||||
|
||||
/**
|
||||
* Literal target declaration.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $literal;
|
||||
|
||||
/**
|
||||
* Annotation constructor.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
if (!isset($values['value'])){
|
||||
$values['value'] = null;
|
||||
}
|
||||
if (is_string($values['value'])){
|
||||
$values['value'] = array($values['value']);
|
||||
}
|
||||
if (!is_array($values['value'])){
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('@Target expects either a string value, or an array of strings, "%s" given.',
|
||||
is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$bitmask = 0;
|
||||
foreach ($values['value'] as $literal) {
|
||||
if(!isset(self::$map[$literal])){
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Invalid Target "%s". Available targets: [%s]',
|
||||
$literal, implode(', ', array_keys(self::$map)))
|
||||
);
|
||||
}
|
||||
$bitmask |= self::$map[$literal];
|
||||
}
|
||||
|
||||
$this->targets = $bitmask;
|
||||
$this->value = $values['value'];
|
||||
$this->literal = implode(', ', $this->value);
|
||||
}
|
||||
}
|
|
@ -1,197 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Description of AnnotationException
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class AnnotationException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Syntax error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function syntaxError($message)
|
||||
{
|
||||
return new self('[Syntax Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a Semantical error.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalError($message)
|
||||
{
|
||||
return new self('[Semantical Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an error which occurred during
|
||||
* the creation of the annotation.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function creationError($message)
|
||||
{
|
||||
return new self('[Creation Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a type error.
|
||||
*
|
||||
* @since 1.1
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function typeError($message)
|
||||
{
|
||||
return new self('[Type Error] ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a constant semantical error.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @param string $identifier
|
||||
* @param string $context
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function semanticalErrorConstants($identifier, $context = null)
|
||||
{
|
||||
return self::semanticalError(sprintf(
|
||||
"Couldn't find constant %s%s.",
|
||||
$identifier,
|
||||
$context ? ', ' . $context : ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an type error of an attribute.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected,
|
||||
is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing an required error of an attribute.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param string $expected
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function requiredError($attributeName, $annotationName, $context, $expected)
|
||||
{
|
||||
return self::typeError(sprintf(
|
||||
'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
$expected
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AnnotationException describing a invalid enummerator.
|
||||
*
|
||||
* @since 2.4
|
||||
*
|
||||
* @param string $attributeName
|
||||
* @param string $annotationName
|
||||
* @param string $context
|
||||
* @param array $available
|
||||
* @param mixed $given
|
||||
*
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
|
||||
$attributeName,
|
||||
$annotationName,
|
||||
$context,
|
||||
implode(', ', $available),
|
||||
is_object($given) ? get_class($given) : $given
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function optimizerPlusSaveComments()
|
||||
{
|
||||
return new self(
|
||||
"You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AnnotationException
|
||||
*/
|
||||
public static function optimizerPlusLoadComments()
|
||||
{
|
||||
return new self(
|
||||
"You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,394 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* A reader for docblock annotations.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AnnotationReader implements Reader
|
||||
{
|
||||
/**
|
||||
* Global map for imports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $globalImports = array(
|
||||
'ignoreannotation' => 'Doctrine\Common\Annotations\Annotation\IgnoreAnnotation',
|
||||
);
|
||||
|
||||
/**
|
||||
* A list with annotations that are not causing exceptions when not resolved to an annotation class.
|
||||
*
|
||||
* The names are case sensitive.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $globalIgnoredNames = array(
|
||||
// Annotation tags
|
||||
'Annotation' => true, 'Attribute' => true, 'Attributes' => true,
|
||||
/* Can we enable this? 'Enum' => true, */
|
||||
'Required' => true,
|
||||
'Target' => true,
|
||||
// Widely used tags (but not existent in phpdoc)
|
||||
'fix' => true , 'fixme' => true,
|
||||
'override' => true,
|
||||
// PHPDocumentor 1 tags
|
||||
'abstract'=> true, 'access'=> true,
|
||||
'code' => true,
|
||||
'deprec'=> true,
|
||||
'endcode' => true, 'exception'=> true,
|
||||
'final'=> true,
|
||||
'ingroup' => true, 'inheritdoc'=> true, 'inheritDoc'=> true,
|
||||
'magic' => true,
|
||||
'name'=> true,
|
||||
'toc' => true, 'tutorial'=> true,
|
||||
'private' => true,
|
||||
'static'=> true, 'staticvar'=> true, 'staticVar'=> true,
|
||||
'throw' => true,
|
||||
// PHPDocumentor 2 tags.
|
||||
'api' => true, 'author'=> true,
|
||||
'category'=> true, 'copyright'=> true,
|
||||
'deprecated'=> true,
|
||||
'example'=> true,
|
||||
'filesource'=> true,
|
||||
'global'=> true,
|
||||
'ignore'=> true, /* Can we enable this? 'index' => true, */ 'internal'=> true,
|
||||
'license'=> true, 'link'=> true,
|
||||
'method' => true,
|
||||
'package'=> true, 'param'=> true, 'property' => true, 'property-read' => true, 'property-write' => true,
|
||||
'return'=> true,
|
||||
'see'=> true, 'since'=> true, 'source' => true, 'subpackage'=> true,
|
||||
'throws'=> true, 'todo'=> true, 'TODO'=> true,
|
||||
'usedby'=> true, 'uses' => true,
|
||||
'var'=> true, 'version'=> true,
|
||||
// PHPUnit tags
|
||||
'codeCoverageIgnore' => true, 'codeCoverageIgnoreStart' => true, 'codeCoverageIgnoreEnd' => true,
|
||||
// PHPCheckStyle
|
||||
'SuppressWarnings' => true,
|
||||
// PHPStorm
|
||||
'noinspection' => true,
|
||||
// PEAR
|
||||
'package_version' => true,
|
||||
// PlantUML
|
||||
'startuml' => true, 'enduml' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Add a new annotation to the globally ignored annotation names with regard to exception handling.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
static public function addGlobalIgnoredName($name)
|
||||
{
|
||||
self::$globalIgnoredNames[$name] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotations parser.
|
||||
*
|
||||
* @var \Doctrine\Common\Annotations\DocParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Annotations parser used to collect parsing metadata.
|
||||
*
|
||||
* @var \Doctrine\Common\Annotations\DocParser
|
||||
*/
|
||||
private $preParser;
|
||||
|
||||
/**
|
||||
* PHP parser used to collect imports.
|
||||
*
|
||||
* @var \Doctrine\Common\Annotations\PhpParser
|
||||
*/
|
||||
private $phpParser;
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store imported annotations per class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $imports = array();
|
||||
|
||||
/**
|
||||
* In-memory cache mechanism to store ignored annotations per class.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $ignoredAnnotationNames = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Initializes a new AnnotationReader.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') == 0) {
|
||||
throw AnnotationException::optimizerPlusSaveComments();
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 70000) {
|
||||
if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.load_comments') === "0" || ini_get('opcache.load_comments') === "0")) {
|
||||
throw AnnotationException::optimizerPlusLoadComments();
|
||||
}
|
||||
|
||||
if (extension_loaded('Zend OPcache') && ini_get('opcache.load_comments') == 0) {
|
||||
throw AnnotationException::optimizerPlusLoadComments();
|
||||
}
|
||||
}
|
||||
|
||||
AnnotationRegistry::registerFile(__DIR__ . '/Annotation/IgnoreAnnotation.php');
|
||||
|
||||
$this->parser = new DocParser;
|
||||
$this->preParser = new DocParser;
|
||||
|
||||
$this->preParser->setImports(self::$globalImports);
|
||||
$this->preParser->setIgnoreNotImportedAnnotations(true);
|
||||
|
||||
$this->phpParser = new PhpParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(ReflectionClass $class)
|
||||
{
|
||||
$this->parser->setTarget(Target::TARGET_CLASS);
|
||||
$this->parser->setImports($this->getClassImports($class));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
|
||||
return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(ReflectionClass $class, $annotationName)
|
||||
{
|
||||
$annotations = $this->getClassAnnotations($class);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$context = 'property ' . $class->getName() . "::\$" . $property->getName();
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_PROPERTY);
|
||||
$this->parser->setImports($this->getPropertyImports($property));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
|
||||
return $this->parser->parse($property->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
$annotations = $this->getPropertyAnnotations($property);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
|
||||
|
||||
$this->parser->setTarget(Target::TARGET_METHOD);
|
||||
$this->parser->setImports($this->getMethodImports($method));
|
||||
$this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
|
||||
|
||||
return $this->parser->parse($method->getDocComment(), $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
$annotations = $this->getMethodAnnotations($method);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignored annotations for the given class.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getIgnoredAnnotationNames(ReflectionClass $class)
|
||||
{
|
||||
if (isset($this->ignoredAnnotationNames[$name = $class->getName()])) {
|
||||
return $this->ignoredAnnotationNames[$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($class);
|
||||
|
||||
return $this->ignoredAnnotationNames[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getClassImports(ReflectionClass $class)
|
||||
{
|
||||
if (isset($this->imports[$name = $class->getName()])) {
|
||||
return $this->imports[$name];
|
||||
}
|
||||
|
||||
$this->collectParsingMetadata($class);
|
||||
|
||||
return $this->imports[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for methods.
|
||||
*
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getMethodImports(ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$classImports = $this->getClassImports($class);
|
||||
if (!method_exists($class, 'getTraits')) {
|
||||
return $classImports;
|
||||
}
|
||||
|
||||
$traitImports = array();
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($method->getName())
|
||||
&& $trait->getFileName() === $method->getFileName()
|
||||
) {
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves imports for properties.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getPropertyImports(ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$classImports = $this->getClassImports($class);
|
||||
if (!method_exists($class, 'getTraits')) {
|
||||
return $classImports;
|
||||
}
|
||||
|
||||
$traitImports = array();
|
||||
|
||||
foreach ($class->getTraits() as $trait) {
|
||||
if ($trait->hasProperty($property->getName())) {
|
||||
$traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($classImports, $traitImports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parsing metadata for a given class.
|
||||
*
|
||||
* @param \ReflectionClass $class
|
||||
*/
|
||||
private function collectParsingMetadata(ReflectionClass $class)
|
||||
{
|
||||
$ignoredAnnotationNames = self::$globalIgnoredNames;
|
||||
$annotations = $this->preParser->parse($class->getDocComment(), 'class ' . $class->name);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof IgnoreAnnotation) {
|
||||
foreach ($annotation->names AS $annot) {
|
||||
$ignoredAnnotationNames[$annot] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$name = $class->getName();
|
||||
|
||||
$this->imports[$name] = array_merge(
|
||||
self::$globalImports,
|
||||
$this->phpParser->parseClass($class),
|
||||
array('__NAMESPACE__' => $class->getNamespaceName())
|
||||
);
|
||||
|
||||
$this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* AnnotationRegistry.
|
||||
*/
|
||||
final class AnnotationRegistry
|
||||
{
|
||||
/**
|
||||
* A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
|
||||
*
|
||||
* Contains the namespace as key and an array of directories as value. If the value is NULL
|
||||
* the include path is used for checking for the corresponding file.
|
||||
*
|
||||
* This autoloading mechanism does not utilize the PHP autoloading but implements autoloading on its own.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static private $autoloadNamespaces = array();
|
||||
|
||||
/**
|
||||
* A map of autoloader callables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static private $loaders = array();
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
static public function reset()
|
||||
{
|
||||
self::$autoloadNamespaces = array();
|
||||
self::$loaders = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers file.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function registerFile($file)
|
||||
{
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace with one or many directories to look for files or null for the include path.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string|array|null $dirs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function registerAutoloadNamespace($namespace, $dirs = null)
|
||||
{
|
||||
self::$autoloadNamespaces[$namespace] = $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers multiple namespaces.
|
||||
*
|
||||
* Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
|
||||
*
|
||||
* @param array $namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static public function registerAutoloadNamespaces(array $namespaces)
|
||||
{
|
||||
self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an autoloading callable for annotations, much like spl_autoload_register().
|
||||
*
|
||||
* NOTE: These class loaders HAVE to be silent when a class was not found!
|
||||
* IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class.
|
||||
*
|
||||
* @param callable $callable
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
static public function registerLoader($callable)
|
||||
{
|
||||
if (!is_callable($callable)) {
|
||||
throw new \InvalidArgumentException("A callable is expected in AnnotationRegistry::registerLoader().");
|
||||
}
|
||||
self::$loaders[] = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloads an annotation class silently.
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
static public function loadAnnotationClass($class)
|
||||
{
|
||||
foreach (self::$autoloadNamespaces AS $namespace => $dirs) {
|
||||
if (strpos($class, $namespace) === 0) {
|
||||
$file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
|
||||
if ($dirs === null) {
|
||||
if ($path = stream_resolve_include_path($file)) {
|
||||
require $path;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
foreach((array)$dirs AS $dir) {
|
||||
if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
|
||||
require $dir . DIRECTORY_SEPARATOR . $file;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::$loaders AS $loader) {
|
||||
if (call_user_func($loader, $class) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,235 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
|
||||
/**
|
||||
* A cache aware annotation reader.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
final class CachedReader implements Reader
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $CACHE_SALT = '@[Annot]';
|
||||
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $delegate;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $loadedAnnotations = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Reader $reader
|
||||
* @param Cache $cache
|
||||
* @param bool $debug
|
||||
*/
|
||||
public function __construct(Reader $reader, Cache $cache, $debug = false)
|
||||
{
|
||||
$this->delegate = $reader;
|
||||
$this->cache = $cache;
|
||||
$this->debug = (boolean) $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(\ReflectionClass $class)
|
||||
{
|
||||
$cacheKey = $class->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
|
||||
$annots = $this->delegate->getClassAnnotations($class);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(\ReflectionClass $class, $annotationName)
|
||||
{
|
||||
foreach ($this->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(\ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
$cacheKey = $class->getName().'$'.$property->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
|
||||
$annots = $this->delegate->getPropertyAnnotations($property);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
foreach ($this->getPropertyAnnotations($property) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(\ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
$cacheKey = $class->getName().'#'.$method->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$cacheKey])) {
|
||||
return $this->loadedAnnotations[$cacheKey];
|
||||
}
|
||||
|
||||
if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
|
||||
$annots = $this->delegate->getMethodAnnotations($method);
|
||||
$this->saveToCache($cacheKey, $annots);
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$cacheKey] = $annots;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
foreach ($this->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears loaded annotations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearLoadedAnnotations()
|
||||
{
|
||||
$this->loadedAnnotations = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a value from the cache.
|
||||
*
|
||||
* @param string $rawCacheKey The cache key.
|
||||
* @param \ReflectionClass $class The related class.
|
||||
*
|
||||
* @return mixed The cached value or false when the value is not in cache.
|
||||
*/
|
||||
private function fetchFromCache($rawCacheKey, \ReflectionClass $class)
|
||||
{
|
||||
$cacheKey = $rawCacheKey . self::$CACHE_SALT;
|
||||
if (($data = $this->cache->fetch($cacheKey)) !== false) {
|
||||
if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a value to the cache.
|
||||
*
|
||||
* @param string $rawCacheKey The cache key.
|
||||
* @param mixed $value The value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function saveToCache($rawCacheKey, $value)
|
||||
{
|
||||
$cacheKey = $rawCacheKey . self::$CACHE_SALT;
|
||||
$this->cache->save($cacheKey, $value);
|
||||
if ($this->debug) {
|
||||
$this->cache->save('[C]'.$cacheKey, time());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the cache is fresh.
|
||||
*
|
||||
* @param string $cacheKey
|
||||
* @param \ReflectionClass $class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isCacheFresh($cacheKey, \ReflectionClass $class)
|
||||
{
|
||||
if (false === $filename = $class->getFilename()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->cache->fetch('[C]'.$cacheKey) >= filemtime($filename);
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
/**
|
||||
* Simple lexer for docblock annotations.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
final class DocLexer extends AbstractLexer
|
||||
{
|
||||
const T_NONE = 1;
|
||||
const T_INTEGER = 2;
|
||||
const T_STRING = 3;
|
||||
const T_FLOAT = 4;
|
||||
|
||||
// All tokens that are also identifiers should be >= 100
|
||||
const T_IDENTIFIER = 100;
|
||||
const T_AT = 101;
|
||||
const T_CLOSE_CURLY_BRACES = 102;
|
||||
const T_CLOSE_PARENTHESIS = 103;
|
||||
const T_COMMA = 104;
|
||||
const T_EQUALS = 105;
|
||||
const T_FALSE = 106;
|
||||
const T_NAMESPACE_SEPARATOR = 107;
|
||||
const T_OPEN_CURLY_BRACES = 108;
|
||||
const T_OPEN_PARENTHESIS = 109;
|
||||
const T_TRUE = 110;
|
||||
const T_NULL = 111;
|
||||
const T_COLON = 112;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $noCase = array(
|
||||
'@' => self::T_AT,
|
||||
',' => self::T_COMMA,
|
||||
'(' => self::T_OPEN_PARENTHESIS,
|
||||
')' => self::T_CLOSE_PARENTHESIS,
|
||||
'{' => self::T_OPEN_CURLY_BRACES,
|
||||
'}' => self::T_CLOSE_CURLY_BRACES,
|
||||
'=' => self::T_EQUALS,
|
||||
':' => self::T_COLON,
|
||||
'\\' => self::T_NAMESPACE_SEPARATOR
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $withCase = array(
|
||||
'true' => self::T_TRUE,
|
||||
'false' => self::T_FALSE,
|
||||
'null' => self::T_NULL
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return array(
|
||||
'[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
|
||||
'(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
|
||||
'"(?:""|[^"])*+"',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return array('\s+', '\*+', '(.)');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
$type = self::T_NONE;
|
||||
|
||||
if ($value[0] === '"') {
|
||||
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
|
||||
|
||||
return self::T_STRING;
|
||||
}
|
||||
|
||||
if (isset($this->noCase[$value])) {
|
||||
return $this->noCase[$value];
|
||||
}
|
||||
|
||||
if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
|
||||
return self::T_IDENTIFIER;
|
||||
}
|
||||
|
||||
$lowerValue = strtolower($value);
|
||||
|
||||
if (isset($this->withCase[$lowerValue])) {
|
||||
return $this->withCase[$lowerValue];
|
||||
}
|
||||
|
||||
// Checking numeric value
|
||||
if (is_numeric($value)) {
|
||||
return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
|
||||
? self::T_FLOAT : self::T_INTEGER;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,288 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* File cache reader for annotations.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*
|
||||
* @deprecated the FileCacheReader is deprecated and will be removed
|
||||
* in version 2.0.0 of doctrine/annotations. Please use the
|
||||
* {@see \Doctrine\Common\Annotations\CachedReader} instead.
|
||||
*/
|
||||
class FileCacheReader implements Reader
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $reader;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dir;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $loadedAnnotations = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $classNameHashes = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $umask;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Reader $reader
|
||||
* @param string $cacheDir
|
||||
* @param boolean $debug
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = 0002)
|
||||
{
|
||||
if ( ! is_int($umask)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The parameter umask must be an integer, was: %s',
|
||||
gettype($umask)
|
||||
));
|
||||
}
|
||||
|
||||
$this->reader = $reader;
|
||||
$this->umask = $umask;
|
||||
|
||||
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777 & (~$this->umask), true)) {
|
||||
throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $cacheDir));
|
||||
}
|
||||
|
||||
$this->dir = rtrim($cacheDir, '\\/');
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(\ReflectionClass $class)
|
||||
{
|
||||
if ( ! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
$key = $this->classNameHashes[$class->name];
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
|
||||
if (!is_file($path)) {
|
||||
$annot = $this->reader->getClassAnnotations($class);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
if ($this->debug
|
||||
&& (false !== $filename = $class->getFilename())
|
||||
&& filemtime($path) < filemtime($filename)) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getClassAnnotations($class);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(\ReflectionProperty $property)
|
||||
{
|
||||
$class = $property->getDeclaringClass();
|
||||
if ( ! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
$key = $this->classNameHashes[$class->name].'$'.$property->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
|
||||
if (!is_file($path)) {
|
||||
$annot = $this->reader->getPropertyAnnotations($property);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
if ($this->debug
|
||||
&& (false !== $filename = $class->getFilename())
|
||||
&& filemtime($path) < filemtime($filename)) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getPropertyAnnotations($property);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(\ReflectionMethod $method)
|
||||
{
|
||||
$class = $method->getDeclaringClass();
|
||||
if ( ! isset($this->classNameHashes[$class->name])) {
|
||||
$this->classNameHashes[$class->name] = sha1($class->name);
|
||||
}
|
||||
$key = $this->classNameHashes[$class->name].'#'.$method->getName();
|
||||
|
||||
if (isset($this->loadedAnnotations[$key])) {
|
||||
return $this->loadedAnnotations[$key];
|
||||
}
|
||||
|
||||
$path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
|
||||
if (!is_file($path)) {
|
||||
$annot = $this->reader->getMethodAnnotations($method);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
if ($this->debug
|
||||
&& (false !== $filename = $class->getFilename())
|
||||
&& filemtime($path) < filemtime($filename)) {
|
||||
@unlink($path);
|
||||
|
||||
$annot = $this->reader->getMethodAnnotations($method);
|
||||
$this->saveCacheFile($path, $annot);
|
||||
return $this->loadedAnnotations[$key] = $annot;
|
||||
}
|
||||
|
||||
return $this->loadedAnnotations[$key] = include $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the cache file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function saveCacheFile($path, $data)
|
||||
{
|
||||
if (!is_writable($this->dir)) {
|
||||
throw new \InvalidArgumentException(sprintf('The directory "%s" is not writable. Both, the webserver and the console user need access. You can manage access rights for multiple users with "chmod +a". If your system does not support this, check out the acl package.', $this->dir));
|
||||
}
|
||||
|
||||
$tempfile = tempnam($this->dir, uniqid('', true));
|
||||
|
||||
if (false === $tempfile) {
|
||||
throw new \RuntimeException(sprintf('Unable to create tempfile in directory: %s', $this->dir));
|
||||
}
|
||||
|
||||
$written = file_put_contents($tempfile, '<?php return unserialize('.var_export(serialize($data), true).');');
|
||||
|
||||
if (false === $written) {
|
||||
throw new \RuntimeException(sprintf('Unable to write cached file to: %s', $tempfile));
|
||||
}
|
||||
|
||||
@chmod($tempfile, 0666 & (~$this->umask));
|
||||
|
||||
if (false === rename($tempfile, $path)) {
|
||||
@unlink($tempfile);
|
||||
throw new \RuntimeException(sprintf('Unable to rename %s to %s', $tempfile, $path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(\ReflectionClass $class, $annotationName)
|
||||
{
|
||||
$annotations = $this->getClassAnnotations($class);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
$annotations = $this->getMethodAnnotations($method);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
$annotations = $this->getPropertyAnnotations($property);
|
||||
|
||||
foreach ($annotations as $annotation) {
|
||||
if ($annotation instanceof $annotationName) {
|
||||
return $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears loaded annotations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearLoadedAnnotations()
|
||||
{
|
||||
$this->loadedAnnotations = array();
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Allows the reader to be used in-place of Doctrine's reader.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class IndexedReader implements Reader
|
||||
{
|
||||
/**
|
||||
* @var Reader
|
||||
*/
|
||||
private $delegate;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Reader $reader
|
||||
*/
|
||||
public function __construct(Reader $reader)
|
||||
{
|
||||
$this->delegate = $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(\ReflectionClass $class)
|
||||
{
|
||||
$annotations = array();
|
||||
foreach ($this->delegate->getClassAnnotations($class) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(\ReflectionClass $class, $annotation)
|
||||
{
|
||||
return $this->delegate->getClassAnnotation($class, $annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(\ReflectionMethod $method)
|
||||
{
|
||||
$annotations = array();
|
||||
foreach ($this->delegate->getMethodAnnotations($method) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $annotation)
|
||||
{
|
||||
return $this->delegate->getMethodAnnotation($method, $annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(\ReflectionProperty $property)
|
||||
{
|
||||
$annotations = array();
|
||||
foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
|
||||
$annotations[get_class($annot)] = $annot;
|
||||
}
|
||||
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotation)
|
||||
{
|
||||
return $this->delegate->getPropertyAnnotation($property, $annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxies all methods to the delegate.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
return call_user_func_array(array($this->delegate, $method), $args);
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
use SplFileObject;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Christian Kaps <christian.kaps@mohiva.com>
|
||||
*/
|
||||
final class PhpParser
|
||||
{
|
||||
/**
|
||||
* Parses a class.
|
||||
*
|
||||
* @param \ReflectionClass $class A <code>ReflectionClass</code> object.
|
||||
*
|
||||
* @return array A list with use statements in the form (Alias => FQN).
|
||||
*/
|
||||
public function parseClass(\ReflectionClass $class)
|
||||
{
|
||||
if (method_exists($class, 'getUseStatements')) {
|
||||
return $class->getUseStatements();
|
||||
}
|
||||
|
||||
if (false === $filename = $class->getFilename()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$content = $this->getFileContent($filename, $class->getStartLine());
|
||||
|
||||
if (null === $content) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$namespace = preg_quote($class->getNamespaceName());
|
||||
$content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
|
||||
$tokenizer = new TokenParser('<?php ' . $content);
|
||||
|
||||
$statements = $tokenizer->parseUseStatements($class->getNamespaceName());
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the file right up to the given line number.
|
||||
*
|
||||
* @param string $filename The name of the file to load.
|
||||
* @param integer $lineNumber The number of lines to read from file.
|
||||
*
|
||||
* @return string The content of the file.
|
||||
*/
|
||||
private function getFileContent($filename, $lineNumber)
|
||||
{
|
||||
if ( ! is_file($filename)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$lineCnt = 0;
|
||||
$file = new SplFileObject($filename);
|
||||
while (!$file->eof()) {
|
||||
if ($lineCnt++ == $lineNumber) {
|
||||
break;
|
||||
}
|
||||
|
||||
$content .= $file->fgets();
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Interface for annotation readers.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
interface Reader
|
||||
{
|
||||
/**
|
||||
* Gets the annotations applied to a class.
|
||||
*
|
||||
* @param \ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getClassAnnotations(\ReflectionClass $class);
|
||||
|
||||
/**
|
||||
* Gets a class annotation.
|
||||
*
|
||||
* @param \ReflectionClass $class The ReflectionClass of the class from which
|
||||
* the class annotations should be read.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getClassAnnotation(\ReflectionClass $class, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a method.
|
||||
*
|
||||
* @param \ReflectionMethod $method The ReflectionMethod of the method from which
|
||||
* the annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getMethodAnnotations(\ReflectionMethod $method);
|
||||
|
||||
/**
|
||||
* Gets a method annotation.
|
||||
*
|
||||
* @param \ReflectionMethod $method The ReflectionMethod to read the annotations from.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getMethodAnnotation(\ReflectionMethod $method, $annotationName);
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a property.
|
||||
*
|
||||
* @param \ReflectionProperty $property The ReflectionProperty of the property
|
||||
* from which the annotations should be read.
|
||||
*
|
||||
* @return array An array of Annotations.
|
||||
*/
|
||||
function getPropertyAnnotations(\ReflectionProperty $property);
|
||||
|
||||
/**
|
||||
* Gets a property annotation.
|
||||
*
|
||||
* @param \ReflectionProperty $property The ReflectionProperty to read the annotations from.
|
||||
* @param string $annotationName The name of the annotation.
|
||||
*
|
||||
* @return object|null The Annotation or NULL, if the requested annotation does not exist.
|
||||
*/
|
||||
function getPropertyAnnotation(\ReflectionProperty $property, $annotationName);
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Simple Annotation Reader.
|
||||
*
|
||||
* This annotation reader is intended to be used in projects where you have
|
||||
* full-control over all annotations that are available.
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class SimpleAnnotationReader implements Reader
|
||||
{
|
||||
/**
|
||||
* @var DocParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Initializes a new SimpleAnnotationReader.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = new DocParser();
|
||||
$this->parser->setIgnoreNotImportedAnnotations(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace in which we will look for annotations.
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addNamespace($namespace)
|
||||
{
|
||||
$this->parser->addNamespace($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotations(\ReflectionClass $class)
|
||||
{
|
||||
return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotations(\ReflectionMethod $method)
|
||||
{
|
||||
return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotations(\ReflectionProperty $property)
|
||||
{
|
||||
return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClassAnnotation(\ReflectionClass $class, $annotationName)
|
||||
{
|
||||
foreach ($this->getClassAnnotations($class) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
|
||||
{
|
||||
foreach ($this->getMethodAnnotations($method) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
|
||||
{
|
||||
foreach ($this->getPropertyAnnotations($property) as $annot) {
|
||||
if ($annot instanceof $annotationName) {
|
||||
return $annot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Annotations;
|
||||
|
||||
/**
|
||||
* Parses a file for namespaces/use/class declarations.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Christian Kaps <christian.kaps@mohiva.com>
|
||||
*/
|
||||
class TokenParser
|
||||
{
|
||||
/**
|
||||
* The token list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tokens;
|
||||
|
||||
/**
|
||||
* The number of tokens.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $numTokens;
|
||||
|
||||
/**
|
||||
* The current array pointer.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $pointer = 0;
|
||||
|
||||
/**
|
||||
* @param string $contents
|
||||
*/
|
||||
public function __construct($contents)
|
||||
{
|
||||
$this->tokens = token_get_all($contents);
|
||||
|
||||
// The PHP parser sets internal compiler globals for certain things. Annoyingly, the last docblock comment it
|
||||
// saw gets stored in doc_comment. When it comes to compile the next thing to be include()d this stored
|
||||
// doc_comment becomes owned by the first thing the compiler sees in the file that it considers might have a
|
||||
// docblock. If the first thing in the file is a class without a doc block this would cause calls to
|
||||
// getDocBlock() on said class to return our long lost doc_comment. Argh.
|
||||
// To workaround, cause the parser to parse an empty docblock. Sure getDocBlock() will return this, but at least
|
||||
// it's harmless to us.
|
||||
token_get_all("<?php\n/**\n *\n */");
|
||||
|
||||
$this->numTokens = count($this->tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next non whitespace and non comment token.
|
||||
*
|
||||
* @param boolean $docCommentIsComment If TRUE then a doc comment is considered a comment and skipped.
|
||||
* If FALSE then only whitespace and normal comments are skipped.
|
||||
*
|
||||
* @return array|null The token if exists, null otherwise.
|
||||
*/
|
||||
public function next($docCommentIsComment = TRUE)
|
||||
{
|
||||
for ($i = $this->pointer; $i < $this->numTokens; $i++) {
|
||||
$this->pointer++;
|
||||
if ($this->tokens[$i][0] === T_WHITESPACE ||
|
||||
$this->tokens[$i][0] === T_COMMENT ||
|
||||
($docCommentIsComment && $this->tokens[$i][0] === T_DOC_COMMENT)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->tokens[$i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a single use statement.
|
||||
*
|
||||
* @return array A list with all found class names for a use statement.
|
||||
*/
|
||||
public function parseUseStatement()
|
||||
{
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$statements = array();
|
||||
$explicitAlias = false;
|
||||
while (($token = $this->next())) {
|
||||
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
|
||||
if (!$explicitAlias && $isNameToken) {
|
||||
$class .= $token[1];
|
||||
$alias = $token[1];
|
||||
} else if ($explicitAlias && $isNameToken) {
|
||||
$alias .= $token[1];
|
||||
} else if ($token[0] === T_AS) {
|
||||
$explicitAlias = true;
|
||||
$alias = '';
|
||||
} else if ($token === ',') {
|
||||
$statements[strtolower($alias)] = $class;
|
||||
$class = '';
|
||||
$alias = '';
|
||||
$explicitAlias = false;
|
||||
} else if ($token === ';') {
|
||||
$statements[strtolower($alias)] = $class;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all use statements.
|
||||
*
|
||||
* @param string $namespaceName The namespace name of the reflected class.
|
||||
*
|
||||
* @return array A list with all found use statements.
|
||||
*/
|
||||
public function parseUseStatements($namespaceName)
|
||||
{
|
||||
$statements = array();
|
||||
while (($token = $this->next())) {
|
||||
if ($token[0] === T_USE) {
|
||||
$statements = array_merge($statements, $this->parseUseStatement());
|
||||
continue;
|
||||
}
|
||||
if ($token[0] !== T_NAMESPACE || $this->parseNamespace() != $namespaceName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get fresh array for new namespace. This is to prevent the parser to collect the use statements
|
||||
// for a previous namespace with the same name. This is the case if a namespace is defined twice
|
||||
// or if a namespace with the same name is commented out.
|
||||
$statements = array();
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace.
|
||||
*
|
||||
* @return string The found namespace.
|
||||
*/
|
||||
public function parseNamespace()
|
||||
{
|
||||
$name = '';
|
||||
while (($token = $this->next()) && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) {
|
||||
$name .= $token[1];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name.
|
||||
*
|
||||
* @return string The found class name.
|
||||
*/
|
||||
public function parseClass()
|
||||
{
|
||||
// Namespaces and class names are tokenized the same: T_STRINGs
|
||||
// separated by T_NS_SEPARATOR so we can use one function to provide
|
||||
// both.
|
||||
return $this->parseNamespace();
|
||||
}
|
||||
}
|
4
vendor/doctrine/cache/.coveralls.yml
vendored
4
vendor/doctrine/cache/.coveralls.yml
vendored
|
@ -1,4 +0,0 @@
|
|||
# for php-coveralls
|
||||
service_name: travis-ci
|
||||
src_dir: lib
|
||||
coverage_clover: build/logs/clover.xml
|
4
vendor/doctrine/cache/.gitignore
vendored
4
vendor/doctrine/cache/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
vendor/
|
||||
build/
|
||||
phpunit.xml
|
||||
composer.lock
|
33
vendor/doctrine/cache/.travis.yml
vendored
33
vendor/doctrine/cache/.travis.yml
vendored
|
@ -1,33 +0,0 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
services:
|
||||
- riak
|
||||
- mongodb
|
||||
- memcached
|
||||
- redis-server
|
||||
|
||||
before_install:
|
||||
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ]; then pecl install riak-beta; fi"
|
||||
- sh -c "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && `php-config --vernum` -ge 50500 ]] ; then pecl config-set preferred_state beta; printf "yes\n" | pecl install apcu ; else echo 'extension="apc.so"' >> ./tests/travis/php.ini ;fi"
|
||||
- composer self-update
|
||||
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ]; then phpenv config-add ./tests/travis/php.ini; fi"
|
||||
|
||||
install:
|
||||
- composer --prefer-source --dev install
|
||||
|
||||
script:
|
||||
- ./vendor/bin/phpunit -c ./tests/travis/phpunit.travis.xml -v
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
19
vendor/doctrine/cache/LICENSE
vendored
19
vendor/doctrine/cache/LICENSE
vendored
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2006-2012 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
14
vendor/doctrine/cache/README.md
vendored
14
vendor/doctrine/cache/README.md
vendored
|
@ -1,14 +0,0 @@
|
|||
# Doctrine Cache
|
||||
|
||||
Master: [](http://travis-ci.org/doctrine/cache) [](https://coveralls.io/r/doctrine/cache?branch=master)
|
||||
|
||||
[](https://packagist.org/packages/doctrine/cache) [](https://packagist.org/packages/doctrine/cache)
|
||||
|
||||
Cache component extracted from the Doctrine Common project.
|
||||
|
||||
## Changelog
|
||||
|
||||
### v1.2
|
||||
|
||||
* Added support for MongoDB as Cache Provider
|
||||
* Fix namespace version reset
|
16
vendor/doctrine/cache/UPGRADE.md
vendored
16
vendor/doctrine/cache/UPGRADE.md
vendored
|
@ -1,16 +0,0 @@
|
|||
# Upgrade to 1.4
|
||||
|
||||
## Minor BC Break: `Doctrine\Common\Cache\FileCache#$extension` is now `private`.
|
||||
|
||||
If you need to override the value of `Doctrine\Common\Cache\FileCache#$extension`, then use the
|
||||
second parameter of `Doctrine\Common\Cache\FileCache#__construct()` instead of overriding
|
||||
the property in your own implementation.
|
||||
|
||||
## Minor BC Break: file based caches paths changed
|
||||
|
||||
`Doctrine\Common\Cache\FileCache`, `Doctrine\Common\Cache\PhpFileCache` and
|
||||
`Doctrine\Common\Cache\FilesystemCache` are using a different cache paths structure.
|
||||
|
||||
If you rely on warmed up caches for deployments, consider that caches generated
|
||||
with `doctrine/cache` `<1.4` are not compatible with the new directory structure,
|
||||
and will be ignored.
|
3
vendor/doctrine/cache/build.properties
vendored
3
vendor/doctrine/cache/build.properties
vendored
|
@ -1,3 +0,0 @@
|
|||
# Version class and file
|
||||
project.version_class = Doctrine\\Common\\Cache\\Version
|
||||
project.version_file = lib/Doctrine/Common/Cache/Version.php
|
110
vendor/doctrine/cache/build.xml
vendored
110
vendor/doctrine/cache/build.xml
vendored
|
@ -1,110 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<project name="DoctrineCommonCache" default="build" basedir=".">
|
||||
<property file="build.properties" />
|
||||
|
||||
<target name="php">
|
||||
<exec executable="which" outputproperty="php_executable">
|
||||
<arg value="php" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="prepare">
|
||||
<mkdir dir="build" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="check-git-checkout-clean,prepare,php,composer">
|
||||
<exec executable="${php_executable}">
|
||||
<arg value="build/composer.phar" />
|
||||
<arg value="archive" />
|
||||
<arg value="--dir=build" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="composer" depends="php,composer-check,composer-download">
|
||||
<exec executable="${php_executable}">
|
||||
<arg value="build/composer.phar" />
|
||||
<arg value="install" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="composer-check" depends="prepare">
|
||||
<available file="build/composer.phar" property="composer.present"/>
|
||||
</target>
|
||||
|
||||
<target name="composer-download" unless="composer.present">
|
||||
<exec executable="wget">
|
||||
<arg value="-Obuild/composer.phar" />
|
||||
<arg value="http://getcomposer.org/composer.phar" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="make-release" depends="check-git-checkout-clean,prepare,php">
|
||||
<replace file="${project.version_file}" token="-DEV" value="" failOnNoReplacements="true" />
|
||||
<exec executable="git" failonerror="true" outputproperty="current_git_branch">
|
||||
<arg value="rev-parse" />
|
||||
<arg value="--abbrev-ref" />
|
||||
<arg value="HEAD" />
|
||||
</exec>
|
||||
<exec executable="${php_executable}" outputproperty="doctrine.current_version" failonerror="true">
|
||||
<arg value="-r" />
|
||||
<arg value="require_once '${project.version_file}';echo ${project.version_class}::VERSION;" />
|
||||
</exec>
|
||||
<exec executable="${php_executable}" outputproperty="doctrine.next_version" failonerror="true">
|
||||
<arg value="-r" />
|
||||
<arg value="$parts = explode('.', str_ireplace(array('-DEV', '-ALPHA', '-BETA'), '', '${doctrine.current_version}'));
|
||||
if (count($parts) != 3) {
|
||||
throw new \InvalidArgumentException('Version is assumed in format x.y.z, ${doctrine.current_version} given');
|
||||
}
|
||||
if ('${current_git_branch}' === 'master') {
|
||||
$parts[1]++;
|
||||
} else {
|
||||
$parts[2]++;
|
||||
}
|
||||
echo implode('.', $parts);
|
||||
" />
|
||||
</exec>
|
||||
|
||||
<git-commit file="${project.version_file}" message="Release ${doctrine.current_version}" />
|
||||
<git-tag version="${doctrine.current_version}" />
|
||||
<replace file="${project.version_file}" token="${doctrine.current_version}" value="${doctrine.next_version}-DEV" />
|
||||
<git-commit file="${project.version_file}" message="Bump version to ${doctrine.next_version}" />
|
||||
</target>
|
||||
|
||||
<target name="check-git-checkout-clean">
|
||||
<exec executable="git" failonerror="true">
|
||||
<arg value="diff-index" />
|
||||
<arg value="--quiet" />
|
||||
<arg value="HEAD" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<macrodef name="git-commit">
|
||||
<attribute name="file" default="NOT SET"/>
|
||||
<attribute name="message" default="NOT SET"/>
|
||||
|
||||
<sequential>
|
||||
<exec executable="git">
|
||||
<arg value="add" />
|
||||
<arg value="@{file}" />
|
||||
</exec>
|
||||
<exec executable="git">
|
||||
<arg value="commit" />
|
||||
<arg value="-m" />
|
||||
<arg value="@{message}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="git-tag">
|
||||
<attribute name="version" default="NOT SET" />
|
||||
|
||||
<sequential>
|
||||
<exec executable="git">
|
||||
<arg value="tag" />
|
||||
<arg value="-m" />
|
||||
<arg value="v@{version}" />
|
||||
<arg value="v@{version}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</project>
|
34
vendor/doctrine/cache/composer.json
vendored
34
vendor/doctrine/cache/composer.json
vendored
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"name": "doctrine/cache",
|
||||
"type": "library",
|
||||
"description": "Caching library offering an object-oriented API for many cache backends",
|
||||
"keywords": ["cache", "caching"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=3.7",
|
||||
"satooshi/php-coveralls": "~0.6",
|
||||
"predis/predis": "~1.0"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/common": ">2.2,<2.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\Common\\Cache\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.5.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* APC cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class ApcCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return apc_fetch($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return apc_exists($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return (bool) apc_store($id, $data, (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return apc_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return apc_clear_cache() && apc_clear_cache('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
return apc_fetch($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$info = apc_cache_info('', true);
|
||||
$sma = apc_sma_info();
|
||||
|
||||
// @TODO - Temporary fix @see https://github.com/krakjoe/apcu/pull/42
|
||||
if (PHP_VERSION_ID >= 50500) {
|
||||
$info['num_hits'] = isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'];
|
||||
$info['num_misses'] = isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'];
|
||||
$info['start_time'] = isset($info['start_time']) ? $info['start_time'] : $info['stime'];
|
||||
}
|
||||
|
||||
return array(
|
||||
Cache::STATS_HITS => $info['num_hits'],
|
||||
Cache::STATS_MISSES => $info['num_misses'],
|
||||
Cache::STATS_UPTIME => $info['start_time'],
|
||||
Cache::STATS_MEMORY_USAGE => $info['mem_size'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $sma['avail_mem'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Array cache driver.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class ArrayCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var array $data
|
||||
*/
|
||||
private $data = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->doContains($id) ? $this->data[$id] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
// isset() is required for performance optimizations, to avoid unnecessary function calls to array_key_exists.
|
||||
return isset($this->data[$id]) || array_key_exists($id, $this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$this->data[$id] = $data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
unset($this->data[$id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
$this->data = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
interface Cache
|
||||
{
|
||||
const STATS_HITS = 'hits';
|
||||
const STATS_MISSES = 'misses';
|
||||
const STATS_UPTIME = 'uptime';
|
||||
const STATS_MEMORY_USAGE = 'memory_usage';
|
||||
const STATS_MEMORY_AVAILABLE = 'memory_available';
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const STATS_MEMORY_AVAILIABLE = 'memory_available';
|
||||
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
*
|
||||
* @return mixed The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*/
|
||||
public function fetch($id);
|
||||
|
||||
/**
|
||||
* Tests if an entry exists in the cache.
|
||||
*
|
||||
* @param string $id The cache id of the entry to check for.
|
||||
*
|
||||
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
|
||||
*/
|
||||
public function contains($id);
|
||||
|
||||
/**
|
||||
* Puts data into the cache.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
* @param mixed $data The cache entry/data.
|
||||
* @param int $lifeTime The cache lifetime.
|
||||
* If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime).
|
||||
*
|
||||
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
|
||||
*/
|
||||
public function save($id, $data, $lifeTime = 0);
|
||||
|
||||
/**
|
||||
* Deletes a cache entry.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
*
|
||||
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
|
||||
*/
|
||||
public function delete($id);
|
||||
|
||||
/**
|
||||
* Retrieves cached information from the data store.
|
||||
*
|
||||
* The server's statistics array has the following values:
|
||||
*
|
||||
* - <b>hits</b>
|
||||
* Number of keys that have been requested and found present.
|
||||
*
|
||||
* - <b>misses</b>
|
||||
* Number of items that have been requested and not found.
|
||||
*
|
||||
* - <b>uptime</b>
|
||||
* Time that the server is running.
|
||||
*
|
||||
* - <b>memory_usage</b>
|
||||
* Memory used by this server to store items.
|
||||
*
|
||||
* - <b>memory_available</b>
|
||||
* Memory allowed to use for storage.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @return array|null An associative array with server's statistics if available, NULL otherwise.
|
||||
*/
|
||||
public function getStats();
|
||||
}
|
|
@ -1,277 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Base class for cache provider implementations.
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, MultiGetCache
|
||||
{
|
||||
const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
|
||||
|
||||
/**
|
||||
* The namespace to prefix all cache ids with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $namespace = '';
|
||||
|
||||
/**
|
||||
* The namespace version.
|
||||
*
|
||||
* @var integer|null
|
||||
*/
|
||||
private $namespaceVersion;
|
||||
|
||||
/**
|
||||
* Sets the namespace to prefix all cache ids with.
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = (string) $namespace;
|
||||
$this->namespaceVersion = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the namespace that prefixes all cache ids.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->doFetch($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetchMultiple(array $keys)
|
||||
{
|
||||
// note: the array_combine() is in place to keep an association between our $keys and the $namespacedKeys
|
||||
$namespacedKeys = array_combine($keys, array_map(array($this, 'getNamespacedId'), $keys));
|
||||
$items = $this->doFetchMultiple($namespacedKeys);
|
||||
$foundItems = array();
|
||||
|
||||
// no internal array function supports this sort of mapping: needs to be iterative
|
||||
// this filters and combines keys in one pass
|
||||
foreach ($namespacedKeys as $requestedKey => $namespacedKey) {
|
||||
if (isset($items[$namespacedKey])) {
|
||||
$foundItems[$requestedKey] = $items[$namespacedKey];
|
||||
}
|
||||
}
|
||||
|
||||
return $foundItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function contains($id)
|
||||
{
|
||||
return $this->doContains($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return $this->doSave($this->getNamespacedId($id), $data, $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->doDelete($this->getNamespacedId($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStats()
|
||||
{
|
||||
return $this->doGetStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function flushAll()
|
||||
{
|
||||
return $this->doFlush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function deleteAll()
|
||||
{
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$namespaceVersion = $this->getNamespaceVersion() + 1;
|
||||
|
||||
$this->namespaceVersion = $namespaceVersion;
|
||||
|
||||
return $this->doSave($namespaceCacheKey, $namespaceVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefixes the passed id with the configured namespace value.
|
||||
*
|
||||
* @param string $id The id to namespace.
|
||||
*
|
||||
* @return string The namespaced id.
|
||||
*/
|
||||
private function getNamespacedId($id)
|
||||
{
|
||||
$namespaceVersion = $this->getNamespaceVersion();
|
||||
|
||||
return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the namespace cache key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getNamespaceCacheKey()
|
||||
{
|
||||
return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the namespace version.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function getNamespaceVersion()
|
||||
{
|
||||
if (null !== $this->namespaceVersion) {
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$namespaceVersion = $this->doFetch($namespaceCacheKey);
|
||||
|
||||
if (false === $namespaceVersion) {
|
||||
$namespaceVersion = 1;
|
||||
|
||||
$this->doSave($namespaceCacheKey, $namespaceVersion);
|
||||
}
|
||||
|
||||
$this->namespaceVersion = $namespaceVersion;
|
||||
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of doFetchMultiple. Each driver that supports multi-get should owerwrite it.
|
||||
*
|
||||
* @param array $keys Array of keys to retrieve from cache
|
||||
* @return array Array of values retrieved for the given keys.
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
$returnValues = array();
|
||||
|
||||
foreach ($keys as $index => $key) {
|
||||
if (false !== ($item = $this->doFetch($key))) {
|
||||
$returnValues[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $returnValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
* @param string $id The id of the cache entry to fetch.
|
||||
*
|
||||
* @return mixed|boolean The cached data or FALSE, if no cache entry exists for the given id.
|
||||
*/
|
||||
abstract protected function doFetch($id);
|
||||
|
||||
/**
|
||||
* Tests if an entry exists in the cache.
|
||||
*
|
||||
* @param string $id The cache id of the entry to check for.
|
||||
*
|
||||
* @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doContains($id);
|
||||
|
||||
/**
|
||||
* Puts data into the cache.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
* @param string $data The cache entry/data.
|
||||
* @param int $lifeTime The lifetime. If != 0, sets a specific lifetime for this
|
||||
* cache entry (0 => infinite lifeTime).
|
||||
*
|
||||
* @return boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doSave($id, $data, $lifeTime = 0);
|
||||
|
||||
/**
|
||||
* Deletes a cache entry.
|
||||
*
|
||||
* @param string $id The cache id.
|
||||
*
|
||||
* @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doDelete($id);
|
||||
|
||||
/**
|
||||
* Flushes all cache entries.
|
||||
*
|
||||
* @return boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.
|
||||
*/
|
||||
abstract protected function doFlush();
|
||||
|
||||
/**
|
||||
* Retrieves cached information from the data store.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @return array|null An associative array with server's statistics if available, NULL otherwise.
|
||||
*/
|
||||
abstract protected function doGetStats();
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Cache provider that allows to easily chain multiple cache providers
|
||||
*
|
||||
* @author Michaël Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class ChainCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var CacheProvider[]
|
||||
*/
|
||||
private $cacheProviders = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CacheProvider[] $cacheProviders
|
||||
*/
|
||||
public function __construct($cacheProviders = array())
|
||||
{
|
||||
$this->cacheProviders = $cacheProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
parent::setNamespace($namespace);
|
||||
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
$cacheProvider->setNamespace($namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
foreach ($this->cacheProviders as $key => $cacheProvider) {
|
||||
if ($cacheProvider->doContains($id)) {
|
||||
$value = $cacheProvider->doFetch($id);
|
||||
|
||||
// We populate all the previous cache layers (that are assumed to be faster)
|
||||
for ($subKey = $key - 1 ; $subKey >= 0 ; $subKey--) {
|
||||
$this->cacheProviders[$subKey]->doSave($id, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
if ($cacheProvider->doContains($id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$stored = true;
|
||||
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
$stored = $cacheProvider->doSave($id, $data, $lifeTime) && $stored;
|
||||
}
|
||||
|
||||
return $stored;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
$deleted = true;
|
||||
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
$deleted = $cacheProvider->doDelete($id) && $deleted;
|
||||
}
|
||||
|
||||
return $deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
$flushed = true;
|
||||
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
$flushed = $cacheProvider->doFlush() && $flushed;
|
||||
}
|
||||
|
||||
return $flushed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
// We return all the stats from all adapters
|
||||
$stats = array();
|
||||
|
||||
foreach ($this->cacheProviders as $cacheProvider) {
|
||||
$stats[] = $cacheProvider->doGetStats();
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache that can be flushed.
|
||||
*
|
||||
* Intended to be used for partial clearing of a cache namespace. For a more
|
||||
* global "flushing", see {@see FlushableCache}.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.4
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
interface ClearableCache
|
||||
{
|
||||
/**
|
||||
* Deletes all cache entries in the current cache namespace.
|
||||
*
|
||||
* @return boolean TRUE if the cache entries were successfully deleted, FALSE otherwise.
|
||||
*/
|
||||
public function deleteAll();
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use \Couchbase;
|
||||
|
||||
/**
|
||||
* Couchbase cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.4
|
||||
* @author Michael Nitschinger <michael@nitschinger.at>
|
||||
*/
|
||||
class CouchbaseCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var Couchbase|null
|
||||
*/
|
||||
private $couchbase;
|
||||
|
||||
/**
|
||||
* Sets the Couchbase instance to use.
|
||||
*
|
||||
* @param Couchbase $couchbase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCouchbase(Couchbase $couchbase)
|
||||
{
|
||||
$this->couchbase = $couchbase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Couchbase instance used by the cache.
|
||||
*
|
||||
* @return Couchbase|null
|
||||
*/
|
||||
public function getCouchbase()
|
||||
{
|
||||
return $this->couchbase;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->couchbase->get($id) ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return (null !== $this->couchbase->get($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 30 * 24 * 3600) {
|
||||
$lifeTime = time() + $lifeTime;
|
||||
}
|
||||
return $this->couchbase->set($id, $data, (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->couchbase->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->couchbase->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$stats = $this->couchbase->getStats();
|
||||
$servers = $this->couchbase->getServers();
|
||||
$server = explode(":", $servers[0]);
|
||||
$key = $server[0] . ":" . "11210";
|
||||
$stats = $stats[$key];
|
||||
return array(
|
||||
Cache::STATS_HITS => $stats['get_hits'],
|
||||
Cache::STATS_MISSES => $stats['get_misses'],
|
||||
Cache::STATS_UPTIME => $stats['uptime'],
|
||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,237 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Base file cache driver.
|
||||
*
|
||||
* @since 2.3
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
abstract class FileCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* The cache directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* The cache file extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $extension;
|
||||
|
||||
/**
|
||||
* @var string[] regular expressions for replacing disallowed characters in file name
|
||||
*/
|
||||
private $disallowedCharacterPatterns = array(
|
||||
'/\-/', // replaced to disambiguate original `-` and `-` derived from replacements
|
||||
'/[^a-zA-Z0-9\-_\[\]]/' // also excludes non-ascii chars (not supported, depending on FS)
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string[] replacements for disallowed file characters
|
||||
*/
|
||||
private $replacementCharacters = array('__', '-');
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $umask;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $directory The cache directory.
|
||||
* @param string $extension The cache file extension.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($directory, $extension = '', $umask = 0002)
|
||||
{
|
||||
// YES, this needs to be *before* createPathIfNeeded()
|
||||
if ( ! is_int($umask)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The umask parameter is required to be integer, was: %s',
|
||||
gettype($umask)
|
||||
));
|
||||
}
|
||||
$this->umask = $umask;
|
||||
|
||||
if ( ! $this->createPathIfNeeded($directory)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The directory "%s" does not exist and could not be created.',
|
||||
$directory
|
||||
));
|
||||
}
|
||||
|
||||
if ( ! is_writable($directory)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The directory "%s" is not writable.',
|
||||
$directory
|
||||
));
|
||||
}
|
||||
|
||||
// YES, this needs to be *after* createPathIfNeeded()
|
||||
$this->directory = realpath($directory);
|
||||
$this->extension = (string) $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDirectory()
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache file extension.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
return $this->extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilename($id)
|
||||
{
|
||||
return $this->directory
|
||||
. DIRECTORY_SEPARATOR
|
||||
. implode(str_split(hash('sha256', $id), 2), DIRECTORY_SEPARATOR)
|
||||
. DIRECTORY_SEPARATOR
|
||||
. preg_replace($this->disallowedCharacterPatterns, $this->replacementCharacters, $id)
|
||||
. $this->extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return @unlink($this->getFilename($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
foreach ($this->getIterator() as $name => $file) {
|
||||
@unlink($name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$usage = 0;
|
||||
foreach ($this->getIterator() as $file) {
|
||||
$usage += $file->getSize();
|
||||
}
|
||||
|
||||
$free = disk_free_space($this->directory);
|
||||
|
||||
return array(
|
||||
Cache::STATS_HITS => null,
|
||||
Cache::STATS_MISSES => null,
|
||||
Cache::STATS_UPTIME => null,
|
||||
Cache::STATS_MEMORY_USAGE => $usage,
|
||||
Cache::STATS_MEMORY_AVAILABLE => $free,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create path if needed.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool TRUE on success or if path already exists, FALSE if path cannot be created.
|
||||
*/
|
||||
private function createPathIfNeeded($path)
|
||||
{
|
||||
if ( ! is_dir($path)) {
|
||||
if (false === @mkdir($path, 0777 & (~$this->umask), true) && !is_dir($path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string content to file in an atomic way.
|
||||
*
|
||||
* @param string $filename Path to the file where to write the data.
|
||||
* @param string $content The content to write
|
||||
*
|
||||
* @return bool TRUE on success, FALSE if path cannot be created, if path is not writable or an any other error.
|
||||
*/
|
||||
protected function writeFile($filename, $content)
|
||||
{
|
||||
$filepath = pathinfo($filename, PATHINFO_DIRNAME);
|
||||
|
||||
if ( ! $this->createPathIfNeeded($filepath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! is_writable($filepath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmpFile = tempnam($filepath, 'swap');
|
||||
@chmod($tmpFile, 0666 & (~$this->umask));
|
||||
|
||||
if (file_put_contents($tmpFile, $content) !== false) {
|
||||
if (@rename($tmpFile, $filename)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@unlink($tmpFile);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Iterator
|
||||
*/
|
||||
private function getIterator()
|
||||
{
|
||||
return new \RegexIterator(
|
||||
new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory)),
|
||||
'/^.+' . preg_quote($this->extension, '/') . '$/i'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Filesystem cache driver.
|
||||
*
|
||||
* @since 2.3
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class FilesystemCache extends FileCache
|
||||
{
|
||||
const EXTENSION = '.doctrinecache.data';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($directory, $extension = self::EXTENSION, $umask = 0002)
|
||||
{
|
||||
parent::__construct($directory, $extension, $umask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$data = '';
|
||||
$lifetime = -1;
|
||||
$filename = $this->getFilename($id);
|
||||
|
||||
if ( ! is_file($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$resource = fopen($filename, "r");
|
||||
|
||||
if (false !== ($line = fgets($resource))) {
|
||||
$lifetime = (integer) $line;
|
||||
}
|
||||
|
||||
if ($lifetime !== 0 && $lifetime < time()) {
|
||||
fclose($resource);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
while (false !== ($line = fgets($resource))) {
|
||||
$data .= $line;
|
||||
}
|
||||
|
||||
fclose($resource);
|
||||
|
||||
return unserialize($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
$lifetime = -1;
|
||||
$filename = $this->getFilename($id);
|
||||
|
||||
if ( ! is_file($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$resource = fopen($filename, "r");
|
||||
|
||||
if (false !== ($line = fgets($resource))) {
|
||||
$lifetime = (integer) $line;
|
||||
}
|
||||
|
||||
fclose($resource);
|
||||
|
||||
return $lifetime === 0 || $lifetime > time();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 0) {
|
||||
$lifeTime = time() + $lifeTime;
|
||||
}
|
||||
|
||||
$data = serialize($data);
|
||||
$filename = $this->getFilename($id);
|
||||
|
||||
return $this->writeFile($filename, $lifeTime . PHP_EOL . $data);
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache that can be flushed.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.4
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
interface FlushableCache
|
||||
{
|
||||
/**
|
||||
* Flushes all cache entries, globally.
|
||||
*
|
||||
* @return boolean TRUE if the cache entries were successfully flushed, FALSE otherwise.
|
||||
*/
|
||||
public function flushAll();
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use \Memcache;
|
||||
|
||||
/**
|
||||
* Memcache cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class MemcacheCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var Memcache|null
|
||||
*/
|
||||
private $memcache;
|
||||
|
||||
/**
|
||||
* Sets the memcache instance to use.
|
||||
*
|
||||
* @param Memcache $memcache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMemcache(Memcache $memcache)
|
||||
{
|
||||
$this->memcache = $memcache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the memcache instance used by the cache.
|
||||
*
|
||||
* @return Memcache|null
|
||||
*/
|
||||
public function getMemcache()
|
||||
{
|
||||
return $this->memcache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->memcache->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
$flags = null;
|
||||
$this->memcache->get($id, $flags);
|
||||
|
||||
//if memcache has changed the value of "flags", it means the value exists
|
||||
return ($flags !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 30 * 24 * 3600) {
|
||||
$lifeTime = time() + $lifeTime;
|
||||
}
|
||||
return $this->memcache->set($id, $data, 0, (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->memcache->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->memcache->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$stats = $this->memcache->getStats();
|
||||
return array(
|
||||
Cache::STATS_HITS => $stats['get_hits'],
|
||||
Cache::STATS_MISSES => $stats['get_misses'],
|
||||
Cache::STATS_UPTIME => $stats['uptime'],
|
||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use \Memcached;
|
||||
|
||||
/**
|
||||
* Memcached cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class MemcachedCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var Memcached|null
|
||||
*/
|
||||
private $memcached;
|
||||
|
||||
/**
|
||||
* Sets the memcache instance to use.
|
||||
*
|
||||
* @param Memcached $memcached
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMemcached(Memcached $memcached)
|
||||
{
|
||||
$this->memcached = $memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the memcached instance used by the cache.
|
||||
*
|
||||
* @return Memcached|null
|
||||
*/
|
||||
public function getMemcached()
|
||||
{
|
||||
return $this->memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->memcached->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
return $this->memcached->getMulti($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return (false !== $this->memcached->get($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 30 * 24 * 3600) {
|
||||
$lifeTime = time() + $lifeTime;
|
||||
}
|
||||
return $this->memcached->set($id, $data, (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->memcached->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->memcached->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$stats = $this->memcached->getStats();
|
||||
$servers = $this->memcached->getServerList();
|
||||
$key = $servers[0]['host'] . ':' . $servers[0]['port'];
|
||||
$stats = $stats[$key];
|
||||
return array(
|
||||
Cache::STATS_HITS => $stats['get_hits'],
|
||||
Cache::STATS_MISSES => $stats['get_misses'],
|
||||
Cache::STATS_UPTIME => $stats['uptime'],
|
||||
Cache::STATS_MEMORY_USAGE => $stats['bytes'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use MongoBinData;
|
||||
use MongoCollection;
|
||||
use MongoDate;
|
||||
|
||||
/**
|
||||
* MongoDB cache provider.
|
||||
*
|
||||
* @since 1.1
|
||||
* @author Jeremy Mikola <jmikola@gmail.com>
|
||||
*/
|
||||
class MongoDBCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* The data field will store the serialized PHP value.
|
||||
*/
|
||||
const DATA_FIELD = 'd';
|
||||
|
||||
/**
|
||||
* The expiration field will store a MongoDate value indicating when the
|
||||
* cache entry should expire.
|
||||
*
|
||||
* With MongoDB 2.2+, entries can be automatically deleted by MongoDB by
|
||||
* indexing this field wit the "expireAfterSeconds" option equal to zero.
|
||||
* This will direct MongoDB to regularly query for and delete any entries
|
||||
* whose date is older than the current time. Entries without a date value
|
||||
* in this field will be ignored.
|
||||
*
|
||||
* The cache provider will also check dates on its own, in case expired
|
||||
* entries are fetched before MongoDB's TTLMonitor pass can expire them.
|
||||
*
|
||||
* @see http://docs.mongodb.org/manual/tutorial/expire-data/
|
||||
*/
|
||||
const EXPIRATION_FIELD = 'e';
|
||||
|
||||
/**
|
||||
* @var MongoCollection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* This provider will default to the write concern and read preference
|
||||
* options set on the MongoCollection instance (or inherited from MongoDB or
|
||||
* MongoClient). Using an unacknowledged write concern (< 1) may make the
|
||||
* return values of delete() and save() unreliable. Reading from secondaries
|
||||
* may make contain() and fetch() unreliable.
|
||||
*
|
||||
* @see http://www.php.net/manual/en/mongo.readpreferences.php
|
||||
* @see http://www.php.net/manual/en/mongo.writeconcerns.php
|
||||
* @param MongoCollection $collection
|
||||
*/
|
||||
public function __construct(MongoCollection $collection)
|
||||
{
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$document = $this->collection->findOne(array('_id' => $id), array(self::DATA_FIELD, self::EXPIRATION_FIELD));
|
||||
|
||||
if ($document === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isExpired($document)) {
|
||||
$this->doDelete($id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return unserialize($document[self::DATA_FIELD]->bin);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
$document = $this->collection->findOne(array('_id' => $id), array(self::EXPIRATION_FIELD));
|
||||
|
||||
if ($document === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isExpired($document)) {
|
||||
$this->doDelete($id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$result = $this->collection->update(
|
||||
array('_id' => $id),
|
||||
array('$set' => array(
|
||||
self::EXPIRATION_FIELD => ($lifeTime > 0 ? new MongoDate(time() + $lifeTime) : null),
|
||||
self::DATA_FIELD => new MongoBinData(serialize($data), MongoBinData::BYTE_ARRAY),
|
||||
)),
|
||||
array('upsert' => true, 'multiple' => false)
|
||||
);
|
||||
|
||||
return isset($result['ok']) ? $result['ok'] == 1 : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
$result = $this->collection->remove(array('_id' => $id));
|
||||
|
||||
return isset($result['n']) ? $result['n'] == 1 : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
// Use remove() in lieu of drop() to maintain any collection indexes
|
||||
$result = $this->collection->remove();
|
||||
|
||||
return isset($result['ok']) ? $result['ok'] == 1 : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$serverStatus = $this->collection->db->command(array(
|
||||
'serverStatus' => 1,
|
||||
'locks' => 0,
|
||||
'metrics' => 0,
|
||||
'recordStats' => 0,
|
||||
'repl' => 0,
|
||||
));
|
||||
|
||||
$collStats = $this->collection->db->command(array('collStats' => 1));
|
||||
|
||||
return array(
|
||||
Cache::STATS_HITS => null,
|
||||
Cache::STATS_MISSES => null,
|
||||
Cache::STATS_UPTIME => (isset($serverStatus['uptime']) ? (integer) $serverStatus['uptime'] : null),
|
||||
Cache::STATS_MEMORY_USAGE => (isset($collStats['size']) ? (integer) $collStats['size'] : null),
|
||||
Cache::STATS_MEMORY_AVAILABLE => null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the document is expired.
|
||||
*
|
||||
* @param array $document
|
||||
* @return boolean
|
||||
*/
|
||||
private function isExpired(array $document)
|
||||
{
|
||||
return isset($document[self::EXPIRATION_FIELD]) &&
|
||||
$document[self::EXPIRATION_FIELD] instanceof MongoDate &&
|
||||
$document[self::EXPIRATION_FIELD]->sec < time();
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Interface for cache drivers that allows to get many items at once.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.4
|
||||
* @author Asmir Mustafic <goetas@gmail.com>
|
||||
*/
|
||||
interface MultiGetCache
|
||||
{
|
||||
/**
|
||||
* Returns an associative array of values for keys is found in cache.
|
||||
*
|
||||
* @param string[] $keys Array of keys to retrieve from cache
|
||||
* @return mixed[] Array of retrieved values, indexed by the specified keys.
|
||||
* Values that couldn't be retrieved are not contained in this array.
|
||||
*/
|
||||
function fetchMultiple(array $keys);
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Php file cache driver.
|
||||
*
|
||||
* @since 2.3
|
||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||
*/
|
||||
class PhpFileCache extends FileCache
|
||||
{
|
||||
const EXTENSION = '.doctrinecache.php';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($directory, $extension = self::EXTENSION, $umask = 0002)
|
||||
{
|
||||
parent::__construct($directory, $extension, $umask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$value = $this->includeFileForId($id);
|
||||
|
||||
if (! $value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($value['lifetime'] !== 0 && $value['lifetime'] < time()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $value['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
$value = $this->includeFileForId($id);
|
||||
|
||||
if (! $value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $value['lifetime'] === 0 || $value['lifetime'] > time();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 0) {
|
||||
$lifeTime = time() + $lifeTime;
|
||||
}
|
||||
|
||||
if (is_object($data) && ! method_exists($data, '__set_state')) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Invalid argument given, PhpFileCache only allows objects that implement __set_state() " .
|
||||
"and fully support var_export(). You can use the FilesystemCache to save arbitrary object " .
|
||||
"graphs using serialize()/deserialize()."
|
||||
);
|
||||
}
|
||||
|
||||
$filename = $this->getFilename($id);
|
||||
|
||||
$value = array(
|
||||
'lifetime' => $lifeTime,
|
||||
'data' => $data
|
||||
);
|
||||
|
||||
$value = var_export($value, true);
|
||||
$code = sprintf('<?php return %s;', $value);
|
||||
|
||||
return $this->writeFile($filename, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
private function includeFileForId($id)
|
||||
{
|
||||
$fileName = $this->getFilename($id);
|
||||
|
||||
// note: error suppression is still faster than `file_exists`, `is_file` and `is_readable`
|
||||
$value = @include $fileName;
|
||||
|
||||
if (! isset($value['lifetime'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use Predis\Client;
|
||||
|
||||
/**
|
||||
* Predis cache provider.
|
||||
*
|
||||
* @author othillo <othillo@othillo.nl>
|
||||
*/
|
||||
class PredisCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$result = $this->client->get($id);
|
||||
if (null === $result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return unserialize($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
$fetchedItems = call_user_func_array(array($this->client, 'mget'), $keys);
|
||||
|
||||
return array_filter(array_combine($keys, array_map('unserialize', $fetchedItems)));
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return $this->client->exists($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$data = serialize($data);
|
||||
if ($lifeTime > 0) {
|
||||
$response = $this->client->setex($id, $lifeTime, $data);
|
||||
} else {
|
||||
$response = $this->client->set($id, $data);
|
||||
}
|
||||
|
||||
return $response === true || $response == 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->client->del($id) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
$response = $this->client->flushdb();
|
||||
|
||||
return $response === true || $response == 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$info = $this->client->info();
|
||||
|
||||
return array(
|
||||
Cache::STATS_HITS => $info['Stats']['keyspace_hits'],
|
||||
Cache::STATS_MISSES => $info['Stats']['keyspace_misses'],
|
||||
Cache::STATS_UPTIME => $info['Server']['uptime_in_seconds'],
|
||||
Cache::STATS_MEMORY_USAGE => $info['Memory']['used_memory'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => false
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use Redis;
|
||||
|
||||
/**
|
||||
* Redis cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Osman Ungur <osmanungur@gmail.com>
|
||||
*/
|
||||
class RedisCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* @var Redis|null
|
||||
*/
|
||||
private $redis;
|
||||
|
||||
/**
|
||||
* Sets the redis instance to use.
|
||||
*
|
||||
* @param Redis $redis
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRedis(Redis $redis)
|
||||
{
|
||||
$redis->setOption(Redis::OPT_SERIALIZER, $this->getSerializerValue());
|
||||
$this->redis = $redis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the redis instance used by the cache.
|
||||
*
|
||||
* @return Redis|null
|
||||
*/
|
||||
public function getRedis()
|
||||
{
|
||||
return $this->redis;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->redis->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
return array_filter(array_combine($keys, $this->redis->mget($keys)));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return $this->redis->exists($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
if ($lifeTime > 0) {
|
||||
return $this->redis->setex($id, $lifeTime, $data);
|
||||
}
|
||||
|
||||
return $this->redis->set($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->redis->delete($id) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->redis->flushDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$info = $this->redis->info();
|
||||
return array(
|
||||
Cache::STATS_HITS => $info['keyspace_hits'],
|
||||
Cache::STATS_MISSES => $info['keyspace_misses'],
|
||||
Cache::STATS_UPTIME => $info['uptime_in_seconds'],
|
||||
Cache::STATS_MEMORY_USAGE => $info['used_memory'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the serializer constant to use. If Redis is compiled with
|
||||
* igbinary support, that is used. Otherwise the default PHP serializer is
|
||||
* used.
|
||||
*
|
||||
* @return integer One of the Redis::SERIALIZER_* constants
|
||||
*/
|
||||
protected function getSerializerValue()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
return Redis::SERIALIZER_PHP;
|
||||
}
|
||||
return defined('Redis::SERIALIZER_IGBINARY') ? Redis::SERIALIZER_IGBINARY : Redis::SERIALIZER_PHP;
|
||||
}
|
||||
}
|
|
@ -1,250 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use Riak\Bucket;
|
||||
use Riak\Connection;
|
||||
use Riak\Input;
|
||||
use Riak\Exception;
|
||||
use Riak\Object;
|
||||
|
||||
/**
|
||||
* Riak cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.1
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
class RiakCache extends CacheProvider
|
||||
{
|
||||
const EXPIRES_HEADER = 'X-Riak-Meta-Expires';
|
||||
|
||||
/**
|
||||
* @var \Riak\Bucket
|
||||
*/
|
||||
private $bucket;
|
||||
|
||||
/**
|
||||
* Sets the riak bucket instance to use.
|
||||
*
|
||||
* @param \Riak\Bucket $bucket
|
||||
*/
|
||||
public function __construct(Bucket $bucket)
|
||||
{
|
||||
$this->bucket = $bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
try {
|
||||
$response = $this->bucket->get($id);
|
||||
|
||||
// No objects found
|
||||
if ( ! $response->hasObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for attempted siblings
|
||||
$object = ($response->hasSiblings())
|
||||
? $this->resolveConflict($id, $response->getVClock(), $response->getObjectList())
|
||||
: $response->getFirstObject();
|
||||
|
||||
// Check for expired object
|
||||
if ($this->isExpired($object)) {
|
||||
$this->bucket->delete($object);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return unserialize($object->getContent());
|
||||
} catch (Exception\RiakException $e) {
|
||||
// Covers:
|
||||
// - Riak\ConnectionException
|
||||
// - Riak\CommunicationException
|
||||
// - Riak\UnexpectedResponseException
|
||||
// - Riak\NotFoundException
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
try {
|
||||
// We only need the HEAD, not the entire object
|
||||
$input = new Input\GetInput();
|
||||
|
||||
$input->setReturnHead(true);
|
||||
|
||||
$response = $this->bucket->get($id, $input);
|
||||
|
||||
// No objects found
|
||||
if ( ! $response->hasObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$object = $response->getFirstObject();
|
||||
|
||||
// Check for expired object
|
||||
if ($this->isExpired($object)) {
|
||||
$this->bucket->delete($object);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception\RiakException $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
try {
|
||||
$object = new Object($id);
|
||||
|
||||
$object->setContent(serialize($data));
|
||||
|
||||
if ($lifeTime > 0) {
|
||||
$object->addMetadata(self::EXPIRES_HEADER, (string) (time() + $lifeTime));
|
||||
}
|
||||
|
||||
$this->bucket->put($object);
|
||||
|
||||
return true;
|
||||
} catch (Exception\RiakException $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
try {
|
||||
$this->bucket->delete($id);
|
||||
|
||||
return true;
|
||||
} catch (Exception\BadArgumentsException $e) {
|
||||
// Key did not exist on cluster already
|
||||
} catch (Exception\RiakException $e) {
|
||||
// Covers:
|
||||
// - Riak\Exception\ConnectionException
|
||||
// - Riak\Exception\CommunicationException
|
||||
// - Riak\Exception\UnexpectedResponseException
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
try {
|
||||
$keyList = $this->bucket->getKeyList();
|
||||
|
||||
foreach ($keyList as $key) {
|
||||
$this->bucket->delete($key);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception\RiakException $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
// Only exposed through HTTP stats API, not Protocol Buffers API
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given Riak Object have expired.
|
||||
*
|
||||
* @param \Riak\Object $object
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function isExpired(Object $object)
|
||||
{
|
||||
$metadataMap = $object->getMetadataMap();
|
||||
|
||||
return isset($metadataMap[self::EXPIRES_HEADER])
|
||||
&& $metadataMap[self::EXPIRES_HEADER] < time();
|
||||
}
|
||||
|
||||
/**
|
||||
* On-read conflict resolution. Applied approach here is last write wins.
|
||||
* Specific needs may override this method to apply alternate conflict resolutions.
|
||||
*
|
||||
* {@internal Riak does not attempt to resolve a write conflict, and store
|
||||
* it as sibling of conflicted one. By following this approach, it is up to
|
||||
* the next read to resolve the conflict. When this happens, your fetched
|
||||
* object will have a list of siblings (read as a list of objects).
|
||||
* In our specific case, we do not care about the intermediate ones since
|
||||
* they are all the same read from storage, and we do apply a last sibling
|
||||
* (last write) wins logic.
|
||||
* If by any means our resolution generates another conflict, it'll up to
|
||||
* next read to properly solve it.}
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $vClock
|
||||
* @param array $objectList
|
||||
*
|
||||
* @return \Riak\Object
|
||||
*/
|
||||
protected function resolveConflict($id, $vClock, array $objectList)
|
||||
{
|
||||
// Our approach here is last-write wins
|
||||
$winner = $objectList[count($objectList)];
|
||||
|
||||
$putInput = new Input\PutInput();
|
||||
$putInput->setVClock($vClock);
|
||||
|
||||
$mergedObject = new Object($id);
|
||||
$mergedObject->setContent($winner->getContent());
|
||||
|
||||
$this->bucket->put($mergedObject, $putInput);
|
||||
|
||||
return $mergedObject;
|
||||
}
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
use SQLite3;
|
||||
use SQLite3Result;
|
||||
|
||||
/**
|
||||
* SQLite3 cache provider.
|
||||
*
|
||||
* @since 1.4
|
||||
* @author Jake Bell <jake@theunraveler.com>
|
||||
*/
|
||||
class SQLite3Cache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* The ID field will store the cache key.
|
||||
*/
|
||||
const ID_FIELD = 'k';
|
||||
|
||||
/**
|
||||
* The data field will store the serialized PHP value.
|
||||
*/
|
||||
const DATA_FIELD = 'd';
|
||||
|
||||
/**
|
||||
* The expiration field will store a date value indicating when the
|
||||
* cache entry should expire.
|
||||
*/
|
||||
const EXPIRATION_FIELD = 'e';
|
||||
|
||||
/**
|
||||
* @var SQLite3
|
||||
*/
|
||||
private $sqlite;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Calling the constructor will ensure that the database file and table
|
||||
* exist and will create both if they don't.
|
||||
*
|
||||
* @param SQLite3 $sqlite
|
||||
* @param string $table
|
||||
*/
|
||||
public function __construct(SQLite3 $sqlite, $table)
|
||||
{
|
||||
$this->sqlite = $sqlite;
|
||||
$this->table = (string) $table;
|
||||
|
||||
list($id, $data, $exp) = $this->getFields();
|
||||
|
||||
return $this->sqlite->exec(sprintf(
|
||||
'CREATE TABLE IF NOT EXISTS %s(%s TEXT PRIMARY KEY NOT NULL, %s BLOB, %s INTEGER)',
|
||||
$table,
|
||||
$id,
|
||||
$data,
|
||||
$exp
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
if ($item = $this->findById($id)) {
|
||||
return unserialize($item[self::DATA_FIELD]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return (boolean) $this->findById($id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$statement = $this->sqlite->prepare(sprintf(
|
||||
'INSERT OR REPLACE INTO %s (%s) VALUES (:id, :data, :expire)',
|
||||
$this->table,
|
||||
implode(',', $this->getFields())
|
||||
));
|
||||
|
||||
$statement->bindValue(':id', $id);
|
||||
$statement->bindValue(':data', serialize($data), SQLITE3_BLOB);
|
||||
$statement->bindValue(':expire', $lifeTime > 0 ? time() + $lifeTime : null);
|
||||
|
||||
return $statement->execute() instanceof SQLite3Result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
list($idField) = $this->getFields();
|
||||
|
||||
$statement = $this->sqlite->prepare(sprintf(
|
||||
'DELETE FROM %s WHERE %s = :id',
|
||||
$this->table,
|
||||
$idField
|
||||
));
|
||||
|
||||
$statement->bindValue(':id', $id);
|
||||
|
||||
return $statement->execute() instanceof SQLite3Result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->sqlite->exec(sprintf('DELETE FROM %s', $this->table));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
// no-op.
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a single row by ID.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param boolean $includeData
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
private function findById($id, $includeData = true)
|
||||
{
|
||||
list($idField) = $fields = $this->getFields();
|
||||
|
||||
if (!$includeData) {
|
||||
$key = array_search(static::DATA_FIELD, $fields);
|
||||
unset($fields[$key]);
|
||||
}
|
||||
|
||||
$statement = $this->sqlite->prepare(sprintf(
|
||||
'SELECT %s FROM %s WHERE %s = :id LIMIT 1',
|
||||
implode(',', $fields),
|
||||
$this->table,
|
||||
$idField
|
||||
));
|
||||
|
||||
$statement->bindValue(':id', $id, SQLITE3_TEXT);
|
||||
|
||||
$item = $statement->execute()->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($item === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isExpired($item)) {
|
||||
$this->doDelete($id);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of the fields in our table.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getFields()
|
||||
{
|
||||
return array(static::ID_FIELD, static::DATA_FIELD, static::EXPIRATION_FIELD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the item is expired.
|
||||
*
|
||||
* @param array $item
|
||||
* @return boolean
|
||||
*/
|
||||
private function isExpired(array $item)
|
||||
{
|
||||
return isset($item[static::EXPIRATION_FIELD]) &&
|
||||
$item[self::EXPIRATION_FIELD] !== null &&
|
||||
$item[self::EXPIRATION_FIELD] < time();
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
class Version
|
||||
{
|
||||
const VERSION = '1.4.0-DEV';
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Void cache driver. The cache could be of use in tests where you don`t need to cache anything.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 1.5
|
||||
* @author Kotlyar Maksim <kotlyar.maksim@gmail.com>
|
||||
*/
|
||||
class VoidCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* WinCache cache provider.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class WinCacheCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return wincache_ucache_get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return wincache_ucache_exists($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return (bool) wincache_ucache_set($id, $data, (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return wincache_ucache_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$info = wincache_ucache_info();
|
||||
$meminfo = wincache_ucache_meminfo();
|
||||
|
||||
return array(
|
||||
Cache::STATS_HITS => $info['total_hit_count'],
|
||||
Cache::STATS_MISSES => $info['total_miss_count'],
|
||||
Cache::STATS_UPTIME => $info['total_cache_uptime'],
|
||||
Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $meminfo['memory_free'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Xcache cache driver.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author David Abdemoulaie <dave@hobodave.com>
|
||||
*/
|
||||
class XcacheCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return $this->doContains($id) ? unserialize(xcache_get($id)) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return xcache_isset($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return xcache_set($id, serialize($data), (int) $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return xcache_unset($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
$this->checkAuthorization();
|
||||
|
||||
xcache_clear_cache(XC_TYPE_VAR);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that xcache.admin.enable_auth is Off.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \BadMethodCallException When xcache.admin.enable_auth is On.
|
||||
*/
|
||||
protected function checkAuthorization()
|
||||
{
|
||||
if (ini_get('xcache.admin.enable_auth')) {
|
||||
throw new \BadMethodCallException(
|
||||
'To use all features of \Doctrine\Common\Cache\XcacheCache, '
|
||||
. 'you must set "xcache.admin.enable_auth" to "Off" in your php.ini.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
$this->checkAuthorization();
|
||||
|
||||
$info = xcache_info(XC_TYPE_VAR, 0);
|
||||
return array(
|
||||
Cache::STATS_HITS => $info['hits'],
|
||||
Cache::STATS_MISSES => $info['misses'],
|
||||
Cache::STATS_UPTIME => null,
|
||||
Cache::STATS_MEMORY_USAGE => $info['size'],
|
||||
Cache::STATS_MEMORY_AVAILABLE => $info['avail'],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Cache;
|
||||
|
||||
/**
|
||||
* Zend Data Cache cache driver.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Ralph Schindler <ralph.schindler@zend.com>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
class ZendDataCache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFetch($id)
|
||||
{
|
||||
return zend_shm_cache_fetch($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return (false !== zend_shm_cache_fetch($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return zend_shm_cache_store($id, $data, $lifeTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return zend_shm_cache_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doFlush()
|
||||
{
|
||||
$namespace = $this->getNamespace();
|
||||
if (empty($namespace)) {
|
||||
return zend_shm_cache_clear();
|
||||
}
|
||||
return zend_shm_cache_clear($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doGetStats()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
25
vendor/doctrine/cache/phpunit.xml.dist
vendored
25
vendor/doctrine/cache/phpunit.xml.dist
vendored
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="./tests/Doctrine/Tests/TestInit.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine Cache Test Suite">
|
||||
<directory>./tests/Doctrine/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./lib/Doctrine/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
1
vendor/doctrine/collections/.gitignore
vendored
1
vendor/doctrine/collections/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
vendor/
|
21
vendor/doctrine/collections/.travis.yml
vendored
21
vendor/doctrine/collections/.travis.yml
vendored
|
@ -1,21 +0,0 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
- hhvm-nightly
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
|
||||
before_script:
|
||||
- composer --prefer-source install
|
||||
|
||||
script:
|
||||
- phpunit
|
19
vendor/doctrine/collections/LICENSE
vendored
19
vendor/doctrine/collections/LICENSE
vendored
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
25
vendor/doctrine/collections/README.md
vendored
25
vendor/doctrine/collections/README.md
vendored
|
@ -1,25 +0,0 @@
|
|||
# Doctrine Collections
|
||||
|
||||
[](https://travis-ci.org/doctrine/collections)
|
||||
|
||||
Collections Abstraction library
|
||||
|
||||
## Changelog
|
||||
|
||||
### v1.3.0
|
||||
|
||||
* [Explicit casting of first and max results in criteria API](https://github.com/doctrine/collections/pull/26)
|
||||
* [Keep keys when using `ArrayCollection#matching()` with sorting](https://github.com/doctrine/collections/pull/49)
|
||||
* [Made `AbstractLazyCollection#$initialized` protected for extensibility](https://github.com/doctrine/collections/pull/52)
|
||||
|
||||
### v1.2.0
|
||||
|
||||
* Add a new ``AbstractLazyCollection``
|
||||
|
||||
### v1.1.0
|
||||
|
||||
* Deprecated ``Comparison::IS``, because it's only there for SQL semantics.
|
||||
These are fixed in the ORM instead.
|
||||
* Add ``Comparison::CONTAINS`` to perform partial string matches:
|
||||
|
||||
$criteria->andWhere($criteria->expr()->contains('property', 'Foo'));
|
29
vendor/doctrine/collections/composer.json
vendored
29
vendor/doctrine/collections/composer.json
vendored
|
@ -1,29 +0,0 @@
|
|||
{
|
||||
"name": "doctrine/collections",
|
||||
"type": "library",
|
||||
"description": "Collections Abstraction library",
|
||||
"keywords": ["collections", "array", "iterator"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\Common\\Collections\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,343 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Lazy collection that is backed by a concrete collection
|
||||
*
|
||||
* @author Michaël Gallego <mic.gallego@gmail.com>
|
||||
* @since 1.2
|
||||
*/
|
||||
abstract class AbstractLazyCollection implements Collection
|
||||
{
|
||||
/**
|
||||
* The backed collection to use
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $initialized = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function add($element)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->add($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function contains($element)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->contains($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove($key)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->remove($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function removeElement($element)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->removeElement($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function containsKey($key)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->containsKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->getKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->getValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function last()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->last();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->key();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->current();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->next();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function exists(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->exists($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function filter(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->filter($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function forAll(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->forAll($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function map(Closure $func)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->map($func);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function partition(Closure $p)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->partition($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function indexOf($element)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->indexOf($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function slice($offset, $length = null)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->slice($offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->getIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->offsetExists($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
$this->initialize();
|
||||
return $this->collection->offsetGet($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->offsetSet($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
$this->initialize();
|
||||
$this->collection->offsetUnset($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the lazy collection already initialized?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInitialized()
|
||||
{
|
||||
return $this->initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the collection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
if ( ! $this->initialized) {
|
||||
$this->doInitialize();
|
||||
$this->initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the initialization logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function doInitialize();
|
||||
}
|
|
@ -1,387 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use ArrayIterator;
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
|
||||
|
||||
/**
|
||||
* An ArrayCollection is a Collection implementation that wraps a regular PHP array.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class ArrayCollection implements Collection, Selectable
|
||||
{
|
||||
/**
|
||||
* An array containing the entries of this collection.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $elements;
|
||||
|
||||
/**
|
||||
* Initializes a new ArrayCollection.
|
||||
*
|
||||
* @param array $elements
|
||||
*/
|
||||
public function __construct(array $elements = array())
|
||||
{
|
||||
$this->elements = $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function first()
|
||||
{
|
||||
return reset($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function last()
|
||||
{
|
||||
return end($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove($key)
|
||||
{
|
||||
if ( ! isset($this->elements[$key]) && ! array_key_exists($key, $this->elements)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$removed = $this->elements[$key];
|
||||
unset($this->elements[$key]);
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function removeElement($element)
|
||||
{
|
||||
$key = array_search($element, $this->elements, true);
|
||||
|
||||
if ($key === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($this->elements[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return $this->containsKey($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->get($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if ( ! isset($offset)) {
|
||||
return $this->add($value);
|
||||
}
|
||||
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface ArrayAccess.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
return $this->remove($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function containsKey($key)
|
||||
{
|
||||
return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function contains($element)
|
||||
{
|
||||
return in_array($element, $this->elements, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function exists(Closure $p)
|
||||
{
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ($p($key, $element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function indexOf($element)
|
||||
{
|
||||
return array_search($element, $this->elements, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return isset($this->elements[$key]) ? $this->elements[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
return array_keys($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return array_values($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->elements[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function add($value)
|
||||
{
|
||||
$this->elements[] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required by interface IteratorAggregate.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function map(Closure $func)
|
||||
{
|
||||
return new static(array_map($func, $this->elements));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function filter(Closure $p)
|
||||
{
|
||||
return new static(array_filter($this->elements, $p));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function forAll(Closure $p)
|
||||
{
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ( ! $p($key, $element)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function partition(Closure $p)
|
||||
{
|
||||
$matches = $noMatches = array();
|
||||
|
||||
foreach ($this->elements as $key => $element) {
|
||||
if ($p($key, $element)) {
|
||||
$matches[$key] = $element;
|
||||
} else {
|
||||
$noMatches[$key] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
return array(new static($matches), new static($noMatches));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return __CLASS__ . '@' . spl_object_hash($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->elements = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function slice($offset, $length = null)
|
||||
{
|
||||
return array_slice($this->elements, $offset, $length, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function matching(Criteria $criteria)
|
||||
{
|
||||
$expr = $criteria->getWhereExpression();
|
||||
$filtered = $this->elements;
|
||||
|
||||
if ($expr) {
|
||||
$visitor = new ClosureExpressionVisitor();
|
||||
$filter = $visitor->dispatch($expr);
|
||||
$filtered = array_filter($filtered, $filter);
|
||||
}
|
||||
|
||||
if ($orderings = $criteria->getOrderings()) {
|
||||
foreach (array_reverse($orderings) as $field => $ordering) {
|
||||
$next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1);
|
||||
}
|
||||
|
||||
uasort($filtered, $next);
|
||||
}
|
||||
|
||||
$offset = $criteria->getFirstResult();
|
||||
$length = $criteria->getMaxResults();
|
||||
|
||||
if ($offset || $length) {
|
||||
$filtered = array_slice($filtered, (int)$offset, $length);
|
||||
}
|
||||
|
||||
return new static($filtered);
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
|
||||
/**
|
||||
* The missing (SPL) Collection/Array/OrderedMap interface.
|
||||
*
|
||||
* A Collection resembles the nature of a regular PHP array. That is,
|
||||
* it is essentially an <b>ordered map</b> that can also be used
|
||||
* like a list.
|
||||
*
|
||||
* A Collection has an internal iterator just like a PHP array. In addition,
|
||||
* a Collection can be iterated with external iterators, which is preferable.
|
||||
* To use an external iterator simply use the foreach language construct to
|
||||
* iterate over the collection (which calls {@link getIterator()} internally) or
|
||||
* explicitly retrieve an iterator though {@link getIterator()} which can then be
|
||||
* used to iterate over the collection.
|
||||
* You can not rely on the internal iterator of the collection being at a certain
|
||||
* position unless you explicitly positioned it before. Prefer iteration with
|
||||
* external iterators.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
interface Collection extends Countable, IteratorAggregate, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Adds an element at the end of the collection.
|
||||
*
|
||||
* @param mixed $element The element to add.
|
||||
*
|
||||
* @return boolean Always TRUE.
|
||||
*/
|
||||
public function add($element);
|
||||
|
||||
/**
|
||||
* Clears the collection, removing all elements.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
|
||||
/**
|
||||
* Checks whether an element is contained in the collection.
|
||||
* This is an O(n) operation, where n is the size of the collection.
|
||||
*
|
||||
* @param mixed $element The element to search for.
|
||||
*
|
||||
* @return boolean TRUE if the collection contains the element, FALSE otherwise.
|
||||
*/
|
||||
public function contains($element);
|
||||
|
||||
/**
|
||||
* Checks whether the collection is empty (contains no elements).
|
||||
*
|
||||
* @return boolean TRUE if the collection is empty, FALSE otherwise.
|
||||
*/
|
||||
public function isEmpty();
|
||||
|
||||
/**
|
||||
* Removes the element at the specified index from the collection.
|
||||
*
|
||||
* @param string|integer $key The kex/index of the element to remove.
|
||||
*
|
||||
* @return mixed The removed element or NULL, if the collection did not contain the element.
|
||||
*/
|
||||
public function remove($key);
|
||||
|
||||
/**
|
||||
* Removes the specified element from the collection, if it is found.
|
||||
*
|
||||
* @param mixed $element The element to remove.
|
||||
*
|
||||
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
|
||||
*/
|
||||
public function removeElement($element);
|
||||
|
||||
/**
|
||||
* Checks whether the collection contains an element with the specified key/index.
|
||||
*
|
||||
* @param string|integer $key The key/index to check for.
|
||||
*
|
||||
* @return boolean TRUE if the collection contains an element with the specified key/index,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
public function containsKey($key);
|
||||
|
||||
/**
|
||||
* Gets the element at the specified key/index.
|
||||
*
|
||||
* @param string|integer $key The key/index of the element to retrieve.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key);
|
||||
|
||||
/**
|
||||
* Gets all keys/indices of the collection.
|
||||
*
|
||||
* @return array The keys/indices of the collection, in the order of the corresponding
|
||||
* elements in the collection.
|
||||
*/
|
||||
public function getKeys();
|
||||
|
||||
/**
|
||||
* Gets all values of the collection.
|
||||
*
|
||||
* @return array The values of all elements in the collection, in the order they
|
||||
* appear in the collection.
|
||||
*/
|
||||
public function getValues();
|
||||
|
||||
/**
|
||||
* Sets an element in the collection at the specified key/index.
|
||||
*
|
||||
* @param string|integer $key The key/index of the element to set.
|
||||
* @param mixed $value The element to set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($key, $value);
|
||||
|
||||
/**
|
||||
* Gets a native PHP array representation of the collection.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray();
|
||||
|
||||
/**
|
||||
* Sets the internal iterator to the first element in the collection and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function first();
|
||||
|
||||
/**
|
||||
* Sets the internal iterator to the last element in the collection and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function last();
|
||||
|
||||
/**
|
||||
* Gets the key/index of the element at the current iterator position.
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public function key();
|
||||
|
||||
/**
|
||||
* Gets the element of the collection at the current iterator position.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current();
|
||||
|
||||
/**
|
||||
* Moves the internal iterator position to the next element and returns this element.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function next();
|
||||
|
||||
/**
|
||||
* Tests for the existence of an element that satisfies the given predicate.
|
||||
*
|
||||
* @param Closure $p The predicate.
|
||||
*
|
||||
* @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
|
||||
*/
|
||||
public function exists(Closure $p);
|
||||
|
||||
/**
|
||||
* Returns all the elements of this collection that satisfy the predicate p.
|
||||
* The order of the elements is preserved.
|
||||
*
|
||||
* @param Closure $p The predicate used for filtering.
|
||||
*
|
||||
* @return Collection A collection with the results of the filter operation.
|
||||
*/
|
||||
public function filter(Closure $p);
|
||||
|
||||
/**
|
||||
* Tests whether the given predicate p holds for all elements of this collection.
|
||||
*
|
||||
* @param Closure $p The predicate.
|
||||
*
|
||||
* @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
|
||||
*/
|
||||
public function forAll(Closure $p);
|
||||
|
||||
/**
|
||||
* Applies the given function to each element in the collection and returns
|
||||
* a new collection with the elements returned by the function.
|
||||
*
|
||||
* @param Closure $func
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function map(Closure $func);
|
||||
|
||||
/**
|
||||
* Partitions this collection in two collections according to a predicate.
|
||||
* Keys are preserved in the resulting collections.
|
||||
*
|
||||
* @param Closure $p The predicate on which to partition.
|
||||
*
|
||||
* @return array An array with two elements. The first element contains the collection
|
||||
* of elements where the predicate returned TRUE, the second element
|
||||
* contains the collection of elements where the predicate returned FALSE.
|
||||
*/
|
||||
public function partition(Closure $p);
|
||||
|
||||
/**
|
||||
* Gets the index/key of a given element. The comparison of two elements is strict,
|
||||
* that means not only the value but also the type must match.
|
||||
* For objects this means reference equality.
|
||||
*
|
||||
* @param mixed $element The element to search for.
|
||||
*
|
||||
* @return int|string|bool The key/index of the element or FALSE if the element was not found.
|
||||
*/
|
||||
public function indexOf($element);
|
||||
|
||||
/**
|
||||
* Extracts a slice of $length elements starting at position $offset from the Collection.
|
||||
*
|
||||
* If $length is null it returns all elements from $offset to the end of the Collection.
|
||||
* Keys have to be preserved by this method. Calling this method will only return the
|
||||
* selected slice and NOT change the elements contained in the collection slice is called on.
|
||||
*
|
||||
* @param int $offset The offset to start from.
|
||||
* @param int|null $length The maximum number of elements to return, or null for no limit.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function slice($offset, $length = null);
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Expression;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
|
||||
/**
|
||||
* Criteria for filtering Selectable collections.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
class Criteria
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ASC = 'ASC';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const DESC = 'DESC';
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\ExpressionBuilder|null
|
||||
*/
|
||||
private static $expressionBuilder;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\Expr\Expression|null
|
||||
*/
|
||||
private $expression;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $orderings = array();
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $firstResult;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxResults;
|
||||
|
||||
/**
|
||||
* Creates an instance of the class.
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expression builder.
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\ExpressionBuilder
|
||||
*/
|
||||
public static function expr()
|
||||
{
|
||||
if (self::$expressionBuilder === null) {
|
||||
self::$expressionBuilder = new ExpressionBuilder();
|
||||
}
|
||||
|
||||
return self::$expressionBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new Criteria.
|
||||
*
|
||||
* @param Expression $expression
|
||||
* @param string[]|null $orderings
|
||||
* @param int|null $firstResult
|
||||
* @param int|null $maxResults
|
||||
*/
|
||||
public function __construct(Expression $expression = null, array $orderings = null, $firstResult = null, $maxResults = null)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
|
||||
$this->setFirstResult($firstResult);
|
||||
$this->setMaxResults($maxResults);
|
||||
|
||||
if (null !== $orderings) {
|
||||
$this->orderBy($orderings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the where expression to evaluate when this Criteria is searched for.
|
||||
*
|
||||
* @param Expression $expression
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function where(Expression $expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the where expression to evaluate when this Criteria is searched for
|
||||
* using an AND with previous expression.
|
||||
*
|
||||
* @param Expression $expression
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function andWhere(Expression $expression)
|
||||
{
|
||||
if ($this->expression === null) {
|
||||
return $this->where($expression);
|
||||
}
|
||||
|
||||
$this->expression = new CompositeExpression(CompositeExpression::TYPE_AND, array(
|
||||
$this->expression, $expression
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the where expression to evaluate when this Criteria is searched for
|
||||
* using an OR with previous expression.
|
||||
*
|
||||
* @param Expression $expression
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function orWhere(Expression $expression)
|
||||
{
|
||||
if ($this->expression === null) {
|
||||
return $this->where($expression);
|
||||
}
|
||||
|
||||
$this->expression = new CompositeExpression(CompositeExpression::TYPE_OR, array(
|
||||
$this->expression, $expression
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the expression attached to this Criteria.
|
||||
*
|
||||
* @return Expression|null
|
||||
*/
|
||||
public function getWhereExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current orderings of this Criteria.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getOrderings()
|
||||
{
|
||||
return $this->orderings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ordering of the result of this Criteria.
|
||||
*
|
||||
* Keys are field and values are the order, being either ASC or DESC.
|
||||
*
|
||||
* @see Criteria::ASC
|
||||
* @see Criteria::DESC
|
||||
*
|
||||
* @param string[] $orderings
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function orderBy(array $orderings)
|
||||
{
|
||||
$this->orderings = array_map(
|
||||
function ($ordering) {
|
||||
return strtoupper($ordering) === Criteria::ASC ? Criteria::ASC : Criteria::DESC;
|
||||
},
|
||||
$orderings
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current first result option of this Criteria.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getFirstResult()
|
||||
{
|
||||
return $this->firstResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of first result that this Criteria should return.
|
||||
*
|
||||
* @param int|null $firstResult The value to set.
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function setFirstResult($firstResult)
|
||||
{
|
||||
$this->firstResult = null === $firstResult ? null : (int) $firstResult;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets maxResults.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getMaxResults()
|
||||
{
|
||||
return $this->maxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets maxResults.
|
||||
*
|
||||
* @param int|null $maxResults The value to set.
|
||||
*
|
||||
* @return Criteria
|
||||
*/
|
||||
public function setMaxResults($maxResults)
|
||||
{
|
||||
$this->maxResults = null === $maxResults ? null : (int) $maxResults;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,227 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Walks an expression graph and turns it into a PHP closure.
|
||||
*
|
||||
* This closure can be used with {@Collection#filter()} and is used internally
|
||||
* by {@ArrayCollection#select()}.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
class ClosureExpressionVisitor extends ExpressionVisitor
|
||||
{
|
||||
/**
|
||||
* Accesses the field of a given object. This field has to be public
|
||||
* directly or indirectly (through an accessor get*, is*, or a magic
|
||||
* method, __get, __call).
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getObjectFieldValue($object, $field)
|
||||
{
|
||||
if (is_array($object)) {
|
||||
return $object[$field];
|
||||
}
|
||||
|
||||
$accessors = array('get', 'is');
|
||||
|
||||
foreach ($accessors as $accessor) {
|
||||
$accessor .= $field;
|
||||
|
||||
if ( ! method_exists($object, $accessor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $object->$accessor();
|
||||
}
|
||||
|
||||
// __call should be triggered for get.
|
||||
$accessor = $accessors[0] . $field;
|
||||
|
||||
if (method_exists($object, '__call')) {
|
||||
return $object->$accessor();
|
||||
}
|
||||
|
||||
if ($object instanceof \ArrayAccess) {
|
||||
return $object[$field];
|
||||
}
|
||||
|
||||
return $object->$field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for sorting arrays of objects based on multiple fields + orientations.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $orientation
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
public static function sortByField($name, $orientation = 1, \Closure $next = null)
|
||||
{
|
||||
if ( ! $next) {
|
||||
$next = function() {
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
return function ($a, $b) use ($name, $next, $orientation) {
|
||||
$aValue = ClosureExpressionVisitor::getObjectFieldValue($a, $name);
|
||||
$bValue = ClosureExpressionVisitor::getObjectFieldValue($b, $name);
|
||||
|
||||
if ($aValue === $bValue) {
|
||||
return $next($a, $b);
|
||||
}
|
||||
|
||||
return (($aValue > $bValue) ? 1 : -1) * $orientation;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkComparison(Comparison $comparison)
|
||||
{
|
||||
$field = $comparison->getField();
|
||||
$value = $comparison->getValue()->getValue(); // shortcut for walkValue()
|
||||
|
||||
switch ($comparison->getOperator()) {
|
||||
case Comparison::EQ:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) === $value;
|
||||
};
|
||||
|
||||
case Comparison::NEQ:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) !== $value;
|
||||
};
|
||||
|
||||
case Comparison::LT:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) < $value;
|
||||
};
|
||||
|
||||
case Comparison::LTE:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) <= $value;
|
||||
};
|
||||
|
||||
case Comparison::GT:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) > $value;
|
||||
};
|
||||
|
||||
case Comparison::GTE:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) >= $value;
|
||||
};
|
||||
|
||||
case Comparison::IN:
|
||||
return function ($object) use ($field, $value) {
|
||||
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
|
||||
};
|
||||
|
||||
case Comparison::NIN:
|
||||
return function ($object) use ($field, $value) {
|
||||
return ! in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
|
||||
};
|
||||
|
||||
case Comparison::CONTAINS:
|
||||
return function ($object) use ($field, $value) {
|
||||
return false !== strpos(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
|
||||
};
|
||||
|
||||
default:
|
||||
throw new \RuntimeException("Unknown comparison operator: " . $comparison->getOperator());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkValue(Value $value)
|
||||
{
|
||||
return $value->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function walkCompositeExpression(CompositeExpression $expr)
|
||||
{
|
||||
$expressionList = array();
|
||||
|
||||
foreach ($expr->getExpressionList() as $child) {
|
||||
$expressionList[] = $this->dispatch($child);
|
||||
}
|
||||
|
||||
switch($expr->getType()) {
|
||||
case CompositeExpression::TYPE_AND:
|
||||
return $this->andExpressions($expressionList);
|
||||
|
||||
case CompositeExpression::TYPE_OR:
|
||||
return $this->orExpressions($expressionList);
|
||||
|
||||
default:
|
||||
throw new \RuntimeException("Unknown composite " . $expr->getType());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expressions
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function andExpressions($expressions)
|
||||
{
|
||||
return function ($object) use ($expressions) {
|
||||
foreach ($expressions as $expression) {
|
||||
if ( ! $expression($object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expressions
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private function orExpressions($expressions)
|
||||
{
|
||||
return function ($object) use ($expressions) {
|
||||
foreach ($expressions as $expression) {
|
||||
if ($expression($object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Comparison of a field with a value by the given operator.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
class Comparison implements Expression
|
||||
{
|
||||
const EQ = '=';
|
||||
const NEQ = '<>';
|
||||
const LT = '<';
|
||||
const LTE = '<=';
|
||||
const GT = '>';
|
||||
const GTE = '>=';
|
||||
const IS = '='; // no difference with EQ
|
||||
const IN = 'IN';
|
||||
const NIN = 'NIN';
|
||||
const CONTAINS = 'CONTAINS';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $field;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $op;
|
||||
|
||||
/**
|
||||
* @var Value
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($field, $operator, $value)
|
||||
{
|
||||
if ( ! ($value instanceof Value)) {
|
||||
$value = new Value($value);
|
||||
}
|
||||
|
||||
$this->field = $field;
|
||||
$this->op = $operator;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Value
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->op;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkComparison($this);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Expression of Expressions combined by AND or OR operation.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
class CompositeExpression implements Expression
|
||||
{
|
||||
const TYPE_AND = 'AND';
|
||||
const TYPE_OR = 'OR';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var Expression[]
|
||||
*/
|
||||
private $expressions = array();
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param array $expressions
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct($type, array $expressions)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
foreach ($expressions as $expr) {
|
||||
if ($expr instanceof Value) {
|
||||
throw new \RuntimeException("Values are not supported expressions as children of and/or expressions.");
|
||||
}
|
||||
if ( ! ($expr instanceof Expression)) {
|
||||
throw new \RuntimeException("No expression given to CompositeExpression.");
|
||||
}
|
||||
|
||||
$this->expressions[] = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of expressions nested in this composite.
|
||||
*
|
||||
* @return Expression[]
|
||||
*/
|
||||
public function getExpressionList()
|
||||
{
|
||||
return $this->expressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkCompositeExpression($this);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* Expression for the {@link Selectable} interface.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
interface Expression
|
||||
{
|
||||
/**
|
||||
* @param ExpressionVisitor $visitor
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
/**
|
||||
* An Expression visitor walks a graph of expressions and turns them into a
|
||||
* query for the underlying implementation.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
abstract class ExpressionVisitor
|
||||
{
|
||||
/**
|
||||
* Converts a comparison expression into the target query language output.
|
||||
*
|
||||
* @param Comparison $comparison
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkComparison(Comparison $comparison);
|
||||
|
||||
/**
|
||||
* Converts a value expression into the target query language part.
|
||||
*
|
||||
* @param Value $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkValue(Value $value);
|
||||
|
||||
/**
|
||||
* Converts a composite expression into the target query language output.
|
||||
*
|
||||
* @param CompositeExpression $expr
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function walkCompositeExpression(CompositeExpression $expr);
|
||||
|
||||
/**
|
||||
* Dispatches walking an expression to the appropriate handler.
|
||||
*
|
||||
* @param Expression $expr
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function dispatch(Expression $expr)
|
||||
{
|
||||
switch (true) {
|
||||
case ($expr instanceof Comparison):
|
||||
return $this->walkComparison($expr);
|
||||
|
||||
case ($expr instanceof Value):
|
||||
return $this->walkValue($expr);
|
||||
|
||||
case ($expr instanceof CompositeExpression):
|
||||
return $this->walkCompositeExpression($expr);
|
||||
|
||||
default:
|
||||
throw new \RuntimeException("Unknown Expression " . get_class($expr));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections\Expr;
|
||||
|
||||
class Value implements Expression
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function visit(ExpressionVisitor $visitor)
|
||||
{
|
||||
return $visitor->walkValue($this);
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
use Doctrine\Common\Collections\Expr\Comparison;
|
||||
use Doctrine\Common\Collections\Expr\CompositeExpression;
|
||||
use Doctrine\Common\Collections\Expr\Value;
|
||||
|
||||
/**
|
||||
* Builder for Expressions in the {@link Selectable} interface.
|
||||
*
|
||||
* Important Notice for interoperable code: You have to use scalar
|
||||
* values only for comparisons, otherwise the behavior of the comparision
|
||||
* may be different between implementations (Array vs ORM vs ODM).
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
class ExpressionBuilder
|
||||
{
|
||||
/**
|
||||
* @param mixed $x
|
||||
*
|
||||
* @return CompositeExpression
|
||||
*/
|
||||
public function andX($x = null)
|
||||
{
|
||||
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $x
|
||||
*
|
||||
* @return CompositeExpression
|
||||
*/
|
||||
public function orX($x = null)
|
||||
{
|
||||
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function eq($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::EQ, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function gt($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::GT, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function lt($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::LT, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function gte($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::GTE, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function lte($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::LTE, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function neq($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::NEQ, new Value($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function isNull($field)
|
||||
{
|
||||
return new Comparison($field, Comparison::EQ, new Value(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $values
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function in($field, array $values)
|
||||
{
|
||||
return new Comparison($field, Comparison::IN, new Value($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $values
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function notIn($field, array $values)
|
||||
{
|
||||
return new Comparison($field, Comparison::NIN, new Value($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Comparison
|
||||
*/
|
||||
public function contains($field, $value)
|
||||
{
|
||||
return new Comparison($field, Comparison::CONTAINS, new Value($value));
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Collections;
|
||||
|
||||
/**
|
||||
* Interface for collections that allow efficient filtering with an expression API.
|
||||
*
|
||||
* Goal of this interface is a backend independent method to fetch elements
|
||||
* from a collections. {@link Expression} is crafted in a way that you can
|
||||
* implement queries from both in-memory and database-backed collections.
|
||||
*
|
||||
* For database backed collections this allows very efficient access by
|
||||
* utilizing the query APIs, for example SQL in the ORM. Applications using
|
||||
* this API can implement efficient database access without having to ask the
|
||||
* EntityManager or Repositories.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.3
|
||||
*/
|
||||
interface Selectable
|
||||
{
|
||||
/**
|
||||
* Selects all elements from a selectable that match the expression and
|
||||
* returns a new collection containing these elements.
|
||||
*
|
||||
* @param Criteria $criteria
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function matching(Criteria $criteria);
|
||||
}
|
31
vendor/doctrine/collections/phpunit.xml.dist
vendored
31
vendor/doctrine/collections/phpunit.xml.dist
vendored
|
@ -1,31 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="./tests/Doctrine/Tests/TestInit.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine Collections Test Suite">
|
||||
<directory>./tests/Doctrine/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./lib/Doctrine/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>performance</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
</phpunit>
|
10
vendor/doctrine/common/.gitignore
vendored
10
vendor/doctrine/common/.gitignore
vendored
|
@ -1,10 +0,0 @@
|
|||
build/
|
||||
logs/
|
||||
reports/
|
||||
dist/
|
||||
tests/Doctrine/Tests/Common/Proxy/generated/
|
||||
vendor/
|
||||
.idea
|
||||
composer.lock
|
||||
doctrine-common-*.tar
|
||||
doctrine-common-*.tar.gz
|
3
vendor/doctrine/common/.gitmodules
vendored
3
vendor/doctrine/common/.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "lib/vendor/doctrine-build-common"]
|
||||
path = lib/vendor/doctrine-build-common
|
||||
url = git://github.com/doctrine/doctrine-build-common.git
|
26
vendor/doctrine/common/.travis.yml
vendored
26
vendor/doctrine/common/.travis.yml
vendored
|
@ -1,26 +0,0 @@
|
|||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directory:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
php:
|
||||
- 5.3.3
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- composer --prefer-source install
|
||||
|
||||
script:
|
||||
- ./vendor/bin/phpunit
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 7.0
|
19
vendor/doctrine/common/LICENSE
vendored
19
vendor/doctrine/common/LICENSE
vendored
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2006-2012 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
12
vendor/doctrine/common/README.md
vendored
12
vendor/doctrine/common/README.md
vendored
|
@ -1,12 +0,0 @@
|
|||
# Doctrine Common
|
||||
|
||||
[](http://travis-ci.org/doctrine/common)
|
||||
|
||||
The Doctrine Common project is a library that provides extensions to core PHP functionality.
|
||||
|
||||
## More resources:
|
||||
|
||||
* [Website](http://www.doctrine-project.org)
|
||||
* [Documentation](http://docs.doctrine-project.org/projects/doctrine-common/en/latest/)
|
||||
* [Issue Tracker](http://www.doctrine-project.org/jira/browse/DCOM)
|
||||
* [Downloads](http://github.com/doctrine/common/downloads)
|
39
vendor/doctrine/common/UPGRADE_TO_2_1
vendored
39
vendor/doctrine/common/UPGRADE_TO_2_1
vendored
|
@ -1,39 +0,0 @@
|
|||
This document details all the possible changes that you should investigate when updating
|
||||
your project from Doctrine Common 2.0.x to 2.1
|
||||
|
||||
## AnnotationReader changes
|
||||
|
||||
The annotation reader was heavily refactored between 2.0 and 2.1-RC1. In theory the operation of the new reader should be backwards compatible, but it has to be setup differently to work that way:
|
||||
|
||||
$reader = new \Doctrine\Common\Annotations\AnnotationReader();
|
||||
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||
// new code necessary starting here
|
||||
$reader->setIgnoreNotImportedAnnotations(true);
|
||||
$reader->setEnableParsePhpImports(false);
|
||||
$reader = new \Doctrine\Common\Annotations\CachedReader(
|
||||
new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
|
||||
);
|
||||
|
||||
## Annotation Base class or @Annotation
|
||||
|
||||
Beginning after 2.1-RC2 you have to either extend ``Doctrine\Common\Annotations\Annotation`` or add @Annotation to your annotations class-level docblock, otherwise the class will simply be ignored.
|
||||
|
||||
## Removed methods on AnnotationReader
|
||||
|
||||
* AnnotationReader::setAutoloadAnnotations()
|
||||
* AnnotationReader::getAutoloadAnnotations()
|
||||
* AnnotationReader::isAutoloadAnnotations()
|
||||
|
||||
## AnnotationRegistry
|
||||
|
||||
Autoloading through the PHP autoloader is removed from the 2.1 AnnotationReader. Instead you have to use the global AnnotationRegistry for loading purposes:
|
||||
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile($fileWithAnnotations);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace($namespace, $dirs = null);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespaces($namespaces);
|
||||
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader($callable);
|
||||
|
||||
The $callable for registering a loader accepts a class as first and only parameter and must try to silently autoload it. On success true has to be returned.
|
||||
The registerAutoloadNamespace function registers a PSR-0 compatible silent autoloader for all classes with the given namespace in the given directories.
|
||||
If null is passed as directory the include path will be used.
|
||||
|
61
vendor/doctrine/common/UPGRADE_TO_2_2
vendored
61
vendor/doctrine/common/UPGRADE_TO_2_2
vendored
|
@ -1,61 +0,0 @@
|
|||
This document details all the possible changes that you should investigate when
|
||||
updating your project from Doctrine Common 2.1 to 2.2:
|
||||
|
||||
## Annotation Changes
|
||||
|
||||
- AnnotationReader::setIgnoreNotImportedAnnotations has been removed, you need to
|
||||
add ignore annotation names which are supposed to be ignored via
|
||||
AnnotationReader::addGlobalIgnoredName
|
||||
|
||||
- AnnotationReader::setAutoloadAnnotations was deprecated by the AnnotationRegistry
|
||||
in 2.1 and has been removed in 2.2
|
||||
|
||||
- AnnotationReader::setEnableParsePhpImports was added to ease transition to the new
|
||||
annotation mechanism in 2.1 and is removed in 2.2
|
||||
|
||||
- AnnotationReader::isParsePhpImportsEnabled is removed (see above)
|
||||
|
||||
- AnnotationReader::setDefaultAnnotationNamespace was deprecated in favor of explicit
|
||||
configuration in 2.1 and will be removed in 2.2 (for isolated projects where you
|
||||
have full-control over _all_ available annotations, we offer a dedicated reader
|
||||
class ``SimpleAnnotationReader``)
|
||||
|
||||
- AnnotationReader::setAnnotationCreationFunction was deprecated in 2.1 and will be
|
||||
removed in 2.2. We only offer two creation mechanisms which cannot be changed
|
||||
anymore to allow the same reader instance to work with all annotations regardless
|
||||
of which library they are coming from.
|
||||
|
||||
- AnnotationReader::setAnnotationNamespaceAlias was deprecated in 2.1 and will be
|
||||
removed in 2.2 (see setDefaultAnnotationNamespace)
|
||||
|
||||
- If you use a class as annotation which has not the @Annotation marker in it's
|
||||
class block, we will now throw an exception instead of silently ignoring it. You
|
||||
can however still achieve the previous behavior using the @IgnoreAnnotation, or
|
||||
AnnotationReader::addGlobalIgnoredName (the exception message will contain detailed
|
||||
instructions when you run into this problem).
|
||||
|
||||
## Cache Changes
|
||||
|
||||
- Renamed old AbstractCache to CacheProvider
|
||||
|
||||
- Dropped the support to the following functions of all cache providers:
|
||||
|
||||
- CacheProvider::deleteByWildcard
|
||||
|
||||
- CacheProvider::deleteByRegEx
|
||||
|
||||
- CacheProvider::deleteByPrefix
|
||||
|
||||
- CacheProvider::deleteBySuffix
|
||||
|
||||
- CacheProvider::deleteAll will not remove ALL entries, it will only mark them as invalid
|
||||
|
||||
- CacheProvider::flushAll will remove ALL entries, namespaced or not
|
||||
|
||||
- Added support to MemcachedCache
|
||||
|
||||
- Added support to WincacheCache
|
||||
|
||||
## ClassLoader Changes
|
||||
|
||||
- ClassLoader::fileExistsInIncludePath() no longer exists. Use the native stream_resolve_include_path() PHP function
|
3
vendor/doctrine/common/build.properties
vendored
3
vendor/doctrine/common/build.properties
vendored
|
@ -1,3 +0,0 @@
|
|||
# Version class and file
|
||||
project.version_class = Doctrine\\Common\\Version
|
||||
project.version_file = lib/Doctrine/Common/Version.php
|
101
vendor/doctrine/common/build.xml
vendored
101
vendor/doctrine/common/build.xml
vendored
|
@ -1,101 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<project name="DoctrineCommon" default="build" basedir=".">
|
||||
<property file="build.properties" />
|
||||
|
||||
<target name="php">
|
||||
<exec executable="which" outputproperty="php_executable">
|
||||
<arg value="php" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="prepare">
|
||||
<mkdir dir="build" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="check-git-checkout-clean,prepare,php,composer">
|
||||
<exec executable="${php_executable}">
|
||||
<arg value="build/composer.phar" />
|
||||
<arg value="archive" />
|
||||
<arg value="--dir=build" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="composer" depends="php,composer-check,composer-download">
|
||||
<exec executable="${php_executable}">
|
||||
<arg value="build/composer.phar" />
|
||||
<arg value="install" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="composer-check" depends="prepare">
|
||||
<available file="build/composer.phar" property="composer.present"/>
|
||||
</target>
|
||||
|
||||
<target name="composer-download" unless="composer.present">
|
||||
<exec executable="wget">
|
||||
<arg value="-Obuild/composer.phar" />
|
||||
<arg value="http://getcomposer.org/composer.phar" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="make-release" depends="check-git-checkout-clean,prepare,php">
|
||||
<replace file="${project.version_file}" token="-DEV" value="" failOnNoReplacements="true" />
|
||||
<exec executable="${php_executable}" outputproperty="doctrine.current_version" failonerror="true">
|
||||
<arg value="-r" />
|
||||
<arg value="require_once '${project.version_file}';echo ${project.version_class}::VERSION;" />
|
||||
</exec>
|
||||
<exec executable="${php_executable}" outputproperty="doctrine.next_version" failonerror="true">
|
||||
<arg value="-r" />
|
||||
<arg value="$parts = explode('.', str_ireplace(array('-DEV', '-ALPHA', '-BETA'), '', '${doctrine.current_version}'));
|
||||
if (count($parts) != 3) {
|
||||
throw new \InvalidArgumentException('Version is assumed in format x.y.z, ${doctrine.current_version} given');
|
||||
}
|
||||
$parts[2]++;
|
||||
echo implode('.', $parts);
|
||||
" />
|
||||
</exec>
|
||||
|
||||
<git-commit file="${project.version_file}" message="Release ${doctrine.current_version}" />
|
||||
<git-tag version="${doctrine.current_version}" />
|
||||
<replace file="${project.version_file}" token="${doctrine.current_version}" value="${doctrine.next_version}-DEV" />
|
||||
<git-commit file="${project.version_file}" message="Bump version to ${doctrine.next_version}" />
|
||||
</target>
|
||||
|
||||
<target name="check-git-checkout-clean">
|
||||
<exec executable="git" failonerror="true">
|
||||
<arg value="diff-index" />
|
||||
<arg value="--quiet" />
|
||||
<arg value="HEAD" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<macrodef name="git-commit">
|
||||
<attribute name="file" default="NOT SET"/>
|
||||
<attribute name="message" default="NOT SET"/>
|
||||
|
||||
<sequential>
|
||||
<exec executable="git">
|
||||
<arg value="add" />
|
||||
<arg value="@{file}" />
|
||||
</exec>
|
||||
<exec executable="git">
|
||||
<arg value="commit" />
|
||||
<arg value="-m" />
|
||||
<arg value="@{message}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="git-tag">
|
||||
<attribute name="version" default="NOT SET" />
|
||||
|
||||
<sequential>
|
||||
<exec executable="git">
|
||||
<arg value="tag" />
|
||||
<arg value="-m" />
|
||||
<arg value="v@{version}" />
|
||||
<arg value="v@{version}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</project>
|
38
vendor/doctrine/common/composer.json
vendored
38
vendor/doctrine/common/composer.json
vendored
|
@ -1,38 +0,0 @@
|
|||
{
|
||||
"name": "doctrine/common",
|
||||
"type": "library",
|
||||
"description": "Common Library for Doctrine projects",
|
||||
"keywords": ["collections", "spl", "eventmanager", "annotations", "persistence"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
|
||||
{"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"doctrine/inflector": "1.*",
|
||||
"doctrine/cache": "1.*",
|
||||
"doctrine/collections": "1.*",
|
||||
"doctrine/lexer": "1.*",
|
||||
"doctrine/annotations": "1.*"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~3.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\Common\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.6.x-dev"
|
||||
}
|
||||
},
|
||||
"archive": {
|
||||
"exclude": ["!vendor", "tests", "*phpunit.xml", ".travis.yml", "build.xml", "build.properties", "composer.phar"]
|
||||
}
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* A <tt>ClassLoader</tt> is an autoloader for class files that can be
|
||||
* installed on the SPL autoload stack. It is a class loader that either loads only classes
|
||||
* of a specific namespace or all namespaces and it is suitable for working together
|
||||
* with other autoloaders in the SPL autoload stack.
|
||||
*
|
||||
* If no include path is configured through the constructor or {@link setIncludePath}, a ClassLoader
|
||||
* relies on the PHP <code>include_path</code>.
|
||||
*
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*
|
||||
* @deprecated the ClassLoader is deprecated and will be removed in version 3.0 of doctrine/common.
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
/**
|
||||
* PHP file extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fileExtension = '.php';
|
||||
|
||||
/**
|
||||
* Current namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $namespace;
|
||||
|
||||
/**
|
||||
* Current include path.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $includePath;
|
||||
|
||||
/**
|
||||
* PHP namespace separator.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespaceSeparator = '\\';
|
||||
|
||||
/**
|
||||
* Creates a new <tt>ClassLoader</tt> that loads classes of the
|
||||
* specified namespace from the specified include path.
|
||||
*
|
||||
* If no include path is given, the ClassLoader relies on the PHP include_path.
|
||||
* If neither a namespace nor an include path is given, the ClassLoader will
|
||||
* be responsible for loading all classes, thereby relying on the PHP include_path.
|
||||
*
|
||||
* @param string|null $ns The namespace of the classes to load.
|
||||
* @param string|null $includePath The base include path to use.
|
||||
*/
|
||||
public function __construct($ns = null, $includePath = null)
|
||||
{
|
||||
$this->namespace = $ns;
|
||||
$this->includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace separator used by classes in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string $sep The separator to use.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNamespaceSeparator($sep)
|
||||
{
|
||||
$this->namespaceSeparator = $sep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the namespace separator used by classes in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespaceSeparator()
|
||||
{
|
||||
return $this->namespaceSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base include path for all class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string|null $includePath
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIncludePath($includePath)
|
||||
{
|
||||
$this->includePath = $includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base include path for all class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIncludePath()
|
||||
{
|
||||
return $this->includePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file extension of class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @param string $fileExtension
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFileExtension($fileExtension)
|
||||
{
|
||||
$this->fileExtension = $fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file extension of class files in the namespace of this ClassLoader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileExtension()
|
||||
{
|
||||
return $this->fileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this ClassLoader on the SPL autoload stack.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this ClassLoader from the SPL autoload stack.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $className The name of the class to load.
|
||||
*
|
||||
* @return boolean TRUE if the class has been successfully loaded, FALSE otherwise.
|
||||
*/
|
||||
public function loadClass($className)
|
||||
{
|
||||
if (self::typeExists($className)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->canLoadClass($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require ($this->includePath !== null ? $this->includePath . DIRECTORY_SEPARATOR : '')
|
||||
. str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className)
|
||||
. $this->fileExtension;
|
||||
|
||||
return self::typeExists($className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks this ClassLoader whether it can potentially load the class (file) with
|
||||
* the given name.
|
||||
*
|
||||
* @param string $className The fully-qualified name of the class.
|
||||
*
|
||||
* @return boolean TRUE if this ClassLoader can load the class, FALSE otherwise.
|
||||
*/
|
||||
public function canLoadClass($className)
|
||||
{
|
||||
if ($this->namespace !== null && strpos($className, $this->namespace.$this->namespaceSeparator) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = str_replace($this->namespaceSeparator, DIRECTORY_SEPARATOR, $className) . $this->fileExtension;
|
||||
|
||||
if ($this->includePath !== null) {
|
||||
return is_file($this->includePath . DIRECTORY_SEPARATOR . $file);
|
||||
}
|
||||
|
||||
return (false !== stream_resolve_include_path($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a class with a given name exists. A class "exists" if it is either
|
||||
* already defined in the current request or if there is an autoloader on the SPL
|
||||
* autoload stack that is a) responsible for the class in question and b) is able to
|
||||
* load a class file in which the class definition resides.
|
||||
*
|
||||
* If the class is not already defined, each autoloader in the SPL autoload stack
|
||||
* is asked whether it is able to tell if the class exists. If the autoloader is
|
||||
* a <tt>ClassLoader</tt>, {@link canLoadClass} is used, otherwise the autoload
|
||||
* function of the autoloader is invoked and expected to return a value that
|
||||
* evaluates to TRUE if the class (file) exists. As soon as one autoloader reports
|
||||
* that the class exists, TRUE is returned.
|
||||
*
|
||||
* Note that, depending on what kinds of autoloaders are installed on the SPL
|
||||
* autoload stack, the class (file) might already be loaded as a result of checking
|
||||
* for its existence. This is not the case with a <tt>ClassLoader</tt>, who separates
|
||||
* these responsibilities.
|
||||
*
|
||||
* @param string $className The fully-qualified name of the class.
|
||||
*
|
||||
* @return boolean TRUE if the class exists as per the definition given above, FALSE otherwise.
|
||||
*/
|
||||
public static function classExists($className)
|
||||
{
|
||||
return self::typeExists($className, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <tt>ClassLoader</tt> from the SPL autoload stack that is responsible
|
||||
* for (and is able to load) the class with the given name.
|
||||
*
|
||||
* @param string $className The name of the class.
|
||||
*
|
||||
* @return ClassLoader The <tt>ClassLoader</tt> for the class or NULL if no such <tt>ClassLoader</tt> exists.
|
||||
*/
|
||||
public static function getClassLoader($className)
|
||||
{
|
||||
foreach (spl_autoload_functions() as $loader) {
|
||||
if (is_array($loader)
|
||||
&& ($classLoader = reset($loader))
|
||||
&& $classLoader instanceof ClassLoader
|
||||
&& $classLoader->canLoadClass($className)
|
||||
) {
|
||||
return $classLoader;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given type exists
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $autoload
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function typeExists($type, $autoload = false)
|
||||
{
|
||||
return class_exists($type, $autoload)
|
||||
|| interface_exists($type, $autoload)
|
||||
|| (function_exists('trait_exists') && trait_exists($type, $autoload));
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* Base exception class for package Doctrine\Common.
|
||||
*
|
||||
* @author heinrich
|
||||
*/
|
||||
class CommonException extends \Exception
|
||||
{
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* Comparable interface that allows to compare two value objects to each other for similarity.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
interface Comparable
|
||||
{
|
||||
/**
|
||||
* Compares the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantical equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* EventArgs is the base class for classes containing event data.
|
||||
*
|
||||
* This class contains no event data. It is used by events that do not pass state
|
||||
* information to an event handler when an event is raised. The single empty EventArgs
|
||||
* instance can be obtained through {@link getEmptyInstance}.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class EventArgs
|
||||
{
|
||||
/**
|
||||
* Single instance of EventArgs.
|
||||
*
|
||||
* @var EventArgs
|
||||
*/
|
||||
private static $_emptyEventArgsInstance;
|
||||
|
||||
/**
|
||||
* Gets the single, empty and immutable EventArgs instance.
|
||||
*
|
||||
* This instance will be used when events are dispatched without any parameter,
|
||||
* like this: EventManager::dispatchEvent('eventname');
|
||||
*
|
||||
* The benefit from this is that only one empty instance is instantiated and shared
|
||||
* (otherwise there would be instances for every dispatched in the abovementioned form).
|
||||
*
|
||||
* @see EventManager::dispatchEvent
|
||||
*
|
||||
* @link http://msdn.microsoft.com/en-us/library/system.eventargs.aspx
|
||||
*
|
||||
* @return EventArgs
|
||||
*/
|
||||
public static function getEmptyInstance()
|
||||
{
|
||||
if ( ! self::$_emptyEventArgsInstance) {
|
||||
self::$_emptyEventArgsInstance = new EventArgs;
|
||||
}
|
||||
|
||||
return self::$_emptyEventArgsInstance;
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* The EventManager is the central point of Doctrine's event listener system.
|
||||
* Listeners are registered on the manager and events are dispatched through the
|
||||
* manager.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class EventManager
|
||||
{
|
||||
/**
|
||||
* Map of registered listeners.
|
||||
* <event> => <listeners>
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_listeners = array();
|
||||
|
||||
/**
|
||||
* Dispatches an event to all registered listeners.
|
||||
*
|
||||
* @param string $eventName The name of the event to dispatch. The name of the event is
|
||||
* the name of the method that is invoked on listeners.
|
||||
* @param EventArgs|null $eventArgs The event arguments to pass to the event handlers/listeners.
|
||||
* If not supplied, the single empty EventArgs instance is used.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
|
||||
{
|
||||
if (isset($this->_listeners[$eventName])) {
|
||||
$eventArgs = $eventArgs === null ? EventArgs::getEmptyInstance() : $eventArgs;
|
||||
|
||||
foreach ($this->_listeners[$eventName] as $listener) {
|
||||
$listener->$eventName($eventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the listeners of a specific event or all listeners.
|
||||
*
|
||||
* @param string|null $event The name of the event.
|
||||
*
|
||||
* @return array The event listeners for the specified event, or all event listeners.
|
||||
*/
|
||||
public function getListeners($event = null)
|
||||
{
|
||||
return $event ? $this->_listeners[$event] : $this->_listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether an event has any registered listeners.
|
||||
*
|
||||
* @param string $event
|
||||
*
|
||||
* @return boolean TRUE if the specified event has any listeners, FALSE otherwise.
|
||||
*/
|
||||
public function hasListeners($event)
|
||||
{
|
||||
return isset($this->_listeners[$event]) && $this->_listeners[$event];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener that listens on the specified events.
|
||||
*
|
||||
* @param string|array $events The event(s) to listen on.
|
||||
* @param object $listener The listener object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addEventListener($events, $listener)
|
||||
{
|
||||
// Picks the hash code related to that listener
|
||||
$hash = spl_object_hash($listener);
|
||||
|
||||
foreach ((array) $events as $event) {
|
||||
// Overrides listener if a previous one was associated already
|
||||
// Prevents duplicate listeners on same event (same instance only)
|
||||
$this->_listeners[$event][$hash] = $listener;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event listener from the specified events.
|
||||
*
|
||||
* @param string|array $events
|
||||
* @param object $listener
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeEventListener($events, $listener)
|
||||
{
|
||||
// Picks the hash code related to that listener
|
||||
$hash = spl_object_hash($listener);
|
||||
|
||||
foreach ((array) $events as $event) {
|
||||
// Check if actually have this listener associated
|
||||
if (isset($this->_listeners[$event][$hash])) {
|
||||
unset($this->_listeners[$event][$hash]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an EventSubscriber. The subscriber is asked for all the events it is
|
||||
* interested in and added as a listener for these events.
|
||||
*
|
||||
* @param \Doctrine\Common\EventSubscriber $subscriber The subscriber.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addEventSubscriber(EventSubscriber $subscriber)
|
||||
{
|
||||
$this->addEventListener($subscriber->getSubscribedEvents(), $subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an EventSubscriber. The subscriber is asked for all the events it is
|
||||
* interested in and removed as a listener for these events.
|
||||
*
|
||||
* @param \Doctrine\Common\EventSubscriber $subscriber The subscriber.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeEventSubscriber(EventSubscriber $subscriber)
|
||||
{
|
||||
$this->removeEventListener($subscriber->getSubscribedEvents(), $subscriber);
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* An EventSubscriber knows himself what events he is interested in.
|
||||
* If an EventSubscriber is added to an EventManager, the manager invokes
|
||||
* {@link getSubscribedEvents} and registers the subscriber as a listener for all
|
||||
* returned events.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
interface EventSubscriber
|
||||
{
|
||||
/**
|
||||
* Returns an array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscribedEvents();
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
/**
|
||||
* Base class for writing simple lexers, i.e. for creating small DSLs.
|
||||
*
|
||||
* Lexer moved into its own Component Doctrine\Common\Lexer. This class
|
||||
* only stays for being BC.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
abstract class Lexer extends AbstractLexer
|
||||
{
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
/**
|
||||
* Contract for classes that provide the service of notifying listeners of
|
||||
* changes to their properties.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
interface NotifyPropertyChanged
|
||||
{
|
||||
/**
|
||||
* Adds a listener that wants to be notified about property changes.
|
||||
*
|
||||
* @param PropertyChangedListener $listener
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPropertyChangedListener(PropertyChangedListener $listener);
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the ManagerRegistry contract.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
|
||||
*/
|
||||
abstract class AbstractManagerRegistry implements ManagerRegistry
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $connections;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $managers;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultConnection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultManager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $proxyInterfaceName;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $connections
|
||||
* @param array $managers
|
||||
* @param string $defaultConnection
|
||||
* @param string $defaultManager
|
||||
* @param string $proxyInterfaceName
|
||||
*/
|
||||
public function __construct($name, array $connections, array $managers, $defaultConnection, $defaultManager, $proxyInterfaceName)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->connections = $connections;
|
||||
$this->managers = $managers;
|
||||
$this->defaultConnection = $defaultConnection;
|
||||
$this->defaultManager = $defaultManager;
|
||||
$this->proxyInterfaceName = $proxyInterfaceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches/creates the given services.
|
||||
*
|
||||
* A service in this context is connection or a manager instance.
|
||||
*
|
||||
* @param string $name The name of the service.
|
||||
*
|
||||
* @return object The instance of the given service.
|
||||
*/
|
||||
abstract protected function getService($name);
|
||||
|
||||
/**
|
||||
* Resets the given services.
|
||||
*
|
||||
* A service in this context is connection or a manager instance.
|
||||
*
|
||||
* @param string $name The name of the service.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function resetService($name);
|
||||
|
||||
/**
|
||||
* Gets the name of the registry.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConnection($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$name = $this->defaultConnection;
|
||||
}
|
||||
|
||||
if (!isset($this->connections[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Doctrine %s Connection named "%s" does not exist.', $this->name, $name));
|
||||
}
|
||||
|
||||
return $this->getService($this->connections[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConnectionNames()
|
||||
{
|
||||
return $this->connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConnections()
|
||||
{
|
||||
$connections = array();
|
||||
foreach ($this->connections as $name => $id) {
|
||||
$connections[$name] = $this->getService($id);
|
||||
}
|
||||
|
||||
return $connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultConnectionName()
|
||||
{
|
||||
return $this->defaultConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultManagerName()
|
||||
{
|
||||
return $this->defaultManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getManager($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$name = $this->defaultManager;
|
||||
}
|
||||
|
||||
if (!isset($this->managers[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
|
||||
}
|
||||
|
||||
return $this->getService($this->managers[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getManagerForClass($class)
|
||||
{
|
||||
// Check for namespace alias
|
||||
if (strpos($class, ':') !== false) {
|
||||
list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
|
||||
$class = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
|
||||
}
|
||||
|
||||
$proxyClass = new \ReflectionClass($class);
|
||||
if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
|
||||
$class = $proxyClass->getParentClass()->getName();
|
||||
}
|
||||
|
||||
foreach ($this->managers as $id) {
|
||||
$manager = $this->getService($id);
|
||||
|
||||
if (!$manager->getMetadataFactory()->isTransient($class)) {
|
||||
return $manager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getManagerNames()
|
||||
{
|
||||
return $this->managers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getManagers()
|
||||
{
|
||||
$dms = array();
|
||||
foreach ($this->managers as $name => $id) {
|
||||
$dms[$name] = $this->getService($id);
|
||||
}
|
||||
|
||||
return $dms;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRepository($persistentObjectName, $persistentManagerName = null)
|
||||
{
|
||||
return $this->getManager($persistentManagerName)->getRepository($persistentObjectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resetManager($name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$name = $this->defaultManager;
|
||||
}
|
||||
|
||||
if (!isset($this->managers[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
|
||||
}
|
||||
|
||||
// force the creation of a new document manager
|
||||
// if the current one is closed
|
||||
$this->resetService($this->managers[$name]);
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence;
|
||||
|
||||
/**
|
||||
* Contract covering connection for a Doctrine persistence layer ManagerRegistry class to implement.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
|
||||
*/
|
||||
interface ConnectionRegistry
|
||||
{
|
||||
/**
|
||||
* Gets the default connection name.
|
||||
*
|
||||
* @return string The default connection name.
|
||||
*/
|
||||
public function getDefaultConnectionName();
|
||||
|
||||
/**
|
||||
* Gets the named connection.
|
||||
*
|
||||
* @param string $name The connection name (null for the default one).
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getConnection($name = null);
|
||||
|
||||
/**
|
||||
* Gets an array of all registered connections.
|
||||
*
|
||||
* @return array An array of Connection instances.
|
||||
*/
|
||||
public function getConnections();
|
||||
|
||||
/**
|
||||
* Gets all connection names.
|
||||
*
|
||||
* @return array An array of connection names.
|
||||
*/
|
||||
public function getConnectionNames();
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence\Event;
|
||||
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Lifecycle Events are triggered by the UnitOfWork during lifecycle transitions
|
||||
* of entities.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Roman Borschel <roman@code-factory.de>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class LifecycleEventArgs extends EventArgs
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $object;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param object $object
|
||||
* @param ObjectManager $objectManager
|
||||
*/
|
||||
public function __construct($object, ObjectManager $objectManager)
|
||||
{
|
||||
$this->object = $object;
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated entity.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getEntity()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated object.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated ObjectManager.
|
||||
*
|
||||
* @return ObjectManager
|
||||
*/
|
||||
public function getObjectManager()
|
||||
{
|
||||
return $this->objectManager;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence\Event;
|
||||
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Class that holds event arguments for a loadMetadata event.
|
||||
*
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @since 2.2
|
||||
*/
|
||||
class LoadClassMetadataEventArgs extends EventArgs
|
||||
{
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
private $classMetadata;
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ClassMetadata $classMetadata
|
||||
* @param ObjectManager $objectManager
|
||||
*/
|
||||
public function __construct(ClassMetadata $classMetadata, ObjectManager $objectManager)
|
||||
{
|
||||
$this->classMetadata = $classMetadata;
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated ClassMetadata.
|
||||
*
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->classMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated ObjectManager.
|
||||
*
|
||||
* @return ObjectManager
|
||||
*/
|
||||
public function getObjectManager()
|
||||
{
|
||||
return $this->objectManager;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence\Event;
|
||||
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Provides event arguments for the preFlush event.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Roman Borschel <roman@code-factory.de>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class ManagerEventArgs extends EventArgs
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ObjectManager $objectManager
|
||||
*/
|
||||
public function __construct(ObjectManager $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated ObjectManager.
|
||||
*
|
||||
* @return ObjectManager
|
||||
*/
|
||||
public function getObjectManager()
|
||||
{
|
||||
return $this->objectManager;
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence\Event;
|
||||
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Provides event arguments for the onClear event.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Roman Borschel <roman@code-factory.de>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class OnClearEventArgs extends EventArgs
|
||||
{
|
||||
/**
|
||||
* @var \Doctrine\Common\Persistence\ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $entityClass;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ObjectManager $objectManager The object manager.
|
||||
* @param string|null $entityClass The optional entity class.
|
||||
*/
|
||||
public function __construct($objectManager, $entityClass = null)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
$this->entityClass = $entityClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the associated ObjectManager.
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectManager
|
||||
*/
|
||||
public function getObjectManager()
|
||||
{
|
||||
return $this->objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the entity class that is cleared, or null if all are cleared.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEntityClass()
|
||||
{
|
||||
return $this->entityClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this event clears all entities.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearsAllEntities()
|
||||
{
|
||||
return ($this->entityClass === null);
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence\Event;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Class that holds event arguments for a preUpdate event.
|
||||
*
|
||||
* @author Guilherme Blanco <guilehrmeblanco@hotmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @since 2.2
|
||||
*/
|
||||
class PreUpdateEventArgs extends LifecycleEventArgs
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $entityChangeSet;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param ObjectManager $objectManager
|
||||
* @param array $changeSet
|
||||
*/
|
||||
public function __construct($entity, ObjectManager $objectManager, array &$changeSet)
|
||||
{
|
||||
parent::__construct($entity, $objectManager);
|
||||
|
||||
$this->entityChangeSet = &$changeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the entity changeset.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEntityChangeSet()
|
||||
{
|
||||
return $this->entityChangeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if field has a changeset.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasChangedField($field)
|
||||
{
|
||||
return isset($this->entityChangeSet[$field]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the old value of the changeset of the changed field.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOldValue($field)
|
||||
{
|
||||
$this->assertValidField($field);
|
||||
|
||||
return $this->entityChangeSet[$field][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new value of the changeset of the changed field.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNewValue($field)
|
||||
{
|
||||
$this->assertValidField($field);
|
||||
|
||||
return $this->entityChangeSet[$field][1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new value of this field.
|
||||
*
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setNewValue($field, $value)
|
||||
{
|
||||
$this->assertValidField($field);
|
||||
|
||||
$this->entityChangeSet[$field][1] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the field exists in changeset.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function assertValidField($field)
|
||||
{
|
||||
if ( ! isset($this->entityChangeSet[$field])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
|
||||
$field,
|
||||
get_class($this->getEntity())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Persistence;
|
||||
|
||||
/**
|
||||
* Contract covering object managers for a Doctrine persistence layer ManagerRegistry class to implement.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.2
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
|
||||
*/
|
||||
interface ManagerRegistry extends ConnectionRegistry
|
||||
{
|
||||
/**
|
||||
* Gets the default object manager name.
|
||||
*
|
||||
* @return string The default object manager name.
|
||||
*/
|
||||
public function getDefaultManagerName();
|
||||
|
||||
/**
|
||||
* Gets a named object manager.
|
||||
*
|
||||
* @param string $name The object manager name (null for the default one).
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectManager
|
||||
*/
|
||||
public function getManager($name = null);
|
||||
|
||||
/**
|
||||
* Gets an array of all registered object managers.
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectManager[] An array of ObjectManager instances
|
||||
*/
|
||||
public function getManagers();
|
||||
|
||||
/**
|
||||
* Resets a named object manager.
|
||||
*
|
||||
* This method is useful when an object manager has been closed
|
||||
* because of a rollbacked transaction AND when you think that
|
||||
* it makes sense to get a new one to replace the closed one.
|
||||
*
|
||||
* Be warned that you will get a brand new object manager as
|
||||
* the existing one is not useable anymore. This means that any
|
||||
* other object with a dependency on this object manager will
|
||||
* hold an obsolete reference. You can inject the registry instead
|
||||
* to avoid this problem.
|
||||
*
|
||||
* @param string|null $name The object manager name (null for the default one).
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectManager
|
||||
*/
|
||||
public function resetManager($name = null);
|
||||
|
||||
/**
|
||||
* Resolves a registered namespace alias to the full namespace.
|
||||
*
|
||||
* This method looks for the alias in all registered object managers.
|
||||
*
|
||||
* @param string $alias The alias.
|
||||
*
|
||||
* @return string The full namespace.
|
||||
*/
|
||||
public function getAliasNamespace($alias);
|
||||
|
||||
/**
|
||||
* Gets all connection names.
|
||||
*
|
||||
* @return array An array of connection names.
|
||||
*/
|
||||
public function getManagerNames();
|
||||
|
||||
/**
|
||||
* Gets the ObjectRepository for an persistent object.
|
||||
*
|
||||
* @param string $persistentObject The name of the persistent object.
|
||||
* @param string $persistentManagerName The object manager name (null for the default one).
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectRepository
|
||||
*/
|
||||
public function getRepository($persistentObject, $persistentManagerName = null);
|
||||
|
||||
/**
|
||||
* Gets the object manager associated with a given class.
|
||||
*
|
||||
* @param string $class A persistent object class name.
|
||||
*
|
||||
* @return \Doctrine\Common\Persistence\ObjectManager|null
|
||||
*/
|
||||
public function getManagerForClass($class);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue