This commit is contained in:
William DURAND 2011-12-05 18:42:24 +01:00
parent 4f9a41df37
commit ab50b5ec39
17 changed files with 1645 additions and 1596 deletions

View file

@ -32,21 +32,47 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
* @var array
*/
protected $additionalPhingArgs = array();
/**
* Temporary XML schemas used on command execution.
* @var array
*/
protected $tempSchemas = array();
/**
* @var string
*/
protected $cacheDir = null;
/**
* The Phing output.
* @string
*/
protected $buffer = null;
/**
* Return the package prefix for a given bundle.
*
* @param Bundle $bundle
* @param string $baseDirectory The base directory to exclude from prefix.
*
* @return string
*/
static public function getPackagePrefix(Bundle $bundle, $baseDirectory = '')
{
$parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
$length = count(explode('\\', $bundle->getNamespace())) * (-1);
$prefix = implode(DIRECTORY_SEPARATOR, array_slice($parts, 1, $length));
$prefix = ltrim(str_replace($baseDirectory, '', $prefix), DIRECTORY_SEPARATOR);
if (!empty($prefix)) {
$prefix = str_replace(DIRECTORY_SEPARATOR, '.', $prefix).'.';
}
return $prefix;
}
/**
* {@inheritdoc}
*/
@ -138,40 +164,6 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
return $returnStatus;
}
/**
* Compiles arguments/properties for the Phing process.
* @return array
*/
private function getPhingArguments(KernelInterface $kernel, $workingDirectory, $properties)
{
$args = array();
// Default properties
$properties = array_merge(array(
'propel.database' => 'mysql',
'project.dir' => $workingDirectory,
'propel.output.dir' => $kernel->getRootDir().'/propel',
'propel.php.dir' => $kernel->getRootDir().'/..',
'propel.packageObjectModel' => true,
), $properties);
// Adding user defined properties from the configuration
$properties = array_merge(
$properties,
$this->getContainer()->get('propel.build_properties')->getProperties()
);
foreach ($properties as $key => $value) {
$args[] = "-D$key=$value";
}
// Build file
$args[] = '-f';
$args[] = realpath($this->getContainer()->getParameter('propel.path').'/generator/build.xml');
return $args;
}
/**
* @param KernelInterface $kernel The application kernel.
*/
@ -188,7 +180,6 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
$finalSchemas = array();
foreach ($kernel->getBundles() as $bundle) {
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
$finder = new Finder();
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
@ -220,7 +211,6 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
$file = $cacheDir.DIRECTORY_SEPARATOR.$tempSchema;
$filesystem->copy((string) $finalSchema, $file, true);
// the package needs to be set absolute
// besides, the automated namespace to package conversion has
// not taken place yet so it needs to be done manually
@ -253,41 +243,6 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
}
}
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
{
$schemaPath = str_replace($bundle->getPath().'/Resources/config/', '', $schema->getPathname());
return sprintf('@%s/Resources/config/%s', $bundle->getName(), $schemaPath);
}
private function getFileLocator()
{
return $this->getContainer()->get('file_locator');
}
/**
* Return the package prefix for a given bundle.
*
* @param Bundle $bundle
* @param string $baseDirectory The base directory to exclude from prefix.
*
* @return string
*/
public static function getPackagePrefix(Bundle $bundle, $baseDirectory = '')
{
$parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
$length = count(explode('\\', $bundle->getNamespace())) * (-1);
$prefix = implode(DIRECTORY_SEPARATOR, array_slice($parts, 1, $length));
$prefix = ltrim(str_replace($baseDirectory, '', $prefix), DIRECTORY_SEPARATOR);
if (!empty($prefix)) {
$prefix = str_replace(DIRECTORY_SEPARATOR, '.', $prefix).'.';
}
return $prefix;
}
/**
* Create a 'build.properties' file.
*
@ -391,7 +346,8 @@ EOT;
* Return the current Propel cache directory.
* @return string The current Propel cache directory.
*/
protected function getCacheDir() {
protected function getCacheDir()
{
return $this->cacheDir;
}
@ -405,7 +361,8 @@ EOT;
* @throw \InvalidArgumentException If the connection does not exist.
* @return array
*/
protected function getConnection(InputInterface $input, OutputInterface $output) {
protected function getConnection(InputInterface $input, OutputInterface $output)
{
$propelConfiguration = $this->getContainer()->get('propel.configuration');
$name = $input->getOption('connection') ?: $this->getContainer()->getParameter('propel.dbal.default_connection');
@ -427,8 +384,10 @@ EOT;
* @param string $dsn A DSN
* @return string The database name extracted from the given DSN
*/
protected function parseDbName($dsn) {
protected function parseDbName($dsn)
{
preg_match('#dbname=([a-zA-Z0-9\_]+)#', $dsn, $matches);
return $matches[1];
}
@ -521,4 +480,50 @@ EOT;
{
return $this->getHelperSet()->get('dialog')->askConfirmation($output, $question, $default);
}
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
{
$schemaPath = str_replace($bundle->getPath().'/Resources/config/', '', $schema->getPathname());
return sprintf('@%s/Resources/config/%s', $bundle->getName(), $schemaPath);
}
private function getFileLocator()
{
return $this->getContainer()->get('file_locator');
}
/**
* Compiles arguments/properties for the Phing process.
* @return array
*/
private function getPhingArguments(KernelInterface $kernel, $workingDirectory, $properties)
{
$args = array();
// Default properties
$properties = array_merge(array(
'propel.database' => 'mysql',
'project.dir' => $workingDirectory,
'propel.output.dir' => $kernel->getRootDir().'/propel',
'propel.php.dir' => $kernel->getRootDir().'/..',
'propel.packageObjectModel' => true,
), $properties);
// Adding user defined properties from the configuration
$properties = array_merge(
$properties,
$this->getContainer()->get('propel.build_properties')->getProperties()
);
foreach ($properties as $key => $value) {
$args[] = "-D$key=$value";
}
// Build file
$args[] = '-f';
$args[] = realpath($this->getContainer()->getParameter('propel.path').'/generator/build.xml');
return $args;
}
}

View file

@ -60,6 +60,7 @@ EOT
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
$output->writeln('Aborted, nice decision !');
return -2;
}
}

View file

@ -74,6 +74,7 @@ EOT
'[Propel] Exception',
'',
$e->getMessage()), 'fg=white;bg=red');
return false;
}

