Skip to content
Browse files

Update to Doctrine 1.2

  • Loading branch information...
1 parent 7f1197d commit f288268560953c77916c91696538ba7b7162cbc3 @abtris committed
Showing with 1,400 additions and 320 deletions.
  1. +13 −6 library/Doctrine/AuditLog.php
  2. +4 −4 library/Doctrine/AuditLog/Listener.php
  3. +3 −3 library/Doctrine/Cache/Apc.php
  4. +3 −3 library/Doctrine/Cache/Array.php
  5. +3 −3 library/Doctrine/Cache/Db.php
  6. +4 −4 library/Doctrine/Cache/Driver.php
  7. +3 −3 library/Doctrine/Cache/Interface.php
  8. +3 −3 library/Doctrine/Cache/Memcache.php
  9. +1 −1 library/Doctrine/Cache/Xcache.php
  10. +3 −4 library/Doctrine/Collection.php
  11. +5 −5 library/Doctrine/Connection.php
  12. +8 −5 library/Doctrine/Core.php
  13. +6 −3 library/Doctrine/DataDict/Mysql.php
  14. +9 −6 library/Doctrine/Export/Schema.php
  15. +0 −128 library/Doctrine/Expression/Driver.php
  16. +3 −3 library/Doctrine/Hook.php
  17. +7 −6 library/Doctrine/Import.php
  18. +8 −4 library/Doctrine/Import/Builder.php
  19. +1 −1 library/Doctrine/IntegrityMapper.php
  20. +52 −42 library/Doctrine/Node/NestedSet.php
  21. +135 −0 library/Doctrine/Parser/sfYaml/sfYaml.php
  22. +60 −0 library/Doctrine/Parser/sfYaml/sfYamlDumper.php
  23. +424 −0 library/Doctrine/Parser/sfYaml/sfYamlInline.php
  24. +566 −0 library/Doctrine/Parser/sfYaml/sfYamlParser.php
  25. +3 −1 library/Doctrine/Query/Abstract.php
  26. +19 −19 library/Doctrine/Record.php
  27. +1 −1 library/Doctrine/Relation/Parser.php
  28. +12 −2 library/Doctrine/Search.php
  29. +9 −13 library/Doctrine/Search/Indexer.php
  30. +6 −7 library/Doctrine/Table.php
  31. +1 −1 library/Doctrine/Task/Dql.php
  32. +5 −5 library/Doctrine/Template/Listener/Sluggable.php
  33. +5 −4 library/Doctrine/Tree/NestedSet.php
  34. +14 −29 library/vendor/sfYaml/sfYamlInline.php
  35. +1 −1 library/vendor/sfYaml/sfYamlParser.php
