mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Compare commits
187 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7a15316a0 | ||
|
|
2b878fc15d | ||
|
|
4fea26c833 | ||
|
|
bf3ae5f2cf | ||
|
|
2836d14c31 | ||
|
|
a342c87a32 | ||
|
|
192eedc6a7 | ||
|
|
ed78cdb937 | ||
|
|
793c383aa2 | ||
|
|
7595b021cc | ||
|
|
f1bcb3cb80 | ||
|
|
35ea4ed1fd | ||
|
|
ac8a36cda3 | ||
|
|
0917ed5ced | ||
|
|
8068f34c66 | ||
|
|
91a9d4f27c | ||
|
|
7c8590ea74 | ||
|
|
d1cea4f77c | ||
|
|
ae958e73d1 | ||
|
|
3b841883d3 | ||
|
|
cfe36f9a31 | ||
|
|
d2eea18977 | ||
|
|
247887ec0e | ||
|
|
2b309a3682 | ||
|
|
5ebe7ca89e | ||
|
|
c582b7790a | ||
|
|
a98a21b269 | ||
|
|
5c9b3d0b92 | ||
|
|
7f3bdab34c | ||
|
|
e075ab6958 | ||
|
|
a1bc743568 | ||
|
|
20d8ebfd43 | ||
|
|
3587f3bcb3 | ||
|
|
ec87cb779c | ||
|
|
ac40ce8042 | ||
|
|
d4302b32e1 | ||
|
|
3c95b0ec35 | ||
|
|
c12c6e82b6 | ||
|
|
505f7bd252 | ||
|
|
d5459616d2 | ||
|
|
97d9fb7efa | ||
|
|
2da1fadaf1 | ||
|
|
a612ca7231 | ||
|
|
bd4faa6a7d | ||
|
|
be03811753 | ||
|
|
636fa34136 | ||
|
|
016810af7f | ||
|
|
178fe38a39 | ||
|
|
35a318148c | ||
|
|
c63115efa9 | ||
|
|
7cba650aff | ||
|
|
d9475cbfd0 | ||
|
|
ee1708b04a | ||
|
|
a8057dfe26 | ||
|
|
60e7b8eff4 | ||
|
|
28291f0fa7 | ||
|
|
eecd9afc09 | ||
|
|
8f9f85da39 | ||
|
|
5d7063b2e1 | ||
|
|
cc26080a00 | ||
|
|
2b900e2c26 | ||
|
|
aedda4a21d | ||
|
|
de6f0e4594 | ||
|
|
d1191c3f74 | ||
|
|
bd117fc9eb | ||
|
|
ac04ce4114 | ||
|
|
8d39f2a36d | ||
|
|
e86cbd65fa | ||
|
|
410dd69c5b | ||
|
|
222a90fc8a | ||
|
|
c8e2ee05d1 | ||
|
|
7c9c7369fb | ||
|
|
8ec9ee82f9 | ||
|
|
33c896c31f | ||
|
|
9ee3cc98ae | ||
|
|
12bde174c5 | ||
|
|
7634d45a29 | ||
|
|
b2873ab236 | ||
|
|
2978cad198 | ||
|
|
c49467b7fa | ||
|
|
095b8fa930 | ||
|
|
8a2b1058c3 | ||
|
|
2bdceefb2d | ||
|
|
71bcdce031 | ||
|
|
f6a700062d | ||
|
|
fb4db2782c | ||
|
|
39ec8de08b | ||
|
|
7a469581e1 | ||
|
|
1f8cdb77be | ||
|
|
af5bcc148d | ||
|
|
06870fd87f | ||
|
|
26af92f452 | ||
|
|
97d97a8a89 | ||
|
|
3df673cb6a | ||
|
|
85474a0c7a | ||
|
|
1c05831b20 | ||
|
|
26126a10cd | ||
|
|
b6c5de3ef5 | ||
|
|
48fe910978 | ||
|
|
0df6086960 | ||
|
|
3d406afa38 | ||
|
|
526f21ad3d | ||
|
|
31722cf8f6 | ||
|
|
758a09dfe8 | ||
|
|
ba00dd13b6 | ||
|
|
ff65aeed60 | ||
|
|
3a5d70fbf3 | ||
|
|
68257a8c93 | ||
|
|
3b4596691f | ||
|
|
ecb409412f | ||
|
|
91ea598eb7 | ||
|
|
75e42f8145 | ||
|
|
c6cc39ddee | ||
|
|
211fd2a69e | ||
|
|
8eef747aba | ||
|
|
ceb6924aae | ||
|
|
af4e836f4f | ||
|
|
d650ade2b1 | ||
|
|
521e4880aa | ||
|
|
ee951a19aa | ||
|
|
b1a616dfa5 | ||
|
|
859ca72426 | ||
|
|
a655188e55 | ||
|
|
5be16db9ec | ||
|
|
f6aca7c6ef | ||
|
|
4271706cab | ||
|
|
98d4075de1 | ||
|
|
81cff239f8 | ||
|
|
46dbce9b6c | ||
|
|
64129c66e0 | ||
|
|
479ae3e22a | ||
|
|
0d42c686e1 | ||
|
|
2ba48d58e7 | ||
|
|
c3ab35a8f5 | ||
|
|
6dcbbdae4d | ||
|
|
4a020f2c48 | ||
|
|
5e4811a3cd | ||
|
|
1dd85fe19e | ||
|
|
fd7442a056 | ||
|
|
1d4b188a52 | ||
|
|
6c57ec12ee | ||
|
|
7a3ee2a8da | ||
|
|
5e61b73619 | ||
|
|
23ac0026a0 | ||
|
|
65e85aa471 | ||
|
|
d5b61ec897 | ||
|
|
adc2f24c9a | ||
|
|
8423c0c608 | ||
|
|
44aa098b37 | ||
|
|
839ec8f25a | ||
|
|
0893d2eb00 | ||
|
|
b63babc7b8 | ||
|
|
7350d85a4b | ||
|
|
a6b81d684a | ||
|
|
9e864c3662 | ||
|
|
024cc43189 | ||
|
|
1e79672147 | ||
|
|
3b7448bcf4 | ||
|
|
d5025235f3 | ||
|
|
dbc1a4da4b | ||
|
|
837d3f0f80 | ||
|
|
203fb59115 | ||
|
|
ecdc0fad64 | ||
|
|
e1fd2c158b | ||
|
|
479dae2a99 | ||
|
|
d94c2a11e8 | ||
|
|
d44b9fb05c | ||
|
|
fc16ecc6d7 | ||
|
|
1c9007fb0e | ||
|
|
79dc69b920 | ||
|
|
5e22a08ee1 | ||
|
|
3d43049426 | ||
|
|
95464c95fa | ||
|
|
392d23e401 | ||
|
|
19db4f304d | ||
|
|
aeaeff9002 | ||
|
|
9bc236b4fa | ||
|
|
cd6611ad3e | ||
|
|
41e5fc6b34 | ||
|
|
615a1159a7 | ||
|
|
1059991865 | ||
|
|
18fc94b395 | ||
|
|
b288eac530 | ||
|
|
699cd2cf4b | ||
|
|
c1f10b4673 | ||
|
|
6bff8c338f | ||
|
|
1ca924d021 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -4,3 +4,9 @@
|
||||
[submodule "lib/vendor/doctrine-dbal"]
|
||||
path = lib/vendor/doctrine-dbal
|
||||
url = git://github.com/doctrine/dbal.git
|
||||
[submodule "lib/vendor/Symfony/Component/Yaml"]
|
||||
path = lib/vendor/Symfony/Component/Yaml
|
||||
url = git://github.com/symfony/Yaml.git
|
||||
[submodule "lib/vendor/Symfony/Component/Console"]
|
||||
path = lib/vendor/Symfony/Component/Console
|
||||
url = git://github.com/symfony/Console.git
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
version=2.0.0BETA2
|
||||
dependencies.common=2.0.0BETA4
|
||||
dependencies.dbal=2.0.0BETA4
|
||||
version=2.0.1
|
||||
dependencies.common=2.0.1
|
||||
dependencies.dbal=2.0.1
|
||||
stability=beta
|
||||
build.dir=build
|
||||
dist.dir=dist
|
||||
|
||||
72
build.xml
72
build.xml
@@ -100,6 +100,9 @@
|
||||
</copy>
|
||||
<exec command="sed 's/${version}-DEV/${version}/' ${build.dir}/doctrine-orm/Doctrine/ORM/Version.php > ${build.dir}/doctrine-orm/Doctrine/ORM/Version2.php" passthru="true" />
|
||||
<exec command="mv ${build.dir}/doctrine-orm/Doctrine/ORM/Version2.php ${build.dir}/doctrine-orm/Doctrine/ORM/Version.php" passthru="true" />
|
||||
<delete dir="${build.dir}/doctrine-orm/Doctrine/Symfony/Component/Yaml/.git" includeemptydirs="true"/>
|
||||
<delete dir="${build.dir}/doctrine-orm/Doctrine/Symfony/Component/Console/.git" includeemptydirs="true"/>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="build" depends="test, build-orm"/>
|
||||
@@ -160,6 +163,8 @@
|
||||
<pear minimum_version="1.6.0" recommended_version="1.6.1" />
|
||||
<package name="DoctrineCommon" channel="pear.doctrine-project.org" minimum_version="${dependencies.common}" />
|
||||
<package name="DoctrineDBAL" channel="pear.doctrine-project.org" minimum_version="${dependencies.dbal}" />
|
||||
<package name="DoctrineSymfonyConsole" channel="pear.doctrine-project.org" minimum_version="2.0.0" />
|
||||
<package name="DoctrineSymfonyYaml" channel="pear.doctrine-project.org" minimum_version="2.0.0" />
|
||||
</dependencies>
|
||||
<dirroles key="bin">script</dirroles>
|
||||
<ignore>Doctrine/Common/</ignore>
|
||||
@@ -184,9 +189,12 @@
|
||||
</target>
|
||||
|
||||
<target name="git-tag">
|
||||
<exec command="grep '${version}' ${project.basedir}/lib/Doctrine/ORM/Version.php" checkreturn="true"/>
|
||||
<exec command="git tag -a ${version}" passthru="true" />
|
||||
<exec command="git push origin ${version}" passthru="true" />
|
||||
<exec command="grep '${version}-DEV' ${project.basedir}/lib/Doctrine/ORM/Version.php" checkreturn="true"/>
|
||||
<exec command="sed 's/${version}-DEV/${version}/' ${project.basedir}/lib/Doctrine/ORM/Version.php > ${project.basedir}/lib/Doctrine/ORM/Version2.php" passthru="true" />
|
||||
<exec command="mv ${project.basedir}/lib/Doctrine/ORM/Version2.php ${project.basedir}/lib/Doctrine/ORM/Version.php" passthru="true" />
|
||||
<exec command="git add ${project.basedir}/lib/Doctrine/ORM/Version.php" passthru="true" />
|
||||
<exec command="git commit -m 'Release ${version}'" />
|
||||
<exec command="git tag -m 'Tag ${version}' -a ${version}" passthru="true" />
|
||||
</target>
|
||||
|
||||
<target name="pirum-release">
|
||||
@@ -201,12 +209,64 @@
|
||||
<target name="update-dev-version">
|
||||
<exec command="grep '${version}' ${project.basedir}/lib/Doctrine/ORM/Version.php" checkreturn="true"/>
|
||||
<propertyprompt propertyName="next_version" defaultValue="${version}" promptText="Enter next version string (without -DEV)" />
|
||||
<exec command="sed 's/${version}-DEV/${next_version}-DEV/' ${project.basedir}/lib/Doctrine/ORM/Version.php > ${project.basedir}/lib/Doctrine/ORM/Version2.php" passthru="true" />
|
||||
<exec command="sed 's/${version}/${next_version}-DEV/' ${project.basedir}/lib/Doctrine/ORM/Version.php > ${project.basedir}/lib/Doctrine/ORM/Version2.php" passthru="true" />
|
||||
<exec command="mv ${project.basedir}/lib/Doctrine/ORM/Version2.php ${project.basedir}/lib/Doctrine/ORM/Version.php" passthru="true" />
|
||||
<exec command="git add ${project.basedir}/lib/Doctrine/ORM/Version.php" passthru="true" />
|
||||
<exec command="git commit -m 'Bump Dev Version to ${next_version}-DEV'" passthru="true" />
|
||||
<exec command="git push origin master" passthru="true" />
|
||||
</target>
|
||||
|
||||
<target name="release" depends="git-tag,build-packages,distribute-download,pirum-release,update-dev-version" />
|
||||
</project>
|
||||
|
||||
<!--
|
||||
Builds distributable PEAR packages for the Symfony Dependencies
|
||||
-->
|
||||
<target name="release-symfony-dependencies" depends="build-orm">
|
||||
<d51pearpkg2 baseinstalldir="/" dir="${build.dir}/doctrine-orm">
|
||||
<name>DoctrineSymfonyConsole</name>
|
||||
<summary>Symfony Console Component</summary>
|
||||
<channel>pear.doctrine-project.org</channel>
|
||||
<description>A command line interface tool from the Symfony project. Packaged for shipping with Doctrine projects using ORM version numbers.</description>
|
||||
<lead user="fabpot" name="Fabien Potencier" email="fabien.potencier@symfony-project.com" />
|
||||
<license>NewBSD License</license>
|
||||
<version release="${version}" api="${version}" />
|
||||
<stability release="${stability}" api="${stability}" />
|
||||
<notes>-</notes>
|
||||
<dependencies>
|
||||
<php minimum_version="5.3.0" />
|
||||
<pear minimum_version="1.6.0" recommended_version="1.6.1" />
|
||||
</dependencies>
|
||||
<ignore>Doctrine/Common/</ignore>
|
||||
<ignore>Doctrine/DBAL/</ignore>
|
||||
<ignore>Doctrine/ORM/</ignore>
|
||||
<ignore>Symfony/Component/Yaml/</ignore>
|
||||
</d51pearpkg2>
|
||||
<exec command="pear package" dir="${build.dir}/doctrine-orm" passthru="true" />
|
||||
<exec command="mv DoctrineSymfonyConsole-${version}.tgz ../../dist" dir="${build.dir}/doctrine-orm" passthru="true" />
|
||||
|
||||
<d51pearpkg2 baseinstalldir="/" dir="${build.dir}/doctrine-orm">
|
||||
<name>DoctrineSymfonyYaml</name>
|
||||
<summary>Symfony Yaml Component</summary>
|
||||
<channel>pear.doctrine-project.org</channel>
|
||||
<description>A YAML Parser from the Symfony project. Packaged for shipping with Doctrine projects using ORM version numbers.</description>
|
||||
<lead user="fabpot" name="Fabien Potencier" email="fabien.potencier@symfony-project.com" />
|
||||
<license>NewBSD License</license>
|
||||
<version release="${version}" api="${version}" />
|
||||
<stability release="${stability}" api="${stability}" />
|
||||
<notes>-</notes>
|
||||
<dependencies>
|
||||
<php minimum_version="5.3.0" />
|
||||
<pear minimum_version="1.6.0" recommended_version="1.6.1" />
|
||||
</dependencies>
|
||||
<ignore>Doctrine/Common/</ignore>
|
||||
<ignore>Doctrine/DBAL/</ignore>
|
||||
<ignore>Doctrine/ORM/</ignore>
|
||||
<ignore>Symfony/Component/Console/</ignore>
|
||||
</d51pearpkg2>
|
||||
<exec command="pear package" dir="${build.dir}/doctrine-orm" passthru="true" />
|
||||
<exec command="mv DoctrineSymfonyYaml-${version}.tgz ../../dist" dir="${build.dir}/doctrine-orm" passthru="true" />
|
||||
|
||||
<exec command="sudo pirum add ${project.pirum_dir} ${project.basedir}/dist/DoctrineSymfonyConsole-${version}.tgz" dir="." passthru="true" />
|
||||
<exec command="sudo pirum add ${project.pirum_dir} ${project.basedir}/dist/DoctrineSymfonyYaml-${version}.tgz" dir="." passthru="true" />
|
||||
<exec command="sudo pirum build ${project.pirum_dir}" passthru="true" />
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
|
||||
<xs:complexType name="discriminator-mapping">
|
||||
<xs:attribute name="value" type="xs:NMTOKEN" use="required"/>
|
||||
<xs:attribute name="class" type="xs:NMTOKEN" use="required"/>
|
||||
<xs:attribute name="class" type="xs:string" use="required"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="discriminator-map">
|
||||
|
||||
@@ -458,6 +458,16 @@ abstract class AbstractQuery
|
||||
return isset($this->_hints[$name]) ? $this->_hints[$name] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key value map of query hints that are currently set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHints()
|
||||
{
|
||||
return $this->_hints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the query and returns an IterableResult that can be used to incrementally
|
||||
* iterate over the result.
|
||||
@@ -466,17 +476,27 @@ abstract class AbstractQuery
|
||||
* @param integer $hydrationMode The hydration mode to use.
|
||||
* @return IterableResult
|
||||
*/
|
||||
public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
|
||||
public function iterate(array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
if ($hydrationMode !== null) {
|
||||
$this->setHydrationMode($hydrationMode);
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
$this->setParameters($params);
|
||||
}
|
||||
|
||||
$stmt = $this->_doExecute();
|
||||
|
||||
return $this->_em->newHydrator($this->_hydrationMode)->iterate(
|
||||
$this->_doExecute($params, $hydrationMode), $this->_resultSetMapping, $this->_hints
|
||||
$stmt, $this->_resultSetMapping, $this->_hints
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the query.
|
||||
*
|
||||
* @param string $params Any additional query parameters.
|
||||
* @param array $params Any additional query parameters.
|
||||
* @param integer $hydrationMode Processing mode to be used during the hydration process.
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -496,10 +516,10 @@ abstract class AbstractQuery
|
||||
|
||||
// Check result cache
|
||||
if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) {
|
||||
$id = $this->_getResultCacheId();
|
||||
$cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id);
|
||||
list($key, $hash) = $this->getResultCacheId();
|
||||
$cached = $this->_expireResultCache ? false : $cacheDriver->fetch($hash);
|
||||
|
||||
if ($cached === false) {
|
||||
if ($cached === false || !isset($cached[$key])) {
|
||||
// Cache miss.
|
||||
$stmt = $this->_doExecute();
|
||||
|
||||
@@ -507,12 +527,12 @@ abstract class AbstractQuery
|
||||
$stmt, $this->_resultSetMapping, $this->_hints
|
||||
);
|
||||
|
||||
$cacheDriver->save($id, $result, $this->_resultCacheTTL);
|
||||
$cacheDriver->save($hash, array($key => $result), $this->_resultCacheTTL);
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
// Cache hit.
|
||||
return $cached;
|
||||
return $cached[$key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,12 +566,12 @@ abstract class AbstractQuery
|
||||
* Will return the configured id if it exists otherwise a hash will be
|
||||
* automatically generated for you.
|
||||
*
|
||||
* @return string $id
|
||||
* @return array ($key, $hash)
|
||||
*/
|
||||
protected function _getResultCacheId()
|
||||
protected function getResultCacheId()
|
||||
{
|
||||
if ($this->_resultCacheId) {
|
||||
return $this->_resultCacheId;
|
||||
return array($this->_resultCacheId, $this->_resultCacheId);
|
||||
} else {
|
||||
$params = $this->_params;
|
||||
foreach ($params AS $key => $value) {
|
||||
@@ -563,13 +583,16 @@ abstract class AbstractQuery
|
||||
$idValues = $class->getIdentifierValues($value);
|
||||
}
|
||||
$params[$key] = $idValues;
|
||||
} else {
|
||||
$params[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = $this->getSql();
|
||||
ksort($this->_hints);
|
||||
return md5(implode(";", (array)$sql) . var_export($params, true) .
|
||||
var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode);
|
||||
$key = implode(";", (array)$sql) . var_export($params, true) .
|
||||
var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode;
|
||||
return array($key, md5($key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +96,16 @@ class EntityManager
|
||||
private $proxyFactory;
|
||||
|
||||
/**
|
||||
* @var ExpressionBuilder The expression builder instance used to generate query expressions.
|
||||
* The expression builder instance used to generate query expressions.
|
||||
*
|
||||
* @var Doctrine\ORM\Query\Expr
|
||||
*/
|
||||
private $expressionBuilder;
|
||||
|
||||
/**
|
||||
* Whether the EntityManager is closed or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $closed = false;
|
||||
|
||||
@@ -163,7 +167,7 @@ class EntityManager
|
||||
* ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
|
||||
* </code>
|
||||
*
|
||||
* @return ExpressionBuilder
|
||||
* @return Doctrine\ORM\Query\Expr
|
||||
*/
|
||||
public function getExpressionBuilder()
|
||||
{
|
||||
@@ -354,7 +358,7 @@ class EntityManager
|
||||
|
||||
// Check identity map first, if its already in there just return it.
|
||||
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
|
||||
return $entity;
|
||||
return ($entity instanceof $class->name) ? $entity : null;
|
||||
}
|
||||
if ($class->subClasses) {
|
||||
$entity = $this->find($entityName, $identifier);
|
||||
@@ -394,7 +398,7 @@ class EntityManager
|
||||
|
||||
// Check identity map first, if its already in there just return it.
|
||||
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
|
||||
return $entity;
|
||||
return ($entity instanceof $class->name) ? $entity : null;
|
||||
}
|
||||
if ( ! is_array($identifier)) {
|
||||
$identifier = array($class->identifier[0] => $identifier);
|
||||
|
||||
@@ -97,6 +97,10 @@ class EntityRepository
|
||||
{
|
||||
// Check identity map first
|
||||
if ($entity = $this->_em->getUnitOfWork()->tryGetById($id, $this->_class->rootEntityName)) {
|
||||
if (!($entity instanceof $this->_class->name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($lockMode != LockMode::NONE) {
|
||||
$this->_em->lock($entity, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ class ObjectHydrator extends AbstractHydrator
|
||||
* This local cache is maintained between hydration runs and not cleared.
|
||||
*/
|
||||
private $_ce = array();
|
||||
|
||||
|
||||
/* The following parts are reinitialized on every hydration run. */
|
||||
|
||||
|
||||
private $_identifierMap;
|
||||
private $_resultPointers;
|
||||
private $_idTemplate;
|
||||
@@ -50,7 +50,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
private $_initializedCollections = array();
|
||||
private $_existingCollections = array();
|
||||
//private $_createdEntities;
|
||||
|
||||
|
||||
|
||||
/** @override */
|
||||
protected function _prepare()
|
||||
@@ -59,7 +59,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->_resultPointers =
|
||||
$this->_idTemplate = array();
|
||||
$this->_resultCounter = 0;
|
||||
|
||||
|
||||
foreach ($this->_rsm->aliasMap as $dqlAlias => $className) {
|
||||
$this->_identifierMap[$dqlAlias] = array();
|
||||
$this->_idTemplate[$dqlAlias] = '';
|
||||
@@ -68,10 +68,14 @@ class ObjectHydrator extends AbstractHydrator
|
||||
if ( ! isset($this->_ce[$className])) {
|
||||
$this->_ce[$className] = $class;
|
||||
}
|
||||
|
||||
|
||||
// Remember which associations are "fetch joined", so that we know where to inject
|
||||
// collection stubs or proxies and where not.
|
||||
if (isset($this->_rsm->relationMap[$dqlAlias])) {
|
||||
if ( ! isset($this->_rsm->aliasMap[$this->_rsm->parentAliasMap[$dqlAlias]])) {
|
||||
throw HydrationException::parentObjectOfRelationNotFound($dqlAlias, $this->_rsm->parentAliasMap[$dqlAlias]);
|
||||
}
|
||||
|
||||
$sourceClassName = $this->_rsm->aliasMap[$this->_rsm->parentAliasMap[$dqlAlias]];
|
||||
$sourceClass = $this->_getClassMetadata($sourceClassName);
|
||||
$assoc = $sourceClass->associationMappings[$this->_rsm->relationMap[$dqlAlias]];
|
||||
@@ -176,7 +180,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets an entity instance.
|
||||
*
|
||||
@@ -186,7 +190,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
*/
|
||||
private function _getEntity(array $data, $dqlAlias)
|
||||
{
|
||||
$className = $this->_rsm->aliasMap[$dqlAlias];
|
||||
$className = $this->_rsm->aliasMap[$dqlAlias];
|
||||
if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) {
|
||||
$discrColumn = $this->_rsm->metaMappings[$this->_rsm->discriminatorColumns[$dqlAlias]];
|
||||
$className = $this->_ce[$className]->discriminatorMap[$data[$discrColumn]];
|
||||
@@ -194,7 +198,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
return $this->_uow->createEntity($className, $data, $this->_hints);
|
||||
}
|
||||
|
||||
|
||||
private function _getEntityFromIdentityMap($className, array $data)
|
||||
{
|
||||
$class = $this->_ce[$className];
|
||||
@@ -208,7 +212,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
return $this->_uow->tryGetByIdHash($data[$class->identifier[0]], $class->rootEntityName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a ClassMetadata instance from the local cache.
|
||||
* If the instance is not yet in the local cache, it is loaded into the
|
||||
@@ -266,7 +270,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
// Hydrate the data chunks
|
||||
foreach ($rowData as $dqlAlias => $data) {
|
||||
$entityName = $this->_rsm->aliasMap[$dqlAlias];
|
||||
|
||||
|
||||
if (isset($this->_rsm->parentAliasMap[$dqlAlias])) {
|
||||
// It's a joined result
|
||||
|
||||
@@ -277,7 +281,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// Get a reference to the parent object to which the joined element belongs.
|
||||
if ($this->_rsm->isMixed && isset($this->_rootAliases[$parentAlias])) {
|
||||
$first = reset($this->_resultPointers);
|
||||
$first = reset($this->_resultPointers);
|
||||
$parentObject = $this->_resultPointers[$parentAlias][key($first)];
|
||||
} else if (isset($this->_resultPointers[$parentAlias])) {
|
||||
$parentObject = $this->_resultPointers[$parentAlias];
|
||||
@@ -302,11 +306,11 @@ class ObjectHydrator extends AbstractHydrator
|
||||
} else if ( ! isset($this->_existingCollections[$collKey])) {
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField);
|
||||
}
|
||||
|
||||
|
||||
$indexExists = isset($this->_identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]]);
|
||||
$index = $indexExists ? $this->_identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]] : false;
|
||||
$indexIsValid = $index !== false ? isset($reflFieldValue[$index]) : false;
|
||||
|
||||
|
||||
if ( ! $indexExists || ! $indexIsValid) {
|
||||
if (isset($this->_existingCollections[$collKey])) {
|
||||
// Collection exists, only look for the element in the identity map.
|
||||
|
||||
@@ -284,10 +284,6 @@ class ClassMetadataFactory
|
||||
throw MappingException::reflectionFailure($className, $e);
|
||||
}
|
||||
|
||||
// Verify & complete identifier mapping
|
||||
if ( ! $class->identifier && ! $class->isMappedSuperclass) {
|
||||
throw MappingException::identifierRequired($className);
|
||||
}
|
||||
if ($parent && ! $parent->isMappedSuperclass) {
|
||||
if ($parent->isIdGeneratorSequence()) {
|
||||
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
|
||||
@@ -315,6 +311,11 @@ class ClassMetadataFactory
|
||||
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
|
||||
}
|
||||
|
||||
// Verify & complete identifier mapping
|
||||
if ( ! $class->identifier && ! $class->isMappedSuperclass) {
|
||||
throw MappingException::identifierRequired($className);
|
||||
}
|
||||
|
||||
// verify inheritance
|
||||
if (!$parent && !$class->isMappedSuperclass && !$class->isInheritanceTypeNone()) {
|
||||
if (count($class->discriminatorMap) == 0) {
|
||||
@@ -382,6 +383,9 @@ class ClassMetadataFactory
|
||||
{
|
||||
foreach ($parentClass->associationMappings as $field => $mapping) {
|
||||
if ($parentClass->isMappedSuperclass) {
|
||||
if ($mapping['type'] & ClassMetadata::TO_MANY && !$mapping['isOwningSide']) {
|
||||
throw MappingException::illegalToManyAssocationOnMappedSuperclass($parentClass->name, $field);
|
||||
}
|
||||
$mapping['sourceEntity'] = $subClass->name;
|
||||
}
|
||||
|
||||
|
||||
@@ -643,8 +643,8 @@ class ClassMetadataInfo
|
||||
protected function _validateAndCompleteFieldMapping(array &$mapping)
|
||||
{
|
||||
// Check mandatory fields
|
||||
if ( ! isset($mapping['fieldName'])) {
|
||||
throw MappingException::missingFieldName($this->name, $mapping);
|
||||
if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
|
||||
throw MappingException::missingFieldName($this->name);
|
||||
}
|
||||
if ( ! isset($mapping['type'])) {
|
||||
// Default to string
|
||||
@@ -711,8 +711,8 @@ class ClassMetadataInfo
|
||||
}
|
||||
|
||||
// Mandatory: fieldName, targetEntity
|
||||
if ( ! isset($mapping['fieldName'])) {
|
||||
throw MappingException::missingFieldName();
|
||||
if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
|
||||
throw MappingException::missingFieldName($this->name);
|
||||
}
|
||||
if ( ! isset($mapping['targetEntity'])) {
|
||||
throw MappingException::missingTargetEntity($mapping['fieldName']);
|
||||
@@ -836,8 +836,17 @@ class ClassMetadataInfo
|
||||
{
|
||||
$mapping = $this->_validateAndCompleteAssociationMapping($mapping);
|
||||
if ($mapping['isOwningSide']) {
|
||||
$sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1));
|
||||
$targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1));
|
||||
if (strpos($mapping['sourceEntity'], '\\') !== false) {
|
||||
$sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1));
|
||||
} else {
|
||||
$sourceShortName = strtolower($mapping['sourceEntity']);
|
||||
}
|
||||
if (strpos($mapping['targetEntity'], '\\') !== false) {
|
||||
$targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1));
|
||||
} else {
|
||||
$targetShortName = strtolower($mapping['targetEntity']);
|
||||
}
|
||||
|
||||
// owning side MUST have a join table
|
||||
if ( ! isset($mapping['joinTable']['name'])) {
|
||||
$mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName;
|
||||
@@ -1128,7 +1137,8 @@ class ClassMetadataInfo
|
||||
*/
|
||||
public function getTemporaryIdTableName()
|
||||
{
|
||||
return $this->table['name'] . '_id_tmp';
|
||||
// replace dots with underscores because PostgreSQL creates temporary tables in a special schema
|
||||
return str_replace('.', '_', $this->table['name'] . '_id_tmp');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1470,6 +1480,7 @@ class ClassMetadataInfo
|
||||
if (strpos($className, '\\') === false && strlen($this->namespace)) {
|
||||
$className = $this->namespace . '\\' . $className;
|
||||
}
|
||||
$className = ltrim($className, '\\');
|
||||
$this->discriminatorMap[$value] = $className;
|
||||
if ($this->name == $className) {
|
||||
$this->discriminatorValue = $value;
|
||||
|
||||
@@ -67,10 +67,10 @@ class AnnotationDriver implements Driver
|
||||
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
|
||||
* docblock annotations.
|
||||
*
|
||||
* @param $reader The AnnotationReader to use.
|
||||
* @param AnnotationReader $reader The AnnotationReader to use, duck-typed.
|
||||
* @param string|array $paths One or multiple paths where mapping classes can be found.
|
||||
*/
|
||||
public function __construct(AnnotationReader $reader, $paths = null)
|
||||
public function __construct($reader, $paths = null)
|
||||
{
|
||||
$this->_reader = $reader;
|
||||
if ($paths) {
|
||||
@@ -367,7 +367,8 @@ class AnnotationDriver implements Driver
|
||||
// Evaluate @HasLifecycleCallbacks annotation
|
||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
||||
foreach ($class->getMethods() as $method) {
|
||||
if ($method->isPublic()) {
|
||||
// filter for the declaring class only, callbacks from parents will already be registered.
|
||||
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
|
||||
$annotations = $this->_reader->getMethodAnnotations($method);
|
||||
|
||||
if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Doctrine\ORM\Mapping\Driver;
|
||||
use Doctrine\Common\Cache\ArrayCache,
|
||||
Doctrine\Common\Annotations\AnnotationReader,
|
||||
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
||||
Doctrine\DBAL\Schema\SchemaException,
|
||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||
Doctrine\ORM\Mapping\MappingException,
|
||||
Doctrine\Common\Util\Inflector;
|
||||
@@ -66,6 +67,26 @@ class DatabaseDriver implements Driver
|
||||
$this->_sm = $schemaManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tables manually instead of relying on the reverse engeneering capabilities of SchemaManager.
|
||||
*
|
||||
* @param array $entityTables
|
||||
* @param array $manyToManyTables
|
||||
* @return void
|
||||
*/
|
||||
public function setTables($entityTables, $manyToManyTables)
|
||||
{
|
||||
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
|
||||
foreach ($entityTables AS $table) {
|
||||
$className = Inflector::classify(strtolower($table->getName()));
|
||||
$this->classToTableNames[$className] = $table->getName();
|
||||
$this->tables[$table->getName()] = $table;
|
||||
}
|
||||
foreach ($manyToManyTables AS $table) {
|
||||
$this->manyToManyTables[$table->getName()] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
private function reverseEngineerMappingFromDatabase()
|
||||
{
|
||||
if ($this->tables !== null) {
|
||||
@@ -76,7 +97,7 @@ class DatabaseDriver implements Driver
|
||||
$tables[$tableName] = $this->_sm->listTableDetails($tableName);
|
||||
}
|
||||
|
||||
$this->tables = array();
|
||||
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
|
||||
foreach ($tables AS $tableName => $table) {
|
||||
/* @var $table Table */
|
||||
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
@@ -94,11 +115,7 @@ class DatabaseDriver implements Driver
|
||||
sort($pkColumns);
|
||||
sort($allForeignKeyColumns);
|
||||
|
||||
if ($pkColumns == $allForeignKeyColumns) {
|
||||
if (count($table->getForeignKeys()) > 2) {
|
||||
throw new \InvalidArgumentException("ManyToMany table '" . $tableName . "' with more or less than two foreign keys are not supported by the Database Reverese Engineering Driver.");
|
||||
}
|
||||
|
||||
if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) {
|
||||
$this->manyToManyTables[$tableName] = $table;
|
||||
} else {
|
||||
// lower-casing is necessary because of Oracle Uppercase Tablenames,
|
||||
@@ -128,6 +145,11 @@ class DatabaseDriver implements Driver
|
||||
|
||||
$columns = $this->tables[$tableName]->getColumns();
|
||||
$indexes = $this->tables[$tableName]->getIndexes();
|
||||
try {
|
||||
$primaryKeyColumns = $this->tables[$tableName]->getPrimaryKey()->getColumns();
|
||||
} catch(SchemaException $e) {
|
||||
$primaryKeyColumns = array();
|
||||
}
|
||||
|
||||
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$foreignKeys = $this->tables[$tableName]->getForeignKeys();
|
||||
@@ -144,7 +166,7 @@ class DatabaseDriver implements Driver
|
||||
$fieldMappings = array();
|
||||
foreach ($columns as $column) {
|
||||
$fieldMapping = array();
|
||||
if (isset($indexes['primary']) && in_array($column->getName(), $indexes['primary']->getColumns())) {
|
||||
if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) {
|
||||
$fieldMapping['id'] = true;
|
||||
} else if (in_array($column->getName(), $allForeignKeyColumns)) {
|
||||
continue;
|
||||
@@ -185,8 +207,10 @@ class DatabaseDriver implements Driver
|
||||
|
||||
foreach ($this->manyToManyTables AS $manyTable) {
|
||||
foreach ($manyTable->getForeignKeys() AS $foreignKey) {
|
||||
// foreign key maps to the table of the current entity, many to many association probably exists
|
||||
if (strtolower($tableName) == strtolower($foreignKey->getForeignTableName())) {
|
||||
$myFk = $foreignKey;
|
||||
$otherFk = null;
|
||||
foreach ($manyTable->getForeignKeys() AS $foreignKey) {
|
||||
if ($foreignKey != $myFk) {
|
||||
$otherFk = $foreignKey;
|
||||
@@ -194,6 +218,12 @@ class DatabaseDriver implements Driver
|
||||
}
|
||||
}
|
||||
|
||||
if (!$otherFk) {
|
||||
// the definition of this many to many table does not contain
|
||||
// enough foreign key information to continue reverse engeneering.
|
||||
continue;
|
||||
}
|
||||
|
||||
$localColumn = current($myFk->getColumns());
|
||||
$associationMapping = array();
|
||||
$associationMapping['fieldName'] = Inflector::camelize(str_replace('_id', '', strtolower(current($otherFk->getColumns()))));
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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
|
||||
@@ -22,7 +20,7 @@
|
||||
namespace Doctrine\ORM\Mapping\Driver;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||
Doctrine\ORM\Mapping\MappingException;
|
||||
Doctrine\ORM\Mapping\MappingException;
|
||||
|
||||
/**
|
||||
* The StaticPHPDriver calls a static loadMetadata() method on your entity
|
||||
@@ -31,15 +29,33 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class StaticPHPDriver implements Driver
|
||||
{
|
||||
/**
|
||||
* Paths of entity directories.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_paths = array();
|
||||
|
||||
/**
|
||||
* Map of all class names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_classNames;
|
||||
|
||||
/**
|
||||
* The file extension of mapping documents.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_fileExtension = '.php';
|
||||
|
||||
public function __construct($paths)
|
||||
{
|
||||
@@ -58,7 +74,7 @@ class StaticPHPDriver implements Driver
|
||||
{
|
||||
call_user_func_array(array($className, 'loadMetadata'), array($metadata));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it?
|
||||
@@ -77,13 +93,13 @@ class StaticPHPDriver implements Driver
|
||||
$includedFiles = array();
|
||||
|
||||
foreach ($this->_paths as $path) {
|
||||
if ( ! is_dir($path)) {
|
||||
if (!is_dir($path)) {
|
||||
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
|
||||
}
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($path),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||
new \RecursiveDirectoryIterator($path),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||
);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
@@ -102,7 +118,7 @@ class StaticPHPDriver implements Driver
|
||||
foreach ($declared as $className) {
|
||||
$rc = new \ReflectionClass($className);
|
||||
$sourceFile = $rc->getFileName();
|
||||
if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
|
||||
if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
|
||||
$classes[] = $className;
|
||||
}
|
||||
}
|
||||
@@ -119,4 +135,4 @@ class StaticPHPDriver implements Driver
|
||||
{
|
||||
return method_exists($className, 'loadMetadata') ? false : true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,8 +262,8 @@ class XmlDriver extends AbstractFileDriver
|
||||
$mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
|
||||
}
|
||||
|
||||
if (isset($oneToOneElement->{'orphan-removal'})) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToOneElement->{'orphan-removal'};
|
||||
if (isset($oneToOneElement['orphan-removal'])) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToOneElement['orphan-removal'];
|
||||
}
|
||||
|
||||
$metadata->mapOneToOne($mapping);
|
||||
@@ -287,8 +287,8 @@ class XmlDriver extends AbstractFileDriver
|
||||
$mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
|
||||
}
|
||||
|
||||
if (isset($oneToManyElement->{'orphan-removal'})) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'};
|
||||
if (isset($oneToManyElement['orphan-removal'])) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToManyElement['orphan-removal'];
|
||||
}
|
||||
|
||||
if (isset($oneToManyElement->{'order-by'})) {
|
||||
@@ -325,9 +325,6 @@ class XmlDriver extends AbstractFileDriver
|
||||
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
|
||||
} else if (isset($manyToOneElement->{'join-columns'})) {
|
||||
foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
|
||||
if (!isset($joinColumnElement['name'])) {
|
||||
$joinColumnElement['name'] = $name;
|
||||
}
|
||||
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +266,10 @@ class YamlDriver extends AbstractFileDriver
|
||||
$mapping['cascade'] = $oneToOneElement['cascade'];
|
||||
}
|
||||
|
||||
if (isset($oneToOneElement['orphanRemoval'])) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToOneElement['orphanRemoval'];
|
||||
}
|
||||
|
||||
$metadata->mapOneToOne($mapping);
|
||||
}
|
||||
}
|
||||
@@ -283,6 +287,10 @@ class YamlDriver extends AbstractFileDriver
|
||||
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . $oneToManyElement['fetch']);
|
||||
}
|
||||
|
||||
if (isset($oneToManyElement['orphanRemoval'])) {
|
||||
$mapping['orphanRemoval'] = (bool)$oneToManyElement['orphanRemoval'];
|
||||
}
|
||||
|
||||
if (isset($oneToManyElement['cascade'])) {
|
||||
$mapping['cascade'] = $oneToManyElement['cascade'];
|
||||
}
|
||||
@@ -450,6 +458,6 @@ class YamlDriver extends AbstractFileDriver
|
||||
*/
|
||||
protected function _loadMappingFile($file)
|
||||
{
|
||||
return \Symfony\Component\Yaml\Yaml::load($file);
|
||||
return \Symfony\Component\Yaml\Yaml::parse($file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ class MappingException extends \Doctrine\ORM\ORMException
|
||||
return new self("Id generators can't be used with a composite id.");
|
||||
}
|
||||
|
||||
public static function missingFieldName()
|
||||
public static function missingFieldName($entity)
|
||||
{
|
||||
return new self("The association mapping misses the 'fieldName' attribute.");
|
||||
return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
|
||||
}
|
||||
|
||||
public static function missingTargetEntity($fieldName)
|
||||
@@ -68,9 +68,9 @@ class MappingException extends \Doctrine\ORM\ORMException
|
||||
return new self("No mapping file found named '$fileName' for class '$entityName'.");
|
||||
}
|
||||
|
||||
public static function mappingNotFound($fieldName)
|
||||
public static function mappingNotFound($className, $fieldName)
|
||||
{
|
||||
return new self("No mapping found for field '$fieldName'.");
|
||||
return new self("No mapping found for field '$fieldName' on class '$className'.");
|
||||
}
|
||||
|
||||
public static function oneToManyRequiresMappedBy($fieldName)
|
||||
@@ -227,4 +227,8 @@ class MappingException extends \Doctrine\ORM\ORMException
|
||||
return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
|
||||
}
|
||||
|
||||
public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
|
||||
{
|
||||
return new self("It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ class OptimisticLockException extends ORMException
|
||||
|
||||
public function __construct($msg, $entity)
|
||||
{
|
||||
parent::__construct($msg);
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -576,6 +576,7 @@ final class PersistentCollection implements Collection
|
||||
}
|
||||
}
|
||||
$this->coll->clear();
|
||||
$this->initialized = true; // direct call, {@link initialize()} is too expensive
|
||||
if ($this->association['isOwningSide']) {
|
||||
$this->changed();
|
||||
$this->em->getUnitOfWork()->scheduleCollectionDeletion($this);
|
||||
|
||||
@@ -33,11 +33,18 @@ use Doctrine\ORM\Mapping\ClassMetadata,
|
||||
abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
|
||||
{
|
||||
/**
|
||||
* Map from column names to class names that declare the field the column is mapped to.
|
||||
* Map from column names to class metadata instances that declare the field the column is mapped to.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_declaringClassMap = array();
|
||||
private $declaringClassMap = array();
|
||||
|
||||
/**
|
||||
* Map from column names to class names that declare the field the association with join column is mapped to.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $declaringJoinColumnMap = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -70,8 +77,8 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
|
||||
unset($sqlResult[$discrColumnName]);
|
||||
foreach ($sqlResult as $column => $value) {
|
||||
$realColumnName = $this->_resultColumnNames[$column];
|
||||
if (isset($this->_declaringClassMap[$column])) {
|
||||
$class = $this->_declaringClassMap[$column];
|
||||
if (isset($this->declaringClassMap[$column])) {
|
||||
$class = $this->declaringClassMap[$column];
|
||||
if ($class->name == $entityName || is_subclass_of($entityName, $class->name)) {
|
||||
$field = $class->fieldNames[$realColumnName];
|
||||
if (isset($data[$field])) {
|
||||
@@ -81,6 +88,10 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
|
||||
->convertToPHPValue($value, $this->_platform);
|
||||
}
|
||||
}
|
||||
} else if (isset($this->declaringJoinColumnMap[$column])) {
|
||||
if ($this->declaringJoinColumnMap[$column] == $entityName || is_subclass_of($entityName, $this->declaringJoinColumnMap[$column])) {
|
||||
$data[$realColumnName] = $value;
|
||||
}
|
||||
} else {
|
||||
$data[$realColumnName] = $value;
|
||||
}
|
||||
@@ -99,9 +110,21 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
|
||||
$columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
|
||||
if ( ! isset($this->_resultColumnNames[$columnAlias])) {
|
||||
$this->_resultColumnNames[$columnAlias] = $columnName;
|
||||
$this->_declaringClassMap[$columnAlias] = $class;
|
||||
$this->declaringClassMap[$columnAlias] = $class;
|
||||
}
|
||||
|
||||
return "$sql AS $columnAlias";
|
||||
}
|
||||
|
||||
protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className)
|
||||
{
|
||||
$columnAlias = $joinColumnName . $this->_sqlAliasCounter++;
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $joinColumnName;
|
||||
$this->declaringJoinColumnMap[$resultColumnName] = $className;
|
||||
}
|
||||
|
||||
return $tableAlias . ".$joinColumnName AS $columnAlias";
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,9 @@ use PDO,
|
||||
Doctrine\ORM\Query,
|
||||
Doctrine\ORM\PersistentCollection,
|
||||
Doctrine\ORM\Mapping\MappingException,
|
||||
Doctrine\ORM\Mapping\ClassMetadata;
|
||||
Doctrine\ORM\Mapping\ClassMetadata,
|
||||
Doctrine\ORM\Events,
|
||||
Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
|
||||
/**
|
||||
* A BasicEntityPersiter maps an entity to a single table in a relational database.
|
||||
@@ -170,6 +172,14 @@ class BasicEntityPersister
|
||||
$this->_platform = $this->_conn->getDatabasePlatform();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Doctrine\ORM\Mapping\ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entity to the queued insertions.
|
||||
* The entity remains queued until {@link executeInserts} is invoked.
|
||||
@@ -223,7 +233,7 @@ class BasicEntityPersister
|
||||
}
|
||||
|
||||
if ($this->_class->isVersioned) {
|
||||
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
|
||||
$this->assignDefaultVersionValue($entity, $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,22 +248,33 @@ class BasicEntityPersister
|
||||
* by the preceding INSERT statement and assigns it back in to the
|
||||
* entities version field.
|
||||
*
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $class
|
||||
* @param object $entity
|
||||
* @param mixed $id
|
||||
*/
|
||||
protected function _assignDefaultVersionValue($class, $entity, $id)
|
||||
protected function assignDefaultVersionValue($entity, $id)
|
||||
{
|
||||
$versionField = $this->_class->versionField;
|
||||
$identifier = $this->_class->getIdentifierColumnNames();
|
||||
$versionFieldColumnName = $this->_class->getColumnName($versionField);
|
||||
$value = $this->fetchVersionValue($this->_class, $id);
|
||||
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current version value of a versioned entity.
|
||||
*
|
||||
* @param Doctrine\ORM\Mapping\ClassMetadata $versionedClass
|
||||
* @param mixed $id
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fetchVersionValue($versionedClass, $id)
|
||||
{
|
||||
$versionField = $versionedClass->versionField;
|
||||
$identifier = $versionedClass->getIdentifierColumnNames();
|
||||
$versionFieldColumnName = $versionedClass->getColumnName($versionField);
|
||||
//FIXME: Order with composite keys might not be correct
|
||||
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform)
|
||||
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $versionedClass->getQuotedTableName($this->_platform)
|
||||
. " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
|
||||
$value = $this->_conn->fetchColumn($sql, array_values((array)$id));
|
||||
|
||||
$value = Type::getType($class->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform);
|
||||
$this->_class->setFieldValue($entity, $versionField, $value);
|
||||
return Type::getType($versionedClass->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +303,7 @@ class BasicEntityPersister
|
||||
|
||||
if ($this->_class->isVersioned) {
|
||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
|
||||
$this->assignDefaultVersionValue($entity, $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,7 +358,7 @@ class BasicEntityPersister
|
||||
|
||||
$result = $this->_conn->executeUpdate($sql, $params, $types);
|
||||
|
||||
if ($this->_class->isVersioned && ! $result) {
|
||||
if ($versioned && ! $result) {
|
||||
throw OptimisticLockException::lockFailed($entity);
|
||||
}
|
||||
}
|
||||
@@ -525,7 +546,8 @@ class BasicEntityPersister
|
||||
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = 0)
|
||||
{
|
||||
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc, $lockMode);
|
||||
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
|
||||
list($params, $types) = $this->expandParameters($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -608,7 +630,8 @@ class BasicEntityPersister
|
||||
public function refresh(array $id, $entity)
|
||||
{
|
||||
$sql = $this->_getSelectEntitiesSQL($id);
|
||||
$stmt = $this->_conn->executeQuery($sql, array_values($id));
|
||||
list($params, $types) = $this->expandParameters($id);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -682,6 +705,14 @@ class BasicEntityPersister
|
||||
}
|
||||
|
||||
$this->_em->getUnitOfWork()->setOriginalEntityData($entity, $newData);
|
||||
|
||||
if (isset($this->_class->lifecycleCallbacks[Events::postLoad])) {
|
||||
$this->_class->invokeLifecycleCallbacks(Events::postLoad, $entity);
|
||||
}
|
||||
$evm = $this->_em->getEventManager();
|
||||
if ($evm->hasListeners(Events::postLoad)) {
|
||||
$evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($entity, $this->_em));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -694,7 +725,8 @@ class BasicEntityPersister
|
||||
{
|
||||
$entities = array();
|
||||
$sql = $this->_getSelectEntitiesSQL($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
|
||||
list($params, $types) = $this->expandParameters($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
@@ -718,9 +750,10 @@ class BasicEntityPersister
|
||||
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
|
||||
$joinTableConditions = array();
|
||||
if ($assoc['isOwningSide']) {
|
||||
$quotedJoinTable = $sourceClass->getQuotedJoinTableName($assoc, $this->_platform);
|
||||
foreach ($assoc['relationToSourceKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
|
||||
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
|
||||
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
$criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
} else {
|
||||
throw MappingException::joinColumnMustPointToMappedField(
|
||||
$sourceClass->name, $sourceKeyColumn
|
||||
@@ -729,10 +762,11 @@ class BasicEntityPersister
|
||||
}
|
||||
} else {
|
||||
$owningAssoc = $this->_em->getClassMetadata($assoc['targetEntity'])->associationMappings[$assoc['mappedBy']];
|
||||
$quotedJoinTable = $sourceClass->getQuotedJoinTableName($owningAssoc, $this->_platform);
|
||||
// TRICKY: since the association is inverted source and target are flipped
|
||||
foreach ($owningAssoc['relationToTargetKeyColumns'] as $relationKeyColumn => $sourceKeyColumn) {
|
||||
if (isset($sourceClass->fieldNames[$sourceKeyColumn])) {
|
||||
$criteria[$relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
$criteria[$quotedJoinTable . "." . $relationKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
} else {
|
||||
throw MappingException::joinColumnMustPointToMappedField(
|
||||
$sourceClass->name, $sourceKeyColumn
|
||||
@@ -742,7 +776,8 @@ class BasicEntityPersister
|
||||
}
|
||||
|
||||
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
|
||||
$stmt = $this->_conn->executeQuery($sql, array_values($criteria));
|
||||
list($params, $types) = $this->expandParameters($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$coll->hydrateAdd($this->_createEntity($result));
|
||||
}
|
||||
@@ -1084,8 +1119,8 @@ class BasicEntityPersister
|
||||
$sql = 'SELECT 1 '
|
||||
. $this->_platform->appendLockHint($this->getLockTablesSql(), $lockMode)
|
||||
. ($conditionSql ? ' WHERE ' . $conditionSql : '') . ' ' . $lockSql;
|
||||
$params = array_values($criteria);
|
||||
$this->_conn->executeQuery($sql, $params);
|
||||
list($params, $types) = $this->expandParameters($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1136,18 +1171,16 @@ class BasicEntityPersister
|
||||
|
||||
|
||||
$conditionSql .= $this->_class->associationMappings[$field]['joinColumns'][0]['name'];
|
||||
} else if ($assoc !== null) {
|
||||
if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) {
|
||||
$owningAssoc = $assoc['isOwningSide'] ? $assoc : $this->_em->getClassMetadata($assoc['targetEntity'])
|
||||
->associationMappings[$assoc['mappedBy']];
|
||||
$conditionSql .= $this->_class->getQuotedJoinTableName($owningAssoc, $this->_platform) . '.' . $field;
|
||||
} else {
|
||||
$conditionSql .= $field;
|
||||
}
|
||||
} else if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
|
||||
// very careless developers could potentially open up this normally hidden api for userland attacks,
|
||||
// therefore checking for spaces and function calls which are not allowed.
|
||||
|
||||
// found a join column condition, not really a "field"
|
||||
$conditionSql .= $field;
|
||||
} else {
|
||||
throw ORMException::unrecognizedField($field);
|
||||
}
|
||||
$conditionSql .= ' = ?';
|
||||
$conditionSql .= ($value === null) ? ' IS NULL' : ' = ?';
|
||||
}
|
||||
return $conditionSql;
|
||||
}
|
||||
@@ -1164,19 +1197,49 @@ class BasicEntityPersister
|
||||
$criteria = array();
|
||||
$owningAssoc = $this->_class->associationMappings[$assoc['mappedBy']];
|
||||
$sourceClass = $this->_em->getClassMetadata($assoc['sourceEntity']);
|
||||
|
||||
$tableAlias = isset($owningAssoc['inherited']) ?
|
||||
$this->_getSQLTableAlias($owningAssoc['inherited'])
|
||||
: $this->_getSQLTableAlias($this->_class->name);
|
||||
|
||||
foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) {
|
||||
$criteria[$targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
$criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity);
|
||||
}
|
||||
|
||||
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
|
||||
$params = array_values($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params);
|
||||
list($params, $types) = $this->expandParameters($criteria);
|
||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$coll->hydrateAdd($this->_createEntity($result));
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the parameters from the given criteria and use the correct binding types if found.
|
||||
*
|
||||
* @param array $criteria
|
||||
* @return array
|
||||
*/
|
||||
private function expandParameters($criteria)
|
||||
{
|
||||
$params = $types = array();
|
||||
|
||||
foreach ($criteria AS $field => $value) {
|
||||
if ($value === null) {
|
||||
continue; // skip null values.
|
||||
}
|
||||
|
||||
$type = null;
|
||||
if (isset($this->_class->fieldMappings[$field])) {
|
||||
$type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType();
|
||||
}
|
||||
$params[] = $value;
|
||||
$types[] = $type;
|
||||
}
|
||||
return array($params, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given managed entity exists in the database.
|
||||
*
|
||||
|
||||
@@ -107,10 +107,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_class->isVersioned) {
|
||||
$versionedClass = $this->_getVersionedClassMetadata();
|
||||
}
|
||||
|
||||
$postInsertIds = array();
|
||||
$idGen = $this->_class->idGenerator;
|
||||
$isPostInsertId = $idGen->isPostInsertGenerator();
|
||||
@@ -176,8 +172,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
if (isset($versionedClass)) {
|
||||
$this->_assignDefaultVersionValue($versionedClass, $entity, $id);
|
||||
if ($this->_class->isVersioned) {
|
||||
$this->assignDefaultVersionValue($entity, $id);
|
||||
}
|
||||
|
||||
$this->_queuedInserts = array();
|
||||
@@ -207,7 +203,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
$this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true);
|
||||
|
||||
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
|
||||
$this->_assignDefaultVersionValue($this->_class, $entity, $id);
|
||||
$this->assignDefaultVersionValue($entity, $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,12 +259,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
$this->_getSQLTableAlias($assoc2['inherited'])
|
||||
: $baseTableAlias;
|
||||
foreach ($assoc2['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
|
||||
$columnList .= ", $tableAlias.$srcColumn AS $columnAlias";
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
|
||||
}
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $this->getSelectJoinColumnSQL($tableAlias, $srcColumn,
|
||||
isset($assoc2['inherited']) ? $assoc2['inherited'] : $this->_class->name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,12 +312,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
if ($assoc2['isOwningSide'] && $assoc2['type'] & ClassMetadata::TO_ONE
|
||||
&& ! isset($assoc2['inherited'])) {
|
||||
foreach ($assoc2['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
|
||||
$columnList .= ', ' . $tableAlias . ".$srcColumn AS $columnAlias";
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
|
||||
}
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $this->getSelectJoinColumnSQL($tableAlias, $srcColumn,
|
||||
isset($assoc2['inherited']) ? $assoc2['inherited'] : $subClass->name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -423,4 +415,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function assignDefaultVersionValue($entity, $id)
|
||||
{
|
||||
$value = $this->fetchVersionValue($this->_getVersionedClassMetadata(), $id);
|
||||
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,10 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
|
||||
foreach ($subClass->associationMappings as $assoc) {
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE && ! isset($assoc['inherited'])) {
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
|
||||
$columnList .= ', ' . $tableAlias . ".$srcColumn AS $columnAlias";
|
||||
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
if ( ! isset($this->_resultColumnNames[$resultColumnName])) {
|
||||
$this->_resultColumnNames[$resultColumnName] = $srcColumn;
|
||||
}
|
||||
if ($columnList != '') $columnList .= ', ';
|
||||
$columnList .= $this->getSelectJoinColumnSQL($tableAlias, $srcColumn,
|
||||
isset($assoc['inherited']) ? $assoc['inherited'] : $this->_class->name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,11 +130,12 @@ class ProxyFactory
|
||||
{
|
||||
$methods = $this->_generateMethods($class);
|
||||
$sleepImpl = $this->_generateSleep($class);
|
||||
$cloneImpl = $class->reflClass->hasMethod('__clone') ? 'parent::__clone();' : ''; // hasMethod() checks case-insensitive
|
||||
|
||||
$placeholders = array(
|
||||
'<namespace>',
|
||||
'<proxyClassName>', '<className>',
|
||||
'<methods>', '<sleepImpl>'
|
||||
'<methods>', '<sleepImpl>', '<cloneImpl>'
|
||||
);
|
||||
|
||||
if(substr($class->name, 0, 1) == "\\") {
|
||||
@@ -146,7 +147,7 @@ class ProxyFactory
|
||||
$replacements = array(
|
||||
$this->_proxyNamespace,
|
||||
$proxyClassName, $className,
|
||||
$methods, $sleepImpl
|
||||
$methods, $sleepImpl, $cloneImpl
|
||||
);
|
||||
|
||||
$file = str_replace($placeholders, $replacements, $file);
|
||||
@@ -166,7 +167,7 @@ class ProxyFactory
|
||||
|
||||
foreach ($class->reflClass->getMethods() as $method) {
|
||||
/* @var $method ReflectionMethod */
|
||||
if ($method->isConstructor() || strtolower($method->getName()) == "__sleep") {
|
||||
if ($method->isConstructor() || in_array(strtolower($method->getName()), array("__sleep", "__clone"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ class ProxyFactory
|
||||
|
||||
$methods .= $parameterString . ')';
|
||||
$methods .= PHP_EOL . ' {' . PHP_EOL;
|
||||
$methods .= ' $this->_load();' . PHP_EOL;
|
||||
$methods .= ' $this->__load();' . PHP_EOL;
|
||||
$methods .= ' return parent::' . $method->getName() . '(' . $argumentString . ');';
|
||||
$methods .= PHP_EOL . ' }' . PHP_EOL;
|
||||
}
|
||||
@@ -268,22 +269,48 @@ class <proxyClassName> extends \<className> implements \Doctrine\ORM\Proxy\Proxy
|
||||
$this->_entityPersister = $entityPersister;
|
||||
$this->_identifier = $identifier;
|
||||
}
|
||||
private function _load()
|
||||
/** @private */
|
||||
public function __load()
|
||||
{
|
||||
if (!$this->__isInitialized__ && $this->_entityPersister) {
|
||||
$this->__isInitialized__ = true;
|
||||
|
||||
if (method_exists($this, "__wakeup")) {
|
||||
// call this after __isInitialized__to avoid infinite recursion
|
||||
// but before loading to emulate what ClassMetadata::newInstance()
|
||||
// provides.
|
||||
$this->__wakeup();
|
||||
}
|
||||
|
||||
if ($this->_entityPersister->load($this->_identifier, $this) === null) {
|
||||
throw new \Doctrine\ORM\EntityNotFoundException();
|
||||
}
|
||||
unset($this->_entityPersister, $this->_identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
<methods>
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
<sleepImpl>
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if (!$this->__isInitialized__ && $this->_entityPersister) {
|
||||
$this->__isInitialized__ = true;
|
||||
$class = $this->_entityPersister->getClassMetadata();
|
||||
$original = $this->_entityPersister->load($this->_identifier);
|
||||
if ($original === null) {
|
||||
throw new \Doctrine\ORM\EntityNotFoundException();
|
||||
}
|
||||
foreach ($class->reflFields AS $field => $reflProperty) {
|
||||
$reflProperty->setValue($this, $reflProperty->getValue($original));
|
||||
}
|
||||
unset($this->_entityPersister, $this->_identifier);
|
||||
}
|
||||
<cloneImpl>
|
||||
}
|
||||
}';
|
||||
}
|
||||
|
||||
@@ -249,7 +249,12 @@ final class Query extends AbstractQuery
|
||||
$idValues = $class->getIdentifierValues($value);
|
||||
}
|
||||
$sqlPositions = $paramMappings[$key];
|
||||
$sqlParams += array_combine((array)$sqlPositions, $idValues);
|
||||
$cSqlPos = count($sqlPositions);
|
||||
$cIdValues = count($idValues);
|
||||
$idValues = array_values($idValues);
|
||||
for ($i = 0; $i < $cSqlPos; $i++) {
|
||||
$sqlParams[$sqlPositions[$i]] = $idValues[ ($i % $cIdValues) ];
|
||||
}
|
||||
} else {
|
||||
foreach ($paramMappings[$key] as $position) {
|
||||
$sqlParams[$position] = $value;
|
||||
|
||||
@@ -55,7 +55,7 @@ abstract class Base
|
||||
|
||||
public function add($arg)
|
||||
{
|
||||
if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) {
|
||||
if ( $arg !== null || ($arg instanceof self && $arg->count() > 0)) {
|
||||
// If we decide to keep Expr\Base instances, we can use this check
|
||||
if ( ! is_string($arg)) {
|
||||
$class = get_class($arg);
|
||||
|
||||
@@ -126,7 +126,7 @@ class Lexer extends \Doctrine\Common\Lexer
|
||||
'[a-z_\\\][a-z0-9_\:\\\]*[a-z0-9_]{1}',
|
||||
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
||||
"'(?:[^']|'')*'",
|
||||
'\?[1-9][0-9]*|:[a-z][a-z0-9_]+'
|
||||
'\?[1-9][0-9]*|:[a-z]{1}[a-z0-9_]{0,}'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -277,20 +277,8 @@ class Parser
|
||||
{
|
||||
$AST = $this->getAST();
|
||||
|
||||
// Fix order of identification variables.
|
||||
// They have to appear in the select clause in the same order as the
|
||||
// declarations (from ... x join ... y join ... z ...) appear in the query
|
||||
// as the hydration process relies on that order for proper operation.
|
||||
if ( count($this->_identVariableExpressions) > 1) {
|
||||
foreach ($this->_queryComponents as $dqlAlias => $qComp) {
|
||||
if (isset($this->_identVariableExpressions[$dqlAlias])) {
|
||||
$expr = $this->_identVariableExpressions[$dqlAlias];
|
||||
$key = array_search($expr, $AST->selectClause->selectExpressions);
|
||||
unset($AST->selectClause->selectExpressions[$key]);
|
||||
$AST->selectClause->selectExpressions[] = $expr;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->fixIdentificationVariableOrder($AST);
|
||||
$this->assertSelectEntityRootAliasRequirement();
|
||||
|
||||
if (($customWalkers = $this->_query->getHint(Query::HINT_CUSTOM_TREE_WALKERS)) !== false) {
|
||||
$this->_customTreeWalkers = $customWalkers;
|
||||
@@ -332,6 +320,46 @@ class Parser
|
||||
|
||||
return $this->_parserResult;
|
||||
}
|
||||
|
||||
private function assertSelectEntityRootAliasRequirement()
|
||||
{
|
||||
if ( count($this->_identVariableExpressions) > 0) {
|
||||
$foundRootEntity = false;
|
||||
foreach ($this->_identVariableExpressions AS $dqlAlias => $expr) {
|
||||
if (isset($this->_queryComponents[$dqlAlias]) && $this->_queryComponents[$dqlAlias]['parent'] === null) {
|
||||
$foundRootEntity = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$foundRootEntity) {
|
||||
$this->semanticalError('Cannot select entity through identification variables without choosing at least one root entity alias.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix order of identification variables.
|
||||
*
|
||||
* They have to appear in the select clause in the same order as the
|
||||
* declarations (from ... x join ... y join ... z ...) appear in the query
|
||||
* as the hydration process relies on that order for proper operation.
|
||||
*
|
||||
* @param AST\SelectStatement|AST\DeleteStatement|AST\UpdateStatement $AST
|
||||
* @return void
|
||||
*/
|
||||
private function fixIdentificationVariableOrder($AST)
|
||||
{
|
||||
if ( count($this->_identVariableExpressions) > 1) {
|
||||
foreach ($this->_queryComponents as $dqlAlias => $qComp) {
|
||||
if (isset($this->_identVariableExpressions[$dqlAlias])) {
|
||||
$expr = $this->_identVariableExpressions[$dqlAlias];
|
||||
$key = array_search($expr, $AST->selectClause->selectExpressions);
|
||||
unset($AST->selectClause->selectExpressions[$key]);
|
||||
$AST->selectClause->selectExpressions[] = $expr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new syntax error.
|
||||
@@ -1296,6 +1324,10 @@ class Parser
|
||||
$token = $this->_lexer->lookahead;
|
||||
$identVariable = $this->IdentificationVariable();
|
||||
|
||||
if (!isset($this->_queryComponents[$identVariable])) {
|
||||
$this->semanticalError('Cannot group by undefined identification variable.');
|
||||
}
|
||||
|
||||
return $identVariable;
|
||||
}
|
||||
|
||||
@@ -1605,7 +1637,7 @@ class Parser
|
||||
return $this->StateFieldPathExpression();
|
||||
} else if ($lookahead == Lexer::T_INTEGER || $lookahead == Lexer::T_FLOAT) {
|
||||
return $this->SimpleArithmeticExpression();
|
||||
} else if ($this->_isFunction()) {
|
||||
} else if ($this->_isFunction() || $this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
|
||||
// We may be in an ArithmeticExpression (find the matching ")" and inspect for Math operator)
|
||||
$this->_lexer->peek(); // "("
|
||||
$peek = $this->_peekBeyondClosingParenthesis();
|
||||
@@ -1613,8 +1645,12 @@ class Parser
|
||||
if ($this->_isMathOperator($peek)) {
|
||||
return $this->SimpleArithmeticExpression();
|
||||
}
|
||||
|
||||
return $this->FunctionDeclaration();
|
||||
|
||||
if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
|
||||
return $this->AggregateExpression();
|
||||
} else {
|
||||
return $this->FunctionDeclaration();
|
||||
}
|
||||
} else if ($lookahead == Lexer::T_STRING) {
|
||||
return $this->StringPrimary();
|
||||
} else if ($lookahead == Lexer::T_INPUT_PARAMETER) {
|
||||
@@ -1689,7 +1725,8 @@ class Parser
|
||||
$expression = $this->PartialObjectExpression();
|
||||
$identVariable = $expression->identificationVariable;
|
||||
} else if ($this->_lexer->lookahead['type'] == Lexer::T_INTEGER ||
|
||||
$this->_lexer->lookahead['type'] == Lexer::T_FLOAT) {
|
||||
$this->_lexer->lookahead['type'] == Lexer::T_FLOAT ||
|
||||
$this->_lexer->lookahead['type'] == Lexer::T_STRING) {
|
||||
// Shortcut: ScalarExpression => SimpleArithmeticExpression
|
||||
$expression = $this->SimpleArithmeticExpression();
|
||||
} else {
|
||||
@@ -1758,15 +1795,8 @@ class Parser
|
||||
}
|
||||
|
||||
$this->_lexer->peek();
|
||||
$beyond = $this->_peekBeyondClosingParenthesis();
|
||||
|
||||
if ($this->_isMathOperator($beyond)) {
|
||||
$expression = $this->ScalarExpression();
|
||||
} else if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
|
||||
$expression = $this->AggregateExpression();
|
||||
} else {
|
||||
$expression = $this->FunctionDeclaration();
|
||||
}
|
||||
$expression = $this->ScalarExpression();
|
||||
|
||||
$expr = new AST\SimpleSelectExpression($expression);
|
||||
|
||||
@@ -2271,7 +2301,8 @@ class Parser
|
||||
if ($peek['value'] == '.') {
|
||||
return $this->StateFieldPathExpression();
|
||||
} else if ($peek['value'] == '(') {
|
||||
return $this->FunctionsReturningStrings();
|
||||
// do NOT directly go to FunctionsReturningString() because it doesnt check for custom functions.
|
||||
return $this->FunctionDeclaration();
|
||||
} else {
|
||||
$this->syntaxError("'.' or '('");
|
||||
}
|
||||
@@ -2358,7 +2389,7 @@ class Parser
|
||||
|
||||
$functionName = $this->_lexer->token['value'];
|
||||
$this->match(Lexer::T_OPEN_PARENTHESIS);
|
||||
$pathExp = $this->StateFieldPathExpression();
|
||||
$pathExp = $this->SimpleArithmeticExpression();
|
||||
$this->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ class QueryException extends \Doctrine\ORM\ORMException
|
||||
public static function invalidPathExpression($pathExpr)
|
||||
{
|
||||
return new self(
|
||||
"Invalid PathExpression '" . $pathExpr->identificationVariable .
|
||||
"." . implode('.', $pathExpr->parts) . "'."
|
||||
"Invalid PathExpression '" . $pathExpr->identificationVariable . "." . $pathExpr->field . "'."
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -209,9 +209,13 @@ class SqlWalker implements TreeWalker
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $alias
|
||||
* @param string $dqlAlias
|
||||
* @return string
|
||||
*/
|
||||
public function setSqlTableAlias($tableName, $alias)
|
||||
public function setSqlTableAlias($tableName, $alias, $dqlAlias = '')
|
||||
{
|
||||
$tableName .= $dqlAlias;
|
||||
|
||||
$this->_tableAliasMap[$tableName] = $alias;
|
||||
|
||||
return $alias;
|
||||
@@ -714,6 +718,14 @@ class SqlWalker implements TreeWalker
|
||||
$join = $joinVarDecl->join;
|
||||
$joinType = $join->joinType;
|
||||
|
||||
if ($joinVarDecl->indexBy) {
|
||||
// For Many-To-One or One-To-One associations this obviously makes no sense, but is ignored silently.
|
||||
$this->_rsm->addIndexBy(
|
||||
$joinVarDecl->indexBy->simpleStateFieldPathExpression->identificationVariable,
|
||||
$joinVarDecl->indexBy->simpleStateFieldPathExpression->field
|
||||
);
|
||||
}
|
||||
|
||||
if ($joinType == AST\Join::JOIN_TYPE_LEFT || $joinType == AST\Join::JOIN_TYPE_LEFTOUTER) {
|
||||
$sql = ' LEFT JOIN ';
|
||||
} else {
|
||||
@@ -915,7 +927,8 @@ class SqlWalker implements TreeWalker
|
||||
$expr instanceof AST\SimpleArithmeticExpression ||
|
||||
$expr instanceof AST\ArithmeticTerm ||
|
||||
$expr instanceof AST\ArithmeticFactor ||
|
||||
$expr instanceof AST\ArithmeticPrimary
|
||||
$expr instanceof AST\ArithmeticPrimary ||
|
||||
$expr instanceof AST\Literal
|
||||
) {
|
||||
if ( ! $selectExpression->fieldIdentificationVariable) {
|
||||
$resultAlias = $this->_scalarResultCounter++;
|
||||
@@ -924,7 +937,11 @@ class SqlWalker implements TreeWalker
|
||||
}
|
||||
|
||||
$columnAlias = 'sclr' . $this->_aliasCounter++;
|
||||
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
|
||||
if ($expr instanceof AST\Literal) {
|
||||
$sql .= $this->walkLiteral($expr) . ' AS ' .$columnAlias;
|
||||
} else {
|
||||
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
|
||||
}
|
||||
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
|
||||
|
||||
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
|
||||
@@ -1174,7 +1191,7 @@ class SqlWalker implements TreeWalker
|
||||
public function walkAggregateExpression($aggExpression)
|
||||
{
|
||||
return $aggExpression->functionName . '(' . ($aggExpression->isDistinct ? 'DISTINCT ' : '')
|
||||
. $this->walkPathExpression($aggExpression->pathExpression) . ')';
|
||||
. $this->walkSimpleArithmeticExpression($aggExpression->pathExpression) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1185,9 +1202,25 @@ class SqlWalker implements TreeWalker
|
||||
*/
|
||||
public function walkGroupByClause($groupByClause)
|
||||
{
|
||||
return ' GROUP BY ' . implode(
|
||||
', ', array_map(array($this, 'walkGroupByItem'), $groupByClause->groupByItems)
|
||||
);
|
||||
$sql = '';
|
||||
foreach ($groupByClause->groupByItems AS $groupByItem) {
|
||||
if (is_string($groupByItem)) {
|
||||
foreach ($this->_queryComponents[$groupByItem]['metadata']->identifier AS $idField) {
|
||||
if ($sql != '') {
|
||||
$sql .= ', ';
|
||||
}
|
||||
$groupByItem = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $idField);
|
||||
$groupByItem->type = AST\PathExpression::TYPE_STATE_FIELD;
|
||||
$sql .= $this->walkGroupByItem($groupByItem);
|
||||
}
|
||||
} else {
|
||||
if ($sql != '') {
|
||||
$sql .= ', ';
|
||||
}
|
||||
$sql .= $this->walkGroupByItem($groupByItem);
|
||||
}
|
||||
}
|
||||
return ' GROUP BY ' . $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1213,9 +1246,7 @@ class SqlWalker implements TreeWalker
|
||||
$class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName);
|
||||
$sql .= $class->getQuotedTableName($this->_platform);
|
||||
|
||||
if ($this->_useSqlTableAliases) {
|
||||
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
|
||||
}
|
||||
$this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $deleteClause->aliasIdentificationVariable);
|
||||
|
||||
$this->_rootAliases[] = $deleteClause->aliasIdentificationVariable;
|
||||
|
||||
@@ -1234,9 +1265,7 @@ class SqlWalker implements TreeWalker
|
||||
$class = $this->_em->getClassMetadata($updateClause->abstractSchemaName);
|
||||
$sql .= $class->getQuotedTableName($this->_platform);
|
||||
|
||||
if ($this->_useSqlTableAliases) {
|
||||
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
|
||||
}
|
||||
$this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $updateClause->aliasIdentificationVariable);
|
||||
|
||||
$this->_rootAliases[] = $updateClause->aliasIdentificationVariable;
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@ class ConvertMappingCommand extends Console\Command\Command
|
||||
'dest-path', InputArgument::REQUIRED,
|
||||
'The path to generate your entities classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'force', null, InputOption::VALUE_NONE,
|
||||
'Force to overwrite existing mapping files.'
|
||||
),
|
||||
new InputOption(
|
||||
'from-database', null, null, 'Whether or not to convert mapping information from existing database.'
|
||||
),
|
||||
@@ -73,10 +77,24 @@ class ConvertMappingCommand extends Console\Command\Command
|
||||
new InputOption(
|
||||
'num-spaces', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines the number of indentation spaces', 4
|
||||
)
|
||||
),
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Convert mapping information between supported formats.
|
||||
|
||||
This is an execute <info>one-time</info> command. It should not be necessary for
|
||||
you to call this method multiple times, escpecially when using the <comment>--from-database</comment>
|
||||
flag.
|
||||
|
||||
Converting an existing databsae schema into mapping files only solves about 70-80%
|
||||
of the necessary mapping information. Additionally the detection from an existing
|
||||
database cannot detect inverse associations, inheritance types,
|
||||
entities with foreign keys as primary keys and many of the
|
||||
semantical operations on associations such as cascade.
|
||||
|
||||
<comment>Hint:</comment> There is no need to convert YAML or XML mapping files to annotations
|
||||
every time you make changes. All mapping drivers are first class citizens
|
||||
in Doctrine 2 and can be used as runtime mapping for the ORM.
|
||||
EOT
|
||||
);
|
||||
}
|
||||
@@ -119,8 +137,8 @@ EOT
|
||||
|
||||
$toType = strtolower($input->getArgument('to-type'));
|
||||
|
||||
$cme = new ClassMetadataExporter();
|
||||
$exporter = $cme->getExporter($toType, $destPath);
|
||||
$exporter = $this->getExporter($toType, $destPath);
|
||||
$exporter->setOverwriteExistingFiles( ($input->getOption('force') !== false) );
|
||||
|
||||
if ($toType == 'annotation') {
|
||||
$entityGenerator = new EntityGenerator();
|
||||
@@ -148,4 +166,11 @@ EOT
|
||||
$output->write('No Metadata Classes to process.' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getExporter($toType, $destPath)
|
||||
{
|
||||
$cme = new ClassMetadataExporter();
|
||||
|
||||
return $cme->getExporter($toType, $destPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,23 @@ class GenerateEntitiesCommand extends Console\Command\Command
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Generate entity classes and method stubs from your mapping information.
|
||||
|
||||
If you use the <comment>--update-entities</comment> or <comment>--regenerate-entities</comment> flags your exisiting
|
||||
code gets overwritten. The EntityGenerator will only append new code to your
|
||||
file and will not delete the old code. However this approach may still be prone
|
||||
to error and we suggest you use code repositories such as GIT or SVN to make
|
||||
backups of your code.
|
||||
|
||||
It makes sense to generate the entity code if you are using entities as Data
|
||||
Access Objects only and dont put much additional logic on them. If you are
|
||||
however putting much more logic on the entities you should refrain from using
|
||||
the entity-generator and code your entities manually.
|
||||
|
||||
<error>Important:</error> Even if you specified Inheritance options in your
|
||||
XML or YAML Mapping files the generator cannot generate the base and
|
||||
child classes for you correctly, because it doesn't know which
|
||||
class is supposed to extend which. You have to adjust the entity
|
||||
code manually for inheritance to work!
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,10 +70,10 @@ class ConvertDoctrine1Schema
|
||||
if (is_dir($path)) {
|
||||
$files = glob($path . '/*.yml');
|
||||
foreach ($files as $file) {
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($file));
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::parse($file));
|
||||
}
|
||||
} else {
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($path));
|
||||
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::parse($path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,6 @@ class ConvertDoctrine1Schema
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
||||
} else if (isset($column['sequence'])) {
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
|
||||
$metadata->setSequenceGeneratorDefinition($definition);
|
||||
$definition = array(
|
||||
'sequenceName' => is_array($column['sequence']) ? $column['sequence']['name']:$column['sequence']
|
||||
);
|
||||
@@ -198,6 +197,7 @@ class ConvertDoctrine1Schema
|
||||
if (isset($column['sequence']['value'])) {
|
||||
$definition['initialValue'] = $column['sequence']['value'];
|
||||
}
|
||||
$metadata->setSequenceGeneratorDefinition($definition);
|
||||
}
|
||||
return $fieldMapping;
|
||||
}
|
||||
|
||||
@@ -47,14 +47,18 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||
*/
|
||||
class EntityGenerator
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $_backupExisting = true;
|
||||
|
||||
/** The extension to use for written php files */
|
||||
private $_extension = '.php';
|
||||
|
||||
/** Whether or not the current ClassMetadataInfo instance is new or old */
|
||||
private $_isNew = true;
|
||||
|
||||
/** If isNew is false then this variable contains instance of ReflectionClass for current entity */
|
||||
private $_reflection;
|
||||
private $_staticReflection = array();
|
||||
|
||||
/** Number of spaces to use for indention in generated code */
|
||||
private $_numSpaces = 4;
|
||||
@@ -68,6 +72,11 @@ class EntityGenerator
|
||||
/** Whether or not to generation annotations */
|
||||
private $_generateAnnotations = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $_annotationsPrefix = '';
|
||||
|
||||
/** Whether or not to generated sub methods */
|
||||
private $_generateEntityStubMethods = false;
|
||||
|
||||
@@ -130,6 +139,13 @@ public function <methodName>()
|
||||
<spaces>// Add your code here
|
||||
}';
|
||||
|
||||
private static $_constructorMethodTemplate =
|
||||
'public function __construct()
|
||||
{
|
||||
<spaces><collections>
|
||||
}
|
||||
';
|
||||
|
||||
/**
|
||||
* Generate and write entity classes for the given array of ClassMetadataInfo instances
|
||||
*
|
||||
@@ -160,16 +176,21 @@ public function <methodName>()
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
$this->_isNew = ! file_exists($path);
|
||||
$this->_isNew = !file_exists($path) || (file_exists($path) && $this->_regenerateEntityIfExists);
|
||||
|
||||
if ( ! $this->_isNew) {
|
||||
require_once $path;
|
||||
$this->_parseTokensInEntityFile(file_get_contents($path));
|
||||
}
|
||||
|
||||
$this->_reflection = new \ReflectionClass($metadata->name);
|
||||
if ($this->_backupExisting && file_exists($path)) {
|
||||
$backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~";
|
||||
if (!copy($path, $backupPath)) {
|
||||
throw new \RuntimeException("Attempt to backup overwritten entitiy file but copy operation failed.");
|
||||
}
|
||||
}
|
||||
|
||||
// If entity doesn't exist or we're re-generating the entities entirely
|
||||
if ($this->_isNew || ( ! $this->_isNew && $this->_regenerateEntityIfExists)) {
|
||||
if ($this->_isNew) {
|
||||
file_put_contents($path, $this->generateEntityClass($metadata));
|
||||
// If entity exists and we're allowed to update the entity class
|
||||
} else if ( ! $this->_isNew && $this->_updateEntityIfExists) {
|
||||
@@ -265,6 +286,16 @@ public function <methodName>()
|
||||
$this->_generateAnnotations = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an annotation prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
*/
|
||||
public function setAnnotationPrefix($prefix)
|
||||
{
|
||||
$this->_annotationsPrefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not to try and update the entity if it already exists
|
||||
*
|
||||
@@ -298,6 +329,14 @@ public function <methodName>()
|
||||
$this->_generateEntityStubMethods = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should an existing entity be backed up if it already exists?
|
||||
*/
|
||||
public function setBackupExisting($bool)
|
||||
{
|
||||
$this->_backupExisting = $bool;
|
||||
}
|
||||
|
||||
private function _generateEntityNamespace(ClassMetadataInfo $metadata)
|
||||
{
|
||||
if ($this->_hasNamespace($metadata)) {
|
||||
@@ -313,7 +352,7 @@ public function <methodName>()
|
||||
|
||||
private function _generateEntityBody(ClassMetadataInfo $metadata)
|
||||
{
|
||||
$fieldMappingProperties = $this->_generateEntityFieldMappingProperties($metadata);
|
||||
$fieldMappingProperties = $this->_generateEntityFieldMappingProperties($metadata);
|
||||
$associationMappingProperties = $this->_generateEntityAssociationMappingProperties($metadata);
|
||||
$stubMethods = $this->_generateEntityStubMethods ? $this->_generateEntityStubMethods($metadata) : null;
|
||||
$lifecycleCallbackMethods = $this->_generateEntityLifecycleCallbackMethods($metadata);
|
||||
@@ -328,6 +367,8 @@ public function <methodName>()
|
||||
$code[] = $associationMappingProperties;
|
||||
}
|
||||
|
||||
$code[] = $this->_generateEntityConstructor($metadata);
|
||||
|
||||
if ($stubMethods) {
|
||||
$code[] = $stubMethods;
|
||||
}
|
||||
@@ -339,14 +380,88 @@ public function <methodName>()
|
||||
return implode("\n", $code);
|
||||
}
|
||||
|
||||
private function _generateEntityConstructor(ClassMetadataInfo $metadata)
|
||||
{
|
||||
if ($this->_hasMethod('__construct', $metadata)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$collections = array();
|
||||
foreach ($metadata->associationMappings AS $mapping) {
|
||||
if ($mapping['type'] & ClassMetadataInfo::TO_MANY) {
|
||||
$collections[] = '$this->'.$mapping['fieldName'].' = new \Doctrine\Common\Collections\ArrayCollection();';
|
||||
}
|
||||
}
|
||||
if ($collections) {
|
||||
return $this->_prefixCodeWithSpaces(str_replace("<collections>", implode("\n", $collections), self::$_constructorMethodTemplate));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo this won't work if there is a namespace in brackets and a class outside of it.
|
||||
* @param string $src
|
||||
*/
|
||||
private function _parseTokensInEntityFile($src)
|
||||
{
|
||||
$tokens = token_get_all($src);
|
||||
$lastSeenNamespace = "";
|
||||
$lastSeenClass = false;
|
||||
|
||||
$inNamespace = false;
|
||||
$inClass = false;
|
||||
for ($i = 0; $i < count($tokens); $i++) {
|
||||
$token = $tokens[$i];
|
||||
if (in_array($token[0], array(T_WHITESPACE, T_COMMENT, T_DOC_COMMENT))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($inNamespace) {
|
||||
if ($token[0] == T_NS_SEPARATOR || $token[0] == T_STRING) {
|
||||
$lastSeenNamespace .= $token[1];
|
||||
} else if (is_string($token) && in_array($token, array(';', '{'))) {
|
||||
$inNamespace = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($inClass) {
|
||||
$inClass = false;
|
||||
$lastSeenClass = $lastSeenNamespace . '\\' . $token[1];
|
||||
$this->_staticReflection[$lastSeenClass]['properties'] = array();
|
||||
$this->_staticReflection[$lastSeenClass]['methods'] = array();
|
||||
}
|
||||
|
||||
if ($token[0] == T_NAMESPACE) {
|
||||
$lastSeenNamespace = "";
|
||||
$inNamespace = true;
|
||||
} else if ($token[0] == T_CLASS) {
|
||||
$inClass = true;
|
||||
} else if ($token[0] == T_FUNCTION) {
|
||||
if ($tokens[$i+2][0] == T_STRING) {
|
||||
$this->_staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+2][1];
|
||||
} else if ($tokens[$i+2] == "&" && $tokens[$i+3][0] == T_STRING) {
|
||||
$this->_staticReflection[$lastSeenClass]['methods'][] = $tokens[$i+3][1];
|
||||
}
|
||||
} else if (in_array($token[0], array(T_VAR, T_PUBLIC, T_PRIVATE, T_PROTECTED)) && $tokens[$i+2][0] != T_FUNCTION) {
|
||||
$this->_staticReflection[$lastSeenClass]['properties'][] = substr($tokens[$i+2][1], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _hasProperty($property, ClassMetadataInfo $metadata)
|
||||
{
|
||||
return ($this->_isNew) ? false : $this->_reflection->hasProperty($property);
|
||||
return (
|
||||
isset($this->_staticReflection[$metadata->name]) &&
|
||||
in_array($property, $this->_staticReflection[$metadata->name]['properties'])
|
||||
);
|
||||
}
|
||||
|
||||
private function _hasMethod($method, ClassMetadataInfo $metadata)
|
||||
{
|
||||
return ($this->_isNew) ? false : $this->_reflection->hasMethod($method);
|
||||
return (
|
||||
isset($this->_staticReflection[$metadata->name]) &&
|
||||
in_array($method, $this->_staticReflection[$metadata->name]['methods'])
|
||||
);
|
||||
}
|
||||
|
||||
private function _hasNamespace(ClassMetadataInfo $metadata)
|
||||
@@ -405,9 +520,9 @@ public function <methodName>()
|
||||
}
|
||||
|
||||
if ($metadata->isMappedSuperclass) {
|
||||
$lines[] = ' * @MappedSupperClass';
|
||||
$lines[] = ' * @' . $this->_annotationsPrefix . 'MappedSuperClass';
|
||||
} else {
|
||||
$lines[] = ' * @Entity';
|
||||
$lines[] = ' * @' . $this->_annotationsPrefix . 'Entity';
|
||||
}
|
||||
|
||||
if ($metadata->customRepositoryClassName) {
|
||||
@@ -415,7 +530,7 @@ public function <methodName>()
|
||||
}
|
||||
|
||||
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
||||
$lines[] = ' * @HasLifecycleCallbacks';
|
||||
$lines[] = ' * @' . $this->_annotationsPrefix . 'HasLifecycleCallbacks';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,17 +546,13 @@ public function <methodName>()
|
||||
$table[] = 'name="' . $metadata->table['name'] . '"';
|
||||
}
|
||||
|
||||
if (isset($metadata->table['schema'])) {
|
||||
$table[] = 'schema="' . $metadata->table['schema'] . '"';
|
||||
}
|
||||
|
||||
return '@Table(' . implode(', ', $table) . ')';
|
||||
return '@' . $this->_annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
|
||||
}
|
||||
|
||||
private function _generateInheritanceAnnotation($metadata)
|
||||
{
|
||||
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
||||
return '@InheritanceType("'.$this->_getInheritanceTypeString($metadata->inheritanceType).'")';
|
||||
return '@' . $this->_annotationsPrefix . 'InheritanceType("'.$this->_getInheritanceTypeString($metadata->inheritanceType).'")';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +564,7 @@ public function <methodName>()
|
||||
. '", type="' . $discrColumn['type']
|
||||
. '", length=' . $discrColumn['length'];
|
||||
|
||||
return '@DiscriminatorColumn(' . $columnDefinition . ')';
|
||||
return '@' . $this->_annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +577,7 @@ public function <methodName>()
|
||||
$inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"';
|
||||
}
|
||||
|
||||
return '@DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
|
||||
return '@' . $this->_annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,7 +586,7 @@ public function <methodName>()
|
||||
$methods = array();
|
||||
|
||||
foreach ($metadata->fieldMappings as $fieldMapping) {
|
||||
if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id']) {
|
||||
if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id'] || $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE) {
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
@@ -494,23 +605,7 @@ public function <methodName>()
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
} else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
|
||||
if ($associationMapping['isOwningSide']) {
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
} else {
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], 'Doctrine\Common\Collections\Collection')) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
}
|
||||
} else if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
|
||||
} else if ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) {
|
||||
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping['fieldName'], $associationMapping['targetEntity'])) {
|
||||
$methods[] = $code;
|
||||
}
|
||||
@@ -536,8 +631,10 @@ public function <methodName>()
|
||||
}
|
||||
}
|
||||
|
||||
return implode('', $methods);
|
||||
return implode("\n\n", $methods);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private function _generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
|
||||
@@ -562,7 +659,8 @@ public function <methodName>()
|
||||
$lines = array();
|
||||
|
||||
foreach ($metadata->fieldMappings as $fieldMapping) {
|
||||
if ($this->_hasProperty($fieldMapping['fieldName'], $metadata)) {
|
||||
if ($this->_hasProperty($fieldMapping['fieldName'], $metadata) ||
|
||||
$metadata->isInheritedField($fieldMapping['fieldName'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -581,6 +679,7 @@ public function <methodName>()
|
||||
if ($this->_hasMethod($methodName, $metadata)) {
|
||||
return;
|
||||
}
|
||||
$this->_staticReflection[$metadata->name]['methods'][] = $methodName;
|
||||
|
||||
$var = sprintf('_%sMethodTemplate', $type);
|
||||
$template = self::$$var;
|
||||
@@ -613,9 +712,10 @@ public function <methodName>()
|
||||
if ($this->_hasMethod($methodName, $metadata)) {
|
||||
return;
|
||||
}
|
||||
$this->_staticReflection[$metadata->name]['methods'][] = $methodName;
|
||||
|
||||
$replacements = array(
|
||||
'<name>' => $name,
|
||||
'<name>' => $this->_annotationsPrefix . $name,
|
||||
'<methodName>' => $methodName,
|
||||
);
|
||||
|
||||
@@ -660,7 +760,7 @@ public function <methodName>()
|
||||
$joinColumnAnnot[] = 'columnDefinition="' . $joinColumn['columnDefinition'] . '"';
|
||||
}
|
||||
|
||||
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
|
||||
return '@' . $this->_annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
|
||||
}
|
||||
|
||||
private function _generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata)
|
||||
@@ -717,10 +817,10 @@ public function <methodName>()
|
||||
$typeOptions[] = 'orphanRemoval=' . ($associationMapping['orphanRemoval'] ? 'true' : 'false');
|
||||
}
|
||||
|
||||
$lines[] = $this->_spaces . ' * @' . $type . '(' . implode(', ', $typeOptions) . ')';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . '' . $type . '(' . implode(', ', $typeOptions) . ')';
|
||||
|
||||
if (isset($associationMapping['joinColumns']) && $associationMapping['joinColumns']) {
|
||||
$lines[] = $this->_spaces . ' * @JoinColumns({';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'JoinColumns({';
|
||||
|
||||
$joinColumnsLines = array();
|
||||
|
||||
@@ -742,7 +842,7 @@ public function <methodName>()
|
||||
$joinTable[] = 'schema="' . $associationMapping['joinTable']['schema'] . '"';
|
||||
}
|
||||
|
||||
$lines[] = $this->_spaces . ' * @JoinTable(' . implode(', ', $joinTable) . ',';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'JoinTable(' . implode(', ', $joinTable) . ',';
|
||||
$lines[] = $this->_spaces . ' * joinColumns={';
|
||||
|
||||
foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) {
|
||||
@@ -761,7 +861,7 @@ public function <methodName>()
|
||||
}
|
||||
|
||||
if (isset($associationMapping['orderBy'])) {
|
||||
$lines[] = $this->_spaces . ' * @OrderBy({';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'OrderBy({';
|
||||
|
||||
foreach ($associationMapping['orderBy'] as $name => $direction) {
|
||||
$lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",';
|
||||
@@ -815,31 +915,17 @@ public function <methodName>()
|
||||
$column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['options'])) {
|
||||
$options = array();
|
||||
|
||||
foreach ($fieldMapping['options'] as $key => $value) {
|
||||
$value = var_export($value, true);
|
||||
$value = str_replace("'", '"', $value);
|
||||
$options[] = ! is_numeric($key) ? $key . '=' . $value:$value;
|
||||
}
|
||||
|
||||
if ($options) {
|
||||
$column[] = 'options={' . implode(', ', $options) . '}';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['unique'])) {
|
||||
$column[] = 'unique=' . var_export($fieldMapping['unique'], true);
|
||||
}
|
||||
|
||||
$lines[] = $this->_spaces . ' * @Column(' . implode(', ', $column) . ')';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Column(' . implode(', ', $column) . ')';
|
||||
|
||||
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
|
||||
$lines[] = $this->_spaces . ' * @Id';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Id';
|
||||
|
||||
if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
|
||||
$lines[] = $this->_spaces.' * @GeneratedValue(strategy="' . $generatorType . '")';
|
||||
$lines[] = $this->_spaces.' * @' . $this->_annotationsPrefix . 'GeneratedValue(strategy="' . $generatorType . '")';
|
||||
}
|
||||
|
||||
if ($metadata->sequenceGeneratorDefinition) {
|
||||
@@ -857,12 +943,12 @@ public function <methodName>()
|
||||
$sequenceGenerator[] = 'initialValue="' . $metadata->sequenceGeneratorDefinition['initialValue'] . '"';
|
||||
}
|
||||
|
||||
$lines[] = $this->_spaces . ' * @SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
||||
$lines[] = $this->_spaces . ' * @Version';
|
||||
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'Version';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Doctrine\ORM\Tools\Export\Driver;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Doctrine\ORM\Tools\Export\ExportException;
|
||||
|
||||
/**
|
||||
* Abstract base class which is to be used for the Exporter drivers
|
||||
@@ -39,12 +40,18 @@ abstract class AbstractExporter
|
||||
protected $_metadata = array();
|
||||
protected $_outputDir;
|
||||
protected $_extension;
|
||||
protected $_overwriteExistingFiles = false;
|
||||
|
||||
public function __construct($dir = null)
|
||||
{
|
||||
$this->_outputDir = $dir;
|
||||
}
|
||||
|
||||
public function setOverwriteExistingFiles($overwrite)
|
||||
{
|
||||
$this->_overwriteExistingFiles = $overwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
@@ -110,6 +117,9 @@ abstract class AbstractExporter
|
||||
if ( ! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
if (file_exists($path) && !$this->_overwriteExistingFiles) {
|
||||
throw ExportException::attemptOverwriteExistingFile($path);
|
||||
}
|
||||
file_put_contents($path, $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,9 @@ class ExportException extends ORMException
|
||||
{
|
||||
return new self("The mapping driver '$type' does not exist");
|
||||
}
|
||||
|
||||
public static function attemptOverwriteExistingFile($file)
|
||||
{
|
||||
return new self("Attempting to overwrite an existing file '".$file."'.");
|
||||
}
|
||||
}
|
||||
@@ -179,13 +179,13 @@ class SchemaTool
|
||||
$this->_gatherColumn($class, $idMapping, $table);
|
||||
$columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform);
|
||||
// TODO: This seems rather hackish, can we optimize it?
|
||||
$table->getColumn($class->identifier[0])->setAutoincrement(false);
|
||||
$table->getColumn($columnName)->setAutoincrement(false);
|
||||
|
||||
$pkColumns[] = $columnName;
|
||||
|
||||
// Add a FK constraint on the ID column
|
||||
$table->addUnnamedForeignKeyConstraint(
|
||||
$this->_em->getClassMetadata($class->rootEntityName)->getTableName(),
|
||||
$this->_em->getClassMetadata($class->rootEntityName)->getQuotedTableName($this->_platform),
|
||||
array($columnName), array($columnName), array('onDelete' => 'CASCADE')
|
||||
);
|
||||
}
|
||||
@@ -275,6 +275,10 @@ class SchemaTool
|
||||
$pkColumns = array();
|
||||
|
||||
foreach ($class->fieldMappings as $fieldName => $mapping) {
|
||||
if ($class->isInheritanceTypeSingleTable() && isset($mapping['inherited'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$column = $this->_gatherColumn($class, $mapping, $table);
|
||||
|
||||
if ($class->isIdentifier($mapping['fieldName'])) {
|
||||
@@ -420,6 +424,7 @@ class SchemaTool
|
||||
$localColumns = array();
|
||||
$foreignColumns = array();
|
||||
$fkOptions = array();
|
||||
$foreignTableName = $class->getQuotedTableName($this->_platform);
|
||||
|
||||
foreach ($joinColumns as $joinColumn) {
|
||||
$columnName = $joinColumn['name'];
|
||||
@@ -453,7 +458,7 @@ class SchemaTool
|
||||
if (isset($joinColumn['nullable'])) {
|
||||
$columnOptions['notnull'] = !$joinColumn['nullable'];
|
||||
}
|
||||
if ($fieldMapping['type'] == "string") {
|
||||
if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) {
|
||||
$columnOptions['length'] = $fieldMapping['length'];
|
||||
} else if ($fieldMapping['type'] == "decimal") {
|
||||
$columnOptions['scale'] = $fieldMapping['scale'];
|
||||
@@ -479,7 +484,7 @@ class SchemaTool
|
||||
}
|
||||
|
||||
$theJoinTable->addUnnamedForeignKeyConstraint(
|
||||
$class->getTableName(), $localColumns, $foreignColumns, $fkOptions
|
||||
$foreignTableName, $localColumns, $foreignColumns, $fkOptions
|
||||
);
|
||||
}
|
||||
|
||||
@@ -498,7 +503,11 @@ class SchemaTool
|
||||
$conn = $this->_em->getConnection();
|
||||
|
||||
foreach ($dropSchemaSql as $sql) {
|
||||
$conn->executeQuery($sql);
|
||||
try {
|
||||
$conn->executeQuery($sql);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,58 +543,55 @@ class SchemaTool
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get SQL to drop the tables defined by the passed classes.
|
||||
*
|
||||
* @param array $classes
|
||||
* @return array
|
||||
*/
|
||||
public function getDropSchemaSQL(array $classes)
|
||||
{
|
||||
$visitor = new \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector($this->_platform);
|
||||
$schema = $this->getSchemaFromMetadata($classes);
|
||||
|
||||
$sm = $this->_em->getConnection()->getSchemaManager();
|
||||
$fullSchema = $sm->createSchema();
|
||||
foreach ($fullSchema->getTables() AS $table) {
|
||||
if (!$schema->hasTable($table->getName())) {
|
||||
foreach ($table->getForeignKeys() AS $foreignKey) {
|
||||
/* @var $foreignKey \Doctrine\DBAL\Schema\ForeignKeyConstraint */
|
||||
if ($schema->hasTable($foreignKey->getForeignTableName())) {
|
||||
$visitor->acceptForeignKey($table, $foreignKey);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$visitor->acceptTable($table);
|
||||
foreach ($table->getForeignKeys() AS $foreignKey) {
|
||||
$visitor->acceptForeignKey($table, $foreignKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = array();
|
||||
$orderedTables = array();
|
||||
|
||||
foreach ($classes AS $class) {
|
||||
if ($class->isIdGeneratorSequence() && !$class->isMappedSuperclass && $class->name == $class->rootEntityName && $this->_platform->supportsSequences()) {
|
||||
$sql[] = $this->_platform->getDropSequenceSQL($class->sequenceGeneratorDefinition['sequenceName']);
|
||||
if ($this->_platform->supportsSequences()) {
|
||||
foreach ($schema->getSequences() AS $sequence) {
|
||||
$visitor->acceptSequence($sequence);
|
||||
}
|
||||
foreach ($schema->getTables() AS $table) {
|
||||
/* @var $sequence Table */
|
||||
foreach ($table->getIndexes() AS $index) {
|
||||
if ($index->isPrimary()) {
|
||||
$columns = $index->getColumns();
|
||||
if (count($columns) == 1) {
|
||||
$checkSequence = $table->getName() . "_" . $columns[0] . "_seq";
|
||||
if ($fullSchema->hasSequence($checkSequence)) {
|
||||
$visitor->acceptSequence($fullSchema->getSequence($checkSequence));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$commitOrder = $this->_getCommitOrder($classes);
|
||||
$associationTables = $this->_getAssociationTables($commitOrder);
|
||||
|
||||
// Drop association tables first
|
||||
foreach ($associationTables as $associationTable) {
|
||||
if (!in_array($associationTable, $orderedTables)) {
|
||||
$orderedTables[] = $associationTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Drop tables in reverse commit order
|
||||
for ($i = count($commitOrder) - 1; $i >= 0; --$i) {
|
||||
$class = $commitOrder[$i];
|
||||
|
||||
if (($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName)
|
||||
|| $class->isMappedSuperclass) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($class->getTableName(), $orderedTables)) {
|
||||
$orderedTables[] = $class->getTableName();
|
||||
}
|
||||
}
|
||||
|
||||
$dropTablesSql = array();
|
||||
foreach ($orderedTables AS $tableName) {
|
||||
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
||||
$foreignKeys = $sm->listTableForeignKeys($tableName);
|
||||
foreach ($foreignKeys AS $foreignKey) {
|
||||
$sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName);
|
||||
}
|
||||
$dropTablesSql[] = $this->_platform->getDropTableSQL($tableName);
|
||||
}
|
||||
|
||||
return array_merge($sql, $dropTablesSql);
|
||||
return $visitor->getQueries();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -628,44 +634,4 @@ class SchemaTool
|
||||
return $schemaDiff->toSql($this->_platform);
|
||||
}
|
||||
}
|
||||
|
||||
private function _getCommitOrder(array $classes)
|
||||
{
|
||||
$calc = new CommitOrderCalculator;
|
||||
|
||||
// Calculate dependencies
|
||||
foreach ($classes as $class) {
|
||||
$calc->addClass($class);
|
||||
|
||||
foreach ($class->associationMappings as $assoc) {
|
||||
if ($assoc['isOwningSide']) {
|
||||
$targetClass = $this->_em->getClassMetadata($assoc['targetEntity']);
|
||||
|
||||
if ( ! $calc->hasClass($targetClass->name)) {
|
||||
$calc->addClass($targetClass);
|
||||
}
|
||||
|
||||
// add dependency ($targetClass before $class)
|
||||
$calc->addDependency($targetClass, $class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $calc->getCommitOrder();
|
||||
}
|
||||
|
||||
private function _getAssociationTables(array $classes)
|
||||
{
|
||||
$associationTables = array();
|
||||
|
||||
foreach ($classes as $class) {
|
||||
foreach ($class->associationMappings as $assoc) {
|
||||
if ($assoc['isOwningSide'] && $assoc['type'] == ClassMetadata::MANY_TO_MANY) {
|
||||
$associationTables[] = $assoc['joinTable']['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $associationTables;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,8 +399,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$actualData = array();
|
||||
foreach ($class->reflFields as $name => $refProp) {
|
||||
$value = $refProp->getValue($entity);
|
||||
if ($class->isCollectionValuedAssociation($name) && $value !== null
|
||||
if (isset($class->associationMappings[$name])
|
||||
&& ($class->associationMappings[$name]['type'] & ClassMetadata::TO_MANY)
|
||||
&& $value !== null
|
||||
&& ! ($value instanceof PersistentCollection)) {
|
||||
|
||||
// If $value is not a Collection then use an ArrayCollection.
|
||||
if ( ! $value instanceof Collection) {
|
||||
$value = new ArrayCollection($value);
|
||||
@@ -419,7 +422,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$coll->setDirty( ! $coll->isEmpty());
|
||||
$class->reflFields[$name]->setValue($entity, $coll);
|
||||
$actualData[$name] = $coll;
|
||||
} else if ( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) {
|
||||
} else if ( (! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) && ($name !== $class->versionField) ) {
|
||||
$actualData[$name] = $value;
|
||||
}
|
||||
}
|
||||
@@ -462,6 +465,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
// A PersistentCollection was de-referenced, so delete it.
|
||||
if ( ! in_array($orgValue, $this->collectionDeletions, true)) {
|
||||
$this->collectionDeletions[] = $orgValue;
|
||||
$changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
|
||||
}
|
||||
}
|
||||
} else if ($isChangeTrackingNotify) {
|
||||
@@ -737,7 +741,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$hasPostUpdateListeners = $this->evm->hasListeners(Events::postUpdate);
|
||||
|
||||
foreach ($this->entityUpdates as $oid => $entity) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && $entity instanceof $className) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && get_parent_class($entity) == $className) {
|
||||
|
||||
if ($hasPreUpdateLifecycleCallbacks) {
|
||||
$class->invokeLifecycleCallbacks(Events::preUpdate, $entity);
|
||||
@@ -777,7 +781,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$hasListeners = $this->evm->hasListeners(Events::postRemove);
|
||||
|
||||
foreach ($this->entityDeletions as $oid => $entity) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && $entity instanceof $className) {
|
||||
if (get_class($entity) == $className || $entity instanceof Proxy && get_parent_class($entity) == $className) {
|
||||
$persister->delete($entity);
|
||||
unset(
|
||||
$this->entityDeletions[$oid],
|
||||
@@ -971,7 +975,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ($this->isInIdentityMap($entity)) {
|
||||
$this->removeFromIdentityMap($entity);
|
||||
}
|
||||
unset($this->entityInsertions[$oid]);
|
||||
unset($this->entityInsertions[$oid], $this->entityStates[$oid]);
|
||||
return; // entity has not been persisted yet, so nothing more to do.
|
||||
}
|
||||
|
||||
@@ -986,6 +990,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
if ( ! isset($this->entityDeletions[$oid])) {
|
||||
$this->entityDeletions[$oid] = $entity;
|
||||
$this->entityStates[$oid] = self::STATE_REMOVED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1281,6 +1286,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
|
||||
$visited[$oid] = $entity; // mark visited
|
||||
|
||||
// Cascade first, because scheduleForDelete() removes the entity from the identity map, which
|
||||
// can cause problems when a lazy proxy has to be initialized for the cascade operation.
|
||||
$this->cascadeRemove($entity, $visited);
|
||||
|
||||
$class = $this->em->getClassMetadata(get_class($entity));
|
||||
$entityState = $this->getEntityState($entity);
|
||||
@@ -1304,7 +1313,6 @@ class UnitOfWork implements PropertyChangedListener
|
||||
throw new UnexpectedValueException("Unexpected entity state: $entityState.");
|
||||
}
|
||||
|
||||
$this->cascadeRemove($entity, $visited);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1439,7 +1447,8 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
if ($assoc2['isCascadeMerge']) {
|
||||
$managedCol->initialize();
|
||||
if (!$managedCol->isEmpty()) {
|
||||
// clear and set dirty a managed collection if its not also the same collection to merge from.
|
||||
if (!$managedCol->isEmpty() && $managedCol != $mergeCol) {
|
||||
$managedCol->unwrap()->clear();
|
||||
$managedCol->setDirty(true);
|
||||
if ($assoc2['isOwningSide'] && $assoc2['type'] == ClassMetadata::MANY_TO_MANY && $class->isChangeTrackingNotify()) {
|
||||
@@ -1638,6 +1647,10 @@ class UnitOfWork implements PropertyChangedListener
|
||||
}
|
||||
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
|
||||
if ($relatedEntities instanceof Collection) {
|
||||
if ($relatedEntities === $class->reflFields[$assoc['fieldName']]->getValue($managedCopy)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($relatedEntities instanceof PersistentCollection) {
|
||||
// Unwrap so that foreach() does not initialize
|
||||
$relatedEntities = $relatedEntities->unwrap();
|
||||
@@ -1665,6 +1678,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ( ! $assoc['isCascadePersist']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
|
||||
if (($relatedEntities instanceof Collection || is_array($relatedEntities))) {
|
||||
if ($relatedEntities instanceof PersistentCollection) {
|
||||
@@ -1693,7 +1707,11 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ( ! $assoc['isCascadeRemove']) {
|
||||
continue;
|
||||
}
|
||||
//TODO: If $entity instanceof Proxy => Initialize ?
|
||||
|
||||
if ($entity instanceof Proxy && !$entity->__isInitialized__) {
|
||||
$entity->__load();
|
||||
}
|
||||
|
||||
$relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity);
|
||||
if ($relatedEntities instanceof Collection || is_array($relatedEntities)) {
|
||||
// If its a PersistentCollection initialization is intended! No unwrap!
|
||||
@@ -1844,8 +1862,8 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$idHash = $data[$class->identifier[0]];
|
||||
$id = array($class->identifier[0] => $idHash);
|
||||
}
|
||||
|
||||
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
||||
|
||||
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
||||
$entity = $this->identityMap[$class->rootEntityName][$idHash];
|
||||
$oid = spl_object_hash($entity);
|
||||
if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
|
||||
@@ -2256,7 +2274,28 @@ class UnitOfWork implements PropertyChangedListener
|
||||
{
|
||||
return $this->collectionUpdates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to initialize a lazy loading proxy or persistent collection.
|
||||
*
|
||||
* @param object
|
||||
* @return void
|
||||
*/
|
||||
public function initializeObject($obj)
|
||||
{
|
||||
if ($obj instanceof Proxy) {
|
||||
$obj->__load();
|
||||
} else if ($obj instanceof PersistentCollection) {
|
||||
$obj->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to show an object as string.
|
||||
*
|
||||
* @param object $obj
|
||||
* @return string
|
||||
*/
|
||||
private static function objToStr($obj)
|
||||
{
|
||||
return method_exists($obj, '__toString') ? (string)$obj : get_class($obj).'@'.spl_object_hash($obj);
|
||||
|
||||
@@ -36,7 +36,7 @@ class Version
|
||||
/**
|
||||
* Current Doctrine Version
|
||||
*/
|
||||
const VERSION = '2.0.0-DEV';
|
||||
const VERSION = '2.0.7';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
1
lib/vendor/Symfony/Component/Console
vendored
Submodule
1
lib/vendor/Symfony/Component/Console
vendored
Submodule
Submodule lib/vendor/Symfony/Component/Console added at 3762cec59a
743
lib/vendor/Symfony/Component/Console/Application.php
vendored
743
lib/vendor/Symfony/Component/Console/Application.php
vendored
@@ -1,743 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Command\HelpCommand;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\DialogHelper;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* An Application is the container for a collection of commands.
|
||||
*
|
||||
* It is the main entry point of a Console application.
|
||||
*
|
||||
* This class is optimized for a standard CLI environment.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $app = new Application('myapp', '1.0 (stable)');
|
||||
* $app->add(new SimpleCommand());
|
||||
* $app->run();
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Application
|
||||
{
|
||||
protected $commands;
|
||||
protected $aliases;
|
||||
protected $wantHelps = false;
|
||||
protected $runningCommand;
|
||||
protected $name;
|
||||
protected $version;
|
||||
protected $catchExceptions;
|
||||
protected $autoExit;
|
||||
protected $definition;
|
||||
protected $helperSet;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the application
|
||||
* @param string $version The version of the application
|
||||
*/
|
||||
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->version = $version;
|
||||
$this->catchExceptions = true;
|
||||
$this->autoExit = true;
|
||||
$this->commands = array();
|
||||
$this->aliases = array();
|
||||
$this->helperSet = new HelperSet(array(
|
||||
new FormatterHelper(),
|
||||
new DialogHelper(),
|
||||
));
|
||||
|
||||
$this->add(new HelpCommand());
|
||||
$this->add(new ListCommand());
|
||||
|
||||
$this->definition = new InputDefinition(array(
|
||||
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
|
||||
|
||||
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
|
||||
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
|
||||
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
|
||||
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
|
||||
new InputOption('--ansi', '-a', InputOption::VALUE_NONE, 'Force ANSI output.'),
|
||||
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the current application.
|
||||
*
|
||||
* @param InputInterface $input An Input instance
|
||||
* @param OutputInterface $output An Output instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
*
|
||||
* @throws \Exception When doRun returns Exception
|
||||
*/
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null)
|
||||
{
|
||||
if (null === $input) {
|
||||
$input = new ArgvInput();
|
||||
}
|
||||
|
||||
if (null === $output) {
|
||||
$output = new ConsoleOutput();
|
||||
}
|
||||
|
||||
try {
|
||||
$statusCode = $this->doRun($input, $output);
|
||||
} catch (\Exception $e) {
|
||||
if (!$this->catchExceptions) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->renderException($e, $output);
|
||||
$statusCode = $e->getCode();
|
||||
|
||||
$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1;
|
||||
}
|
||||
|
||||
if ($this->autoExit) {
|
||||
if ($statusCode > 255) {
|
||||
$statusCode = 255;
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
exit($statusCode);
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
return $statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the current application.
|
||||
*
|
||||
* @param InputInterface $input An Input instance
|
||||
* @param OutputInterface $output An Output instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
*/
|
||||
public function doRun(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$name = $this->getCommandName($input);
|
||||
|
||||
if (true === $input->hasParameterOption(array('--ansi', '-a'))) {
|
||||
$output->setDecorated(true);
|
||||
}
|
||||
|
||||
if (true === $input->hasParameterOption(array('--help', '-h'))) {
|
||||
if (!$name) {
|
||||
$name = 'help';
|
||||
$input = new ArrayInput(array('command' => 'help'));
|
||||
} else {
|
||||
$this->wantHelps = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
|
||||
$input->setInteractive(false);
|
||||
}
|
||||
|
||||
if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
|
||||
$output->setVerbosity(Output::VERBOSITY_QUIET);
|
||||
} elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
|
||||
$output->setVerbosity(Output::VERBOSITY_VERBOSE);
|
||||
}
|
||||
|
||||
if (true === $input->hasParameterOption(array('--version', '-V'))) {
|
||||
$output->writeln($this->getLongVersion());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!$name) {
|
||||
$name = 'list';
|
||||
$input = new ArrayInput(array('command' => 'list'));
|
||||
}
|
||||
|
||||
// the command name MUST be the first element of the input
|
||||
$command = $this->find($name);
|
||||
|
||||
$this->runningCommand = $command;
|
||||
$statusCode = $command->run($input, $output);
|
||||
$this->runningCommand = null;
|
||||
|
||||
return is_numeric($statusCode) ? $statusCode : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a helper set to be used with the command.
|
||||
*
|
||||
* @param HelperSet $helperSet The helper set
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the helper set associated with the command
|
||||
*
|
||||
* @return HelperSet The HelperSet instance associated with this command
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
return $this->helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the InputDefinition related to this Application.
|
||||
*
|
||||
* @return InputDefinition The InputDefinition instance
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the help message.
|
||||
*
|
||||
* @return string A help message.
|
||||
*/
|
||||
public function getHelp()
|
||||
{
|
||||
$messages = array(
|
||||
$this->getLongVersion(),
|
||||
'',
|
||||
'<comment>Usage:</comment>',
|
||||
sprintf(" [options] command [arguments]\n"),
|
||||
'<comment>Options:</comment>',
|
||||
);
|
||||
|
||||
foreach ($this->definition->getOptions() as $option) {
|
||||
$messages[] = sprintf(' %-29s %s %s',
|
||||
'<info>--'.$option->getName().'</info>',
|
||||
$option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' : ' ',
|
||||
$option->getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to catch exceptions or not during commands execution.
|
||||
*
|
||||
* @param Boolean $boolean Whether to catch exceptions or not during commands execution
|
||||
*/
|
||||
public function setCatchExceptions($boolean)
|
||||
{
|
||||
$this->catchExceptions = (Boolean) $boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to automatically exit after a command execution or not.
|
||||
*
|
||||
* @param Boolean $boolean Whether to automatically exit after a command execution or not
|
||||
*/
|
||||
public function setAutoExit($boolean)
|
||||
{
|
||||
$this->autoExit = (Boolean) $boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the application.
|
||||
*
|
||||
* @return string The application name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application name.
|
||||
*
|
||||
* @param string $name The application name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application version.
|
||||
*
|
||||
* @return string The application version
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application version.
|
||||
*
|
||||
* @param string $version The application version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long version of the application.
|
||||
*
|
||||
* @return string The long application version
|
||||
*/
|
||||
public function getLongVersion()
|
||||
{
|
||||
if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {
|
||||
return sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());
|
||||
} else {
|
||||
return '<info>Console Tool</info>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new command.
|
||||
*
|
||||
* @param string $name The command name
|
||||
*
|
||||
* @return Command The newly created command
|
||||
*/
|
||||
public function register($name)
|
||||
{
|
||||
return $this->add(new Command($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of command objects.
|
||||
*
|
||||
* @param Command[] $commands An array of commands
|
||||
*/
|
||||
public function addCommands(array $commands)
|
||||
{
|
||||
foreach ($commands as $command) {
|
||||
$this->add($command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a command object.
|
||||
*
|
||||
* If a command with the same name already exists, it will be overridden.
|
||||
*
|
||||
* @param Command $command A Command object
|
||||
*
|
||||
* @return Command The registered command
|
||||
*/
|
||||
public function add(Command $command)
|
||||
{
|
||||
$command->setApplication($this);
|
||||
|
||||
$this->commands[$command->getFullName()] = $command;
|
||||
|
||||
foreach ($command->getAliases() as $alias) {
|
||||
$this->aliases[$alias] = $command;
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a registered command by name or alias.
|
||||
*
|
||||
* @param string $name The command name or alias
|
||||
*
|
||||
* @return Command A Command object
|
||||
*
|
||||
* @throws \InvalidArgumentException When command name given does not exist
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
|
||||
}
|
||||
|
||||
$command = isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
|
||||
|
||||
if ($this->wantHelps) {
|
||||
$this->wantHelps = false;
|
||||
|
||||
$helpCommand = $this->get('help');
|
||||
$helpCommand->setCommand($command);
|
||||
|
||||
return $helpCommand;
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the command exists, false otherwise
|
||||
*
|
||||
* @param string $name The command name or alias
|
||||
*
|
||||
* @return Boolean true if the command exists, false otherwise
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return isset($this->commands[$name]) || isset($this->aliases[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all unique namespaces used by currently registered commands.
|
||||
*
|
||||
* It does not returns the global namespace which always exists.
|
||||
*
|
||||
* @return array An array of namespaces
|
||||
*/
|
||||
public function getNamespaces()
|
||||
{
|
||||
$namespaces = array();
|
||||
foreach ($this->commands as $command) {
|
||||
if ($command->getNamespace()) {
|
||||
$namespaces[$command->getNamespace()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a registered namespace by a name or an abbreviation.
|
||||
*
|
||||
* @return string A registered namespace
|
||||
*
|
||||
* @throws \InvalidArgumentException When namespace is incorrect or ambiguous
|
||||
*/
|
||||
public function findNamespace($namespace)
|
||||
{
|
||||
$abbrevs = static::getAbbreviations($this->getNamespaces());
|
||||
|
||||
if (!isset($abbrevs[$namespace])) {
|
||||
throw new \InvalidArgumentException(sprintf('There are no commands defined in the "%s" namespace.', $namespace));
|
||||
}
|
||||
|
||||
if (count($abbrevs[$namespace]) > 1) {
|
||||
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($abbrevs[$namespace])));
|
||||
}
|
||||
|
||||
return $abbrevs[$namespace][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a command by name or alias.
|
||||
*
|
||||
* Contrary to get, this command tries to find the best
|
||||
* match if you give it an abbreviation of a name or alias.
|
||||
*
|
||||
* @param string $name A command name or a command alias
|
||||
*
|
||||
* @return Command A Command instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When command name is incorrect or ambiguous
|
||||
*/
|
||||
public function find($name)
|
||||
{
|
||||
// namespace
|
||||
$namespace = '';
|
||||
if (false !== $pos = strrpos($name, ':')) {
|
||||
$namespace = $this->findNamespace(substr($name, 0, $pos));
|
||||
$name = substr($name, $pos + 1);
|
||||
}
|
||||
|
||||
$fullName = $namespace ? $namespace.':'.$name : $name;
|
||||
|
||||
// name
|
||||
$commands = array();
|
||||
foreach ($this->commands as $command) {
|
||||
if ($command->getNamespace() == $namespace) {
|
||||
$commands[] = $command->getName();
|
||||
}
|
||||
}
|
||||
|
||||
$abbrevs = static::getAbbreviations($commands);
|
||||
if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) {
|
||||
return $this->get($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
|
||||
}
|
||||
|
||||
if (isset($abbrevs[$name]) && count($abbrevs[$name]) > 1) {
|
||||
$suggestions = $this->getAbbreviationSuggestions(array_map(function ($command) use ($namespace) { return $namespace.':'.$command; }, $abbrevs[$name]));
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $suggestions));
|
||||
}
|
||||
|
||||
// aliases
|
||||
$abbrevs = static::getAbbreviations(array_keys($this->aliases));
|
||||
if (!isset($abbrevs[$fullName])) {
|
||||
throw new \InvalidArgumentException(sprintf('Command "%s" is not defined.', $fullName));
|
||||
}
|
||||
|
||||
if (count($abbrevs[$fullName]) > 1) {
|
||||
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $this->getAbbreviationSuggestions($abbrevs[$fullName])));
|
||||
}
|
||||
|
||||
return $this->get($abbrevs[$fullName][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the commands (registered in the given namespace if provided).
|
||||
*
|
||||
* The array keys are the full names and the values the command instances.
|
||||
*
|
||||
* @param string $namespace A namespace name
|
||||
*
|
||||
* @return array An array of Command instances
|
||||
*/
|
||||
public function all($namespace = null)
|
||||
{
|
||||
if (null === $namespace) {
|
||||
return $this->commands;
|
||||
}
|
||||
|
||||
$commands = array();
|
||||
foreach ($this->commands as $name => $command) {
|
||||
if ($namespace === $command->getNamespace()) {
|
||||
$commands[$name] = $command;
|
||||
}
|
||||
}
|
||||
|
||||
return $commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible abbreviations given a set of names.
|
||||
*
|
||||
* @param array $names An array of names
|
||||
*
|
||||
* @return array An array of abbreviations
|
||||
*/
|
||||
static public function getAbbreviations($names)
|
||||
{
|
||||
$abbrevs = array();
|
||||
foreach ($names as $name) {
|
||||
for ($len = strlen($name) - 1; $len > 0; --$len) {
|
||||
$abbrev = substr($name, 0, $len);
|
||||
if (!isset($abbrevs[$abbrev])) {
|
||||
$abbrevs[$abbrev] = array($name);
|
||||
} else {
|
||||
$abbrevs[$abbrev][] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Non-abbreviations always get entered, even if they aren't unique
|
||||
foreach ($names as $name) {
|
||||
$abbrevs[$name] = array($name);
|
||||
}
|
||||
|
||||
return $abbrevs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text representation of the Application.
|
||||
*
|
||||
* @param string $namespace An optional namespace name
|
||||
*
|
||||
* @return string A string representing the Application
|
||||
*/
|
||||
public function asText($namespace = null)
|
||||
{
|
||||
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
|
||||
|
||||
$messages = array($this->getHelp(), '');
|
||||
if ($namespace) {
|
||||
$messages[] = sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $namespace);
|
||||
} else {
|
||||
$messages[] = '<comment>Available commands:</comment>';
|
||||
}
|
||||
|
||||
$width = 0;
|
||||
foreach ($commands as $command) {
|
||||
$width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
|
||||
}
|
||||
$width += 2;
|
||||
|
||||
// add commands by namespace
|
||||
foreach ($this->sortCommands($commands) as $space => $commands) {
|
||||
if (!$namespace && '_global' !== $space) {
|
||||
$messages[] = '<comment>'.$space.'</comment>';
|
||||
}
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$aliases = $command->getAliases() ? '<comment> ('.implode(', ', $command->getAliases()).')</comment>' : '';
|
||||
|
||||
$messages[] = sprintf(" <info>%-${width}s</info> %s%s", ($command->getNamespace() ? ':' : '').$command->getName(), $command->getDescription(), $aliases);
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML representation of the Application.
|
||||
*
|
||||
* @param string $namespace An optional namespace name
|
||||
* @param Boolean $asDom Whether to return a DOM or an XML string
|
||||
*
|
||||
* @return string|DOMDocument An XML string representing the Application
|
||||
*/
|
||||
public function asXml($namespace = null, $asDom = false)
|
||||
{
|
||||
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
|
||||
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = true;
|
||||
$dom->appendChild($xml = $dom->createElement('symfony'));
|
||||
|
||||
$xml->appendChild($commandsXML = $dom->createElement('commands'));
|
||||
|
||||
if ($namespace) {
|
||||
$commandsXML->setAttribute('namespace', $namespace);
|
||||
} else {
|
||||
$xml->appendChild($namespacesXML = $dom->createElement('namespaces'));
|
||||
}
|
||||
|
||||
// add commands by namespace
|
||||
foreach ($this->sortCommands($commands) as $space => $commands) {
|
||||
if (!$namespace) {
|
||||
$namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
|
||||
$namespaceArrayXML->setAttribute('id', $space);
|
||||
}
|
||||
|
||||
foreach ($commands as $command) {
|
||||
if (!$namespace) {
|
||||
$namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
|
||||
$commandXML->appendChild($dom->createTextNode($command->getName()));
|
||||
}
|
||||
|
||||
$node = $command->asXml(true)->getElementsByTagName('command')->item(0);
|
||||
$node = $dom->importNode($node, true);
|
||||
|
||||
$commandsXML->appendChild($node);
|
||||
}
|
||||
}
|
||||
|
||||
return $asDom ? $dom : $dom->saveXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a catched exception.
|
||||
*
|
||||
* @param Exception $e An exception instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
public function renderException($e, $output)
|
||||
{
|
||||
$strlen = function ($string)
|
||||
{
|
||||
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
|
||||
};
|
||||
|
||||
$title = sprintf(' [%s] ', get_class($e));
|
||||
$len = $strlen($title);
|
||||
$lines = array();
|
||||
foreach (explode("\n", $e->getMessage()) as $line) {
|
||||
$lines[] = sprintf(' %s ', $line);
|
||||
$len = max($strlen($line) + 4, $len);
|
||||
}
|
||||
|
||||
$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title)));
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$messages[] = $line.str_repeat(' ', $len - $strlen($line));
|
||||
}
|
||||
|
||||
$messages[] = str_repeat(' ', $len);
|
||||
|
||||
$output->writeln("\n");
|
||||
foreach ($messages as $message) {
|
||||
$output->writeln('<error>'.$message.'</error>');
|
||||
}
|
||||
$output->writeln("\n");
|
||||
|
||||
if (null !== $this->runningCommand) {
|
||||
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
|
||||
$output->writeln("\n");
|
||||
}
|
||||
|
||||
if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
|
||||
$output->writeln('</comment>Exception trace:</comment>');
|
||||
|
||||
// exception related properties
|
||||
$trace = $e->getTrace();
|
||||
array_unshift($trace, array(
|
||||
'function' => '',
|
||||
'file' => $e->getFile() != null ? $e->getFile() : 'n/a',
|
||||
'line' => $e->getLine() != null ? $e->getLine() : 'n/a',
|
||||
'args' => array(),
|
||||
));
|
||||
|
||||
for ($i = 0, $count = count($trace); $i < $count; $i++) {
|
||||
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
|
||||
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
|
||||
$function = $trace[$i]['function'];
|
||||
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
|
||||
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
|
||||
|
||||
$output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
|
||||
}
|
||||
|
||||
$output->writeln("\n");
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCommandName(InputInterface $input)
|
||||
{
|
||||
return $input->getFirstArgument('command');
|
||||
}
|
||||
|
||||
protected function sortCommands($commands)
|
||||
{
|
||||
$namespacedCommands = array();
|
||||
foreach ($commands as $name => $command) {
|
||||
$key = $command->getNamespace() ? $command->getNamespace() : '_global';
|
||||
|
||||
if (!isset($namespacedCommands[$key])) {
|
||||
$namespacedCommands[$key] = array();
|
||||
}
|
||||
|
||||
$namespacedCommands[$key][$name] = $command;
|
||||
}
|
||||
ksort($namespacedCommands);
|
||||
|
||||
foreach ($namespacedCommands as $name => &$commands) {
|
||||
ksort($commands);
|
||||
}
|
||||
|
||||
return $namespacedCommands;
|
||||
}
|
||||
|
||||
protected function getAbbreviationSuggestions($abbrevs)
|
||||
{
|
||||
return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
|
||||
}
|
||||
}
|
||||
@@ -1,512 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all commands.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
protected $name;
|
||||
protected $namespace;
|
||||
protected $aliases;
|
||||
protected $definition;
|
||||
protected $help;
|
||||
protected $application;
|
||||
protected $description;
|
||||
protected $ignoreValidationErrors;
|
||||
protected $applicationDefinitionMerged;
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the command
|
||||
*
|
||||
* @throws \LogicException When the command name is empty
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->definition = new InputDefinition();
|
||||
$this->ignoreValidationErrors = false;
|
||||
$this->applicationDefinitionMerged = false;
|
||||
$this->aliases = array();
|
||||
|
||||
if (null !== $name) {
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
$this->configure();
|
||||
|
||||
if (!$this->name) {
|
||||
throw new \LogicException('The command name cannot be empty.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application instance for this command.
|
||||
*
|
||||
* @param Application $application An Application instance
|
||||
*/
|
||||
public function setApplication(Application $application = null)
|
||||
{
|
||||
$this->application = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the current command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the current command.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
*
|
||||
* @throws \LogicException When this abstract class is not implemented
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
throw new \LogicException('You must override the execute() method in the concrete command class.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Interacts with the user.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
protected function interact(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the command just after the input has been validated.
|
||||
*
|
||||
* This is mainly useful when a lot of commands extends one main command
|
||||
* where some things need to be initialized based on the input arguments and options.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
protected function initialize(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the command.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
public function run(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// add the application arguments and options
|
||||
$this->mergeApplicationDefinition();
|
||||
|
||||
// bind the input against the command specific arguments/options
|
||||
try {
|
||||
$input->bind($this->definition);
|
||||
} catch (\Exception $e) {
|
||||
if (!$this->ignoreValidationErrors) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialize($input, $output);
|
||||
|
||||
if ($input->isInteractive()) {
|
||||
$this->interact($input, $output);
|
||||
}
|
||||
|
||||
$input->validate();
|
||||
|
||||
if ($this->code) {
|
||||
return call_user_func($this->code, $input, $output);
|
||||
} else {
|
||||
return $this->execute($input, $output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the code to execute when running this command.
|
||||
*
|
||||
* @param \Closure $code A \Closure
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function setCode(\Closure $code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the application definition with the command definition.
|
||||
*/
|
||||
protected function mergeApplicationDefinition()
|
||||
{
|
||||
if (null === $this->application || true === $this->applicationDefinitionMerged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->definition->setArguments(array_merge(
|
||||
$this->application->getDefinition()->getArguments(),
|
||||
$this->definition->getArguments()
|
||||
));
|
||||
|
||||
$this->definition->addOptions($this->application->getDefinition()->getOptions());
|
||||
|
||||
$this->applicationDefinitionMerged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array of argument and option instances.
|
||||
*
|
||||
* @param array|Definition $definition An array of argument and option instances or a definition instance
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function setDefinition($definition)
|
||||
{
|
||||
if ($definition instanceof InputDefinition) {
|
||||
$this->definition = $definition;
|
||||
} else {
|
||||
$this->definition->setDefinition($definition);
|
||||
}
|
||||
|
||||
$this->applicationDefinitionMerged = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the InputDefinition attached to this Command.
|
||||
*
|
||||
* @return InputDefinition An InputDefinition instance
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an argument.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param integer $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (for InputArgument::OPTIONAL mode only)
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function addArgument($name, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an option.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $shortcut The shortcut (can be null)
|
||||
* @param integer $mode The option mode: One of the InputOption::VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or self::VALUE_NONE)
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the command.
|
||||
*
|
||||
* This method can set both the namespace and the name if
|
||||
* you separate them by a colon (:)
|
||||
*
|
||||
* $command->setName('foo:bar');
|
||||
*
|
||||
* @param string $name The command name
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When command name given is empty
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
if (false !== $pos = strrpos($name, ':')) {
|
||||
$namespace = substr($name, 0, $pos);
|
||||
$name = substr($name, $pos + 1);
|
||||
} else {
|
||||
$namespace = $this->namespace;
|
||||
}
|
||||
|
||||
if (!$name) {
|
||||
throw new \InvalidArgumentException('A command name cannot be empty.');
|
||||
}
|
||||
|
||||
$this->namespace = $namespace;
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command namespace.
|
||||
*
|
||||
* @return string The command namespace
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command name
|
||||
*
|
||||
* @return string The command name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fully qualified command name.
|
||||
*
|
||||
* @return string The fully qualified command name
|
||||
*/
|
||||
public function getFullName()
|
||||
{
|
||||
return $this->getNamespace() ? $this->getNamespace().':'.$this->getName() : $this->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description for the command.
|
||||
*
|
||||
* @param string $description The description for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description for the command.
|
||||
*
|
||||
* @return string The description for the command
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the help for the command.
|
||||
*
|
||||
* @param string $help The help for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function setHelp($help)
|
||||
{
|
||||
$this->help = $help;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help for the command.
|
||||
*
|
||||
* @return string The help for the command
|
||||
*/
|
||||
public function getHelp()
|
||||
{
|
||||
return $this->help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the processed help for the command replacing the %command.name% and
|
||||
* %command.full_name% patterns with the real values dynamically.
|
||||
*
|
||||
* @return string The processed help for the command
|
||||
*/
|
||||
public function getProcessedHelp()
|
||||
{
|
||||
$name = $this->namespace.':'.$this->name;
|
||||
|
||||
$placeholders = array(
|
||||
'%command.name%',
|
||||
'%command.full_name%'
|
||||
);
|
||||
$replacements = array(
|
||||
$name,
|
||||
$_SERVER['PHP_SELF'].' '.$name
|
||||
);
|
||||
|
||||
return str_replace($placeholders, $replacements, $this->getHelp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the aliases for the command.
|
||||
*
|
||||
* @param array $aliases An array of aliases for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*/
|
||||
public function setAliases($aliases)
|
||||
{
|
||||
$this->aliases = $aliases;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the aliases for the command.
|
||||
*
|
||||
* @return array An array of aliases for the command
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the synopsis for the command.
|
||||
*
|
||||
* @return string The synopsis
|
||||
*/
|
||||
public function getSynopsis()
|
||||
{
|
||||
return sprintf('%s %s', $this->getFullName(), $this->definition->getSynopsis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a helper instance by name.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return mixed The helper value
|
||||
*
|
||||
* @throws \InvalidArgumentException if the helper is not defined
|
||||
*/
|
||||
protected function getHelper($name)
|
||||
{
|
||||
return $this->application->getHelperSet()->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a helper instance by name.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return mixed The helper value
|
||||
*
|
||||
* @throws \InvalidArgumentException if the helper is not defined
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->application->getHelperSet()->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text representation of the command.
|
||||
*
|
||||
* @return string A string representing the command
|
||||
*/
|
||||
public function asText()
|
||||
{
|
||||
$messages = array(
|
||||
'<comment>Usage:</comment>',
|
||||
' '.$this->getSynopsis(),
|
||||
'',
|
||||
);
|
||||
|
||||
if ($this->getAliases()) {
|
||||
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $this->getAliases()).'</info>';
|
||||
}
|
||||
|
||||
$messages[] = $this->definition->asText();
|
||||
|
||||
if ($help = $this->getProcessedHelp()) {
|
||||
$messages[] = '<comment>Help:</comment>';
|
||||
$messages[] = ' '.implode("\n ", explode("\n", $help))."\n";
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML representation of the command.
|
||||
*
|
||||
* @param Boolean $asDom Whether to return a DOM or an XML string
|
||||
*
|
||||
* @return string|DOMDocument An XML string representing the command
|
||||
*/
|
||||
public function asXml($asDom = false)
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = true;
|
||||
$dom->appendChild($commandXML = $dom->createElement('command'));
|
||||
$commandXML->setAttribute('id', $this->getFullName());
|
||||
$commandXML->setAttribute('namespace', $this->getNamespace() ? $this->getNamespace() : '_global');
|
||||
$commandXML->setAttribute('name', $this->getName());
|
||||
|
||||
$commandXML->appendChild($usageXML = $dom->createElement('usage'));
|
||||
$usageXML->appendChild($dom->createTextNode(sprintf($this->getSynopsis(), '')));
|
||||
|
||||
$commandXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode(implode("\n ", explode("\n", $this->getDescription()))));
|
||||
|
||||
$commandXML->appendChild($helpXML = $dom->createElement('help'));
|
||||
$help = $this->help;
|
||||
$helpXML->appendChild($dom->createTextNode(implode("\n ", explode("\n", $help))));
|
||||
|
||||
$commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
|
||||
foreach ($this->getAliases() as $alias) {
|
||||
$aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
|
||||
$aliasXML->appendChild($dom->createTextNode($alias));
|
||||
}
|
||||
|
||||
$definition = $this->definition->asXml(true);
|
||||
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true));
|
||||
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true));
|
||||
|
||||
return $asDom ? $dom : $dom->saveXml();
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* HelpCommand displays the help for a given command.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class HelpCommand extends Command
|
||||
{
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->ignoreValidationErrors = true;
|
||||
|
||||
$this
|
||||
->setDefinition(array(
|
||||
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
|
||||
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
|
||||
))
|
||||
->setName('help')
|
||||
->setAliases(array('?'))
|
||||
->setDescription('Displays help for a command')
|
||||
->setHelp(<<<EOF
|
||||
The <info>help</info> command displays help for a given command:
|
||||
|
||||
<info>./symfony help list</info>
|
||||
|
||||
You can also output the help as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>./symfony help --xml list</info>
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
public function setCommand(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (null === $this->command) {
|
||||
$this->command = $this->application->get($input->getArgument('command_name'));
|
||||
}
|
||||
|
||||
if ($input->getOption('xml')) {
|
||||
$output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
|
||||
} else {
|
||||
$output->writeln($this->command->asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ListCommand displays the list of all available commands for the application.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class ListCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition(array(
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
|
||||
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
|
||||
))
|
||||
->setName('list')
|
||||
->setDescription('Lists commands')
|
||||
->setHelp(<<<EOF
|
||||
The <info>list</info> command lists all commands:
|
||||
|
||||
<info>./symfony list</info>
|
||||
|
||||
You can also display the commands for a specific namespace:
|
||||
|
||||
<info>./symfony list test</info>
|
||||
|
||||
You can also output the information as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>./symfony list --xml</info>
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ($input->getOption('xml')) {
|
||||
$output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
|
||||
} else {
|
||||
$output->writeln($this->application->asText($input->getArgument('namespace')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Dialog class provides helpers to interact with the user.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class DialogHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* Asks a question to the user.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string|array $question The question to ask
|
||||
* @param string $default The default answer if none is given by the user
|
||||
*
|
||||
* @return string The user answer
|
||||
*/
|
||||
public function ask(OutputInterface $output, $question, $default = null)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
$output->writeln($question);
|
||||
|
||||
$ret = trim(fgets(STDIN));
|
||||
|
||||
return $ret ? $ret : $default;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks a confirmation to the user.
|
||||
*
|
||||
* The question will be asked until the user answer by nothing, yes, or no.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string|array $question The question to ask
|
||||
* @param Boolean $default The default answer if the user enters nothing
|
||||
*
|
||||
* @return Boolean true if the user has confirmed, false otherwise
|
||||
*/
|
||||
public function askConfirmation(OutputInterface $output, $question, $default = true)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
$answer = 'z';
|
||||
while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
|
||||
$answer = $this->ask($output, $question);
|
||||
}
|
||||
|
||||
if (false === $default) {
|
||||
return $answer && 'y' == strtolower($answer[0]);
|
||||
} else {
|
||||
return !$answer || 'y' == strtolower($answer[0]);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks for a value and validates the response.
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param string|array $question
|
||||
* @param Closure $validator
|
||||
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception When any of the validator returns an error
|
||||
*/
|
||||
public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
$error = null;
|
||||
while (false === $attempts || $attempts--) {
|
||||
if (null !== $error) {
|
||||
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
|
||||
}
|
||||
|
||||
$value = $this->ask($output, $question, null);
|
||||
|
||||
try {
|
||||
return $validator($value);
|
||||
} catch (\Exception $error) {
|
||||
}
|
||||
}
|
||||
|
||||
throw $error;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's canonical name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'dialog';
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Formatter class provides helpers to format messages.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class FormatterHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* Formats a message within a section.
|
||||
*
|
||||
* @param string $section The section name
|
||||
* @param string $message The message
|
||||
* @param string $style The style to apply to the section
|
||||
*/
|
||||
public function formatSection($section, $message, $style = 'info')
|
||||
{
|
||||
return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a message as a block of text.
|
||||
*
|
||||
* @param string|array $messages The message to write in the block
|
||||
* @param string $style The style to apply to the whole block
|
||||
* @param Boolean $large Whether to return a large block
|
||||
*
|
||||
* @return string The formatter message
|
||||
*/
|
||||
public function formatBlock($messages, $style, $large = false)
|
||||
{
|
||||
if (!is_array($messages)) {
|
||||
$messages = array($messages);
|
||||
}
|
||||
|
||||
$len = 0;
|
||||
$lines = array();
|
||||
foreach ($messages as $message) {
|
||||
$lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
|
||||
$len = max($this->strlen($message) + ($large ? 4 : 2), $len);
|
||||
}
|
||||
|
||||
$messages = $large ? array(str_repeat(' ', $len)) : array();
|
||||
foreach ($lines as $line) {
|
||||
$messages[] = $line.str_repeat(' ', $len - $this->strlen($line));
|
||||
}
|
||||
if ($large) {
|
||||
$messages[] = str_repeat(' ', $len);
|
||||
}
|
||||
|
||||
foreach ($messages as &$message) {
|
||||
$message = sprintf('<%s>%s</%s>', $style, $message, $style);
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
protected function strlen($string)
|
||||
{
|
||||
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's canonical name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'formatter';
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper is the base class for all helper classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
abstract class Helper implements HelperInterface
|
||||
{
|
||||
protected $helperSet = null;
|
||||
|
||||
/**
|
||||
* Sets the helper set associated with this helper.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet = null)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the helper set associated with this helper.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
return $this->helperSet;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* HelperInterface is the interface all helpers must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
interface HelperInterface
|
||||
{
|
||||
/**
|
||||
* Sets the helper set associated with this helper.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*/
|
||||
function setHelperSet(HelperSet $helperSet = null);
|
||||
|
||||
/**
|
||||
* Gets the helper set associated with this helper.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*/
|
||||
function getHelperSet();
|
||||
|
||||
/**
|
||||
* Returns the canonical name of this helper.
|
||||
*
|
||||
* @return string The canonical name
|
||||
*/
|
||||
function getName();
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* HelperSet represents a set of helpers to be used with a command.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class HelperSet
|
||||
{
|
||||
protected $helpers;
|
||||
protected $command;
|
||||
|
||||
/**
|
||||
* @param Helper[] $helpers An array of helper.
|
||||
*/
|
||||
public function __construct(array $helpers = array())
|
||||
{
|
||||
$this->helpers = array();
|
||||
foreach ($helpers as $alias => $helper) {
|
||||
$this->set($helper, is_int($alias) ? null : $alias);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a helper.
|
||||
*
|
||||
* @param HelperInterface $value The helper instance
|
||||
* @param string $alias An alias
|
||||
*/
|
||||
public function set(HelperInterface $helper, $alias = null)
|
||||
{
|
||||
$this->helpers[$helper->getName()] = $helper;
|
||||
if (null !== $alias) {
|
||||
$this->helpers[$alias] = $helper;
|
||||
}
|
||||
|
||||
$helper->setHelperSet($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the helper if defined.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return Boolean true if the helper is defined, false otherwise
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return isset($this->helpers[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a helper value.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return HelperInterface The helper instance
|
||||
*
|
||||
* @throws \InvalidArgumentException if the helper is not defined
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!$this->has($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this->helpers[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command associated with this helper set.
|
||||
*
|
||||
* @param Command $command A Command instance
|
||||
*/
|
||||
public function setCommand(Command $command = null)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command associated with this helper set.
|
||||
*
|
||||
* @return Command A Command instance
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ArgvInput represents an input coming from the CLI arguments.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new ArgvInput();
|
||||
*
|
||||
* By default, the `$_SERVER['argv']` array is used for the input values.
|
||||
*
|
||||
* This can be overridden by explicitly passing the input values in the constructor:
|
||||
*
|
||||
* $input = new ArgvInput($_SERVER['argv']);
|
||||
*
|
||||
* If you pass it yourself, don't forget that the first element of the array
|
||||
* is the name of the running program.
|
||||
*
|
||||
* When passing an argument to the constructor, be sure that it respects
|
||||
* the same rules as the argv one. It's almost always better to use the
|
||||
* `StringInput` when you want to provide your own input.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* @see http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
|
||||
* @see http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02
|
||||
*/
|
||||
class ArgvInput extends Input
|
||||
{
|
||||
protected $tokens;
|
||||
protected $parsed;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $argv An array of parameters from the CLI (in the argv format)
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function __construct(array $argv = null, InputDefinition $definition = null)
|
||||
{
|
||||
if (null === $argv) {
|
||||
$argv = $_SERVER['argv'];
|
||||
}
|
||||
|
||||
// strip the program name
|
||||
array_shift($argv);
|
||||
|
||||
$this->tokens = $argv;
|
||||
|
||||
parent::__construct($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
protected function parse()
|
||||
{
|
||||
$this->parsed = $this->tokens;
|
||||
while (null !== $token = array_shift($this->parsed)) {
|
||||
if ('--' === substr($token, 0, 2)) {
|
||||
$this->parseLongOption($token);
|
||||
} elseif ('-' === $token[0]) {
|
||||
$this->parseShortOption($token);
|
||||
} else {
|
||||
$this->parseArgument($token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a short option.
|
||||
*
|
||||
* @param string $token The current token.
|
||||
*/
|
||||
protected function parseShortOption($token)
|
||||
{
|
||||
$name = substr($token, 1);
|
||||
|
||||
if (strlen($name) > 1) {
|
||||
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
|
||||
// an option with a value (with no space)
|
||||
$this->addShortOption($name[0], substr($name, 1));
|
||||
} else {
|
||||
$this->parseShortOptionSet($name);
|
||||
}
|
||||
} else {
|
||||
$this->addShortOption($name, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a short option set.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
protected function parseShortOptionSet($name)
|
||||
{
|
||||
$len = strlen($name);
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if (!$this->definition->hasShortcut($name[$i])) {
|
||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOptionForShortcut($name[$i]);
|
||||
if ($option->acceptValue()) {
|
||||
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
|
||||
|
||||
break;
|
||||
} else {
|
||||
$this->addLongOption($option->getName(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a long option.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*/
|
||||
protected function parseLongOption($token)
|
||||
{
|
||||
$name = substr($token, 2);
|
||||
|
||||
if (false !== $pos = strpos($name, '=')) {
|
||||
$this->addLongOption(substr($name, 0, $pos), substr($name, $pos + 1));
|
||||
} else {
|
||||
$this->addLongOption($name, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an argument.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*
|
||||
* @throws \RuntimeException When too many arguments are given
|
||||
*/
|
||||
protected function parseArgument($token)
|
||||
{
|
||||
if (!$this->definition->hasArgument(count($this->arguments))) {
|
||||
throw new \RuntimeException('Too many arguments.');
|
||||
}
|
||||
|
||||
$this->arguments[$this->definition->getArgument(count($this->arguments))->getName()] = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
protected function addShortOption($shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
protected function addLongOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOption($name);
|
||||
|
||||
if (null === $value && $option->acceptValue()) {
|
||||
// if option accepts an optional or mandatory argument
|
||||
// let's see if there is one provided
|
||||
$next = array_shift($this->parsed);
|
||||
if ('-' !== $next[0]) {
|
||||
$value = $next;
|
||||
} else {
|
||||
array_unshift($this->parsed, $next);
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
if ($option->isValueRequired()) {
|
||||
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
|
||||
}
|
||||
|
||||
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->tokens as $token) {
|
||||
if ($token && '-' === $token[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contains a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before it has been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
public function hasParameterOption($values)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
foreach ($this->tokens as $v) {
|
||||
if (in_array($v, $values)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ArrayInput represents an input provided as an array.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class ArrayInput extends Input
|
||||
{
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $param An array of parameters
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function __construct(array $parameters, InputDefinition $definition = null)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
parent::__construct($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ($key && '-' === $key[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contains a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before it has been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $value The values to look for in the raw parameters (can be an array)
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
public function hasParameterOption($values)
|
||||
{
|
||||
if (!is_array($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
foreach ($this->parameters as $k => $v) {
|
||||
if (!is_int($k)) {
|
||||
$v = $k;
|
||||
}
|
||||
|
||||
if (in_array($v, $values)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
protected function parse()
|
||||
{
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ('--' === substr($key, 0, 2)) {
|
||||
$this->addLongOption(substr($key, 2), $value);
|
||||
} elseif ('-' === $key[0]) {
|
||||
$this->addShortOption(substr($key, 1), $value);
|
||||
} else {
|
||||
$this->addArgument($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
protected function addShortOption($shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
* @throws \InvalidArgumentException When a required value is missing
|
||||
*/
|
||||
protected function addLongOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOption($name);
|
||||
|
||||
if (null === $value) {
|
||||
if ($option->isValueRequired()) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
|
||||
}
|
||||
|
||||
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an argument value.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param mixed $value The value for the argument
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
protected function addArgument($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->arguments[$name] = $value;
|
||||
}
|
||||
}
|
||||
199
lib/vendor/Symfony/Component/Console/Input/Input.php
vendored
199
lib/vendor/Symfony/Component/Console/Input/Input.php
vendored
@@ -1,199 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Input is the base class for all concrete Input classes.
|
||||
*
|
||||
* Three concrete classes are provided by default:
|
||||
*
|
||||
* * `ArgvInput`: The input comes from the CLI arguments (argv)
|
||||
* * `StringInput`: The input is provided as a string
|
||||
* * `ArrayInput`: The input is provided as an array
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
abstract class Input implements InputInterface
|
||||
{
|
||||
protected $definition;
|
||||
protected $options;
|
||||
protected $arguments;
|
||||
protected $interactive = true;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function __construct(InputDefinition $definition = null)
|
||||
{
|
||||
if (null === $definition) {
|
||||
$this->definition = new InputDefinition();
|
||||
} else {
|
||||
$this->bind($definition);
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the current Input instance with the given arguments and options.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function bind(InputDefinition $definition)
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->options = array();
|
||||
$this->definition = $definition;
|
||||
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
abstract protected function parse();
|
||||
|
||||
/**
|
||||
* @throws \RuntimeException When not enough arguments are given
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
|
||||
throw new \RuntimeException('Not enough arguments.');
|
||||
}
|
||||
}
|
||||
|
||||
public function isInteractive()
|
||||
{
|
||||
return $this->interactive;
|
||||
}
|
||||
|
||||
public function setInteractive($interactive)
|
||||
{
|
||||
$this->interactive = (Boolean) $interactive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument values.
|
||||
*
|
||||
* @return array An array of argument values
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument value for a given argument name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
*
|
||||
* @return mixed The argument value
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function getArgument($name)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an argument value by name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param string $value The argument value
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function setArgument($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->arguments[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return Boolean true if the InputArgument object exists, false otherwise
|
||||
*/
|
||||
public function hasArgument($name)
|
||||
{
|
||||
return $this->definition->hasArgument($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options values.
|
||||
*
|
||||
* @return array An array of option values
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return array_merge($this->definition->getOptionDefaults(), $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the option value for a given option name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
*
|
||||
* @return mixed The option value
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option value by name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $value The option value
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return $this->definition->hasOption($name);
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a command line argument.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class InputArgument
|
||||
{
|
||||
const REQUIRED = 1;
|
||||
const OPTIONAL = 2;
|
||||
const IS_ARRAY = 4;
|
||||
|
||||
protected $name;
|
||||
protected $mode;
|
||||
protected $default;
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param integer $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (for self::OPTIONAL mode only)
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument mode is not valid
|
||||
*/
|
||||
public function __construct($name, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
if (null === $mode) {
|
||||
$mode = self::OPTIONAL;
|
||||
} else if (is_string($mode) || $mode > 7) {
|
||||
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
$this->mode = $mode;
|
||||
$this->description = $description;
|
||||
|
||||
$this->setDefault($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument name.
|
||||
*
|
||||
* @return string The argument name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the argument is required.
|
||||
*
|
||||
* @return Boolean true if parameter mode is self::REQUIRED, false otherwise
|
||||
*/
|
||||
public function isRequired()
|
||||
{
|
||||
return self::REQUIRED === (self::REQUIRED & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the argument can take multiple values.
|
||||
*
|
||||
* @return Boolean true if mode is self::IS_ARRAY, false otherwise
|
||||
*/
|
||||
public function isArray()
|
||||
{
|
||||
return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param mixed $default The default value
|
||||
*
|
||||
* @throws \LogicException When incorrect default value is given
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
if (self::REQUIRED === $this->mode && null !== $default) {
|
||||
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
|
||||
}
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
} else if (!is_array($default)) {
|
||||
throw new \LogicException('A default value for an array argument must be an array.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return mixed The default value
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description text.
|
||||
*
|
||||
* @return string The description text
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
@@ -1,471 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A InputDefinition represents a set of valid command line arguments and options.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $definition = new InputDefinition(array(
|
||||
* new InputArgument('name', InputArgument::REQUIRED),
|
||||
* new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
|
||||
* ));
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class InputDefinition
|
||||
{
|
||||
protected $arguments;
|
||||
protected $requiredCount;
|
||||
protected $hasAnArrayArgument = false;
|
||||
protected $hasOptional;
|
||||
protected $options;
|
||||
protected $shortcuts;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $definition An array of InputArgument and InputOption instance
|
||||
*/
|
||||
public function __construct(array $definition = array())
|
||||
{
|
||||
$this->setDefinition($definition);
|
||||
}
|
||||
|
||||
public function setDefinition(array $definition)
|
||||
{
|
||||
$arguments = array();
|
||||
$options = array();
|
||||
foreach ($definition as $item) {
|
||||
if ($item instanceof InputOption) {
|
||||
$options[] = $item;
|
||||
} else {
|
||||
$arguments[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setArguments($arguments);
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputArgument objects.
|
||||
*
|
||||
* @param array $arguments An array of InputArgument objects
|
||||
*/
|
||||
public function setArguments($arguments = array())
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->requiredCount = 0;
|
||||
$this->hasOptional = false;
|
||||
$this->hasAnArrayArgument = false;
|
||||
$this->addArguments($arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of InputArgument objects.
|
||||
*
|
||||
* @param InputArgument[] $arguments An array of InputArgument objects
|
||||
*/
|
||||
public function addArguments($arguments = array())
|
||||
{
|
||||
if (null !== $arguments) {
|
||||
foreach ($arguments as $argument) {
|
||||
$this->addArgument($argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an InputArgument object.
|
||||
*
|
||||
* @param InputArgument $argument An InputArgument object
|
||||
*
|
||||
* @throws \LogicException When incorrect argument is given
|
||||
*/
|
||||
public function addArgument(InputArgument $argument)
|
||||
{
|
||||
if (isset($this->arguments[$argument->getName()])) {
|
||||
throw new \LogicException(sprintf('An argument with name "%s" already exist.', $argument->getName()));
|
||||
}
|
||||
|
||||
if ($this->hasAnArrayArgument) {
|
||||
throw new \LogicException('Cannot add an argument after an array argument.');
|
||||
}
|
||||
|
||||
if ($argument->isRequired() && $this->hasOptional) {
|
||||
throw new \LogicException('Cannot add a required argument after an optional one.');
|
||||
}
|
||||
|
||||
if ($argument->isArray()) {
|
||||
$this->hasAnArrayArgument = true;
|
||||
}
|
||||
|
||||
if ($argument->isRequired()) {
|
||||
++$this->requiredCount;
|
||||
} else {
|
||||
$this->hasOptional = true;
|
||||
}
|
||||
|
||||
$this->arguments[$argument->getName()] = $argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an InputArgument by name or by position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return InputArgument An InputArgument object
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function getArgument($name)
|
||||
{
|
||||
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
||||
|
||||
if (!$this->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
return $arguments[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return Boolean true if the InputArgument object exists, false otherwise
|
||||
*/
|
||||
public function hasArgument($name)
|
||||
{
|
||||
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
||||
|
||||
return isset($arguments[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of InputArgument objects.
|
||||
*
|
||||
* @return array An array of InputArgument objects
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of InputArguments.
|
||||
*
|
||||
* @return integer The number of InputArguments
|
||||
*/
|
||||
public function getArgumentCount()
|
||||
{
|
||||
return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of required InputArguments.
|
||||
*
|
||||
* @return integer The number of required InputArguments
|
||||
*/
|
||||
public function getArgumentRequiredCount()
|
||||
{
|
||||
return $this->requiredCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default values.
|
||||
*
|
||||
* @return array An array of default values
|
||||
*/
|
||||
public function getArgumentDefaults()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->arguments as $argument) {
|
||||
$values[$argument->getName()] = $argument->getDefault();
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputOption objects.
|
||||
*
|
||||
* @param array $options An array of InputOption objects
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
{
|
||||
$this->options = array();
|
||||
$this->shortcuts = array();
|
||||
$this->addOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of InputOption objects.
|
||||
*
|
||||
* @param InputOption[] $options An array of InputOption objects
|
||||
*/
|
||||
public function addOptions($options = array())
|
||||
{
|
||||
foreach ($options as $option) {
|
||||
$this->addOption($option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an InputOption object.
|
||||
*
|
||||
* @param InputOption $option An InputOption object
|
||||
*
|
||||
* @throws \LogicException When option given already exist
|
||||
*/
|
||||
public function addOption(InputOption $option)
|
||||
{
|
||||
if (isset($this->options[$option->getName()])) {
|
||||
throw new \LogicException(sprintf('An option named "%s" already exist.', $option->getName()));
|
||||
} else if (isset($this->shortcuts[$option->getShortcut()])) {
|
||||
throw new \LogicException(sprintf('An option with shortcut "%s" already exist.', $option->getShortcut()));
|
||||
}
|
||||
|
||||
$this->options[$option->getName()] = $option;
|
||||
if ($option->getShortcut()) {
|
||||
$this->shortcuts[$option->getShortcut()] = $option->getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an InputOption by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return InputOption A InputOption object
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
if (!$this->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return isset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of InputOption objects.
|
||||
*
|
||||
* @return array An array of InputOption objects
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by shortcut.
|
||||
*
|
||||
* @param string $name The InputOption shortcut
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasShortcut($name)
|
||||
{
|
||||
return isset($this->shortcuts[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an InputOption by shortcut.
|
||||
*
|
||||
* @return InputOption An InputOption object
|
||||
*/
|
||||
public function getOptionForShortcut($shortcut)
|
||||
{
|
||||
return $this->getOption($this->shortcutToName($shortcut));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of default values.
|
||||
*
|
||||
* @return array An array of all default values
|
||||
*/
|
||||
public function getOptionDefaults()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->options as $option) {
|
||||
$values[$option->getName()] = $option->getDefault();
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the InputOption name given a shortcut.
|
||||
*
|
||||
* @param string $shortcut The shortcut
|
||||
*
|
||||
* @return string The InputOption name
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given does not exist
|
||||
*/
|
||||
protected function shortcutToName($shortcut)
|
||||
{
|
||||
if (!isset($this->shortcuts[$shortcut])) {
|
||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
return $this->shortcuts[$shortcut];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the synopsis.
|
||||
*
|
||||
* @return string The synopsis
|
||||
*/
|
||||
public function getSynopsis()
|
||||
{
|
||||
$elements = array();
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
|
||||
$elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
|
||||
}
|
||||
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : ''));
|
||||
|
||||
if ($argument->isArray()) {
|
||||
$elements[] = sprintf('... [%sN]', $argument->getName());
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual representation of the InputDefinition.
|
||||
*
|
||||
* @return string A string representing the InputDefinition
|
||||
*/
|
||||
public function asText()
|
||||
{
|
||||
// find the largest option or argument name
|
||||
$max = 0;
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$max = strlen($option->getName()) + 2 > $max ? strlen($option->getName()) + 2 : $max;
|
||||
}
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$max = strlen($argument->getName()) > $max ? strlen($argument->getName()) : $max;
|
||||
}
|
||||
++$max;
|
||||
|
||||
$text = array();
|
||||
|
||||
if ($this->getArguments()) {
|
||||
$text[] = '<comment>Arguments:</comment>';
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
|
||||
$default = sprintf('<comment> (default: %s)</comment>', is_array($argument->getDefault()) ? str_replace("\n", '', var_export($argument->getDefault(), true)): $argument->getDefault());
|
||||
} else {
|
||||
$default = '';
|
||||
}
|
||||
|
||||
$text[] = sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $argument->getDescription(), $default);
|
||||
}
|
||||
|
||||
$text[] = '';
|
||||
}
|
||||
|
||||
if ($this->getOptions()) {
|
||||
$text[] = '<comment>Options:</comment>';
|
||||
|
||||
foreach ($this->getOptions() as $option) {
|
||||
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
|
||||
$default = sprintf('<comment> (default: %s)</comment>', is_array($option->getDefault()) ? str_replace("\n", '', print_r($option->getDefault(), true)): $option->getDefault());
|
||||
} else {
|
||||
$default = '';
|
||||
}
|
||||
|
||||
$multiple = $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '';
|
||||
$text[] = sprintf(' %-'.$max.'s %s%s%s%s', '<info>--'.$option->getName().'</info>', $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', $option->getDescription(), $default, $multiple);
|
||||
}
|
||||
|
||||
$text[] = '';
|
||||
}
|
||||
|
||||
return implode("\n", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML representation of the InputDefinition.
|
||||
*
|
||||
* @param Boolean $asDom Whether to return a DOM or an XML string
|
||||
*
|
||||
* @return string|DOMDocument An XML string representing the InputDefinition
|
||||
*/
|
||||
public function asXml($asDom = false)
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = true;
|
||||
$dom->appendChild($definitionXML = $dom->createElement('definition'));
|
||||
|
||||
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$argumentsXML->appendChild($argumentXML = $dom->createElement('argument'));
|
||||
$argumentXML->setAttribute('name', $argument->getName());
|
||||
$argumentXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
|
||||
$argumentXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
|
||||
$argumentXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
|
||||
|
||||
$argumentXML->appendChild($defaultsXML = $dom->createElement('defaults'));
|
||||
$defaults = is_array($argument->getDefault()) ? $argument->getDefault() : ($argument->getDefault() ? array($argument->getDefault()) : array());
|
||||
foreach ($defaults as $default) {
|
||||
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
|
||||
$defaultXML->appendChild($dom->createTextNode($default));
|
||||
}
|
||||
}
|
||||
|
||||
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$optionsXML->appendChild($optionXML = $dom->createElement('option'));
|
||||
$optionXML->setAttribute('name', '--'.$option->getName());
|
||||
$optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
|
||||
$optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
|
||||
$optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
|
||||
$optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
|
||||
$optionXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
|
||||
|
||||
if ($option->acceptValue()) {
|
||||
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
|
||||
$defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array());
|
||||
foreach ($defaults as $default) {
|
||||
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
|
||||
$defaultXML->appendChild($dom->createTextNode($default));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $asDom ? $dom : $dom->saveXml();
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* InputInterface is the interface implemented by all input classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
interface InputInterface
|
||||
{
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
function getFirstArgument();
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contains a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before it has been validated. It must be used carefully.
|
||||
*
|
||||
* @param string $value The value to look for in the raw parameters
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
function hasParameterOption($value);
|
||||
|
||||
/**
|
||||
* Binds the current Input instance with the given arguments and options.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
function bind(InputDefinition $definition);
|
||||
|
||||
function validate();
|
||||
|
||||
function getArguments();
|
||||
|
||||
function getArgument($name);
|
||||
|
||||
function getOptions();
|
||||
|
||||
function getOption($name);
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a command line option.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class InputOption
|
||||
{
|
||||
const VALUE_NONE = 1;
|
||||
const VALUE_REQUIRED = 2;
|
||||
const VALUE_OPTIONAL = 4;
|
||||
const VALUE_IS_ARRAY = 8;
|
||||
|
||||
protected $name;
|
||||
protected $shortcut;
|
||||
protected $mode;
|
||||
protected $default;
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $shortcut The shortcut (can be null)
|
||||
* @param integer $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
||||
*
|
||||
* @throws \InvalidArgumentException If option mode is invalid or incompatible
|
||||
*/
|
||||
public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
if ('--' === substr($name, 0, 2)) {
|
||||
$name = substr($name, 2);
|
||||
}
|
||||
|
||||
if (empty($shortcut)) {
|
||||
$shortcut = null;
|
||||
}
|
||||
|
||||
if (null !== $shortcut) {
|
||||
if ('-' === $shortcut[0]) {
|
||||
$shortcut = substr($shortcut, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $mode) {
|
||||
$mode = self::VALUE_NONE;
|
||||
} else if (!is_int($mode) || $mode > 15) {
|
||||
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
$this->shortcut = $shortcut;
|
||||
$this->mode = $mode;
|
||||
$this->description = $description;
|
||||
|
||||
if ($this->isArray() && !$this->acceptValue()) {
|
||||
throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
|
||||
}
|
||||
|
||||
$this->setDefault($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shortcut.
|
||||
*
|
||||
* @return string The shortcut
|
||||
*/
|
||||
public function getShortcut()
|
||||
{
|
||||
return $this->shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
*
|
||||
* @return string The name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option accepts a value.
|
||||
*
|
||||
* @return Boolean true if value mode is not self::VALUE_NONE, false otherwise
|
||||
*/
|
||||
public function acceptValue()
|
||||
{
|
||||
return $this->isValueRequired() || $this->isValueOptional();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option requires a value.
|
||||
*
|
||||
* @return Boolean true if value mode is self::VALUE_REQUIRED, false otherwise
|
||||
*/
|
||||
public function isValueRequired()
|
||||
{
|
||||
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option takes an optional value.
|
||||
*
|
||||
* @return Boolean true if value mode is self::VALUE_OPTIONAL, false otherwise
|
||||
*/
|
||||
public function isValueOptional()
|
||||
{
|
||||
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option can take multiple values.
|
||||
*
|
||||
* @return Boolean true if mode is self::VALUE_IS_ARRAY, false otherwise
|
||||
*/
|
||||
public function isArray()
|
||||
{
|
||||
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param mixed $default The default value
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
|
||||
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
|
||||
}
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
} elseif (!is_array($default)) {
|
||||
throw new \LogicException('A default value for an array option must be an array.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->default = $this->acceptValue() ? $default : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return mixed The default value
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description text.
|
||||
*
|
||||
* @return string The description text
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* StringInput represents an input provided as a string.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new StringInput('foo --bar="foobar"');
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class StringInput extends ArgvInput
|
||||
{
|
||||
const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $input An array of parameters from the CLI (in the argv format)
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function __construct($input, InputDefinition $definition = null)
|
||||
{
|
||||
parent::__construct(array(), $definition);
|
||||
|
||||
$this->tokens = $this->tokenize($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException When unable to parse input (should never happen)
|
||||
*/
|
||||
protected function tokenize($input)
|
||||
{
|
||||
$input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
|
||||
|
||||
$tokens = array();
|
||||
$length = strlen($input);
|
||||
$cursor = 0;
|
||||
while ($cursor < $length) {
|
||||
if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
|
||||
} elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
|
||||
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
|
||||
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes($match[1]);
|
||||
} else {
|
||||
// should never happen
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$cursor += strlen($match[0]);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.
|
||||
*
|
||||
* This class is a convenient wrapper around `StreamOutput`.
|
||||
*
|
||||
* $output = new ConsoleOutput();
|
||||
*
|
||||
* This is equivalent to:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('php://stdout', 'w'));
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class ConsoleOutput extends StreamOutput
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
*/
|
||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null)
|
||||
{
|
||||
parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* NullOutput suppresses all output.
|
||||
*
|
||||
* $output = new NullOutput();
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class NullOutput extends Output
|
||||
{
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*/
|
||||
public function doWrite($message, $newline)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for output classes.
|
||||
*
|
||||
* There is three level of verbosity:
|
||||
*
|
||||
* * normal: no option passed (normal output - information)
|
||||
* * verbose: -v (more output - debug)
|
||||
* * quiet: -q (no output)
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
abstract class Output implements OutputInterface
|
||||
{
|
||||
const VERBOSITY_QUIET = 0;
|
||||
const VERBOSITY_NORMAL = 1;
|
||||
const VERBOSITY_VERBOSE = 2;
|
||||
|
||||
const OUTPUT_NORMAL = 0;
|
||||
const OUTPUT_RAW = 1;
|
||||
const OUTPUT_PLAIN = 2;
|
||||
|
||||
protected $verbosity;
|
||||
protected $decorated;
|
||||
|
||||
static protected $styles = array(
|
||||
'error' => array('bg' => 'red', 'fg' => 'white'),
|
||||
'info' => array('fg' => 'green'),
|
||||
'comment' => array('fg' => 'yellow'),
|
||||
'question' => array('bg' => 'cyan', 'fg' => 'black'),
|
||||
);
|
||||
static protected $options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8);
|
||||
static protected $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37);
|
||||
static protected $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
*/
|
||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null)
|
||||
{
|
||||
$this->decorated = (Boolean) $decorated;
|
||||
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new style.
|
||||
*
|
||||
* @param string $name The style name
|
||||
* @param array $options An array of options
|
||||
*/
|
||||
static public function setStyle($name, $options = array())
|
||||
{
|
||||
static::$styles[strtolower($name)] = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorated the messages or not
|
||||
*/
|
||||
public function setDecorated($decorated)
|
||||
{
|
||||
$this->decorated = (Boolean) $decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the decorated flag.
|
||||
*
|
||||
* @return Boolean true if the output will decorate messages, false otherwise
|
||||
*/
|
||||
public function isDecorated()
|
||||
{
|
||||
return $this->decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the verbosity of the output.
|
||||
*
|
||||
* @param integer $level The level of verbosity
|
||||
*/
|
||||
public function setVerbosity($level)
|
||||
{
|
||||
$this->verbosity = (int) $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current verbosity of the output.
|
||||
*
|
||||
* @return integer The current level of verbosity
|
||||
*/
|
||||
public function getVerbosity()
|
||||
{
|
||||
return $this->verbosity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output and adds a newline at the end.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param integer $type The type of output
|
||||
*/
|
||||
public function writeln($messages, $type = 0)
|
||||
{
|
||||
$this->write($messages, true, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
* @param integer $type The type of output
|
||||
*
|
||||
* @throws \InvalidArgumentException When unknown output type is given
|
||||
*/
|
||||
public function write($messages, $newline = false, $type = 0)
|
||||
{
|
||||
if (self::VERBOSITY_QUIET === $this->verbosity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($messages)) {
|
||||
$messages = array($messages);
|
||||
}
|
||||
|
||||
foreach ($messages as $message) {
|
||||
switch ($type) {
|
||||
case Output::OUTPUT_NORMAL:
|
||||
$message = $this->format($message);
|
||||
break;
|
||||
case Output::OUTPUT_RAW:
|
||||
break;
|
||||
case Output::OUTPUT_PLAIN:
|
||||
$message = strip_tags($this->format($message));
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
|
||||
}
|
||||
|
||||
$this->doWrite($message, $newline);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*/
|
||||
abstract public function doWrite($message, $newline);
|
||||
|
||||
/**
|
||||
* Formats a message according to the given styles.
|
||||
*
|
||||
* @param string $message The message to style
|
||||
*
|
||||
* @return string The styled message
|
||||
*/
|
||||
protected function format($message)
|
||||
{
|
||||
$message = preg_replace_callback('#<([a-z][a-z0-9\-_=;]+)>#i', array($this, 'replaceStartStyle'), $message);
|
||||
|
||||
return preg_replace_callback('#</([a-z][a-z0-9\-_]*)?>#i', array($this, 'replaceEndStyle'), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \InvalidArgumentException When style is unknown
|
||||
*/
|
||||
protected function replaceStartStyle($match)
|
||||
{
|
||||
if (!$this->decorated) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (isset(static::$styles[strtolower($match[1])])) {
|
||||
$parameters = static::$styles[strtolower($match[1])];
|
||||
} else {
|
||||
// bg=blue;fg=red
|
||||
if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($match[1]), $matches, PREG_SET_ORDER)) {
|
||||
throw new \InvalidArgumentException(sprintf('Unknown style "%s".', $match[1]));
|
||||
}
|
||||
|
||||
$parameters = array();
|
||||
foreach ($matches as $match) {
|
||||
$parameters[$match[1]] = $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
$codes = array();
|
||||
|
||||
if (isset($parameters['fg'])) {
|
||||
$codes[] = static::$foreground[$parameters['fg']];
|
||||
}
|
||||
|
||||
if (isset($parameters['bg'])) {
|
||||
$codes[] = static::$background[$parameters['bg']];
|
||||
}
|
||||
|
||||
foreach (static::$options as $option => $value) {
|
||||
if (isset($parameters[$option]) && $parameters[$option]) {
|
||||
$codes[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return "\033[".implode(';', $codes).'m';
|
||||
}
|
||||
|
||||
protected function replaceEndStyle($match)
|
||||
{
|
||||
if (!$this->decorated) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return "\033[0m";
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* OutputInterface is the interface implemented by all Output classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
interface OutputInterface
|
||||
{
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
* @param integer $type The type of output
|
||||
*
|
||||
* @throws \InvalidArgumentException When unknown output type is given
|
||||
*/
|
||||
function write($messages, $newline = false, $type = 0);
|
||||
|
||||
/**
|
||||
* Sets the verbosity of the output.
|
||||
*
|
||||
* @param integer $level The level of verbosity
|
||||
*/
|
||||
function setVerbosity($level);
|
||||
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorated the messages or not
|
||||
*/
|
||||
function setDecorated($decorated);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* StreamOutput writes the output to a given stream.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('php://stdout', 'w'));
|
||||
*
|
||||
* As `StreamOutput` can use any stream, you can also use a file:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class StreamOutput extends Output
|
||||
{
|
||||
protected $stream;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $stream A stream resource
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
*
|
||||
* @throws \InvalidArgumentException When first argument is not a real stream
|
||||
*/
|
||||
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null)
|
||||
{
|
||||
if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
|
||||
throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
|
||||
}
|
||||
|
||||
$this->stream = $stream;
|
||||
|
||||
if (null === $decorated) {
|
||||
$decorated = $this->hasColorSupport($decorated);
|
||||
}
|
||||
|
||||
parent::__construct($verbosity, $decorated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stream attached to this StreamOutput instance.
|
||||
*
|
||||
* @return resource A stream resource
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*
|
||||
* @throws \RuntimeException When unable to write output (should never happen)
|
||||
*/
|
||||
public function doWrite($message, $newline)
|
||||
{
|
||||
if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// should never happen
|
||||
throw new \RuntimeException('Unable to write output.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the stream supports colorization.
|
||||
*
|
||||
* Colorization is disabled if not supported by the stream:
|
||||
*
|
||||
* - windows without ansicon
|
||||
* - non tty consoles
|
||||
*
|
||||
* @return Boolean true if the stream supports colorization, false otherwise
|
||||
*/
|
||||
protected function hasColorSupport()
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if (DIRECTORY_SEPARATOR == '\\') {
|
||||
return false !== getenv('ANSICON');
|
||||
} else {
|
||||
return function_exists('posix_isatty') && @posix_isatty($this->stream);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
136
lib/vendor/Symfony/Component/Console/Shell.php
vendored
136
lib/vendor/Symfony/Component/Console/Shell.php
vendored
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Shell wraps an Application to add shell capabilities to it.
|
||||
*
|
||||
* This class only works with a PHP compiled with readline support
|
||||
* (either --with-readline or --with-libedit)
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Shell
|
||||
{
|
||||
protected $application;
|
||||
protected $history;
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* If there is no readline support for the current PHP executable
|
||||
* a \RuntimeException exception is thrown.
|
||||
*
|
||||
* @param Application $application An application instance
|
||||
*
|
||||
* @throws \RuntimeException When Readline extension is not enabled
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
if (!function_exists('readline')) {
|
||||
throw new \RuntimeException('Unable to start the shell as the Readline extension is not enabled.');
|
||||
}
|
||||
|
||||
$this->application = $application;
|
||||
$this->history = getenv('HOME').'/.history_'.$application->getName();
|
||||
$this->output = new ConsoleOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the shell.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->application->setAutoExit(false);
|
||||
$this->application->setCatchExceptions(true);
|
||||
|
||||
readline_read_history($this->history);
|
||||
readline_completion_function(array($this, 'autocompleter'));
|
||||
|
||||
$this->output->writeln($this->getHeader());
|
||||
while (true) {
|
||||
$command = readline($this->application->getName().' > ');
|
||||
|
||||
if (false === $command) {
|
||||
$this->output->writeln("\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
readline_add_history($command);
|
||||
readline_write_history($this->history);
|
||||
|
||||
if (0 !== $ret = $this->application->run(new StringInput($command), $this->output)) {
|
||||
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to return autocompletion for the current entered text.
|
||||
*
|
||||
* @param string $text The last segment of the entered text
|
||||
* @param integer $position The current position
|
||||
*/
|
||||
protected function autocompleter($text, $position)
|
||||
{
|
||||
$info = readline_info();
|
||||
$text = substr($info['line_buffer'], 0, $info['end']);
|
||||
|
||||
if ($info['point'] !== $info['end']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// task name?
|
||||
if (false === strpos($text, ' ') || !$text) {
|
||||
return array_keys($this->application->all());
|
||||
}
|
||||
|
||||
// options and arguments?
|
||||
try {
|
||||
$command = $this->application->findCommand(substr($text, 0, strpos($text, ' ')));
|
||||
} catch (\Exception $e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$list = array('--help');
|
||||
foreach ($command->getDefinition()->getOptions() as $option) {
|
||||
$list[] = '--'.$option->getName();
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shell header.
|
||||
*
|
||||
* @return string The header string
|
||||
*/
|
||||
protected function getHeader()
|
||||
{
|
||||
return <<<EOF
|
||||
|
||||
Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
|
||||
|
||||
At the prompt, type <comment>help</comment> for some help,
|
||||
or <comment>list</comment> to get a list available commands.
|
||||
|
||||
To exit the shell, type <comment>^D</comment>.
|
||||
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Tester;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class ApplicationTester
|
||||
{
|
||||
protected $application;
|
||||
protected $display;
|
||||
protected $input;
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Application $application A Application instance to test.
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->application = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the application.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * interactive: Sets the input interactive flag
|
||||
* * decorated: Sets the output decorated flag
|
||||
* * verbosity: Sets the output verbosity flag
|
||||
*
|
||||
* @param array $input An array of arguments and options
|
||||
* @param array $options An array of options
|
||||
*/
|
||||
public function run(array $input, $options = array())
|
||||
{
|
||||
$this->input = new ArrayInput($input);
|
||||
if (isset($options['interactive'])) {
|
||||
$this->input->setInteractive($options['interactive']);
|
||||
}
|
||||
|
||||
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
|
||||
if (isset($options['decorated'])) {
|
||||
$this->output->setDecorated($options['decorated']);
|
||||
}
|
||||
if (isset($options['verbosity'])) {
|
||||
$this->output->setVerbosity($options['verbosity']);
|
||||
}
|
||||
|
||||
$ret = $this->application->run($this->input, $this->output);
|
||||
|
||||
rewind($this->output->getStream());
|
||||
|
||||
return $this->display = stream_get_contents($this->output->getStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display returned by the last execution of the application.
|
||||
*
|
||||
* @return string The display
|
||||
*/
|
||||
public function getDisplay()
|
||||
{
|
||||
return $this->display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input instance used by the last execution of the application.
|
||||
*
|
||||
* @return InputInterface The current input instance
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output instance used by the last execution of the application.
|
||||
*
|
||||
* @return OutputInterface The current output instance
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Console\Tester;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class CommandTester
|
||||
{
|
||||
protected $command;
|
||||
protected $display;
|
||||
protected $input;
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Command $command A Command instance to test.
|
||||
*/
|
||||
public function __construct(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * interactive: Sets the input interactive flag
|
||||
* * decorated: Sets the output decorated flag
|
||||
* * verbosity: Sets the output verbosity flag
|
||||
*
|
||||
* @param array $input An array of arguments and options
|
||||
* @param array $options An array of options
|
||||
*/
|
||||
public function execute(array $input, array $options = array())
|
||||
{
|
||||
$this->input = new ArrayInput($input);
|
||||
if (isset($options['interactive'])) {
|
||||
$this->input->setInteractive($options['interactive']);
|
||||
}
|
||||
|
||||
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
|
||||
if (isset($options['decorated'])) {
|
||||
$this->output->setDecorated($options['decorated']);
|
||||
}
|
||||
if (isset($options['verbosity'])) {
|
||||
$this->output->setVerbosity($options['verbosity']);
|
||||
}
|
||||
|
||||
$ret = $this->command->run($this->input, $this->output);
|
||||
|
||||
rewind($this->output->getStream());
|
||||
|
||||
return $this->display = stream_get_contents($this->output->getStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display returned by the last execution of the command.
|
||||
*
|
||||
* @return string The display
|
||||
*/
|
||||
public function getDisplay()
|
||||
{
|
||||
return $this->display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input instance used by the last execution of the command.
|
||||
*
|
||||
* @return InputInterface The current input instance
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output instance used by the last execution of the command.
|
||||
*
|
||||
* @return OutputInterface The current output instance
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
1
lib/vendor/Symfony/Component/Yaml
vendored
Submodule
1
lib/vendor/Symfony/Component/Yaml
vendored
Submodule
Submodule lib/vendor/Symfony/Component/Yaml added at c3e1d03eff
59
lib/vendor/Symfony/Component/Yaml/Dumper.php
vendored
59
lib/vendor/Symfony/Component/Yaml/Dumper.php
vendored
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dumper dumps PHP variables to YAML strings.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Dumper
|
||||
{
|
||||
/**
|
||||
* Dumps a PHP value to YAML.
|
||||
*
|
||||
* @param mixed $input The PHP value
|
||||
* @param integer $inline The level where you switch to inline YAML
|
||||
* @param integer $indent The level o indentation indentation (used internally)
|
||||
*
|
||||
* @return string The YAML representation of the PHP value
|
||||
*/
|
||||
public function dump($input, $inline = 0, $indent = 0)
|
||||
{
|
||||
$output = '';
|
||||
$prefix = $indent ? str_repeat(' ', $indent) : '';
|
||||
|
||||
if ($inline <= 0 || !is_array($input) || empty($input))
|
||||
{
|
||||
$output .= $prefix.Inline::dump($input);
|
||||
}
|
||||
else
|
||||
{
|
||||
$isAHash = array_keys($input) !== range(0, count($input) - 1);
|
||||
|
||||
foreach ($input as $key => $value)
|
||||
{
|
||||
$willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
|
||||
|
||||
$output .= sprintf('%s%s%s%s',
|
||||
$prefix,
|
||||
$isAHash ? Inline::dump($key).':' : '-',
|
||||
$willBeInlined ? ' ' : "\n",
|
||||
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
|
||||
).($willBeInlined ? "\n" : '');
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
23
lib/vendor/Symfony/Component/Yaml/Exception.php
vendored
23
lib/vendor/Symfony/Component/Yaml/Exception.php
vendored
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class used by all exceptions thrown by the component.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
410
lib/vendor/Symfony/Component/Yaml/Inline.php
vendored
410
lib/vendor/Symfony/Component/Yaml/Inline.php
vendored
@@ -1,410 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Inline implements a YAML parser/dumper for the YAML inline syntax.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Inline
|
||||
{
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
|
||||
|
||||
/**
|
||||
* Convert a YAML string to a PHP array.
|
||||
*
|
||||
* @param string $value A YAML string
|
||||
*
|
||||
* @return array A PHP array representing the YAML string
|
||||
*/
|
||||
static public function load($value)
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if (0 == strlen($value))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
switch ($value[0])
|
||||
{
|
||||
case '[':
|
||||
return self::parseSequence($value);
|
||||
case '{':
|
||||
return self::parseMapping($value);
|
||||
default:
|
||||
return self::parseScalar($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a given PHP variable to a YAML string.
|
||||
*
|
||||
* @param mixed $value The PHP variable to convert
|
||||
*
|
||||
* @return string The YAML string representing the PHP array
|
||||
*/
|
||||
static public function dump($value)
|
||||
{
|
||||
$trueValues = '1.1' == Yaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true');
|
||||
$falseValues = '1.1' == Yaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false');
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case is_resource($value):
|
||||
throw new Exception('Unable to dump PHP resources in a YAML file.');
|
||||
case is_object($value):
|
||||
return '!!php/object:'.serialize($value);
|
||||
case is_array($value):
|
||||
return self::dumpArray($value);
|
||||
case null === $value:
|
||||
return 'null';
|
||||
case true === $value:
|
||||
return 'true';
|
||||
case false === $value:
|
||||
return 'false';
|
||||
case ctype_digit($value):
|
||||
return is_string($value) ? "'$value'" : (int) $value;
|
||||
case is_numeric($value):
|
||||
return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value);
|
||||
case false !== strpos($value, "\n") || false !== strpos($value, "\r"):
|
||||
return sprintf('"%s"', str_replace(array('"', "\n", "\r"), array('\\"', '\n', '\r'), $value));
|
||||
case preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value):
|
||||
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
|
||||
case '' == $value:
|
||||
return "''";
|
||||
case preg_match(self::getTimestampRegex(), $value):
|
||||
return "'$value'";
|
||||
case in_array(strtolower($value), $trueValues):
|
||||
return "'$value'";
|
||||
case in_array(strtolower($value), $falseValues):
|
||||
return "'$value'";
|
||||
case in_array(strtolower($value), array('null', '~')):
|
||||
return "'$value'";
|
||||
default:
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a PHP array to a YAML string.
|
||||
*
|
||||
* @param array $value The PHP array to dump
|
||||
*
|
||||
* @return string The YAML string representing the PHP array
|
||||
*/
|
||||
static protected function dumpArray($value)
|
||||
{
|
||||
// array
|
||||
$keys = array_keys($value);
|
||||
if (
|
||||
(1 == count($keys) && '0' == $keys[0])
|
||||
||
|
||||
(count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (integer) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2))
|
||||
{
|
||||
$output = array();
|
||||
foreach ($value as $val)
|
||||
{
|
||||
$output[] = self::dump($val);
|
||||
}
|
||||
|
||||
return sprintf('[%s]', implode(', ', $output));
|
||||
}
|
||||
|
||||
// mapping
|
||||
$output = array();
|
||||
foreach ($value as $key => $val)
|
||||
{
|
||||
$output[] = sprintf('%s: %s', self::dump($key), self::dump($val));
|
||||
}
|
||||
|
||||
return sprintf('{ %s }', implode(', ', $output));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a scalar to a YAML string.
|
||||
*
|
||||
* @param scalar $scalar
|
||||
* @param string $delimiters
|
||||
* @param array $stringDelimiter
|
||||
* @param integer $i
|
||||
* @param boolean $evaluate
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
static public function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true)
|
||||
{
|
||||
if (in_array($scalar[$i], $stringDelimiters))
|
||||
{
|
||||
// quoted scalar
|
||||
$output = self::parseQuotedScalar($scalar, $i);
|
||||
}
|
||||
else
|
||||
{
|
||||
// "normal" string
|
||||
if (!$delimiters)
|
||||
{
|
||||
$output = substr($scalar, $i);
|
||||
$i += strlen($output);
|
||||
|
||||
// remove comments
|
||||
if (false !== $strpos = strpos($output, ' #'))
|
||||
{
|
||||
$output = rtrim(substr($output, 0, $strpos));
|
||||
}
|
||||
}
|
||||
else if (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match))
|
||||
{
|
||||
$output = $match[1];
|
||||
$i += strlen($output);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ParserException(sprintf('Malformed inline YAML string (%s).', $scalar));
|
||||
}
|
||||
|
||||
$output = $evaluate ? self::evaluateScalar($output) : $output;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a quoted scalar to YAML.
|
||||
*
|
||||
* @param string $scalar
|
||||
* @param integer $i
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
static protected function parseQuotedScalar($scalar, &$i)
|
||||
{
|
||||
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/A', substr($scalar, $i), $match))
|
||||
{
|
||||
throw new ParserException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
|
||||
}
|
||||
|
||||
$output = substr($match[0], 1, strlen($match[0]) - 2);
|
||||
|
||||
if ('"' == $scalar[$i])
|
||||
{
|
||||
// evaluate the string
|
||||
$output = str_replace(array('\\"', '\\n', '\\r'), array('"', "\n", "\r"), $output);
|
||||
}
|
||||
else
|
||||
{
|
||||
// unescape '
|
||||
$output = str_replace('\'\'', '\'', $output);
|
||||
}
|
||||
|
||||
$i += strlen($match[0]);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a sequence to a YAML string.
|
||||
*
|
||||
* @param string $sequence
|
||||
* @param integer $i
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
static protected function parseSequence($sequence, &$i = 0)
|
||||
{
|
||||
$output = array();
|
||||
$len = strlen($sequence);
|
||||
$i += 1;
|
||||
|
||||
// [foo, bar, ...]
|
||||
while ($i < $len)
|
||||
{
|
||||
switch ($sequence[$i])
|
||||
{
|
||||
case '[':
|
||||
// nested sequence
|
||||
$output[] = self::parseSequence($sequence, $i);
|
||||
break;
|
||||
case '{':
|
||||
// nested mapping
|
||||
$output[] = self::parseMapping($sequence, $i);
|
||||
break;
|
||||
case ']':
|
||||
return $output;
|
||||
case ',':
|
||||
case ' ':
|
||||
break;
|
||||
default:
|
||||
$isQuoted = in_array($sequence[$i], array('"', "'"));
|
||||
$value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i);
|
||||
|
||||
if (!$isQuoted && false !== strpos($value, ': '))
|
||||
{
|
||||
// embedded mapping?
|
||||
try
|
||||
{
|
||||
$value = self::parseMapping('{'.$value.'}');
|
||||
}
|
||||
catch (\InvalidArgumentException $e)
|
||||
{
|
||||
// no, it's not
|
||||
}
|
||||
}
|
||||
|
||||
$output[] = $value;
|
||||
|
||||
--$i;
|
||||
}
|
||||
|
||||
++$i;
|
||||
}
|
||||
|
||||
throw new ParserException(sprintf('Malformed inline YAML string %s', $sequence));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a mapping to a YAML string.
|
||||
*
|
||||
* @param string $mapping
|
||||
* @param integer $i
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
static protected function parseMapping($mapping, &$i = 0)
|
||||
{
|
||||
$output = array();
|
||||
$len = strlen($mapping);
|
||||
$i += 1;
|
||||
|
||||
// {foo: bar, bar:foo, ...}
|
||||
while ($i < $len)
|
||||
{
|
||||
switch ($mapping[$i])
|
||||
{
|
||||
case ' ':
|
||||
case ',':
|
||||
++$i;
|
||||
continue 2;
|
||||
case '}':
|
||||
return $output;
|
||||
}
|
||||
|
||||
// key
|
||||
$key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false);
|
||||
|
||||
// value
|
||||
$done = false;
|
||||
while ($i < $len)
|
||||
{
|
||||
switch ($mapping[$i])
|
||||
{
|
||||
case '[':
|
||||
// nested sequence
|
||||
$output[$key] = self::parseSequence($mapping, $i);
|
||||
$done = true;
|
||||
break;
|
||||
case '{':
|
||||
// nested mapping
|
||||
$output[$key] = self::parseMapping($mapping, $i);
|
||||
$done = true;
|
||||
break;
|
||||
case ':':
|
||||
case ' ':
|
||||
break;
|
||||
default:
|
||||
$output[$key] = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i);
|
||||
$done = true;
|
||||
--$i;
|
||||
}
|
||||
|
||||
++$i;
|
||||
|
||||
if ($done)
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ParserException(sprintf('Malformed inline YAML string %s', $mapping));
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates scalars and replaces magic values.
|
||||
*
|
||||
* @param string $scalar
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
static protected function evaluateScalar($scalar)
|
||||
{
|
||||
$scalar = trim($scalar);
|
||||
|
||||
$trueValues = '1.1' == Yaml::getSpecVersion() ? array('true', 'on', '+', 'yes', 'y') : array('true');
|
||||
$falseValues = '1.1' == Yaml::getSpecVersion() ? array('false', 'off', '-', 'no', 'n') : array('false');
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case 'null' == strtolower($scalar):
|
||||
case '' == $scalar:
|
||||
case '~' == $scalar:
|
||||
return null;
|
||||
case 0 === strpos($scalar, '!str'):
|
||||
return (string) substr($scalar, 5);
|
||||
case 0 === strpos($scalar, '! '):
|
||||
return intval(self::parseScalar(substr($scalar, 2)));
|
||||
case 0 === strpos($scalar, '!!php/object:'):
|
||||
return unserialize(substr($scalar, 13));
|
||||
case ctype_digit($scalar):
|
||||
$raw = $scalar;
|
||||
$cast = intval($scalar);
|
||||
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
|
||||
case in_array(strtolower($scalar), $trueValues):
|
||||
return true;
|
||||
case in_array(strtolower($scalar), $falseValues):
|
||||
return false;
|
||||
case is_numeric($scalar):
|
||||
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
|
||||
case 0 == strcasecmp($scalar, '.inf'):
|
||||
case 0 == strcasecmp($scalar, '.NaN'):
|
||||
return -log(0);
|
||||
case 0 == strcasecmp($scalar, '-.inf'):
|
||||
return log(0);
|
||||
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
|
||||
return floatval(str_replace(',', '', $scalar));
|
||||
case preg_match(self::getTimestampRegex(), $scalar):
|
||||
return strtotime($scalar);
|
||||
default:
|
||||
return (string) $scalar;
|
||||
}
|
||||
}
|
||||
|
||||
static protected function getTimestampRegex()
|
||||
{
|
||||
return <<<EOF
|
||||
~^
|
||||
(?P<year>[0-9][0-9][0-9][0-9])
|
||||
-(?P<month>[0-9][0-9]?)
|
||||
-(?P<day>[0-9][0-9]?)
|
||||
(?:(?:[Tt]|[ \t]+)
|
||||
(?P<hour>[0-9][0-9]?)
|
||||
:(?P<minute>[0-9][0-9])
|
||||
:(?P<second>[0-9][0-9])
|
||||
(?:\.(?P<fraction>[0-9]*))?
|
||||
(?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
|
||||
(?::(?P<tz_minute>[0-9][0-9]))?))?)?
|
||||
$~x
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
587
lib/vendor/Symfony/Component/Yaml/Parser.php
vendored
587
lib/vendor/Symfony/Component/Yaml/Parser.php
vendored
@@ -1,587 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parser parses YAML strings to convert them to PHP arrays.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
protected $offset = 0;
|
||||
protected $lines = array();
|
||||
protected $currentLineNb = -1;
|
||||
protected $currentLine = '';
|
||||
protected $refs = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param integer $offset The offset of YAML document (used for line numbers in error messages)
|
||||
*/
|
||||
public function __construct($offset = 0)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a YAML string to a PHP value.
|
||||
*
|
||||
* @param string $value A YAML string
|
||||
*
|
||||
* @return mixed A PHP value
|
||||
*
|
||||
* @throws \InvalidArgumentException If the YAML is not valid
|
||||
*/
|
||||
public function parse($value)
|
||||
{
|
||||
$this->currentLineNb = -1;
|
||||
$this->currentLine = '';
|
||||
$this->lines = explode("\n", $this->cleanup($value));
|
||||
|
||||
$data = array();
|
||||
while ($this->moveToNextLine())
|
||||
{
|
||||
if ($this->isCurrentLineEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// tab?
|
||||
if (preg_match('#^\t+#', $this->currentLine))
|
||||
{
|
||||
throw new ParserException(sprintf('A YAML file cannot contain tabs as indentation at line %d (%s).', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
|
||||
$isRef = $isInPlace = $isProcessed = false;
|
||||
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#', $this->currentLine, $values))
|
||||
{
|
||||
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches))
|
||||
{
|
||||
$isRef = $matches['ref'];
|
||||
$values['value'] = $matches['value'];
|
||||
}
|
||||
|
||||
// array
|
||||
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
|
||||
{
|
||||
$c = $this->getRealCurrentLineNb() + 1;
|
||||
$parser = new Parser($c);
|
||||
$parser->refs =& $this->refs;
|
||||
$data[] = $parser->parse($this->getNextEmbedBlock());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($values['leadspaces'])
|
||||
&& ' ' == $values['leadspaces']
|
||||
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
|
||||
{
|
||||
// this is a compact notation element, add to next block and parse
|
||||
$c = $this->getRealCurrentLineNb();
|
||||
$parser = new Parser($c);
|
||||
$parser->refs =& $this->refs;
|
||||
|
||||
$block = $values['value'];
|
||||
if (!$this->isNextLineIndented())
|
||||
{
|
||||
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
|
||||
}
|
||||
|
||||
$data[] = $parser->parse($block);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data[] = $this->parseValue($values['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
|
||||
{
|
||||
$key = Inline::parseScalar($values['key']);
|
||||
|
||||
if ('<<' === $key)
|
||||
{
|
||||
if (isset($values['value']) && '*' === substr($values['value'], 0, 1))
|
||||
{
|
||||
$isInPlace = substr($values['value'], 1);
|
||||
if (!array_key_exists($isInPlace, $this->refs))
|
||||
{
|
||||
throw new ParserException(sprintf('Reference "%s" does not exist at line %s (%s).', $isInPlace, $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($values['value']) && $values['value'] !== '')
|
||||
{
|
||||
$value = $values['value'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = $this->getNextEmbedBlock();
|
||||
}
|
||||
$c = $this->getRealCurrentLineNb() + 1;
|
||||
$parser = new Parser($c);
|
||||
$parser->refs =& $this->refs;
|
||||
$parsed = $parser->parse($value);
|
||||
|
||||
$merged = array();
|
||||
if (!is_array($parsed))
|
||||
{
|
||||
throw new ParserException(sprintf("YAML merge keys used with a scalar value instead of an array at line %s (%s)", $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
else if (isset($parsed[0]))
|
||||
{
|
||||
// Numeric array, merge individual elements
|
||||
foreach (array_reverse($parsed) as $parsedItem)
|
||||
{
|
||||
if (!is_array($parsedItem))
|
||||
{
|
||||
throw new ParserException(sprintf("Merge items must be arrays at line %s (%s).", $this->getRealCurrentLineNb() + 1, $parsedItem));
|
||||
}
|
||||
$merged = array_merge($parsedItem, $merged);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Associative array, merge
|
||||
$merged = array_merge($merge, $parsed);
|
||||
}
|
||||
|
||||
$isProcessed = $merged;
|
||||
}
|
||||
}
|
||||
else if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches))
|
||||
{
|
||||
$isRef = $matches['ref'];
|
||||
$values['value'] = $matches['value'];
|
||||
}
|
||||
|
||||
if ($isProcessed)
|
||||
{
|
||||
// Merge keys
|
||||
$data = $isProcessed;
|
||||
}
|
||||
// hash
|
||||
else if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#'))
|
||||
{
|
||||
// if next line is less indented or equal, then it means that the current value is null
|
||||
if ($this->isNextLineIndented())
|
||||
{
|
||||
$data[$key] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c = $this->getRealCurrentLineNb() + 1;
|
||||
$parser = new Parser($c);
|
||||
$parser->refs =& $this->refs;
|
||||
$data[$key] = $parser->parse($this->getNextEmbedBlock());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($isInPlace)
|
||||
{
|
||||
$data = $this->refs[$isInPlace];
|
||||
}
|
||||
else
|
||||
{
|
||||
$data[$key] = $this->parseValue($values['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1-liner followed by newline
|
||||
if (2 == count($this->lines) && empty($this->lines[1]))
|
||||
{
|
||||
$value = Inline::load($this->lines[0]);
|
||||
if (is_array($value))
|
||||
{
|
||||
$first = reset($value);
|
||||
if ('*' === substr($first, 0, 1))
|
||||
{
|
||||
$data = array();
|
||||
foreach ($value as $alias)
|
||||
{
|
||||
$data[] = $this->refs[substr($alias, 1)];
|
||||
}
|
||||
$value = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
switch (preg_last_error())
|
||||
{
|
||||
case PREG_INTERNAL_ERROR:
|
||||
$error = 'Internal PCRE error on line';
|
||||
break;
|
||||
case PREG_BACKTRACK_LIMIT_ERROR:
|
||||
$error = 'pcre.backtrack_limit reached on line';
|
||||
break;
|
||||
case PREG_RECURSION_LIMIT_ERROR:
|
||||
$error = 'pcre.recursion_limit reached on line';
|
||||
break;
|
||||
case PREG_BAD_UTF8_ERROR:
|
||||
$error = 'Malformed UTF-8 data on line';
|
||||
break;
|
||||
case PREG_BAD_UTF8_OFFSET_ERROR:
|
||||
$error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point on line';
|
||||
break;
|
||||
default:
|
||||
$error = 'Unable to parse line';
|
||||
}
|
||||
|
||||
throw new ParserException(sprintf('%s %d (%s).', $error, $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
|
||||
if ($isRef)
|
||||
{
|
||||
$this->refs[$isRef] = end($data);
|
||||
}
|
||||
}
|
||||
|
||||
return empty($data) ? null : $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current line number (takes the offset into account).
|
||||
*
|
||||
* @return integer The current line number
|
||||
*/
|
||||
protected function getRealCurrentLineNb()
|
||||
{
|
||||
return $this->currentLineNb + $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current line indentation.
|
||||
*
|
||||
* @return integer The current line indentation
|
||||
*/
|
||||
protected function getCurrentLineIndentation()
|
||||
{
|
||||
return strlen($this->currentLine) - strlen(ltrim($this->currentLine, ' '));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next embed block of YAML.
|
||||
*
|
||||
* @param integer $indentation The indent level at which the block is to be read, or null for default
|
||||
*
|
||||
* @return string A YAML string
|
||||
*/
|
||||
protected function getNextEmbedBlock($indentation = null)
|
||||
{
|
||||
$this->moveToNextLine();
|
||||
|
||||
if (null === $indentation)
|
||||
{
|
||||
$newIndent = $this->getCurrentLineIndentation();
|
||||
|
||||
if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
|
||||
{
|
||||
throw new ParserException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$newIndent = $indentation;
|
||||
}
|
||||
|
||||
$data = array(substr($this->currentLine, $newIndent));
|
||||
|
||||
while ($this->moveToNextLine())
|
||||
{
|
||||
if ($this->isCurrentLineEmpty())
|
||||
{
|
||||
if ($this->isCurrentLineBlank())
|
||||
{
|
||||
$data[] = substr($this->currentLine, $newIndent);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$indent = $this->getCurrentLineIndentation();
|
||||
|
||||
if (preg_match('#^(?P<text> *)$#', $this->currentLine, $match))
|
||||
{
|
||||
// empty line
|
||||
$data[] = $match['text'];
|
||||
}
|
||||
else if ($indent >= $newIndent)
|
||||
{
|
||||
$data[] = substr($this->currentLine, $newIndent);
|
||||
}
|
||||
else if (0 == $indent)
|
||||
{
|
||||
$this->moveToPreviousLine();
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ParserException(sprintf('Indentation problem at line %d (%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the parser to the next line.
|
||||
*/
|
||||
protected function moveToNextLine()
|
||||
{
|
||||
if ($this->currentLineNb >= count($this->lines) - 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->currentLine = $this->lines[++$this->currentLineNb];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the parser to the previous line.
|
||||
*/
|
||||
protected function moveToPreviousLine()
|
||||
{
|
||||
$this->currentLine = $this->lines[--$this->currentLineNb];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a YAML value.
|
||||
*
|
||||
* @param string $value A YAML value
|
||||
*
|
||||
* @return mixed A PHP value
|
||||
*/
|
||||
protected function parseValue($value)
|
||||
{
|
||||
if ('*' === substr($value, 0, 1))
|
||||
{
|
||||
if (false !== $pos = strpos($value, '#'))
|
||||
{
|
||||
$value = substr($value, 1, $pos - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
if (!array_key_exists($value, $this->refs))
|
||||
{
|
||||
throw new ParserException(sprintf('Reference "%s" does not exist (%s).', $value, $this->currentLine));
|
||||
}
|
||||
return $this->refs[$value];
|
||||
}
|
||||
|
||||
if (preg_match('/^(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?$/', $value, $matches))
|
||||
{
|
||||
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
|
||||
|
||||
return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Inline::load($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a folded scalar.
|
||||
*
|
||||
* @param string $separator The separator that was used to begin this folded scalar (| or >)
|
||||
* @param string $indicator The indicator that was used to begin this folded scalar (+ or -)
|
||||
* @param integer $indentation The indentation that was used to begin this folded scalar
|
||||
*
|
||||
* @return string The text value
|
||||
*/
|
||||
protected function parseFoldedScalar($separator, $indicator = '', $indentation = 0)
|
||||
{
|
||||
$separator = '|' == $separator ? "\n" : ' ';
|
||||
$text = '';
|
||||
|
||||
$notEOF = $this->moveToNextLine();
|
||||
|
||||
while ($notEOF && $this->isCurrentLineBlank())
|
||||
{
|
||||
$text .= "\n";
|
||||
|
||||
$notEOF = $this->moveToNextLine();
|
||||
}
|
||||
|
||||
if (!$notEOF)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#', $this->currentLine, $matches))
|
||||
{
|
||||
$this->moveToPreviousLine();
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$textIndent = $matches['indent'];
|
||||
$previousIndent = 0;
|
||||
|
||||
$text .= $matches['text'].$separator;
|
||||
while ($this->currentLineNb + 1 < count($this->lines))
|
||||
{
|
||||
$this->moveToNextLine();
|
||||
|
||||
if (preg_match('#^(?P<indent> {'.strlen($textIndent).',})(?P<text>.+)$#', $this->currentLine, $matches))
|
||||
{
|
||||
if (' ' == $separator && $previousIndent != $matches['indent'])
|
||||
{
|
||||
$text = substr($text, 0, -1)."\n";
|
||||
}
|
||||
$previousIndent = $matches['indent'];
|
||||
|
||||
$text .= str_repeat(' ', $diff = strlen($matches['indent']) - strlen($textIndent)).$matches['text'].($diff ? "\n" : $separator);
|
||||
}
|
||||
else if (preg_match('#^(?P<text> *)$#', $this->currentLine, $matches))
|
||||
{
|
||||
$text .= preg_replace('#^ {1,'.strlen($textIndent).'}#', '', $matches['text'])."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->moveToPreviousLine();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (' ' == $separator)
|
||||
{
|
||||
// replace last separator by a newline
|
||||
$text = preg_replace('/ (\n*)$/', "\n$1", $text);
|
||||
}
|
||||
|
||||
switch ($indicator)
|
||||
{
|
||||
case '':
|
||||
$text = preg_replace('#\n+$#s', "\n", $text);
|
||||
break;
|
||||
case '+':
|
||||
break;
|
||||
case '-':
|
||||
$text = preg_replace('#\n+$#s', '', $text);
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the next line is indented.
|
||||
*
|
||||
* @return Boolean Returns true if the next line is indented, false otherwise
|
||||
*/
|
||||
protected function isNextLineIndented()
|
||||
{
|
||||
$currentIndentation = $this->getCurrentLineIndentation();
|
||||
$notEOF = $this->moveToNextLine();
|
||||
|
||||
while ($notEOF && $this->isCurrentLineEmpty())
|
||||
{
|
||||
$notEOF = $this->moveToNextLine();
|
||||
}
|
||||
|
||||
if (false === $notEOF)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$ret = false;
|
||||
if ($this->getCurrentLineIndentation() <= $currentIndentation)
|
||||
{
|
||||
$ret = true;
|
||||
}
|
||||
|
||||
$this->moveToPreviousLine();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is blank or if it is a comment line.
|
||||
*
|
||||
* @return Boolean Returns true if the current line is empty or if it is a comment line, false otherwise
|
||||
*/
|
||||
protected function isCurrentLineEmpty()
|
||||
{
|
||||
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is blank.
|
||||
*
|
||||
* @return Boolean Returns true if the current line is blank, false otherwise
|
||||
*/
|
||||
protected function isCurrentLineBlank()
|
||||
{
|
||||
return '' == trim($this->currentLine, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is a comment line.
|
||||
*
|
||||
* @return Boolean Returns true if the current line is a comment line, false otherwise
|
||||
*/
|
||||
protected function isCurrentLineComment()
|
||||
{
|
||||
//checking explicitly the first char of the trim is faster than loops or strpos
|
||||
$ltrimmedLine = ltrim($this->currentLine, ' ');
|
||||
return $ltrimmedLine[0] === '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanups a YAML string to be parsed.
|
||||
*
|
||||
* @param string $value The input YAML string
|
||||
*
|
||||
* @return string A cleaned up YAML string
|
||||
*/
|
||||
protected function cleanup($value)
|
||||
{
|
||||
$value = str_replace(array("\r\n", "\r"), "\n", $value);
|
||||
|
||||
if (!preg_match("#\n$#", $value))
|
||||
{
|
||||
$value .= "\n";
|
||||
}
|
||||
|
||||
// strip YAML header
|
||||
$count = 0;
|
||||
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value, -1, $count);
|
||||
$this->offset += $count;
|
||||
|
||||
// remove leading comments and/or ---
|
||||
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#s', '', $value, -1, $count);
|
||||
if ($count == 1)
|
||||
{
|
||||
// items have been removed, update the offset
|
||||
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
||||
$value = $trimmedValue;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception class used by all exceptions thrown by the component.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class ParserException extends Exception
|
||||
{
|
||||
}
|
||||
121
lib/vendor/Symfony/Component/Yaml/Yaml.php
vendored
121
lib/vendor/Symfony/Component/Yaml/Yaml.php
vendored
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Yaml;
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Yaml offers convenience methods to load and dump YAML.
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage yaml
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class Yaml
|
||||
{
|
||||
static protected $spec = '1.2';
|
||||
|
||||
/**
|
||||
* Sets the YAML specification version to use.
|
||||
*
|
||||
* @param string $version The YAML specification version
|
||||
*/
|
||||
static public function setSpecVersion($version)
|
||||
{
|
||||
if (!in_array($version, array('1.1', '1.2')))
|
||||
{
|
||||
throw new \InvalidArgumentException(sprintf('Version %s of the YAML specifications is not supported', $version));
|
||||
}
|
||||
|
||||
self::$spec = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the YAML specification version to use.
|
||||
*
|
||||
* @return string The YAML specification version
|
||||
*/
|
||||
static public function getSpecVersion()
|
||||
{
|
||||
return self::$spec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads YAML into a PHP array.
|
||||
*
|
||||
* The load method, when supplied with a YAML stream (string or file),
|
||||
* will do its best to convert YAML in a file into a PHP array.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $array = Yaml::load('config.yml');
|
||||
* print_r($array);
|
||||
* </code>
|
||||
*
|
||||
* @param string $input Path of YAML file or string containing YAML
|
||||
*
|
||||
* @return array The YAML converted to a PHP array
|
||||
*
|
||||
* @throws \InvalidArgumentException If the YAML is not valid
|
||||
*/
|
||||
public static function load($input)
|
||||
{
|
||||
$file = '';
|
||||
|
||||
// if input is a file, process it
|
||||
if (strpos($input, "\n") === false && is_file($input))
|
||||
{
|
||||
$file = $input;
|
||||
|
||||
ob_start();
|
||||
$retval = include($input);
|
||||
$content = ob_get_clean();
|
||||
|
||||
// if an array is returned by the config file assume it's in plain php form else in YAML
|
||||
$input = is_array($retval) ? $retval : $content;
|
||||
}
|
||||
|
||||
// if an array is returned by the config file assume it's in plain php form else in YAML
|
||||
if (is_array($input))
|
||||
{
|
||||
return $input;
|
||||
}
|
||||
|
||||
$yaml = new Parser();
|
||||
|
||||
try
|
||||
{
|
||||
$ret = $yaml->parse($input);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
throw new \InvalidArgumentException(sprintf('Unable to parse %s: %s', $file ? sprintf('file "%s"', $file) : 'string', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a PHP array to a YAML string.
|
||||
*
|
||||
* The dump method, when supplied with an array, will do its best
|
||||
* to convert the array into friendly YAML.
|
||||
*
|
||||
* @param array $array PHP array
|
||||
* @param integer $inline The level where you switch to inline YAML
|
||||
*
|
||||
* @return string A YAML string representing the original PHP array
|
||||
*/
|
||||
public static function dump($array, $inline = 2)
|
||||
{
|
||||
$yaml = new Dumper();
|
||||
|
||||
return $yaml->dump($array, $inline);
|
||||
}
|
||||
}
|
||||
2
lib/vendor/doctrine-common
vendored
2
lib/vendor/doctrine-common
vendored
Submodule lib/vendor/doctrine-common updated: 9eb66b7cf9...ffd9dc7460
2
lib/vendor/doctrine-dbal
vendored
2
lib/vendor/doctrine-dbal
vendored
Submodule lib/vendor/doctrine-dbal updated: e97fbbf755...71a3109738
@@ -55,6 +55,9 @@ class ECommerceProduct
|
||||
*/
|
||||
private $related;
|
||||
|
||||
public $isCloned = false;
|
||||
public $wakeUp = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->features = new ArrayCollection;
|
||||
@@ -159,4 +162,17 @@ class ECommerceProduct
|
||||
$related->removeRelated($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->isCloned = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing docblock contents here
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->wakeUp = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,40 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1230
|
||||
*/
|
||||
public function testRemove()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
$user->name = 'Guilherme';
|
||||
$user->username = 'gblanco';
|
||||
$user->status = 'developer';
|
||||
|
||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
|
||||
|
||||
$this->_em->persist($user);
|
||||
|
||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user));
|
||||
|
||||
$this->_em->remove($user);
|
||||
|
||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
$id = $user->getId();
|
||||
|
||||
$this->_em->remove($user);
|
||||
|
||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_REMOVED, $this->_em->getUnitOfWork()->getEntityState($user));
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user));
|
||||
|
||||
$this->assertNull($this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $id));
|
||||
}
|
||||
|
||||
public function testOneToManyOrphanRemoval()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
@@ -827,36 +861,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses where id=".$addressId.""));
|
||||
}
|
||||
|
||||
public function testClearingCollectionDoesNotInitialize()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->username = "beberlei";
|
||||
$user->name = "Benjamin E.";
|
||||
$user->status = 'active';
|
||||
|
||||
$grp = new CmsGroup();
|
||||
$grp->setName("The Dudes");
|
||||
|
||||
$grp->addUser($user);
|
||||
$user->addGroup($grp);
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->persist($grp);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups"));
|
||||
|
||||
$user2 = $this->_em->find(get_class($user), $user->id);
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
$user2->groups->clear();
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
$this->_em->flush();
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
|
||||
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups"));
|
||||
}
|
||||
|
||||
public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt()
|
||||
{
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
|
||||
@@ -410,4 +410,29 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId());
|
||||
$this->assertType('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-992
|
||||
*/
|
||||
public function testGetSubClassManyToManyCollection()
|
||||
{
|
||||
$manager = new CompanyManager();
|
||||
$manager->setName('gblanco');
|
||||
$manager->setSalary(1234);
|
||||
$manager->setTitle('Awesome!');
|
||||
$manager->setDepartment('IT');
|
||||
|
||||
$person = new CompanyPerson();
|
||||
$person->setName('friend');
|
||||
|
||||
$manager->addFriend($person);
|
||||
|
||||
$this->_em->persist($manager);
|
||||
$this->_em->persist($person);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId());
|
||||
$this->assertEquals(1, count($manager->getFriends()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,9 +104,42 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertArrayHasKey('user', $metadatas['CmsGroups']->associationMappings);
|
||||
}
|
||||
|
||||
public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails()
|
||||
{
|
||||
$tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar");
|
||||
$tableB->addColumn('id', 'integer');
|
||||
$tableB->setPrimaryKey(array('id'));
|
||||
|
||||
$tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz");
|
||||
$tableA->addColumn('id', 'integer');
|
||||
$tableA->setPrimaryKey(array('id'));
|
||||
|
||||
$tableMany = new \Doctrine\DBAL\Schema\Table("dbdriver_bar_baz");
|
||||
$tableMany->addColumn('bar_id', 'integer');
|
||||
$tableMany->addColumn('baz_id', 'integer');
|
||||
$tableMany->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id'));
|
||||
|
||||
$metadatas = $this->convertToClassMetadata(array($tableA, $tableB), array($tableMany));
|
||||
|
||||
$this->assertEquals(0, count($metadatas['DbdriverBaz']->associationMappings), "no association mappings should be detected.");
|
||||
}
|
||||
|
||||
protected function convertToClassMetadata(array $entityTables, array $manyTables = array())
|
||||
{
|
||||
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm);
|
||||
$driver->setTables($entityTables, $manyTables);
|
||||
|
||||
$metadatas = array();
|
||||
foreach ($driver->getAllClassNames() AS $className) {
|
||||
$class = new ClassMetadataInfo($className);
|
||||
$driver->loadMetadataForClass($className, $class);
|
||||
$metadatas[$className] = $class;
|
||||
}
|
||||
|
||||
return $metadatas;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $className
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
|
||||
@@ -290,5 +290,17 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertType('Doctrine\Tests\Models\CMS\CmsAddress', $address);
|
||||
$this->assertEquals($addressId, $address->id);
|
||||
}
|
||||
/**
|
||||
* @group DDC-1087
|
||||
*/
|
||||
public function testIsNullCriteria()
|
||||
{
|
||||
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
|
||||
$users = $repos->findBy(array('status' => null, 'username' => 'romanb'));
|
||||
|
||||
$params = $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params'];
|
||||
$this->assertEquals(1, count($params), "Should only execute with one parameter.");
|
||||
$this->assertEquals(array('romanb'), $params);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,27 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertTrue($reference->postLoadCallbackInvoked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-958
|
||||
*/
|
||||
public function testPostLoadTriggeredOnRefresh()
|
||||
{
|
||||
$entity = new LifecycleCallbackTestEntity;
|
||||
$entity->value = 'hello';
|
||||
$this->_em->persist($entity);
|
||||
$this->_em->flush();
|
||||
$id = $entity->getId();
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$reference = $this->_em->find('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id);
|
||||
$this->assertTrue($reference->postLoadCallbackInvoked);
|
||||
$reference->postLoadCallbackInvoked = false;
|
||||
|
||||
$this->_em->refresh($reference);
|
||||
$this->assertTrue($reference->postLoadCallbackInvoked, "postLoad should be invoked when refresh() is called.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-113
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Tests\Models\CMS\CmsUser,
|
||||
Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
Doctrine\Tests\Models\CMS\CmsGroup,
|
||||
Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
@@ -299,4 +300,81 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-980
|
||||
*/
|
||||
public function testUpdateDeleteSizeSubselectQueries()
|
||||
{
|
||||
$this->_em->createQuery("DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10")->execute();
|
||||
$this->_em->createQuery("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10")->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-978
|
||||
*/
|
||||
public function testClearAndResetCollection()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
$group1 = new CmsGroup;
|
||||
$group1->name = 'Developers_New1';
|
||||
$group2 = new CmsGroup;
|
||||
$group2->name = 'Developers_New2';
|
||||
|
||||
$this->_em->persist($group1);
|
||||
$this->_em->persist($group2);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$coll = new ArrayCollection(array($group1, $group2));
|
||||
$user->groups = $coll;
|
||||
$this->_em->flush();
|
||||
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups,
|
||||
"UnitOfWork should have replaced ArrayCollection with PersistentCollection.");
|
||||
$this->_em->flush();
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
$this->assertEquals(2, count($user->groups));
|
||||
$this->assertEquals('Developers_New1', $user->groups[0]->name);
|
||||
$this->assertEquals('Developers_New2', $user->groups[1]->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-733
|
||||
*/
|
||||
public function testInitializePersistentCollection()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
|
||||
$this->assertFalse($user->groups->isInitialized(), "Pre-condition: lazy collection");
|
||||
$this->_em->getUnitOfWork()->initializeObject($user->groups);
|
||||
$this->assertTrue($user->groups->isInitialized(), "Collection should be initialized after calling UnitOfWork::initializeObject()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1189
|
||||
* @group DDC-956
|
||||
*/
|
||||
public function testClearBeforeLazyLoad()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(4);
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
$user->groups->clear();
|
||||
$this->assertEquals(0, count($user->groups));
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
$this->assertEquals(0, count($user->groups));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\Tests\Models\CMS\CmsUser,
|
||||
Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
@@ -135,6 +137,39 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$users = $q->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1070
|
||||
*/
|
||||
public function testIterateResultAsArrayAndParams()
|
||||
{
|
||||
$article1 = new CmsArticle;
|
||||
$article1->topic = "Doctrine 2";
|
||||
$article1->text = "This is an introduction to Doctrine 2.";
|
||||
|
||||
$article2 = new CmsArticle;
|
||||
$article2->topic = "Symfony 2";
|
||||
$article2->text = "This is an introduction to Symfony 2.";
|
||||
|
||||
$this->_em->persist($article1);
|
||||
$this->_em->persist($article2);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
$articleId = $article1->id;
|
||||
|
||||
$query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1");
|
||||
$articles = $query->iterate(array(1 => 'Doctrine 2'), Query::HYDRATE_ARRAY);
|
||||
|
||||
$found = array();
|
||||
foreach ($articles AS $article) {
|
||||
$found[] = $article;
|
||||
}
|
||||
$this->assertEquals(1, count($found));
|
||||
$this->assertEquals(array(
|
||||
array(array('id' => $articleId, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1))
|
||||
), $found);
|
||||
}
|
||||
|
||||
public function testIterateResult_IterativelyBuildUpUnitOfWork()
|
||||
{
|
||||
$article1 = new CmsArticle;
|
||||
|
||||
@@ -26,7 +26,7 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
true);
|
||||
}
|
||||
|
||||
public function testLazyLoadsFieldValuesFromDatabase()
|
||||
public function createProduct()
|
||||
{
|
||||
$product = new ECommerceProduct();
|
||||
$product->setName('Doctrine Cookbook');
|
||||
@@ -34,8 +34,13 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$id = $product->getId();
|
||||
|
||||
return $product->getId();
|
||||
}
|
||||
|
||||
public function testLazyLoadsFieldValuesFromDatabase()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
$productProxy = $this->_factory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id));
|
||||
$this->assertEquals('Doctrine Cookbook', $productProxy->getName());
|
||||
@@ -46,9 +51,100 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
*/
|
||||
public function testAccessMetatadaForProxy()
|
||||
{
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , 1);
|
||||
$id = $this->createProduct();
|
||||
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$class = $this->_em->getClassMetadata(get_class($entity));
|
||||
|
||||
$this->assertEquals('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $class->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1033
|
||||
*/
|
||||
public function testReferenceFind()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$entity2 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
|
||||
$this->assertSame($entity, $entity2);
|
||||
$this->assertEquals('Doctrine Cookbook', $entity2->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1033
|
||||
*/
|
||||
public function testCloneProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
|
||||
/* @var $clone Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$clone = clone $entity;
|
||||
|
||||
$this->assertEquals($id, $entity->getId());
|
||||
$this->assertEquals('Doctrine Cookbook', $entity->getName());
|
||||
|
||||
$this->assertFalse($this->_em->contains($clone), "Cloning a reference proxy should return an unmanaged/detached entity.");
|
||||
$this->assertEquals($id, $clone->getId(), "Cloning a reference proxy should return same id.");
|
||||
$this->assertEquals('Doctrine Cookbook', $clone->getName(), "Cloning a reference proxy should return same product name.");
|
||||
|
||||
// domain logic, Product::__clone sets isCloned public property
|
||||
$this->assertTrue($clone->isCloned);
|
||||
$this->assertFalse($entity->isCloned);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-733
|
||||
*/
|
||||
public function testInitializeProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
|
||||
$this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy.");
|
||||
$this->_em->getUnitOfWork()->initializeObject($entity);
|
||||
$this->assertTrue($entity->__isInitialized__, "Should be initialized after called UnitOfWork::initializeObject()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1163
|
||||
*/
|
||||
public function testInitializeChangeAndFlushProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$entity->setName('Doctrine 2 Cookbook');
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
$this->assertEquals('Doctrine 2 Cookbook', $entity->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1022
|
||||
*/
|
||||
public function testWakeupCalledOnProxy()
|
||||
{
|
||||
$id = $this->createProduct();
|
||||
|
||||
/* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */
|
||||
$entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id);
|
||||
|
||||
$this->assertFalse($entity->wakeUp);
|
||||
|
||||
$entity->setName('Doctrine 2 Cookbook');
|
||||
|
||||
$this->assertTrue($entity->wakeUp, "Loading the proxy should call __wakeup().");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,35 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->getConfiguration()->setResultCacheImpl(new ArrayCache());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1026
|
||||
*/
|
||||
public function testUseResultCacheParams()
|
||||
{
|
||||
$cache = new \Doctrine\Common\Cache\ArrayCache();
|
||||
$this->_em->getConfiguration()->setResultCacheImpl($cache);
|
||||
|
||||
$sqlCount = count($this->_sqlLoggerStack->queries);
|
||||
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1');
|
||||
$query->setParameter(1, 1);
|
||||
$query->useResultCache(true);
|
||||
$query->getResult();
|
||||
|
||||
$query->setParameter(1, 2);
|
||||
$query->getResult();
|
||||
|
||||
$this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "Two non-cached queries.");
|
||||
|
||||
$query->setParameter(1, 1);
|
||||
$query->useResultCache(true);
|
||||
$query->getResult();
|
||||
|
||||
$query->setParameter(1, 2);
|
||||
$query->getResult();
|
||||
|
||||
$this->assertEquals($sqlCount + 2, count($this->_sqlLoggerStack->queries), "The next two sql should have been cached, but were not.");
|
||||
}
|
||||
|
||||
public function testNativeQueryResultCaching()
|
||||
{
|
||||
$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
|
||||
|
||||
@@ -19,6 +19,7 @@ class AllTests
|
||||
{
|
||||
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Orm Functional Tools');
|
||||
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\CompanySchemaTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\MySqlSchemaToolTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\PostgreSqlSchemaToolTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SchemaTool\DDC214Test');
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\SchemaTool;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* Functional tests for the Class Table Inheritance mapping strategy.
|
||||
*
|
||||
* @author robo
|
||||
*/
|
||||
class CompanySchemaTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('company');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-966
|
||||
* @return Schema
|
||||
*/
|
||||
public function testGeneratedSchema()
|
||||
{
|
||||
$schema = $this->_em->getConnection()->getSchemaManager()->createSchema();
|
||||
|
||||
$this->assertTrue($schema->hasTable('company_contracts'));
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-966
|
||||
* @depends testGeneratedSchema
|
||||
*/
|
||||
public function testSingleTableInheritance(Schema $schema)
|
||||
{
|
||||
$table = $schema->getTable('company_contracts');
|
||||
|
||||
// Check nullability constraints
|
||||
$this->assertTrue($table->getColumn('id')->getNotnull());
|
||||
$this->assertTrue($table->getColumn('completed')->getNotnull());
|
||||
$this->assertFalse($table->getColumn('salesPerson_id')->getNotnull());
|
||||
$this->assertTrue($table->getColumn('discr')->getNotnull());
|
||||
$this->assertFalse($table->getColumn('fixPrice')->getNotnull());
|
||||
$this->assertFalse($table->getColumn('hoursWorked')->getNotnull());
|
||||
$this->assertFalse($table->getColumn('pricePerHour')->getNotnull());
|
||||
$this->assertFalse($table->getColumn('maxPrice')->getNotnull());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DBAL-115
|
||||
*/
|
||||
public function testDropPartSchemaWithForeignKeys()
|
||||
{
|
||||
if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped("Foreign Key test");
|
||||
}
|
||||
|
||||
$sql = $this->_schemaTool->getDropSchemaSQL(array(
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyManager'),
|
||||
));
|
||||
$this->assertEquals(3, count($sql));
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,10 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$tool = new SchemaTool($this->_em);
|
||||
$sql = $tool->getCreateSchemaSql($classes);
|
||||
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX cms_addresses_user_id_uniq (user_id), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX cms_users_username_uniq (username), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX cms_users_groups_user_id_idx (user_id), INDEX cms_users_groups_group_id_idx (group_id), PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[2]);
|
||||
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX cms_phonenumbers_user_id_idx (user_id), PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
|
||||
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, UNIQUE INDEX UNIQ_ACAC157BA76ED395 (user_id), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AF03EC5F85E0677 (username), PRIMARY KEY(id)) ENGINE = InnoDB", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_7EA9409AA76ED395 (user_id), INDEX IDX_7EA9409AFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[2]);
|
||||
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_F21F790FA76ED395 (user_id), PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
|
||||
$this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[4]);
|
||||
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[5]);
|
||||
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id)", $sql[6]);
|
||||
|
||||
@@ -34,14 +34,14 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$sql = $tool->getCreateSchemaSql($classes);
|
||||
|
||||
$this->assertEquals("CREATE TABLE cms_addresses (id INT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, PRIMARY KEY(id))", $sql[0]);
|
||||
$this->assertEquals("CREATE UNIQUE INDEX cms_addresses_user_id_uniq ON cms_addresses (user_id)", $sql[1]);
|
||||
$this->assertEquals("CREATE UNIQUE INDEX UNIQ_ACAC157BA76ED395 ON cms_addresses (user_id)", $sql[1]);
|
||||
$this->assertEquals("CREATE TABLE cms_users (id INT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))", $sql[2]);
|
||||
$this->assertEquals("CREATE UNIQUE INDEX cms_users_username_uniq ON cms_users (username)", $sql[3]);
|
||||
$this->assertEquals("CREATE UNIQUE INDEX UNIQ_3AF03EC5F85E0677 ON cms_users (username)", $sql[3]);
|
||||
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id))", $sql[4]);
|
||||
$this->assertEquals("CREATE INDEX cms_users_groups_user_id_idx ON cms_users_groups (user_id)", $sql[5]);
|
||||
$this->assertEquals("CREATE INDEX cms_users_groups_group_id_idx ON cms_users_groups (group_id)", $sql[6]);
|
||||
$this->assertEquals("CREATE INDEX IDX_7EA9409AA76ED395 ON cms_users_groups (user_id)", $sql[5]);
|
||||
$this->assertEquals("CREATE INDEX IDX_7EA9409AFE54D947 ON cms_users_groups (group_id)", $sql[6]);
|
||||
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[7]);
|
||||
$this->assertEquals("CREATE INDEX cms_phonenumbers_user_id_idx ON cms_phonenumbers (user_id)", $sql[8]);
|
||||
$this->assertEquals("CREATE INDEX IDX_F21F790FA76ED395 ON cms_phonenumbers (user_id)", $sql[8]);
|
||||
$this->assertEquals("CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[9]);
|
||||
$this->assertEquals("CREATE SEQUENCE cms_users_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[10]);
|
||||
$this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[11]);
|
||||
@@ -80,4 +80,25 @@ class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]);
|
||||
$this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[1]);
|
||||
}
|
||||
|
||||
public function testGetDropSchemaSql()
|
||||
{
|
||||
$classes = array(
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'),
|
||||
);
|
||||
|
||||
$tool = new SchemaTool($this->_em);
|
||||
$sql = $tool->getDropSchemaSQL($classes);
|
||||
|
||||
$this->assertEquals(13, count($sql));
|
||||
$dropSequenceSQLs = 0;
|
||||
foreach ($sql AS $stmt) {
|
||||
if (strpos($stmt, "DROP SEQUENCE") === 0) {
|
||||
$dropSequenceSQLs++;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(4, $dropSequenceSQLs, "Expect 4 sequences to be dropped.");
|
||||
}
|
||||
}
|
||||
|
||||
83
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php
Normal file
83
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1040
|
||||
*/
|
||||
class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testReuseNamedEntityParameter()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->name = "John Galt";
|
||||
$user->username = "jgalt";
|
||||
$user->status = "inactive";
|
||||
|
||||
$article = new CmsArticle();
|
||||
$article->topic = "This is John Galt speaking!";
|
||||
$article->text = "Yadda Yadda!";
|
||||
$article->setAuthor($user);
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author";
|
||||
$this->_em->createQuery($dql)
|
||||
->setParameter('author', $user)
|
||||
->getResult();
|
||||
|
||||
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author AND a.user = :author";
|
||||
$this->_em->createQuery($dql)
|
||||
->setParameter('author', $user)
|
||||
->getResult();
|
||||
|
||||
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = :topic AND a.user = :author AND a.user = :author AND a.text = :text";
|
||||
$farticle = $this->_em->createQuery($dql)
|
||||
->setParameter('author', $user)
|
||||
->setParameter('topic', 'This is John Galt speaking!')
|
||||
->setParameter('text', 'Yadda Yadda!')
|
||||
->getSingleResult();
|
||||
|
||||
$this->assertSame($article, $farticle);
|
||||
}
|
||||
|
||||
public function testUseMultiplePositionalParameters()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->name = "John Galt";
|
||||
$user->username = "jgalt";
|
||||
$user->status = "inactive";
|
||||
|
||||
$article = new CmsArticle();
|
||||
$article->topic = "This is John Galt speaking!";
|
||||
$article->text = "Yadda Yadda!";
|
||||
$article->setAuthor($user);
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3 AND a.text = ?4";
|
||||
$farticle = $this->_em->createQuery($dql)
|
||||
->setParameter(1, 'This is John Galt speaking!')
|
||||
->setParameter(2, $user)
|
||||
->setParameter(3, $user)
|
||||
->setParameter(4, 'Yadda Yadda!')
|
||||
->getSingleResult();
|
||||
|
||||
$this->assertSame($article, $farticle);
|
||||
}
|
||||
}
|
||||
33
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php
Normal file
33
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1041
|
||||
*/
|
||||
class DDC1041Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('company');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testGrabWrongSubtypeReturnsNull()
|
||||
{
|
||||
$fix = new \Doctrine\Tests\Models\Company\CompanyFixContract();
|
||||
$fix->setFixPrice(2000);
|
||||
|
||||
$this->_em->persist($fix);
|
||||
$this->_em->flush();
|
||||
|
||||
$id = $fix->getId();
|
||||
|
||||
$this->assertNull($this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
|
||||
$this->assertNull($this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
|
||||
$this->assertNull($this->_em->getPartialReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
|
||||
}
|
||||
}
|
||||
46
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php
Normal file
46
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1129Test.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1129
|
||||
*/
|
||||
class DDC1129Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testVersionFieldIgnoredInChangesetComputation()
|
||||
{
|
||||
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
|
||||
$article->text = "I don't know.";
|
||||
$article->topic = "Who is John Galt?";
|
||||
|
||||
$this->_em->persist($article);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(1, $article->version);
|
||||
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle');
|
||||
$uow = $this->_em->getUnitOfWork();
|
||||
|
||||
$uow->computeChangeSet($class, $article);
|
||||
$changeSet = $uow->getEntityChangeSet($article);
|
||||
$this->assertEquals(0, count($changeSet), "No changesets should be computed.");
|
||||
|
||||
$article->text = "This is John Galt speaking.";
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(2, $article->version);
|
||||
|
||||
$uow->computeChangeSet($class, $article);
|
||||
$changeSet = $uow->getEntityChangeSet($article);
|
||||
$this->assertEquals(0, count($changeSet), "No changesets should be computed.");
|
||||
}
|
||||
}
|
||||
56
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php
Normal file
56
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1151
|
||||
*/
|
||||
class DDC1151Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function testQuoteForeignKey()
|
||||
{
|
||||
if ($this->_em->getConnection()->getDatabasePlatform()->getName() != 'postgresql') {
|
||||
$this->markTestSkipped("This test is useful for all databases, but designed only for postgresql.");
|
||||
}
|
||||
|
||||
$sql = $this->_schemaTool->getCreateSchemaSql(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151User'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1151Group'),
|
||||
));
|
||||
|
||||
$this->assertEquals("CREATE TABLE \"User\" (id INT NOT NULL, PRIMARY KEY(id))", $sql[0]);
|
||||
$this->assertEquals("CREATE TABLE ddc1151user_ddc1151group (ddc1151user_id INT NOT NULL, ddc1151group_id INT NOT NULL, PRIMARY KEY(ddc1151user_id, ddc1151group_id))", $sql[1]);
|
||||
$this->assertEquals("CREATE INDEX IDX_88A3259AC5AD08A ON ddc1151user_ddc1151group (ddc1151user_id)", $sql[2]);
|
||||
$this->assertEquals("CREATE INDEX IDX_88A32597357E0B1 ON ddc1151user_ddc1151group (ddc1151group_id)", $sql[3]);
|
||||
$this->assertEquals("CREATE TABLE \"Group\" (id INT NOT NULL, PRIMARY KEY(id))", $sql[4]);
|
||||
$this->assertEquals("CREATE SEQUENCE User_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[5]);
|
||||
$this->assertEquals("CREATE SEQUENCE Group_id_seq INCREMENT BY 1 MINVALUE 1 START 1", $sql[6]);
|
||||
$this->assertEquals("ALTER TABLE ddc1151user_ddc1151group ADD FOREIGN KEY (ddc1151user_id) REFERENCES \"User\"(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[7]);
|
||||
$this->assertEquals("ALTER TABLE ddc1151user_ddc1151group ADD FOREIGN KEY (ddc1151group_id) REFERENCES \"Group\"(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", $sql[8]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="`User`")
|
||||
*/
|
||||
class DDC1151User
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
|
||||
/** @ManyToMany(targetEntity="DDC1151Group") */
|
||||
public $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="`Group`")
|
||||
*/
|
||||
class DDC1151Group
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
}
|
||||
215
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
Normal file
215
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1163
|
||||
*/
|
||||
class DDC1163Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Product'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163SpecialProduct'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163ProxyHolder'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1163Tag'),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$this->createSpecialProductAndProxyHolderReferencingIt();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->createProxyForSpecialProduct();
|
||||
|
||||
$this->setPropertyAndAssignTagToSpecialProduct();
|
||||
|
||||
// fails
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
private function createSpecialProductAndProxyHolderReferencingIt()
|
||||
{
|
||||
$specialProduct = new DDC1163SpecialProduct();
|
||||
$this->_em->persist($specialProduct);
|
||||
|
||||
$proxyHolder = new DDC1163ProxyHolder();
|
||||
$this->_em->persist($proxyHolder);
|
||||
|
||||
$proxyHolder->setSpecialProduct($specialProduct);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$this->productId = $specialProduct->getId();
|
||||
$this->proxyHolderId = $proxyHolder->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* We want Doctrine to instantiate a lazy-load proxy for the previously created
|
||||
* 'SpecialProduct' and register it.
|
||||
*
|
||||
* When Doctrine loads the 'ProxyHolder', it will do just that because the 'ProxyHolder'
|
||||
* references the 'SpecialProduct'.
|
||||
*/
|
||||
private function createProxyForSpecialProduct()
|
||||
{
|
||||
/* @var $proxyHolder ProxyHolder */
|
||||
$proxyHolder = $this->_em->find(__NAMESPACE__ . '\\DDC1163ProxyHolder', $this->proxyHolderId);
|
||||
|
||||
$this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $proxyHolder->getSpecialProduct());
|
||||
}
|
||||
|
||||
private function setPropertyAndAssignTagToSpecialProduct()
|
||||
{
|
||||
/* @var $specialProduct SpecialProduct */
|
||||
$specialProduct = $this->_em->find(__NAMESPACE__ . '\\DDC1163SpecialProduct', $this->productId);
|
||||
|
||||
$this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $specialProduct);
|
||||
$this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $specialProduct);
|
||||
|
||||
$specialProduct->setSubclassProperty('foobar');
|
||||
|
||||
// this screams violation of law of demeter ;)
|
||||
$this->assertEquals(
|
||||
__NAMESPACE__.'\\DDC1163SpecialProduct',
|
||||
$this->_em->getUnitOfWork()->getEntityPersister(get_class($specialProduct))->getClassMetadata()->name
|
||||
);
|
||||
|
||||
$tag = new DDC1163Tag('Foo');
|
||||
$this->_em->persist($tag);
|
||||
$tag->setProduct($specialProduct);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163ProxyHolder
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var SpecialProduct
|
||||
* @OneToOne(targetEntity="DDC1163SpecialProduct")
|
||||
*/
|
||||
private $specialProduct;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setSpecialProduct(DDC1163SpecialProduct $specialProduct)
|
||||
{
|
||||
$this->specialProduct = $specialProduct;
|
||||
}
|
||||
|
||||
public function getSpecialProduct()
|
||||
{
|
||||
return $this->specialProduct;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="type", type="string")
|
||||
* @DiscriminatorMap({"special" = "DDC1163SpecialProduct"})
|
||||
*/
|
||||
abstract class DDC1163Product
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163SpecialProduct extends DDC1163Product
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @Column(name="subclass_property", type="string", nullable=true)
|
||||
*/
|
||||
private $subclassProperty;
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setSubclassProperty($value)
|
||||
{
|
||||
$this->subclassProperty = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1163Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Column(name="id", type="integer")
|
||||
* @Id
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var string
|
||||
* @Column(name="name", type="string")
|
||||
*/
|
||||
private $name;
|
||||
/**
|
||||
* @var Product
|
||||
* @ManyToOne(targetEntity="DDC1163Product", inversedBy="tags")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="product_id", referencedColumnName="id")
|
||||
* })
|
||||
*/
|
||||
private $product;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
*/
|
||||
public function setProduct(DDC1163Product $product)
|
||||
{
|
||||
$this->product = $product;
|
||||
}
|
||||
|
||||
}
|
||||
93
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
Normal file
93
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
use DateTime, Doctrine\DBAL\Types\Type;
|
||||
|
||||
class DDC1193Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Company'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Person'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1193Account')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1193
|
||||
*/
|
||||
public function testIssue()
|
||||
{
|
||||
$company = new DDC1193Company();
|
||||
$person = new DDC1193Person();
|
||||
$account = new DDC1193Account();
|
||||
|
||||
$person->account = $account;
|
||||
$person->company = $company;
|
||||
|
||||
$company->member = $person;
|
||||
|
||||
$this->_em->persist($company);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$companyId = $company->id;
|
||||
$accountId = $account->id;
|
||||
$this->_em->clear();
|
||||
|
||||
$company = $this->_em->find(get_class($company), $companyId);
|
||||
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company), "Company is in identity map.");
|
||||
$this->assertFalse($company->member->__isInitialized__, "Pre-Condition");
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isInIdentityMap($company->member), "Member is in identity map.");
|
||||
|
||||
$this->_em->remove($company);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(count($this->_em->getRepository(get_class($account))->findAll()), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Company {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC1193Person", cascade={"persist", "remove"}) */
|
||||
public $member;
|
||||
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Person {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC1193Account", cascade={"persist", "remove"})
|
||||
*/
|
||||
public $account;
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
class DDC1193Account {
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
50
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php
Normal file
50
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1276
|
||||
*/
|
||||
class DDC1276Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->name = "Benjamin";
|
||||
$user->username = "beberlei";
|
||||
$user->status = "active";
|
||||
$this->_em->persist($user);
|
||||
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$group = new CmsGroup();
|
||||
$group->name = "group".$i;
|
||||
$user->groups[] = $group;
|
||||
$this->_em->persist($group);
|
||||
}
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
|
||||
$cloned = clone $user;
|
||||
|
||||
$this->assertSame($user->groups, $cloned->groups);
|
||||
$this->assertEquals(2, count($user->groups));
|
||||
$this->_em->merge($cloned);
|
||||
|
||||
$this->assertEquals(2, count($user->groups));
|
||||
|
||||
$this->_em->flush();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ use DateTime;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-618
|
||||
*/
|
||||
class DDC618Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
@@ -13,7 +16,8 @@ class DDC618Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Author')
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Author'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC618Book')
|
||||
));
|
||||
|
||||
// Create author 10/Joe with two books 22/JoeA and 20/JoeB
|
||||
@@ -26,6 +30,10 @@ class DDC618Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$author = new DDC618Author();
|
||||
$author->id = 11;
|
||||
$author->name = 'Alice';
|
||||
$author->addBook('In Wonderland');
|
||||
$author->addBook('Reloaded');
|
||||
$author->addBook('Test');
|
||||
|
||||
$this->_em->persist($author);
|
||||
|
||||
$this->_em->flush();
|
||||
@@ -58,11 +66,71 @@ class DDC618Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertArrayHasKey('Joe', $result, "INDEX BY A.name should return an index by the name of 'Joe'.");
|
||||
$this->assertArrayHasKey('Alice', $result, "INDEX BY A.name should return an index by the name of 'Alice'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1018
|
||||
*/
|
||||
public function testIndexByJoin()
|
||||
{
|
||||
$dql = 'SELECT A, B FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Author A '.
|
||||
'INNER JOIN A.books B INDEX BY B.title ORDER BY A.name ASC';
|
||||
$result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
|
||||
|
||||
$this->assertEquals(3, count($result[0]->books)); // Alice, Joe doesnt appear because he has no books.
|
||||
$this->assertEquals('Alice', $result[0]->name);
|
||||
$this->assertTrue( isset($result[0]->books["In Wonderland"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[0]->books["Reloaded"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[0]->books["Test"] ), "Indexing by title should have books by title.");
|
||||
|
||||
$result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
|
||||
|
||||
$this->assertEquals(3, count($result[0]['books'])); // Alice, Joe doesnt appear because he has no books.
|
||||
$this->assertEquals('Alice', $result[0]['name']);
|
||||
$this->assertTrue( isset($result[0]['books']["In Wonderland"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[0]['books']["Reloaded"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[0]['books']["Test"] ), "Indexing by title should have books by title.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1018
|
||||
*/
|
||||
public function testIndexByToOneJoinSilentlyIgnored()
|
||||
{
|
||||
$dql = 'SELECT B, A FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Book B '.
|
||||
'INNER JOIN B.author A INDEX BY A.name ORDER BY A.name ASC';
|
||||
$result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC618Book', $result[0]);
|
||||
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC618Author', $result[0]->author);
|
||||
|
||||
$dql = 'SELECT B, A FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Book B '.
|
||||
'INNER JOIN B.author A INDEX BY A.name ORDER BY A.name ASC';
|
||||
$result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
|
||||
|
||||
$this->assertEquals("Alice", $result[0]['author']['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1018
|
||||
*/
|
||||
public function testCombineIndexBy()
|
||||
{
|
||||
$dql = 'SELECT A, B FROM Doctrine\Tests\ORM\Functional\Ticket\DDC618Author A INDEX BY A.id '.
|
||||
'INNER JOIN A.books B INDEX BY B.title ORDER BY A.name ASC';
|
||||
$result = $this->_em->createQuery($dql)->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
|
||||
|
||||
$this->assertArrayHasKey(11, $result); // Alice
|
||||
|
||||
$this->assertEquals(3, count($result[11]->books)); // Alice, Joe doesnt appear because he has no books.
|
||||
$this->assertEquals('Alice', $result[11]->name);
|
||||
$this->assertTrue( isset($result[11]->books["In Wonderland"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[11]->books["Reloaded"] ), "Indexing by title should have books by title.");
|
||||
$this->assertTrue( isset($result[11]->books["Test"] ), "Indexing by title should have books by title.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table (name="ddc618author", uniqueConstraints={ @Index (name="UQ_authorname", columns={ "name" }) })
|
||||
*/
|
||||
class DDC618Author
|
||||
{
|
||||
@@ -75,8 +143,43 @@ class DDC618Author
|
||||
/** @Column(type="string") */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="DDC618Book", mappedBy="author", cascade={"persist"})
|
||||
*/
|
||||
public $books;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->books = new \Doctrine\Common\Collections\ArrayCollection;
|
||||
}
|
||||
|
||||
public function addBook($title)
|
||||
{
|
||||
$book = new DDC618Book($title, $this);
|
||||
$this->books[] = $book;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC618Book
|
||||
{
|
||||
/**
|
||||
* @Id @GeneratedValue
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/** @column(type="string") */
|
||||
public $title;
|
||||
|
||||
/** @ManyToOne(targetEntity="DDC618Author", inversedBy="books") */
|
||||
public $author;
|
||||
|
||||
function __construct($title, $author)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->author = $author;
|
||||
}
|
||||
}
|
||||
198
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php
Normal file
198
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC837Test.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC837Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Super'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class1'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class2'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Class3'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC837Aggregate'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-837
|
||||
*/
|
||||
public function testIssue()
|
||||
{
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
|
||||
$c1 = new DDC837Class1();
|
||||
$c1->title = "Foo";
|
||||
$c1->description = "Foo";
|
||||
$aggregate1 = new DDC837Aggregate('test1');
|
||||
$c1->aggregate = $aggregate1;
|
||||
|
||||
$c2 = new DDC837Class2();
|
||||
$c2->title = "Bar";
|
||||
$c2->description = "Bar";
|
||||
$c2->text = "Bar";
|
||||
$aggregate2 = new DDC837Aggregate('test2');
|
||||
$c2->aggregate = $aggregate2;
|
||||
|
||||
$c3 = new DDC837Class3();
|
||||
$c3->apples = "Baz";
|
||||
$c3->bananas = "Baz";
|
||||
|
||||
$this->_em->persist($c1);
|
||||
$this->_em->persist($aggregate1);
|
||||
$this->_em->persist($c2);
|
||||
$this->_em->persist($aggregate2);
|
||||
$this->_em->persist($c3);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
// Test Class1
|
||||
$e1 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c1->id);
|
||||
|
||||
$this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class1', $e1);
|
||||
$this->assertEquals('Foo', $e1->title);
|
||||
$this->assertEquals('Foo', $e1->description);
|
||||
$this->assertType(__NAMESPACE__ . '\DDC837Aggregate', $e1->aggregate);
|
||||
$this->assertEquals('test1', $e1->aggregate->getSysname());
|
||||
|
||||
// Test Class 2
|
||||
$e2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC837Super', $c2->id);
|
||||
|
||||
$this->assertType('Doctrine\Tests\ORM\Functional\Ticket\DDC837Class2', $e2);
|
||||
$this->assertEquals('Bar', $e2->title);
|
||||
$this->assertEquals('Bar', $e2->description);
|
||||
$this->assertEquals('Bar', $e2->text);
|
||||
$this->assertType(__NAMESPACE__ . '\DDC837Aggregate', $e2->aggregate);
|
||||
$this->assertEquals('test2', $e2->aggregate->getSysname());
|
||||
|
||||
$all = $this->_em->getRepository(__NAMESPACE__.'\DDC837Super')->findAll();
|
||||
|
||||
foreach ($all as $obj) {
|
||||
if ($obj instanceof DDC837Class1) {
|
||||
$this->assertEquals('Foo', $obj->title);
|
||||
$this->assertEquals('Foo', $obj->description);
|
||||
} else if ($obj instanceof DDC837Class2) {
|
||||
$this->assertTrue($e2 === $obj);
|
||||
$this->assertEquals('Bar', $obj->title);
|
||||
$this->assertEquals('Bar', $obj->description);
|
||||
$this->assertEquals('Bar', $obj->text);
|
||||
} else if ($obj instanceof DDC837Class3) {
|
||||
$this->assertEquals('Baz', $obj->apples);
|
||||
$this->assertEquals('Baz', $obj->bananas);
|
||||
} else {
|
||||
$this->fail('Instance of DDC837Class1, DDC837Class2 or DDC837Class3 expected.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="DDC837Super")
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="type", type="string")
|
||||
* @DiscriminatorMap({"class1" = "DDC837Class1", "class2" = "DDC837Class2", "class3"="DDC837Class3"})
|
||||
*/
|
||||
abstract class DDC837Super
|
||||
{
|
||||
/**
|
||||
* @Id @Column(name="id", type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC837Class1 extends DDC837Super
|
||||
{
|
||||
/**
|
||||
* @Column(name="title", type="string", length="150")
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* @Column(name="content", type="string", length="500")
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC837Aggregate")
|
||||
*/
|
||||
public $aggregate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC837Class2 extends DDC837Super
|
||||
{
|
||||
/**
|
||||
* @Column(name="title", type="string", length="150")
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* @Column(name="content", type="string", length="500")
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @Column(name="text", type="text")
|
||||
*/
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* @OneToOne(targetEntity="DDC837Aggregate")
|
||||
*/
|
||||
public $aggregate;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extra class to demonstrate why title and description aren't in Super
|
||||
*
|
||||
* @Entity
|
||||
*/
|
||||
class DDC837Class3 extends DDC837Super
|
||||
{
|
||||
/**
|
||||
* @Column(name="title", type="string", length="150")
|
||||
*/
|
||||
public $apples;
|
||||
|
||||
/**
|
||||
* @Column(name="content", type="string", length="500")
|
||||
*/
|
||||
public $bananas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC837Aggregate
|
||||
{
|
||||
/**
|
||||
* @Id @Column(name="id", type="integer")
|
||||
* @GeneratedValue
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Column(name="sysname", type="string")
|
||||
*/
|
||||
protected $sysname;
|
||||
|
||||
public function __construct($sysname)
|
||||
{
|
||||
$this->sysname = $sysname;
|
||||
}
|
||||
|
||||
public function getSysname()
|
||||
{
|
||||
return $this->sysname;
|
||||
}
|
||||
}
|
||||
43
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php
Normal file
43
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC949Test.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Tests\Models\Generic\BooleanModel;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC949Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('generic');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-949
|
||||
*/
|
||||
public function testBooleanThroughRepository()
|
||||
{
|
||||
$true = new BooleanModel();
|
||||
$true->booleanField = true;
|
||||
|
||||
$false = new BooleanModel();
|
||||
$false->booleanField = false;
|
||||
|
||||
$this->_em->persist($true);
|
||||
$this->_em->persist($false);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$true = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => true));
|
||||
$false = $this->_em->getRepository('Doctrine\Tests\Models\Generic\BooleanModel')->findOneBy(array('booleanField' => false));
|
||||
|
||||
$this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $true);
|
||||
$this->assertTrue($true->booleanField, "True Boolean Model should be true.");
|
||||
|
||||
$this->assertType('Doctrine\Tests\Models\Generic\BooleanModel', $false);
|
||||
$this->assertFalse($false->booleanField, "False Boolean Model should be false.");
|
||||
}
|
||||
}
|
||||
92
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php
Normal file
92
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
class DDC960Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Root'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Child')
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-960
|
||||
*/
|
||||
public function testUpdateRootVersion()
|
||||
{
|
||||
$child = new DDC960Child('Test');
|
||||
$this->_em->persist($child);
|
||||
$this->_em->flush();
|
||||
|
||||
$child->setName("Test2");
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals(2, $child->getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorMap({
|
||||
* "root" = "DDC960Root",
|
||||
* "child" = "DDC960Child"
|
||||
* })
|
||||
*/
|
||||
class DDC960Root
|
||||
{
|
||||
/**
|
||||
* @Id @GeneratedValue @Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @Column(type="integer") @Version
|
||||
*/
|
||||
private $version;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC960Child extends DDC960Root
|
||||
{
|
||||
/**
|
||||
* @column(type="string")
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
147
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php
Normal file
147
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC992Test.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-992
|
||||
*/
|
||||
class DDC992Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Role'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Parent'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Child'),
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$role = new DDC992Role();
|
||||
$role->name = "Parent";
|
||||
$child = new DDC992Role();
|
||||
$child->name = "child";
|
||||
|
||||
$role->extendedBy[] = $child;
|
||||
$child->extends[] = $role;
|
||||
|
||||
$this->_em->persist($role);
|
||||
$this->_em->persist($child);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$child = $this->_em->getRepository(get_class($role))->find($child->roleID);
|
||||
$parents = count($child->extends);
|
||||
$this->assertEquals(1, $parents);
|
||||
foreach ($child->extends AS $parent) {
|
||||
$this->assertEquals($role->getRoleID(), $parent->getRoleID());
|
||||
}
|
||||
}
|
||||
|
||||
public function testOneToManyChild()
|
||||
{
|
||||
$parent = new DDC992Parent();
|
||||
$child = new DDC992Child();
|
||||
$child->parent = $parent;
|
||||
$parent->childs[] = $child;
|
||||
|
||||
$this->_em->persist($parent);
|
||||
$this->_em->persist($child);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$parentRepository = $this->_em->getRepository(get_class($parent));
|
||||
$childRepository = $this->_em->getRepository(get_class($child));
|
||||
|
||||
$parent = $parentRepository->find($parent->id);
|
||||
$this->assertEquals(1, count($parent->childs));
|
||||
$this->assertEquals(0, count($parent->childs[0]->childs()));
|
||||
|
||||
$child = $parentRepository->findOneBy(array("id" => $child->id));
|
||||
$this->assertSame($parent->childs[0], $child);
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$child = $parentRepository->find($child->id);
|
||||
$this->assertEquals(0, count($child->childs));
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$child = $childRepository->find($child->id);
|
||||
$this->assertEquals(0, count($child->childs));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorMap({"child" = "DDC992Child", "parent" = "DDC992Parent"})
|
||||
*/
|
||||
class DDC992Parent
|
||||
{
|
||||
/** @Id @GeneratedValue @Column(type="integer") */
|
||||
public $id;
|
||||
/** @ManyToOne(targetEntity="DDC992Parent", inversedBy="childs") */
|
||||
public $parent;
|
||||
/** @OneToMany(targetEntity="DDC992Child", mappedBy="parent") */
|
||||
public $childs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC992Child extends DDC992Parent
|
||||
{
|
||||
public function childs()
|
||||
{
|
||||
return $this->childs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC992Role
|
||||
{
|
||||
public function getRoleID()
|
||||
{
|
||||
return $this->roleID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Id @Column(name="roleID", type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
public $roleID;
|
||||
/**
|
||||
* @Column (name="name", type="string", length="45")
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @ManyToMany (targetEntity="DDC992Role", mappedBy="extends")
|
||||
*/
|
||||
public $extendedBy;
|
||||
/**
|
||||
* @ManyToMany (targetEntity="DDC992Role", inversedBy="extendedBy")
|
||||
* @JoinTable (name="RoleRelations",
|
||||
* joinColumns={@JoinColumn(name="roleID", referencedColumnName="roleID")},
|
||||
* inverseJoinColumns={@JoinColumn(name="extendsRoleID", referencedColumnName="roleID")}
|
||||
* )
|
||||
*/
|
||||
public $extends;
|
||||
|
||||
public function __construct() {
|
||||
$this->extends = new ArrayCollection;
|
||||
$this->extendedBy = new ArrayCollection;
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']);
|
||||
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
|
||||
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']);
|
||||
$this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
|
||||
|
||||
// Test Order By
|
||||
$this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']);
|
||||
@@ -329,7 +330,7 @@ class User
|
||||
public $address;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"})
|
||||
* @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
||||
* @OrderBy({"number"="ASC"})
|
||||
*/
|
||||
public $phonenumbers;
|
||||
@@ -425,7 +426,7 @@ class User
|
||||
1 => 'persist',
|
||||
),
|
||||
'mappedBy' => 'user',
|
||||
'orphanRemoval' => false,
|
||||
'orphanRemoval' => true,
|
||||
'orderBy' =>
|
||||
array(
|
||||
'number' => 'ASC',
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user