View file

@ -188,6 +188,7 @@ EOT
'[Propel] Exception',
'',
$e->getMessage()), 'fg=white;bg=red');
return false;
}
@ -279,8 +280,10 @@ EOT
), 'fg=green;bg=black');
} else {
$this->writeTaskError($output, 'insert-sql', false);
return false;
}
return true;
}
}

View file

@ -74,6 +74,7 @@ EOT
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
$output->writeln('<info>Aborted, nice decision !</info>');
return -2;
}
}

View file

@ -202,6 +202,7 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum
}
}
}
return $classes;
}

View file

@ -23,6 +23,7 @@ class XmlDataLoader extends AbstractDataLoader
protected function transformDataToArray($file)
{
$xml = simplexml_load_file($file);
return $this->simpleXmlToArray($xml);
}
@ -54,6 +55,7 @@ class XmlDataLoader extends AbstractDataLoader
}
}
}
return $array;
}
}

View file

@ -188,12 +188,14 @@ class ModelChoiceList extends ArrayChoiceList
if (count($this->identifier) > 1) {
// $key is a collection index
$models = $this->getModels();
return isset($models[$key]) ? $models[$key] : null;
} else if ($this->models) {
return isset($this->models[$key]) ? $this->models[$key] : null;
}
$queryClass = $this->class . 'Query';
return $queryClass::create()->findPk($key);
} catch (NoResultException $e) {
return null;

View file

@ -85,6 +85,7 @@ class ModelUserProvider implements UserProviderInterface
}
$proxyClass = $this->proxyClass;
return new $proxyClass($user);
}

View file

@ -27,8 +27,10 @@ class BookQuery extends BaseBookQuery {
if (1 === $key) {
$book = new Book();
$book->setId(1);
return $book;
}
return null;
}
@ -40,6 +42,7 @@ class BookQuery extends BaseBookQuery {
if ('my-book' == $slug) {
$this->bySlug = true;
}
return $this;
}
@ -61,8 +64,10 @@ class BookQuery extends BaseBookQuery {
$book->setId(1);
$book->setName('My Book');
$book->setSlug('my-book');
return $book;
}
return null;
}
} // BookQuery

View file