View
19 library/Doctrine/AuditLog.php
@@ -64,6 +64,12 @@ public function __construct(array $options = array())
$this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
}
+ public function buildRelation()
+ {
+ $this->buildForeignRelation('Version');
+ $this->buildLocalRelation();
+ }
+
/**
* Set the table definition for the audit log table
*
@@ -114,7 +120,8 @@ public function getVersion(Doctrine_Record $record, $version, $hydrationMode = D
$className = $this->_options['className'];
$method = ($asCollection) ? 'execute' : 'fetchOne';
- $q = new Doctrine_Query();
+ $q = Doctrine_Core::getTable($className)
+ ->createQuery();
$values = array();
foreach ((array) $this->_options['table']->getIdentifier() as $id) {
@@ -126,7 +133,7 @@ public function getVersion(Doctrine_Record $record, $version, $hydrationMode = D
$values[] = $version;
- $q->from($className)->where($where);
+ $q->where($where);
return $q->$method($values, $hydrationMode);
}
@@ -147,10 +154,10 @@ public function getMaxVersion(Doctrine_Record $record)
$values[] = $record->get($id);
}
- $q = Doctrine_Query::create($record->getTable()->getConnection())
- ->select($select)
- ->from($className)
- ->where(implode(' AND ',$conditions));
+ $q = Doctrine_Core::getTable($className)
+ ->createQuery()
+ ->select($select)
+ ->where(implode(' AND ',$conditions));
$result = $q->execute($values, Doctrine_Core::HYDRATE_ARRAY);
View
8 library/Doctrine/AuditLog/Listener.php
@@ -99,15 +99,15 @@ public function preDelete(Doctrine_Event $event)
$event->getInvoker()->set($name, null);
if ($this->_auditLog->getOption('deleteVersions')) {
- $q = Doctrine_Query::create($event->getInvoker()->getTable()->getConnection());
+ $q = Doctrine_Core::getTable($className)
+ ->createQuery('obj')
+ ->delete();
foreach ((array) $this->_auditLog->getOption('table')->getIdentifier() as $id) {
$conditions[] = 'obj.' . $id . ' = ?';
$values[] = $event->getInvoker()->get($id);
}
- $rows = $q->delete($className)
- ->from($className.' obj')
- ->where(implode(' AND ', $conditions))
+ $rows = $q->where(implode(' AND ', $conditions))
->execute($values);
}
}
View
6 library/Doctrine/Cache/Apc.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Apc.php 6559 2009-10-23 17:09:38Z jwage $
+ * $Id: Apc.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6559 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -51,7 +51,7 @@ public function __construct($options = array())
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
protected function _doFetch($id, $testCacheValidity = true)
{
View
6 library/Doctrine/Cache/Array.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Array.php 6559 2009-10-23 17:09:38Z jwage $
+ * $Id: Array.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6559 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -43,7 +43,7 @@ class Doctrine_Cache_Array extends Doctrine_Cache_Driver implements Countable
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
protected function _doFetch($id, $testCacheValidity = true)
{
View
6 library/Doctrine/Cache/Db.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Db.php 6559 2009-10-23 17:09:38Z jwage $
+ * $Id: Db.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6559 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -72,7 +72,7 @@ public function getConnection()
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
protected function _doFetch($id, $testCacheValidity = true)
{
View
8 library/Doctrine/Cache/Driver.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Driver.php 6729 2009-11-16 17:41:40Z jwage $
+ * $Id: Driver.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6729 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -102,7 +102,7 @@ public function count()
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
public function fetch($id, $testCacheValidity = true)
{
@@ -295,7 +295,7 @@ public function _deleteKey($key)
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
abstract protected function _doFetch($id, $testCacheValidity = true);
View
6 library/Doctrine/Cache/Interface.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Interface.php 6559 2009-10-23 17:09:38Z jwage $
+ * $Id: Interface.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6559 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -38,7 +38,7 @@
*
* @param string $id cache id
* @param boolean $testCacheValidity if set to false, the cache validity won't be tested
- * @return string cached datas (or false)
+ * @return mixed Returns either the cached data or false
*/
public function fetch($id, $testCacheValidity = true);
View
6 library/Doctrine/Cache/Memcache.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Memcache.php 6559 2009-10-23 17:09:38Z jwage $
+ * $Id: Memcache.php 6821 2009-11-30 17:32:21Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6559 $
+ * @version $Revision: 6821 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
@@ -76,7 +76,7 @@ public function __construct($options = array())
* Test if a cache record exists for the passed id
*
* @param string $id cache id
- * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
+ * @return mixed Returns either the cached data or false
*/
protected function _doFetch($id, $testCacheValidity = true)
{
View
2 library/Doctrine/Cache/Xcache.php
@@ -52,7 +52,7 @@ public function __construct($options = array())
* Test if a cache record exists for the passed id
*
* @param string $id cache id
- * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
+ * @return mixed Returns either the cached data or false
*/
protected function _doFetch($id, $testCacheValidity = true)
{
View
7 library/Doctrine/Collection.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Collection.php 6734 2009-11-16 18:58:13Z jwage $
+ * $Id: Collection.php 6799 2009-11-24 19:24:33Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -28,7 +28,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6734 $
+ * @version $Revision: 6799 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
@@ -528,7 +528,7 @@ public function merge(Doctrine_Collection $coll)
public function loadRelated($name = null)
{
$list = array();
- $query = new Doctrine_Query($this->_table->getConnection());
+ $query = $this->_table->createQuery();
if ( ! isset($name)) {
foreach ($this->data as $record) {
@@ -537,7 +537,6 @@ public function loadRelated($name = null)
$list[] = $value;
}
}
- $query->from($this->_table->getComponentName());
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
if ( ! $list) {
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')', $list);
View
10 library/Doctrine/Connection.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Connection.php 6797 2009-11-24 00:23:48Z jwage $
+ * $Id: Connection.php 6799 2009-11-24 19:24:33Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -49,7 +49,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6797 $
+ * @version $Revision: 6799 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
*/
@@ -893,7 +893,7 @@ public function fetchBoth($statement, array $params = array())
*/
public function query($query, array $params = array(), $hydrationMode = null)
{
- $parser = new Doctrine_Query($this);
+ $parser = Doctrine_Query::create();
$res = $parser->query($query, $params, $hydrationMode);
$parser->free();
@@ -950,7 +950,7 @@ public function prepare($statement)
*/
public function queryOne($query, array $params = array())
{
- $parser = new Doctrine_Query($this);
+ $parser = Doctrine_Query::create();
$coll = $parser->query($query, $params);
if ( ! $coll->contains(0)) {
@@ -1204,7 +1204,7 @@ public function create($name)
*/
public function createQuery()
{
- return new Doctrine_Query($this);
+ return Doctrine_Query::create();
}
/**
View
13 library/Doctrine/Core.php
@@ -35,7 +35,7 @@ class Doctrine_Core
/**
* VERSION
*/
- const VERSION = '1.2.0-RC1';
+ const VERSION = '1.2.0';
/**
* ERROR CONSTANTS
@@ -207,6 +207,7 @@ class Doctrine_Core
const ATTR_COLLECTION_CLASS = 175;
const ATTR_TABLE_CLASS = 176;
const ATTR_USE_NATIVE_SET = 177;
+ const ATTR_MODEL_CLASS_PREFIX = 178;
/**
* LIMIT CONSTANTS
@@ -622,12 +623,14 @@ public static function loadModels($directory, $modelLoading = null, $classPrefix
{
$manager = Doctrine_Manager::getInstance();
- $modelLoading = $modelLoading === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING):$modelLoading;
+ $modelLoading = $modelLoading === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING) : $modelLoading;
+ $classPrefix = $classPrefix === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) : $classPrefix;
$loadedModels = array();
if ($directory !== null) {
foreach ((array) $directory as $dir) {
+ $dir = rtrim($dir, '/');
if ( ! is_dir($dir)) {
throw new Doctrine_Exception('You must pass a valid path to a directory containing Doctrine models');
}
@@ -681,7 +684,7 @@ public static function loadModels($directory, $modelLoading = null, $classPrefix
$loadedModels = array_merge($loadedModels, $previouslyLoaded);
}
}
- } else {
+ } else if (self::isValidModelClass($className)) {
$loadedModels[$className] = $className;
}
}
@@ -852,7 +855,7 @@ public static function generateYamlFromDb($yamlPath, array $databases = array(),
$export = new Doctrine_Export_Schema();
- $result = $export->exportSchema($yamlPath, 'yml', $directory);
+ $result = $export->exportSchema($yamlPath, 'yml', $directory, array(), Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
Doctrine_Lib::removeDirectories($directory);
@@ -1102,7 +1105,7 @@ public static function compile($target = null, $includedDrivers = array())
public static function autoload($className)
{
if (strpos($className, 'sfYaml') === 0) {
- require dirname(__FILE__) . '/../vendor/sfYaml/' . $className . '.php';
+ require dirname(__FILE__) . '/Parser/sfYaml/' . $className . '.php';
}
if (0 !== stripos($className, 'Doctrine_') || class_exists($className, false) || interface_exists($className, false)) {
View
9 library/Doctrine/DataDict/Mysql.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Mysql.php 6760 2009-11-18 17:24:57Z jwage $
+ * $Id: Mysql.php 6805 2009-11-24 21:14:51Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -25,7 +25,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
- * @version $Revision: 6760 $
+ * @version $Revision: 6805 $
* @link www.phpdoctrine.org
* @since 1.0
*/
@@ -265,7 +265,10 @@ public function getPortableDeclaration(array $field)
$decimal = '';
} else {
$length = strtok('(), ');
- $decimal = strtok('(), ') ? strtok('(), '):null;
+ $decimal = strtok('(), ');
+ if ( ! $decimal ) {
+ $decimal = null;
+ }
}
$type = array();
$unsigned = $fixed = null;
View
15 library/Doctrine/Export/Schema.php
@@ -39,13 +39,15 @@ class Doctrine_Export_Schema
*
* Build schema array that can be dumped to file
*
- * @param string $directory
+ * @param string $directory The directory of models to build the schema from
+ * @param array $models The array of model names to build the schema for
+ * @param integer $modelLoading The model loading strategy to use to load the models from the passed directory
* @return void
*/
- public function buildSchema($directory = null, $models = array())
+ public function buildSchema($directory = null, $models = array(), $modelLoading = null)
{
if ($directory !== null) {
- $loadedModels = Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels($directory));
+ $loadedModels = Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels($directory, $modelLoading));
} else {
$loadedModels = Doctrine_Core::getLoadedModels();
}
@@ -135,12 +137,13 @@ public function buildSchema($directory = null, $models = array())
*
* @param string $schema
* @param string $directory
- * @return string $string of data in the specified format
+ * @param string $string of data in the specified format
+ * @param integer $modelLoading The model loading strategy to use to load the models from the passed directory
* @return void
*/
- public function exportSchema($schema, $format = 'yml', $directory = null, $models = array())
+ public function exportSchema($schema, $format = 'yml', $directory = null, $models = array(), $modelLoading = null)
{
- $array = $this->buildSchema($directory, $models);
+ $array = $this->buildSchema($directory, $models, $modelLoading);
if (is_dir($schema)) {
$schema = $schema . DIRECTORY_SEPARATOR . 'schema.' . $format;
View
128 library/Doctrine/Expression/Driver.php
@@ -314,14 +314,6 @@ public function concat()
/**
* Returns the SQL for a logical not.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- * $q->select('*')->from('table')
- * ->where($e->eq('id', $e->not('null'));
- * </code>
- *
* @return string a logical expression
*/
public function not($expression)
@@ -362,16 +354,6 @@ private function basicMath($type, array $args)
* must contain a value or an expression or an array with values or
* expressions.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- *
- * $q->select('u.*')
- * ->from('User u')
- * ->where($e->eq($e->add('id', 2), 12));
- * </code>
- *
* @param string|array(string)
* @return string an expression
*/
@@ -387,16 +369,6 @@ public function add(array $args)
* must contain a value or an expression or an array with values or
* expressions.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- *
- * $q->select('u.*')
- * ->from('User u')
- * ->where($e->eq($e->sub('id', 2), 12));
- * </code>
- *
* @param string|array(string)
* @return string an expression
*/
@@ -412,16 +384,6 @@ public function sub(array $args)
* must contain a value or an expression or an array with values or
* expressions.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- *
- * $q->select('u.*')
- * ->from('User u')
- * ->where($e->eq($e->mul('id', 2), 12));
- * </code>
- *
* @param string|array(string)
* @return string an expression
*/
@@ -437,16 +399,6 @@ public function mul(array $args)
* must contain a value or an expression or an array with values or
* expressions.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- *
- * $q->select('u.*')
- * ->from('User u')
- * ->where($e->eq($e->div('id', 2), 12));
- * </code>
- *
* @param string|array(string)
* @return string an expression
*/
@@ -458,14 +410,6 @@ public function div(array $args)
/**
* Returns the SQL to check if two values are equal.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->eq('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -480,14 +424,6 @@ public function eq($value1, $value2)
/**
* Returns the SQL to check if two values are unequal.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->neq('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -502,14 +438,6 @@ public function neq($value1, $value2)
/**
* Returns the SQL to check if one value is greater than another value.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->gt('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -525,14 +453,6 @@ public function gt($value1, $value2)
* Returns the SQL to check if one value is greater than or equal to
* another value.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->gte('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -547,14 +467,6 @@ public function gte($value1, $value2)
/**
* Returns the SQL to check if one value is less than another value.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->lt('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -570,14 +482,6 @@ public function lt($value1, $value2)
* Returns the SQL to check if one value is less than or equal to
* another value.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->lte('id', 1));
- * </code>
- *
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
@@ -598,14 +502,6 @@ public function lte($value1, $value2)
* must contain a logical expression or an array with logical expressions.
* These expressions will be matched against the first parameter.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->in( 'id', array(1,2,3)));
- * </code>
- *
* @param string $column the value that should be matched against
* @param string|array(string) values that will be matched against $column
* @return string logical expression
@@ -627,14 +523,6 @@ public function in($column, $values)
/**
* Returns SQL that checks if a expression is null.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->isNull('id'));
- * </code>
- *
* @param string $expression the expression that should be compared to null
* @return string logical expression
*/
@@ -647,14 +535,6 @@ public function isNull($expression)
/**
* Returns SQL that checks if a expression is not null.
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->isNotNull('id'));
- * </code>
- *
* @param string $expression the expression that should be compared to null
* @return string logical expression
*/
@@ -674,14 +554,6 @@ public function isNotNull($expression)
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database
* independence you should avoid using between().
*
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $q->select('u.*')
- * ->from('User u')
- * ->where($q->expr->between('id', 1, 5));
- * </code>
- *
* @param string $expression the value to compare to
* @param string $value1 the lower value to compare with
* @param string $value2 the higher value to compare with
View
6 library/Doctrine/Hook.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Hook.php 5901 2009-06-22 15:44:45Z jwage $
+ * $Id: Hook.php 6799 2009-11-24 19:24:33Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 5901 $
+ * @version $Revision: 6799 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Hook
@@ -79,7 +79,7 @@ class Doctrine_Hook
public function __construct($query)
{
if (is_string($query)) {
- $this->query = new Doctrine_Query();
+ $this->query = Doctrine_Query::create();
$this->query->parseDqlQuery($query);
} elseif ($query instanceof Doctrine_Query) {
$this->query = $query;
View
13 library/Doctrine/Import.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Import.php 6733 2009-11-16 18:26:01Z jwage $
+ * $Id: Import.php 6802 2009-11-24 20:45:54Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -30,7 +30,7 @@
* @link www.phpdoctrine.org
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0
- * @version $Revision: 6733 $
+ * @version $Revision: 6802 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
*/
@@ -393,7 +393,7 @@ public function importSchema($directory, array $databases = array(), array $opti
$relClasses = array();
foreach ($relations as $relation) {
$table = $relation['table'];
- $class = Doctrine_Inflector::classify($table);
+ $class = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));
if (in_array($class, $relClasses)) {
$alias = $class . '_' . (count($relClasses) + 1);
} else {
@@ -409,12 +409,13 @@ public function importSchema($directory, array $databases = array(), array $opti
}
} catch (Exception $e) {}
- $definitions[$definition['className']] = $definition;
+ $definitions[strtolower($definition['className'])] = $definition;
$classes[] = $definition['className'];
}
// Build opposite end of relationships
- foreach ($definitions as $className => $definition) {
+ foreach ($definitions as $definition) {
+ $className = $definition['className'];
$relClasses = array();
foreach ($definition['relations'] as $alias => $relation) {
if (in_array($relation['class'], $relClasses) || isset($definitions[$relation['class']]['relations'][$className])) {
@@ -423,7 +424,7 @@ public function importSchema($directory, array $databases = array(), array $opti
$alias = $className;
}
$relClasses[] = $relation['class'];
- $definitions[$relation['class']]['relations'][$alias] = array(
+ $definitions[strtolower($relation['class'])]['relations'][$alias] = array(
'type' => Doctrine_Relation::MANY,
'alias' => $alias,
'class' => $className,
View
12 library/Doctrine/Import/Builder.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: Builder.php 6716 2009-11-12 19:26:28Z jwage $
+ * $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -30,7 +30,7 @@
* @link www.phpdoctrine.org
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0
- * @version $Revision: 6716 $
+ * @version $Revision: 6820 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @author Nicolas Bérard-Nault <nicobn@php.net>
@@ -180,9 +180,13 @@ class Doctrine_Import_Builder extends Doctrine_Builder
*/
public function __construct()
{
- if ($tableClass = Doctrine_Manager::getInstance()->getAttribute(Doctrine_Core::ATTR_TABLE_CLASS)) {
+ $manager = Doctrine_Manager::getInstance();
+ if ($tableClass = $manager->getAttribute(Doctrine_Core::ATTR_TABLE_CLASS)) {
$this->_baseTableClassName = $tableClass;
}
+ if ($classPrefix = $manager->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX)) {
+ $this->_classPrefix = $classPrefix;
+ }
$this->loadTemplate();
}
@@ -642,7 +646,7 @@ public function buildPhpDocs(array $definition)
$ret[] = '@package ' . $this->_phpDocPackage;
$ret[] = '@subpackage ' . $this->_phpDocSubpackage;
$ret[] = '@author ' . $this->_phpDocName . ' <' . $this->_phpDocEmail . '>';
- $ret[] = '@version SVN: $Id: Builder.php 6716 2009-11-12 19:26:28Z jwage $';
+ $ret[] = '@version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $';
$ret = ' * ' . implode(PHP_EOL . ' * ', $ret);
$ret = ' ' . trim($ret);
View
2 library/Doctrine/IntegrityMapper.php
@@ -87,7 +87,7 @@ public function invokeIntegrityActions(Doctrine_Record $record)
*/
public function buildIntegrityRelationQuery(Doctrine_Record $record)
{
- $q = new Doctrine_Query();
+ $q = $record->getTable()->createQuery();
$aliases = array();
$indexes = array();
View
94 library/Doctrine/Node/NestedSet.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: NestedSet.php 6732 2009-11-16 18:17:34Z jwage $
+ * $Id: NestedSet.php 6799 2009-11-24 19:24:33Z jwage $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -27,7 +27,7 @@
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
- * @version $Revision: 6732 $
+ * @version $Revision: 6799 $
* @author Joe Simms <joe.simms@websites4.com>
* @author Roman Borschel <roman@code-factory.org>
*/
@@ -375,8 +375,9 @@ public function insertAsParentOf(Doctrine_Record $dest)
// Slide child nodes over one and down one to allow new parent to wrap them
$componentName = $this->_tree->getBaseComponent();
- $q = new Doctrine_Query();
- $q->update($componentName);
+ $q = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update();
$q->set("$componentName.lft", "$componentName.lft + 1");
$q->set("$componentName.rgt", "$componentName.rgt + 1");
$q->set("$componentName.level", "$componentName.level + 1");
@@ -648,14 +649,14 @@ private function _moveBetweenTrees(Doctrine_Record $dest, $newLeftValue, $moveTy
$rootColName = $this->_tree->getAttribute('rootColumnName');
// Update lft/rgt/root/level for all descendants
- $q = new Doctrine_Query($conn);
- $q = $q->update($componentName)
- ->set($componentName . '.lft', $componentName.'.lft + ?', $diff)
- ->set($componentName . '.rgt', $componentName.'.rgt + ?', $diff)
- ->set($componentName . '.level', $componentName.'.level + ?', $levelDiff)
- ->set($componentName . '.' . $rootColName, '?', $newRoot)
- ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?',
- array($oldLft, $oldRgt));
+ $q = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update()
+ ->set($componentName . '.lft', $componentName.'.lft + ?', $diff)
+ ->set($componentName . '.rgt', $componentName.'.rgt + ?', $diff)
+ ->set($componentName . '.level', $componentName.'.level + ?', $levelDiff)
+ ->set($componentName . '.' . $rootColName, '?', $newRoot)
+ ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?', array($oldLft, $oldRgt));
$q = $this->_tree->returnQueryWithRootId($q, $oldRoot);
$q->execute();
@@ -808,13 +809,14 @@ public function makeRoot($newRootId)
$newRoot = $newRootId;
$componentName = $this->_tree->getBaseComponent();
$rootColName = $this->_tree->getAttribute('rootColumnName');
- $q = new Doctrine_Query($conn);
- $q = $q->update($componentName)
- ->set($componentName . '.lft', $componentName.'.lft + ?', array($diff))
- ->set($componentName . '.rgt', $componentName.'.rgt + ?', array($diff))
- ->set($componentName . '.level', $componentName.'.level - ?', array($oldLevel))
- ->set($componentName . '.' . $rootColName, '?', array($newRoot))
- ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?', array($oldLft, $oldRgt));
+ $q = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update()
+ ->set($componentName . '.lft', $componentName.'.lft + ?', array($diff))
+ ->set($componentName . '.rgt', $componentName.'.rgt + ?', array($diff))
+ ->set($componentName . '.level', $componentName.'.level - ?', array($oldLevel))
+ ->set($componentName . '.' . $rootColName, '?', array($newRoot))
+ ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?', array($oldLft, $oldRgt));
$q = $this->_tree->returnQueryWithRootId($q, $oldRoot);
$q->execute();
@@ -1014,11 +1016,11 @@ private function updateNode($destLeft, $levelDiff)
}
// update level for descendants
- $q = new Doctrine_Query();
- $q = $q->update($componentName)
- ->set($componentName . '.level', $componentName.'.level + ?', array($levelDiff))
- ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?',
- array($left, $right));
+ $q = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update()
+ ->set($componentName . '.level', $componentName.'.level + ?', array($levelDiff))
+ ->where($componentName . '.lft > ? AND ' . $componentName . '.rgt < ?', array($left, $right));
$q = $this->_tree->returnQueryWithRootId($q, $rootId);
$q->execute();
@@ -1051,22 +1053,26 @@ private function updateNode($destLeft, $levelDiff)
*/
private function shiftRlValues($first, $delta, $rootId = 1)
{
- $qLeft = new Doctrine_Query();
- $qRight = new Doctrine_Query();
-
// shift left columns
$componentName = $this->_tree->getBaseComponent();
- $qLeft = $qLeft->update($componentName)
- ->set($componentName . '.lft', $componentName.'.lft + ?', $delta)
- ->where($componentName . '.lft >= ?', $first);
+
+ $qLeft = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update();
+
+ $qRight = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update();
+
+ $qLeft = $qLeft->set($componentName . '.lft', $componentName.'.lft + ?', $delta)
+ ->where($componentName . '.lft >= ?', $first);
$qLeft = $this->_tree->returnQueryWithRootId($qLeft, $rootId);
$resultLeft = $qLeft->execute();
// shift right columns
- $qRight = $qRight->update($componentName)
- ->set($componentName . '.rgt', $componentName.'.rgt + ?', $delta)
- ->where($componentName . '.rgt >= ?', $first);
+ $qRight = $qRight->set($componentName . '.rgt', $componentName.'.rgt + ?', $delta)
+ ->where($componentName . '.rgt >= ?', $first);
$qRight = $this->_tree->returnQueryWithRootId($qRight, $rootId);
@@ -1086,23 +1092,27 @@ private function shiftRlValues($first, $delta, $rootId = 1)
*/
private function shiftRlRange($first, $last, $delta, $rootId = 1)
{
- $qLeft = new Doctrine_Query();
- $qRight = new Doctrine_Query();
+ $componentName = $this->_tree->getBaseComponent();
+
+ $qLeft = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update();
+
+ $qRight = Doctrine_Core::getTable($componentName)
+ ->createQuery()
+ ->update();
// shift left column values
- $componentName = $this->_tree->getBaseComponent();
- $qLeft = $qLeft->update($componentName)
- ->set($componentName . '.lft', $componentName.'.lft + ?', $delta)
- ->where($componentName . '.lft >= ? AND ' . $componentName . '.lft <= ?', array($first, $last));
+ $qLeft = $qLeft->set($componentName . '.lft', $componentName.'.lft + ?', $delta)
+ ->where($componentName . '.lft >= ? AND ' . $componentName . '.lft <= ?', array($first, $last));
$qLeft = $this->_tree->returnQueryWithRootId($qLeft, $rootId);
$resultLeft = $qLeft->execute();
// shift right column values
- $qRight = $qRight->update($componentName)
- ->set($componentName . '.rgt', $componentName.'.rgt + ?', $delta)
- ->where($componentName . '.rgt >= ? AND ' . $componentName . '.rgt <= ?', array($first, $last));
+ $qRight = $qRight->set($componentName . '.rgt', $componentName.'.rgt + ?', $delta)
+ ->where($componentName . '.rgt >= ? AND ' . $componentName . '.rgt <= ?', array($first, $last));
$qRight = $this->_tree->returnQueryWithRootId($qRight, $rootId);
View
135 library/Doctrine/Parser/sfYaml/sfYaml.php
@@ -0,0 +1,135 @@
+<?php
+
+/*
+ * 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.
+ */
+
+/**
+ * sfYaml offers convenience methods to load and dump YAML.
+ *
+ * @package symfony
+ * @subpackage yaml
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @version SVN: $Id: sfYaml.class.php 8988 2008-05-15 20:24:26Z fabien $
+ */
+class sfYaml
+{
+ 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 = sfYaml::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;
+ }
+
+ require_once dirname(__FILE__).'/sfYamlParser.php';
+
+ $yaml = new sfYamlParser();
+
+ 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)
+ {
+ require_once dirname(__FILE__).'/sfYamlDumper.php';
+
+ $yaml = new sfYamlDumper();
+
+ return $yaml->dump($array, $inline);
+ }
+}
+
+/**
+ * Wraps echo to automatically provide a newline.
+ *
+ * @param string $string The string to echo with new line
+ */
+function echoln($string)
+{
+ echo $string."\n";
+}
View
60 library/Doctrine/Parser/sfYaml/sfYamlDumper.php
@@ -0,0 +1,60 @@
+<?php
+
+/*
+ * 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.
+ */
+
+require_once(dirname(__FILE__).'/sfYamlInline.php');
+
+/**
+ * sfYamlDumper dumps PHP variables to YAML strings.
+ *
+ * @package symfony
+ * @subpackage yaml
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @version SVN: $Id: sfYamlDumper.class.php 10575 2008-08-01 13:08:42Z nicolas $
+ */
+class sfYamlDumper
+{
+ /**
+ * 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.sfYamlInline::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 ? sfYamlInline::dump($key).':' : '-',
+ $willBeInlined ? ' ' : "\n",
+ $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + 2)
+ ).($willBeInlined ? "\n" : '');
+ }
+ }
+
+ return $output;
+ }
+}
View
424 library/Doctrine/Parser/sfYaml/sfYamlInline.php
@@ -0,0 +1,424 @@
+<?php
+
+/*
+ * 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.
+ */
+
+require_once dirname(__FILE__).'/sfYaml.php';
+
+/**
+ * sfYamlInline implements a YAML parser/dumper for the YAML inline syntax.
+ *
+ * @package symfony
+ * @subpackage yaml
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @version SVN: $Id: sfYamlInline.class.php 16177 2009-03-11 08:32:48Z fabien $
+ */
+class sfYamlInline
+{
+ 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)
+ {
+ if ('1.1' === sfYaml::getSpecVersion())
+ {
+ $trueValues = array('true', 'on', '+', 'yes', 'y');
+ $falseValues = array('false', 'off', '-', 'no', 'n');
+ }
+ else
+ {
+ $trueValues = array('true');
+ $falseValues = array('false');
+ }
+
+ switch (true)
+ {
+ case is_resource($value):
+ throw new InvalidArgumentException('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"):
+ 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, create_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 InvalidArgumentException(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)
+ {
+ preg_match('/'.self::REGEX_QUOTED_STRING.'/A', substr($scalar, $i), $match);
+
+ $output = stripcslashes(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 InvalidArgumentException(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 InvalidArgumentException(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);
+
+ if ('1.1' === sfYaml::getSpecVersion())
+ {
+ $trueValues = array('true', 'on', '+', 'yes', 'y');
+ $falseValues = array('false', 'off', '-', 'no', 'n');
+ }
+ else
+ {
+ $trueValues = array('true');
+ $falseValues = 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;
+ }
+}
View
566 library/Doctrine/Parser/sfYaml/sfYamlParser.php
@@ -0,0 +1,566 @@
+<?php
+
+/*
+ * 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.
+ */
+
+require_once(dirname(__FILE__).'/sfYamlInline.php');
+
+if (!defined('PREG_BAD_UTF8_OFFSET_ERROR'))
+{
+ define('PREG_BAD_UTF8_OFFSET_ERROR', 5);
+}
+
+/**
+ * sfYamlParser parses YAML strings to convert them to PHP arrays.
+ *
+ * @package symfony
+ * @subpackage yaml
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ * @version SVN: $Id: sfYamlParser.class.php 10832 2008-08-13 07:46:08Z fabien $
+ */
+class sfYamlParser
+{
+ protected
+ $value = '',
+ $offset = 0,
+ $lines = array(),
+ $currentLineNb = -1,
+ $currentLine = '',
+ $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->value = $this->cleanup($value);
+ $this->currentLineNb = -1;
+ $this->currentLine = '';
+ $this->lines = explode("\n", $this->value);
+
+ $data = array();
+ while ($this->moveToNextLine())
+ {
+ if ($this->isCurrentLineEmpty())
+ {
+ continue;
+ }
+
+ // tab?
+ if (preg_match('#^\t+#', $this->currentLine))
+ {
+ throw new InvalidArgumentException(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('#^\-(\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 sfYamlParser($c);
+ $parser->refs =& $this->refs;
+ $data[] = $parser->parse($this->getNextEmbedBlock());
+ }
+ else
+ {
+ if (preg_match('/^([^ ]+)\: +({.*?)$/', $values['value'], $matches))
+ {
+ $data[] = array($matches[1] => sfYamlInline::load($matches[2]));
+ }
+ else
+ {
+ $data[] = $this->parseValue($values['value']);
+ }
+ }
+ }
+ else if (preg_match('#^(?P<key>'.sfYamlInline::REGEX_QUOTED_STRING.'|[^ ].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
+ {
+ $key = sfYamlInline::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 InvalidArgumentException(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 sfYamlParser($c);
+ $parser->refs =& $this->refs;
+ $parsed = $parser->parse($value);
+
+ $merged = array();
+ if (!is_array($parsed))
+ {
+ throw new InvalidArgumentException(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 InvalidArgumentException(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 sfYamlParser($c);
+ $parser->refs =& $this->refs;
+ $data[$key] = $parser->parse($this->getNextEmbedBlock());
+ }
+ }
+ else
+ {
+ if ($isInPlace)
+ {