@ -349,6 +349,7 @@ abstract class BaseBook extends BaseObject implements Persistent
$affectedRows = 0;
}
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
@ -399,6 +400,7 @@ abstract class BaseBook extends BaseObject implements Persistent
$this->alreadyInSave = false;
}
return $affectedRows;
} // doSave()
@ -436,9 +438,11 @@ abstract class BaseBook extends BaseObject implements Persistent
$res = $this->doValidate($columns);
if ($res === true) {
$this->validationFailures = array();
return true;
} else {
$this->validationFailures = $res;
return false;
}
}
@ -487,6 +491,7 @@ abstract class BaseBook extends BaseObject implements Persistent
{
$pos = BookPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
$field = $this->getByPosition($pos);
return $field;
}
@ -541,6 +546,7 @@ abstract class BaseBook extends BaseObject implements Persistent
$keys[1] => $this->getName(),
$keys[2] => $this->getSlug(),
);
return $result;
}
@ -557,6 +563,7 @@ abstract class BaseBook extends BaseObject implements Persistent
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
{
$pos = BookPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
return $this->setByPosition($pos, $value);
}
@ -709,6 +716,7 @@ abstract class BaseBook extends BaseObject implements Persistent
$clazz = get_class($this);
$copyObj = new $clazz();
$this->copyInto($copyObj, $deepCopy);
return $copyObj;
}
@ -726,6 +734,7 @@ abstract class BaseBook extends BaseObject implements Persistent
if (self::$peer === null) {
self::$peer = new BookPeer();
}
return self::$peer;
}

View file

@ -113,6 +113,7 @@ abstract class BaseBookPeer {
if ($key === null) {
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
}
return $toNames[$key];
}
@ -130,6 +131,7 @@ abstract class BaseBookPeer {
if (!array_key_exists($type, self::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
}
return self::$fieldNames[$type];
}
@ -216,6 +218,7 @@ abstract class BaseBookPeer {
$count = 0; // no rows returned; we infer that means 0 matches.
}
$stmt->closeCursor();
return $count;
}
/**
@ -235,6 +238,7 @@ abstract class BaseBookPeer {
if ($objects) {
return $objects[0];
}
return null;
}
/**
@ -346,6 +350,7 @@ abstract class BaseBookPeer {
return self::$instances[$key];
}
}
return null; // just to be explicit
}
@ -383,6 +388,7 @@ abstract class BaseBookPeer {
if ($row[$startcol] === null) {
return null;
}
return (string) $row[$startcol];
}
@ -429,6 +435,7 @@ abstract class BaseBookPeer {
} // if key exists
}
$stmt->closeCursor();
return $results;
}
/**
@ -454,6 +461,7 @@ abstract class BaseBookPeer {
$col = $obj->hydrate($row, $startcol);
BookPeer::addInstanceToPool($obj, $key);
}
return array($obj, $col);
}
@ -602,6 +610,7 @@ abstract class BaseBookPeer {
BookPeer::clearInstancePool();
BookPeer::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
@ -660,6 +669,7 @@ abstract class BaseBookPeer {
$affectedRows += BasePeer::doDelete($criteria, $con);
BookPeer::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
@ -752,6 +762,7 @@ abstract class BaseBookPeer {
$criteria->add(BookPeer::ID, $pks, Criteria::IN);
$objs = BookPeer::doSelect($criteria, $con);
}
return $objs;
}

View file

@ -73,6 +73,7 @@ abstract class BaseBookQuery extends ModelCriteria
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
}
@ -98,6 +99,7 @@ abstract class BaseBookQuery extends ModelCriteria
$stmt = $criteria
->filterByPrimaryKey($key)
->getSelectStatement($con);
return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
}
}
@ -115,6 +117,7 @@ abstract class BaseBookQuery extends ModelCriteria
public function findPks($keys, $con = null)
{
$criteria = $this->isKeepQuery() ? clone $this : $this;
return $this
->filterByPrimaryKeys($keys)
->find($con);
@ -167,6 +170,7 @@ abstract class BaseBookQuery extends ModelCriteria
if (is_array($id) && null === $comparison) {
$comparison = Criteria::IN;
}
return $this->addUsingAlias(BookPeer::ID, $id, $comparison);
}
@ -195,6 +199,7 @@ abstract class BaseBookQuery extends ModelCriteria
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(BookPeer::NAME, $name, $comparison);
}
@ -223,6 +228,7 @@ abstract class BaseBookQuery extends ModelCriteria
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(BookPeer::SLUG, $slug, $comparison);
}

View file

@ -19,6 +19,7 @@ spl_autoload_register(function($class) {
return false;
}
require_once $path;
return true;
}
});