Removed.
This commit is contained in:
parent
0d056d772f
commit
f63efd9661
@ -1,7 +0,0 @@
|
|||||||
Copyright (c) 2004-2006 Fabien Potencier
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,25 +0,0 @@
|
|||||||
sfDoctrine symfony plugin
|
|
||||||
=========================
|
|
||||||
|
|
||||||
Overview
|
|
||||||
--------
|
|
||||||
|
|
||||||
The sfDoctrine plugin allows you to totally replace propel with doctrine (http://www.phpdoctrine.com/) which is a powerful and easy-to-use ORM.
|
|
||||||
|
|
||||||
|
|
||||||
Contents
|
|
||||||
--------
|
|
||||||
|
|
||||||
This plugin contains:
|
|
||||||
- necessary tools to use doctrine: the main tool is sfDoctrine::getTable() which will allow you to send queries
|
|
||||||
- pake tasks that convert between doctrine and propel schema formats and build doctrine model classes automatically
|
|
||||||
- an admin generator: to use it just specify sfDoctrineAdmin as the main class in your generator.yml config
|
|
||||||
|
|
||||||
You will find more information in the wiki page dedicated to sfDoctrine: http://www.symfony-project.com/trac/wiki/sfDoctrine.
|
|
||||||
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
For the full copyright and license information, please view the LICENSE
|
|
||||||
file that was distributed with this source code.
|
|
@ -1,502 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineClassSchema.class.php 4696 2007-07-20 17:04:44Z gnat $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineClassSchema
|
|
||||||
{
|
|
||||||
// the table associated to this class
|
|
||||||
protected $table;
|
|
||||||
|
|
||||||
// class name
|
|
||||||
protected $phpName;
|
|
||||||
|
|
||||||
// list of columns
|
|
||||||
protected $columns = array();
|
|
||||||
|
|
||||||
// list of relations (foreign keys) linking to this class
|
|
||||||
protected $many = array();
|
|
||||||
|
|
||||||
// inheritance description
|
|
||||||
protected $inheritance = array();
|
|
||||||
|
|
||||||
// i18n description
|
|
||||||
protected $i18n = array();
|
|
||||||
|
|
||||||
// indexes
|
|
||||||
protected $indexes = array();
|
|
||||||
|
|
||||||
// Uniques
|
|
||||||
protected $uniques = array();
|
|
||||||
|
|
||||||
// options
|
|
||||||
protected $options = array();
|
|
||||||
|
|
||||||
public function __construct($name, array $cd = array())
|
|
||||||
{
|
|
||||||
$this->setPhpName($name);
|
|
||||||
|
|
||||||
// elementary key verification
|
|
||||||
$illegalKeys = array_diff_key($cd, array_flip(array('columns', 'tableName', 'inheritance', 'i18n', 'indexes', 'uniques', 'options')));
|
|
||||||
|
|
||||||
if ($illegalKeys)
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Invalid key "%s" in description of class "%s"', array_shift(array_keys($illegalKeys)), $name));
|
|
||||||
|
|
||||||
if (isset($cd['inheritance']))
|
|
||||||
{
|
|
||||||
$this->setInheritance($cd['inheritance']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set i18n
|
|
||||||
if (isset($cd['i18n']))
|
|
||||||
$this->setI18n($cd['i18n']);
|
|
||||||
|
|
||||||
// add indexes
|
|
||||||
if (isset($cd['indexes']))
|
|
||||||
$this->addIndexes($cd['indexes']);
|
|
||||||
|
|
||||||
// add uniques
|
|
||||||
if (isset($cd['uniques']))
|
|
||||||
$this->addUniques($cd['uniques']);
|
|
||||||
|
|
||||||
// add options
|
|
||||||
if (isset($cd['options']))
|
|
||||||
$this->addOptions($cd['options']);
|
|
||||||
|
|
||||||
// add columns
|
|
||||||
if (isset($cd['columns']))
|
|
||||||
foreach ($cd['columns'] as $colName => $column)
|
|
||||||
{
|
|
||||||
$docCol = new sfDoctrineColumnSchema($colName, $column);
|
|
||||||
$this->addColumn($docCol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add a column if none with the same name is already there
|
|
||||||
public function addColumn($docCol)
|
|
||||||
{
|
|
||||||
if (isset($this->columns[$docCol->getName()]))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// sets up the possible relation for that column
|
|
||||||
$docCol->setUpForeignRelation($this->getPhpName());
|
|
||||||
|
|
||||||
$this->columns[$docCol->getName()] = $docCol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColumns()
|
|
||||||
{
|
|
||||||
return $this->columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for testing only
|
|
||||||
public function getColumn($colName)
|
|
||||||
{
|
|
||||||
if (!isset($this->columns[$colName]))
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Column "%s" is not defined', $colName));
|
|
||||||
return $this->columns[$colName];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addToMany($relation)
|
|
||||||
{
|
|
||||||
$this->many[] = $relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPhpName()
|
|
||||||
{
|
|
||||||
return $this->phpName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPhpName($newName)
|
|
||||||
{
|
|
||||||
$this->phpName = $newName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTable($table)
|
|
||||||
{
|
|
||||||
$this->table = $table;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTable()
|
|
||||||
{
|
|
||||||
if (!$this->hasTable())
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Table not defined for class "%s"', $this->getPhpName()));
|
|
||||||
return $this->table;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTableName()
|
|
||||||
{
|
|
||||||
return $this->getTable()->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasTable()
|
|
||||||
{
|
|
||||||
return isset($this->table);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setI18n($i18n)
|
|
||||||
{
|
|
||||||
$check = array('class', 'cultureField');
|
|
||||||
foreach ($check as $key)
|
|
||||||
if (!isset($i18n[$key]))
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('The key "%s" is missing from the i18n information for class "%s".', $key, $this->getPhpName()));
|
|
||||||
$this->i18n = $i18n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasI18n()
|
|
||||||
{
|
|
||||||
return !empty($this->i18n);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getI18n($key)
|
|
||||||
{
|
|
||||||
return $this->i18n[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setInheritance($inh)
|
|
||||||
{
|
|
||||||
$check = array('extends');
|
|
||||||
if (isset($inh['keyField']) || isset($inh['keyValue']))
|
|
||||||
$check = array_merge($check, array('keyField', 'keyValue'));
|
|
||||||
elseif (isset($inh['keyFields']))
|
|
||||||
$check = array_merge($check, array('keyFields'));
|
|
||||||
|
|
||||||
foreach ($check as $key)
|
|
||||||
if (!isset($inh[$key]))
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('The key "%s" is missing from the inheritance information for class "%s".', $key, $this->getPhpName()));
|
|
||||||
$this->inheritance = $inh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getInheritance()
|
|
||||||
{
|
|
||||||
return $this->inheritance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasOneTableInheritance()
|
|
||||||
{
|
|
||||||
if ($inh = $this->inheritance)
|
|
||||||
if (isset($inh['keyValue']) || isset($inh['keyFields']))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOptions()
|
|
||||||
{
|
|
||||||
return $this->options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addOptions($options)
|
|
||||||
{
|
|
||||||
$this->options = $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasOptions()
|
|
||||||
{
|
|
||||||
return count($this->options) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIndexes()
|
|
||||||
{
|
|
||||||
return $this->indexes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addIndexes($indexes)
|
|
||||||
{
|
|
||||||
$this->indexes = $indexes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasIndexes()
|
|
||||||
{
|
|
||||||
return count($this->indexes) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addUniques($uniques)
|
|
||||||
{
|
|
||||||
$this->uniques = $uniques;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasUniques()
|
|
||||||
{
|
|
||||||
return count($this->uniques) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getParentClassName()
|
|
||||||
{
|
|
||||||
return $this->inheritance['extends'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// generates the name of the generated class
|
|
||||||
public function basePhpName($name = null)
|
|
||||||
{
|
|
||||||
if (!$name)
|
|
||||||
$name = $this->getPhpName();
|
|
||||||
return 'Base'.$name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// outputs a function in php
|
|
||||||
public static function outputFunction($functionName, $contents, $phpdoc = '')
|
|
||||||
{
|
|
||||||
if (is_array($contents))
|
|
||||||
$contents = implode("\n ", $contents);
|
|
||||||
return "
|
|
||||||
$phpdoc
|
|
||||||
public function $functionName()
|
|
||||||
{
|
|
||||||
$contents
|
|
||||||
}
|
|
||||||
";
|
|
||||||
}
|
|
||||||
|
|
||||||
// output a class in php
|
|
||||||
public static function outputClass($className, $extends, $contents, $phpdoc = '')
|
|
||||||
{
|
|
||||||
$signature = sprintf("auto-generated by the sfDoctrine plugin");
|
|
||||||
return "<?php
|
|
||||||
/*
|
|
||||||
* $phpdoc
|
|
||||||
*
|
|
||||||
* $signature
|
|
||||||
*/
|
|
||||||
class $className extends $extends
|
|
||||||
{
|
|
||||||
$contents
|
|
||||||
}
|
|
||||||
";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRelation($columnName)
|
|
||||||
{
|
|
||||||
return $this->columns[$columnName]->getRelation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// this function returns an array ('className'=><class name>, 'source'=><class file contents>, 'base'=>true/false) of PHP classes
|
|
||||||
// corresponding to this class
|
|
||||||
public function asPHP()
|
|
||||||
{
|
|
||||||
$classes = array();
|
|
||||||
|
|
||||||
// main base class
|
|
||||||
$out = array();
|
|
||||||
|
|
||||||
$tableDef = array();
|
|
||||||
$setup = array();
|
|
||||||
|
|
||||||
// if that class inherits from another we call the parent methods
|
|
||||||
if ($this->inheritance)
|
|
||||||
{
|
|
||||||
$tableDef[] = "parent::setTableDefinition();\n";
|
|
||||||
$setup[] = "parent::setUp();\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it is a table we define the table name
|
|
||||||
if ($this->hasTable())
|
|
||||||
{
|
|
||||||
$tableDef[] = "\$this->setTableName('{$this->getTableName()}');\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->columns as $column)
|
|
||||||
{
|
|
||||||
$args = array();
|
|
||||||
|
|
||||||
$tableDef[] = $column->asPhp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// declare indexes if any
|
|
||||||
foreach ($this->indexes as $name => $value)
|
|
||||||
{
|
|
||||||
// only write option if value is set
|
|
||||||
if(!empty($value))
|
|
||||||
{
|
|
||||||
$valueExport = is_array($value) ? var_export($value, true) : "'$value'";
|
|
||||||
$tableDef[] = "\$this->index('$name', $valueExport);";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// declare uniques if any
|
|
||||||
foreach ($this->uniques as $name => $value)
|
|
||||||
{
|
|
||||||
// only write option if value is set
|
|
||||||
if(!empty($value))
|
|
||||||
{
|
|
||||||
$valueExport = is_array($value) ? var_export($value, true) : "'$value'";
|
|
||||||
$tableDef[] = "\$this->unique('$name', $valueExport);";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->options as $name => $value)
|
|
||||||
{
|
|
||||||
// only write option if value is set
|
|
||||||
if(!empty($value))
|
|
||||||
{
|
|
||||||
$valueExport = is_array($value) ? var_export($value, true) : "'$value'";
|
|
||||||
$tableDef[] = "\$this->option('$name', $valueExport);";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$out[] = self::outputFunction('setTableDefinition', $tableDef);
|
|
||||||
|
|
||||||
// has/own one
|
|
||||||
foreach($this->columns as $col)
|
|
||||||
if ($rel = $col->getRelation())
|
|
||||||
{
|
|
||||||
$setup[] = $rel->asOnePhp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// has/own many
|
|
||||||
foreach($this->many as $rel)
|
|
||||||
{
|
|
||||||
$setup[] = $rel->asManyPhp();
|
|
||||||
}
|
|
||||||
|
|
||||||
// declare inheritance if needed
|
|
||||||
if ($this->hasOneTableInheritance())
|
|
||||||
{
|
|
||||||
$inh = $this->getInheritance();
|
|
||||||
if (isset($inh['keyFields']))
|
|
||||||
{
|
|
||||||
$keyFields = $inh['keyFields'];
|
|
||||||
$keyFields = is_array($keyFields) ? $keyFields : array($keyFields);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$keyFields = array($inh['keyField'] => $inh['keyValue']);
|
|
||||||
|
|
||||||
$setup[] = '$this->setInheritanceMap('.var_export($keyFields, true).');';
|
|
||||||
}
|
|
||||||
|
|
||||||
// declare i18n if any
|
|
||||||
if ($this->hasI18n())
|
|
||||||
$setup[] = "\$this->hasI18nTable('{$this->getI18n('class')}', '{$this->getI18n('cultureField')}');";
|
|
||||||
|
|
||||||
$out[] = self::outputFunction('setUp', $setup);
|
|
||||||
|
|
||||||
// the following could also be: if ($this->inheritance)
|
|
||||||
// FIXME: create a global class!
|
|
||||||
if (isset($this->inheritance['extends']))
|
|
||||||
$parentName = $this->inheritance['extends'];
|
|
||||||
else
|
|
||||||
$parentName = ($this->hasI18n() ? 'sfDoctrineRecordI18n' : 'sfDoctrineRecord');
|
|
||||||
|
|
||||||
|
|
||||||
$class = array
|
|
||||||
(
|
|
||||||
'name' => $this->getPhpName(), // name of the child class; used only internally
|
|
||||||
'className' => $this->basePHPName(),
|
|
||||||
'source' => self::outputClass($this->basePHPName(), $parentName, implode("\n", $out), 'Base class; DO NOT EDIT'),
|
|
||||||
'overwrite' => true, // carful! even this set to false will overwrite!!!
|
|
||||||
);
|
|
||||||
|
|
||||||
$classes[] = $class;
|
|
||||||
|
|
||||||
$package = $this->getTable()->getPackage();
|
|
||||||
|
|
||||||
// generate the empty user and table classes
|
|
||||||
foreach ($classes as $baseClass)
|
|
||||||
{
|
|
||||||
$name = $baseClass['name'];
|
|
||||||
$parentClass = $baseClass['className'];
|
|
||||||
|
|
||||||
$tableName = $name.'Table'; // convention imposed by Doctrine
|
|
||||||
if (isset($this->inheritance['extends']))
|
|
||||||
$parentTable = $this->inheritance['extends'].'Table';
|
|
||||||
else
|
|
||||||
$parentTable = 'Doctrine_Table';
|
|
||||||
|
|
||||||
if ($package)
|
|
||||||
{
|
|
||||||
$pluginClassName = 'Plugin'.$name;
|
|
||||||
$classes[] = array
|
|
||||||
(
|
|
||||||
'className'=> $pluginClassName,
|
|
||||||
'source' => self::outputClass($pluginClassName, $parentClass, '', 'Plugin class'),
|
|
||||||
'plugin' => true,
|
|
||||||
);
|
|
||||||
// we hook the plugin class name in
|
|
||||||
$parentClass = $pluginClassName;
|
|
||||||
|
|
||||||
// same for tables
|
|
||||||
$pluginTableName = 'Plugin'.$tableName;
|
|
||||||
$classes[] = array
|
|
||||||
(
|
|
||||||
'className' => $pluginTableName,
|
|
||||||
'source' => self::outputClass($pluginTableName, $parentTable, '', 'Plugin table'),
|
|
||||||
'plugin' => true,
|
|
||||||
);
|
|
||||||
$parentTable = $pluginTableName;
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes[] = array
|
|
||||||
(
|
|
||||||
'className'=>$name,
|
|
||||||
'source'=>self::outputClass($name, $parentClass, '', 'Edit this file to customise your model class'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$classes[] = array
|
|
||||||
(
|
|
||||||
'className'=>$tableName,
|
|
||||||
'source'=>self::outputClass($tableName, $parentTable, '', 'Edit this file to customise your model table'),
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// outputs a nested array
|
|
||||||
public function asDoctrineYml()
|
|
||||||
{
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
if ($this->inheritance)
|
|
||||||
$output['inheritance'] = $this->inheritance;
|
|
||||||
else
|
|
||||||
$output['tableName'] = $this->getTableName();
|
|
||||||
|
|
||||||
$cols = array();
|
|
||||||
foreach ($this->columns as $col)
|
|
||||||
{
|
|
||||||
$cols[$col->getName()] = $col->asDoctrineYml();
|
|
||||||
}
|
|
||||||
|
|
||||||
$output['columns'] = $cols;
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
// outputs the columns of that class in propel xml format
|
|
||||||
public function addPropelXmlColumns(&$table)
|
|
||||||
{
|
|
||||||
// we add the id column which is automatically created in doctrine
|
|
||||||
$this->addColumn(new sfDoctrineColumnSchema('id', array('type'=>'integer', 'size'=>10, 'primary'=>true, 'autoincrement'=>true)));
|
|
||||||
foreach($this->columns as $col)
|
|
||||||
{
|
|
||||||
$col->addPropelXml($table);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function debug()
|
|
||||||
{
|
|
||||||
$debug = array();
|
|
||||||
$debug['inheritance'] = $this->inheritance;
|
|
||||||
$debug['many'] = $this->many;
|
|
||||||
$debug['i18n'] = $this->i18n;
|
|
||||||
foreach ($this->columns as $col)
|
|
||||||
{
|
|
||||||
$debug['columns'][$col->getName()] = $col->debug();
|
|
||||||
}
|
|
||||||
return $debug;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,368 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineColumnSchema.class.php 4084 2007-05-23 09:48:50Z chtito $
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
This class stores information about a column in two arrays:
|
|
||||||
- properties: contains the name, type, size and constraints
|
|
||||||
- columnInfo: contains also the foreign relation information
|
|
||||||
*/
|
|
||||||
class sfDoctrineColumnSchema
|
|
||||||
{
|
|
||||||
protected static $propel2docDictionary = array(
|
|
||||||
'types'=> array(
|
|
||||||
'tinyint' => 'integer',
|
|
||||||
'smallint' => 'integer',
|
|
||||||
'bigint' => 'integer',
|
|
||||||
'real' => 'float',
|
|
||||||
'decimal' => 'float',
|
|
||||||
'char' => 'string',
|
|
||||||
'varchar' => 'string',
|
|
||||||
'longvarchar' => 'string',
|
|
||||||
# 'smallint'=> 'enum', // enums are converted to smallints
|
|
||||||
# 'blob' => 'array', // arrays will be blobs
|
|
||||||
# 'integer' => 'integer', // to convert doc integer to integer
|
|
||||||
/*
|
|
||||||
'double' => 'double',
|
|
||||||
'float' => 'float',
|
|
||||||
'boolean' => 'boolean',
|
|
||||||
'date' => 'date',
|
|
||||||
'time' => 'timestamp',
|
|
||||||
'timestamp' => 'timestamp',
|
|
||||||
'blob' => 'blob',
|
|
||||||
'clob' => 'clob'
|
|
||||||
*/
|
|
||||||
),
|
|
||||||
'constraints' => array('autoIncrement' => 'autoincrement', 'primaryKey' => 'primary')
|
|
||||||
);
|
|
||||||
|
|
||||||
//FIXME: double, float,real???
|
|
||||||
protected static $defaultPropelSize = array(
|
|
||||||
'tinyint' => 3,
|
|
||||||
'smallint' => 5,
|
|
||||||
'integer' => 11,
|
|
||||||
'bigint' => 20,
|
|
||||||
'longvarchar'=>4000,
|
|
||||||
);
|
|
||||||
|
|
||||||
protected static $defaultDoctrineSize = array(
|
|
||||||
'string'=> 4000,
|
|
||||||
'integer' => 10,
|
|
||||||
'double' => 10,
|
|
||||||
'float' => 10,
|
|
||||||
'enum' => 2,
|
|
||||||
'array' => 100,
|
|
||||||
);
|
|
||||||
|
|
||||||
static $allowedConstraints = array('primary', 'autoincrement', 'default', 'enum', 'unique', 'nospace', 'notblank', 'notnull', 'email', 'scale', 'zerofill');
|
|
||||||
|
|
||||||
// column properties: name, size, type and constraints
|
|
||||||
protected $properties;
|
|
||||||
|
|
||||||
// column name
|
|
||||||
protected $name;
|
|
||||||
|
|
||||||
// temporary storage of the description array; used when the class sets up the relation
|
|
||||||
protected $columnInfo;
|
|
||||||
|
|
||||||
// set if the column is a foreign key
|
|
||||||
protected $relation = null;
|
|
||||||
|
|
||||||
// we essentially set up the properties array
|
|
||||||
// and translate from propel if needed
|
|
||||||
public function __construct($colName, $columnDescription = array(), $translatePropel = false)
|
|
||||||
{
|
|
||||||
// sometimes we get null if the yml line is empty
|
|
||||||
if ($columnDescription == null)
|
|
||||||
$columnDescription = array();
|
|
||||||
|
|
||||||
// for the short syntax type(size)
|
|
||||||
if (is_string($columnDescription))
|
|
||||||
$columnDescription = array('type'=>$columnDescription);
|
|
||||||
|
|
||||||
$this->setName($colName);
|
|
||||||
|
|
||||||
$columnInfo = new sfParameterHolder();
|
|
||||||
$columnInfo->add($columnDescription);
|
|
||||||
|
|
||||||
if ($translatePropel)
|
|
||||||
{
|
|
||||||
// we translate the propel types to doctrine ones
|
|
||||||
$propelType = strtolower($columnInfo->get('type'));
|
|
||||||
if (array_key_exists($propelType, self::$propel2docDictionary['types']))
|
|
||||||
$columnInfo->set('type', self::$propel2docDictionary['types'][$propelType]);
|
|
||||||
else
|
|
||||||
$columnInfo->set('type', $propelType); // we store it in lowercase
|
|
||||||
|
|
||||||
// if there is a default propel size we set it
|
|
||||||
if (!$columnInfo->get('size'))
|
|
||||||
if (isset(self::$defaultPropelSize[$propelType]))
|
|
||||||
$columnInfo->set('size', self::$defaultPropelSize[$propelType]);
|
|
||||||
|
|
||||||
// we translate the constraints
|
|
||||||
foreach ($columnInfo->getAll() as $key=>$value)
|
|
||||||
{
|
|
||||||
if (array_key_exists($key, self::$propel2docDictionary['constraints']))
|
|
||||||
$columnInfo->set(self::$propel2docDictionary['constraints'][$key], $columnInfo->get($key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we store the raw description, only used in setUpForeignRelation
|
|
||||||
$this->columnInfo = $columnInfo;
|
|
||||||
|
|
||||||
|
|
||||||
// name
|
|
||||||
$this->setProperty('name', $colName);
|
|
||||||
$this->setProperty('columnName', $columnInfo->get('columnName'));
|
|
||||||
|
|
||||||
// type
|
|
||||||
if (!($type = $columnInfo->get('type')))
|
|
||||||
{
|
|
||||||
// we try to figure out the type
|
|
||||||
// FIXME: write a method to detect relations?
|
|
||||||
if ($columnInfo->get('foreignClass') || $columnInfo->get('foreignTable'))
|
|
||||||
$type = 'integer'; // foreign key
|
|
||||||
else
|
|
||||||
$type = 'string'; // default type
|
|
||||||
}
|
|
||||||
elseif(is_string($type)) // we check for the short syntax type
|
|
||||||
{
|
|
||||||
preg_match('/([^\(\s]+)\s*\([\s]*([\d]+)[\s]*\)/', $type, $matches);
|
|
||||||
if (!empty($matches))
|
|
||||||
{
|
|
||||||
$type = $matches[1];
|
|
||||||
$columnInfo->set('size', $matches[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->setProperty('type', $type);
|
|
||||||
|
|
||||||
// size
|
|
||||||
if (!($size = $columnInfo->get('size')))
|
|
||||||
{
|
|
||||||
if (is_string($type))
|
|
||||||
{
|
|
||||||
if (isset(self::$defaultDoctrineSize[$type]))
|
|
||||||
$size = self::$defaultDoctrineSize[$type]; // we have a default size for this type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$size)
|
|
||||||
$size = 'null';
|
|
||||||
|
|
||||||
|
|
||||||
$this->setProperty('size', $size);
|
|
||||||
|
|
||||||
// constraints
|
|
||||||
if ($constraints = array_intersect_key($columnDescription, array_flip(self::$allowedConstraints)))
|
|
||||||
$this->properties = array_merge($this->properties, $constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: simplify this function
|
|
||||||
public function setUpForeignRelation($className)
|
|
||||||
{
|
|
||||||
$colInfo = $this->getColumnInfo();
|
|
||||||
$colName = $this->getName();
|
|
||||||
|
|
||||||
// If there is no relation info for this column
|
|
||||||
if (!$colInfo->has('foreignTable') && !$colInfo->has('foreignClass'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$foreignClass = $colInfo->get('foreignClass');
|
|
||||||
|
|
||||||
// if the localName (plural name) is not specified, we add an "s"
|
|
||||||
// as propel does
|
|
||||||
$localName = $colInfo->get('localName', $className.'s');
|
|
||||||
$foreignTable = $colInfo->get('foreignTable');
|
|
||||||
|
|
||||||
$foreignName = $colInfo->get('foreignName', null);
|
|
||||||
|
|
||||||
$fr = $colInfo->get('foreignReference', 'id');
|
|
||||||
|
|
||||||
$counterpart = $colInfo->get('counterpart');
|
|
||||||
|
|
||||||
$relationInfo = array
|
|
||||||
(
|
|
||||||
'localReference'=>$colName,
|
|
||||||
'foreignReference'=>$fr,
|
|
||||||
'localName'=>$localName,
|
|
||||||
'foreignName'=>$foreignName,
|
|
||||||
'counterpart' => $counterpart,
|
|
||||||
'foreignClass'=>$foreignClass,
|
|
||||||
'foreignTable'=>$foreignTable, // used only for propel import
|
|
||||||
'localClass'=>$className,
|
|
||||||
'options'=>$colInfo, // the remaining relation options
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->relation = new sfDoctrineRelationSchema($relationInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColumnInfo()
|
|
||||||
{
|
|
||||||
return $this->columnInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRelation()
|
|
||||||
{
|
|
||||||
return $this->relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasRelation()
|
|
||||||
{
|
|
||||||
return isset($this->relation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setProperty($name, $value)
|
|
||||||
{
|
|
||||||
$this->properties[$name] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getProperty($name)
|
|
||||||
{
|
|
||||||
return $this->properties[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getProperties()
|
|
||||||
{
|
|
||||||
return $this->properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function niceVarExport($array)
|
|
||||||
{
|
|
||||||
return str_replace(array("\n"), array(''), var_export($array, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected $doctrineArgs = array('name' => false, 'type' => true, 'size' => false);
|
|
||||||
|
|
||||||
// generates the doctrine description of a column in PHP
|
|
||||||
public function asPhp()
|
|
||||||
{
|
|
||||||
$props = $this->getProperties();
|
|
||||||
|
|
||||||
$args = array();
|
|
||||||
|
|
||||||
// take care of the enum type
|
|
||||||
// FIXME: remove this "trick" some day?
|
|
||||||
if (is_array($props['type']))
|
|
||||||
{
|
|
||||||
$props['values'] = $props['type'];
|
|
||||||
$props['type'] = 'enum';
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
foreach (self::$doctrineArgs as $argName => $isString)
|
|
||||||
{
|
|
||||||
$arg = $props[$argName];
|
|
||||||
unset($props[$argName]);
|
|
||||||
if ($isString)
|
|
||||||
$arg = sprintf("'%s'", $arg);
|
|
||||||
$args[] = $arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
$columnAlias = '';
|
|
||||||
if ($props['columnName'])
|
|
||||||
{
|
|
||||||
$columnAlias = $props['columnName'] . ' as ';
|
|
||||||
}
|
|
||||||
unset($props['columnName']);
|
|
||||||
|
|
||||||
$args[0] = sprintf("'%s%s'", $columnAlias, $args[0]);
|
|
||||||
|
|
||||||
// what remains is considered to be constraints
|
|
||||||
$args[] = $this->niceVarExport($props);
|
|
||||||
|
|
||||||
$output[] = sprintf('$this->hasColumn(%s);', implode(', ', $args));
|
|
||||||
|
|
||||||
return implode("\n", $output);
|
|
||||||
}
|
|
||||||
|
|
||||||
// exports this column in propel xml format
|
|
||||||
public function addPropelXml(&$node)
|
|
||||||
{
|
|
||||||
$c = $node->addChild('column');
|
|
||||||
|
|
||||||
$doc2proplDict = array_flip(self::$propel2docDictionary['types']);
|
|
||||||
|
|
||||||
$c->addAttribute('name', $this->getName());
|
|
||||||
|
|
||||||
// type
|
|
||||||
$type = $this->properties['type'];
|
|
||||||
if (array_key_exists($this->properties['type'], $doc2proplDict))
|
|
||||||
$type = $doc2proplDict[$type];
|
|
||||||
$c->addAttribute('type', $type);
|
|
||||||
|
|
||||||
// size
|
|
||||||
$size = $this->properties['size'];
|
|
||||||
if ($type == 'varchar')
|
|
||||||
$c->addAttribute('size', $size);
|
|
||||||
|
|
||||||
// constraints
|
|
||||||
$constraints = array_diff_key($this->properties, array_flip(array('name', 'type', 'size')));
|
|
||||||
$doc2propelDict = array_flip(self::$propel2docDictionary['constraints']);
|
|
||||||
foreach ($constraints as $constraint=>$value)
|
|
||||||
{
|
|
||||||
if (array_key_exists($constraint, $doc2propelDict))
|
|
||||||
$constraint = $doc2propelDict[$constraint];
|
|
||||||
$c->addAttribute($constraint, ($value ? 'true' : 'false'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($rel = $this->getRelation())
|
|
||||||
{
|
|
||||||
$r = $node->addChild('foreign-key');
|
|
||||||
$r->addAttribute('foreignTable', $rel['foreignTable']);
|
|
||||||
$ref = $r->addChild('reference');
|
|
||||||
$ref->addAttribute('local', $this->getName());
|
|
||||||
$ref->addAttribute('foreign', $rel['foreignReference']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// exports this column in doctrine yml format
|
|
||||||
public function asDoctrineYml()
|
|
||||||
{
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
foreach($this->getProperties() as $key=>$value)
|
|
||||||
{
|
|
||||||
if ($key != 'name')
|
|
||||||
$output[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($relation = $this->getRelation())
|
|
||||||
{
|
|
||||||
$output = array_merge($output, $relation->asDoctrineYml());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function debug()
|
|
||||||
{
|
|
||||||
$debug = array();
|
|
||||||
$debug['properties'] = $this->properties;
|
|
||||||
$debug['relation'] = $this->relation;
|
|
||||||
$debug['columnInfo'] = $this->getColumnInfo()->getAll();
|
|
||||||
return $debug;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,149 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineDatabaseSchema.class.php 3455 2007-02-14 16:17:48Z chtito $
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
- class: contains a bunch of columns, toMany relationships, inheritance
|
|
||||||
information, i18n information
|
|
||||||
- table: a special class that is actually a table
|
|
||||||
- column: contains the doctrine properties (name, type, size) and the toOne relation information
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineDatabaseSchema
|
|
||||||
{
|
|
||||||
// the class descriptions
|
|
||||||
protected $classes = array();
|
|
||||||
|
|
||||||
// a subset of the array above: classes which are also tables
|
|
||||||
protected $tables = array();
|
|
||||||
|
|
||||||
public function getClasses()
|
|
||||||
{
|
|
||||||
return $this->classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getClass($className)
|
|
||||||
{
|
|
||||||
if (isset($this->classes[$className]))
|
|
||||||
return $this->classes[$className];
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('The class "%s" has no description', $className));
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieves a class object from its table name
|
|
||||||
protected function findClassByTableName($tableName)
|
|
||||||
{
|
|
||||||
foreach ($this->tables as $table)
|
|
||||||
if ($table->getName() == $tableName)
|
|
||||||
{
|
|
||||||
$tableClasses = $table->getClasses();
|
|
||||||
if (count($tableClasses) != 1)
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('No unique class is associated to table "%s"', $tableName));
|
|
||||||
return array_pop($tableClasses);
|
|
||||||
}
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Table "%s" not found', $tableName));
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the one to many and many to many relationships
|
|
||||||
// finds out what are the foreign classes or foreign tables
|
|
||||||
protected function fixRelationships()
|
|
||||||
{
|
|
||||||
foreach ($this->classes as $className => $class)
|
|
||||||
{
|
|
||||||
foreach ($class->getColumns() as $relCol)
|
|
||||||
if ($relation = $relCol->getRelation())
|
|
||||||
{
|
|
||||||
// if no foreignClass was specified (import from propel) we find it out
|
|
||||||
if (!$relation->get('foreignClass'))
|
|
||||||
{
|
|
||||||
$foreignClass = $this->findClassByTableName($relation->get('foreignTable'));
|
|
||||||
$relation->set('foreignClass', $foreignClass->getPhpName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// if foreignTable was not set (only used for export to propel)
|
|
||||||
// we figure it out
|
|
||||||
if (!$relation->get('foreignTable'))
|
|
||||||
{
|
|
||||||
$className = $relation->get('foreignClass');
|
|
||||||
$relation->set('foreignTable', $this->getClass($className)->getTableName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// the relation is a many2many
|
|
||||||
if ($relation->get('counterpart'))
|
|
||||||
{
|
|
||||||
$counterpartRel = $class->getRelation($relation->get('counterpart'));
|
|
||||||
$relation->set('otherClass', $counterpartRel->get('foreignClass'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// we copy all the toOne relations to the corresponding
|
|
||||||
// foreign class
|
|
||||||
$rel = $relCol->getRelation();
|
|
||||||
$this->getClass($rel->get('foreignClass'))->addToMany($rel); // FIXME: don't copy here
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// exports the current schema as a propel xml file
|
|
||||||
public function asPropelXml()
|
|
||||||
{
|
|
||||||
$xml = new SimpleXmlElement(sprintf('<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<database name="%s" defaultIdMethod="native"></database>', 'connection'));
|
|
||||||
|
|
||||||
foreach ($this->tables as $table)
|
|
||||||
{
|
|
||||||
$table->addPropelXmlClasses($xml);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('source'=>$xml->asXml());
|
|
||||||
}
|
|
||||||
|
|
||||||
// exports the current schema in a sfDoctrine yml file
|
|
||||||
public function asDoctrineYml()
|
|
||||||
{
|
|
||||||
$ymlClasses = array();
|
|
||||||
|
|
||||||
foreach ($this->classes as $class)
|
|
||||||
{
|
|
||||||
$ymlClasses[$class->getPhpName()] = $class->asDoctrineYml();
|
|
||||||
}
|
|
||||||
return array('source'=>sfYaml::dump($ymlClasses));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function debug()
|
|
||||||
{
|
|
||||||
$debug = array();
|
|
||||||
foreach ($this->classes as $class)
|
|
||||||
{
|
|
||||||
$debug[$class->getPhpName()] = $class->debug();
|
|
||||||
}
|
|
||||||
return $debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class sfDoctrineSchemaException extends sfException
|
|
||||||
{
|
|
||||||
public function __construct($message = null, $code = 0)
|
|
||||||
{
|
|
||||||
$this->setName('sfDoctrineSchemaException');
|
|
||||||
parent::__construct($message, $code);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,173 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineRelationSchema.class.php 4705 2007-07-24 20:45:46Z Jonathan.Wage $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineRelationSchema
|
|
||||||
{
|
|
||||||
protected $relationInfo = array();
|
|
||||||
|
|
||||||
public function __construct($relationInfo)
|
|
||||||
{
|
|
||||||
foreach ($relationInfo as $key => $value)
|
|
||||||
{
|
|
||||||
$this->set($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($key, $value)
|
|
||||||
{
|
|
||||||
// we set the default foreign name
|
|
||||||
if ($key == 'foreignClass')
|
|
||||||
{
|
|
||||||
if (!isset($this->relationInfo['foreignName']))
|
|
||||||
{
|
|
||||||
$this->relationInfo['foreignName'] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->relationInfo[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if (isset($this->relationInfo[$key]))
|
|
||||||
{
|
|
||||||
return $this->relationInfo[$key];
|
|
||||||
}
|
|
||||||
else if (isset($this->relationInfo['options']))
|
|
||||||
{
|
|
||||||
if ($option = $this->relationInfo['options']->get($key))
|
|
||||||
{
|
|
||||||
return $option;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asDoctrineYml()
|
|
||||||
{
|
|
||||||
$output = array();
|
|
||||||
foreach(array('foreignClass', 'foreignReference', 'localName', 'foreignName', 'cascadeDelete', 'unique') as $key)
|
|
||||||
{
|
|
||||||
if ($value = $this->get($key))
|
|
||||||
{
|
|
||||||
$output[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: this is clumsy: change the schema syntax?
|
|
||||||
if ($verb == 'owns')
|
|
||||||
{
|
|
||||||
$output['cascadeDelete'] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asPhpArray($array)
|
|
||||||
{
|
|
||||||
$phpArray = 'array(';
|
|
||||||
|
|
||||||
if( !empty($array) )
|
|
||||||
{
|
|
||||||
foreach($array AS $key => $value)
|
|
||||||
{
|
|
||||||
$phpArray .= "'{$key}' => '{$value}', ";
|
|
||||||
}
|
|
||||||
|
|
||||||
$phpArray = substr($phpArray, 0, strlen($phpArray) - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$phpArray .= ')';
|
|
||||||
|
|
||||||
return $phpArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asOnePhp()
|
|
||||||
{
|
|
||||||
// special behaviour for xref tables with cascade delete
|
|
||||||
$verb = ($this->get('cascadeDelete') && ($this->get('counterpart') || $this->get('unique'))) ? 'owns' : 'has';
|
|
||||||
$options['local'] = $this->get('localReference');
|
|
||||||
$options['foreign'] = $this->get('foreignReference');
|
|
||||||
|
|
||||||
//support old and new cascade declarations
|
|
||||||
if ($verb == 'owns' || $this->get('cascadeDelete') === true)
|
|
||||||
{
|
|
||||||
$options['onDelete'] = 'CASCADE';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->get('onDelete'))
|
|
||||||
{
|
|
||||||
$options['onDelete'] = strtoupper($this->get('onDelete'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$phpOptions = $this->asPhpArray($options);
|
|
||||||
|
|
||||||
return "\$this->$verb"."One('{$this->get('foreignClass')} as {$this->get('foreignName')}', $phpOptions);";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asManyPhp()
|
|
||||||
{
|
|
||||||
$quantity = $this->get('unique') ? 'One':'Many';
|
|
||||||
|
|
||||||
// using "owns" for cascade delete except in xref table
|
|
||||||
$verb = ($this->get('cascadeDelete') && !$this->get('counterpart')) ? 'has':'has';
|
|
||||||
|
|
||||||
$otherClass = $this->get('localClass');
|
|
||||||
|
|
||||||
if ($quantity == 'Many' && $this->get('counterpart'))
|
|
||||||
{
|
|
||||||
$localReference = $this->relationInfo['localReference'];
|
|
||||||
$foreignReference = $this->relationInfo['options']->get('counterpart');
|
|
||||||
$otherClass = $this->get('otherClass');
|
|
||||||
} else {
|
|
||||||
$localReference = $this->get('foreignReference');
|
|
||||||
$foreignReference = $this->get('localReference');
|
|
||||||
}
|
|
||||||
|
|
||||||
$localClass = $this->get('localClass');
|
|
||||||
|
|
||||||
// Set refClass to localClass if it is a Many-Many relationship
|
|
||||||
if ($quantity == 'Many' && $this->get('counterpart'))
|
|
||||||
{
|
|
||||||
$refClass = $this->get('localClass');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($refClass) && $refClass)
|
|
||||||
{
|
|
||||||
$options['refClass'] = $refClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($localReference)
|
|
||||||
{
|
|
||||||
$options['local'] = $localReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($foreignReference)
|
|
||||||
{
|
|
||||||
$options['foreign'] = $foreignReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
$phpOptions = $this->asPhpArray($options);
|
|
||||||
|
|
||||||
return "\$this->$verb$quantity('$otherClass as {$this->get('localName')}', $phpOptions);";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function debug()
|
|
||||||
{
|
|
||||||
return $this->relationInfo;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineSchemaDoctrineLoader.class.php 3455 2007-02-14 16:17:48Z chtito $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineSchemaDoctrineLoader extends sfDoctrineDatabaseSchema
|
|
||||||
{
|
|
||||||
// recursively finds out what a class table is
|
|
||||||
// FIXME: check for infinite loop?
|
|
||||||
protected function parentTable($class)
|
|
||||||
{
|
|
||||||
if ($class->hasTable())
|
|
||||||
return $class->getTable();
|
|
||||||
|
|
||||||
return $this->parentTable($this->getClass($class->getParentClassName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// associate a table to each class
|
|
||||||
protected function fixTables()
|
|
||||||
{
|
|
||||||
foreach ($this->classes as $className => $class)
|
|
||||||
{
|
|
||||||
$table = $this->parentTable($class);
|
|
||||||
$table->addClass($class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up the necessary fields in the i18n table: culture, id
|
|
||||||
protected function addI18nFields()
|
|
||||||
{
|
|
||||||
foreach ($this->classes as $className => $class)
|
|
||||||
{
|
|
||||||
if (!$class->hasI18n())
|
|
||||||
continue;
|
|
||||||
$i18nClass = $this->getClass($class->getI18n('class'));
|
|
||||||
$cultureColumn = new sfDoctrineColumnSchema($class->getI18n('cultureField'), array('type'=> 'string', 'size'=> 100, 'primary'=> true));
|
|
||||||
|
|
||||||
$i18nClass->addColumn($cultureColumn);
|
|
||||||
|
|
||||||
// add the foreign key to the main table
|
|
||||||
$idDesc = array('foreignClass'=>$className, 'localName'=>$i18nClass->getPhpName(), 'onDelete'=>'cascade', 'primary'=>true);
|
|
||||||
$i18nClass->addColumn(new sfDoctrineColumnSchema('id', $idDesc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// adds the class key fields
|
|
||||||
protected function addInheritanceFields()
|
|
||||||
{
|
|
||||||
foreach ($this->classes as $className => $class)
|
|
||||||
if ($class->hasOneTableInheritance())
|
|
||||||
{
|
|
||||||
$inh = $class->getInheritance();
|
|
||||||
$class->getTable()->addColumn(new sfDoctrineColumnSchema($inh['keyField'], array('type'=>'integer')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($file, $package = null)
|
|
||||||
{
|
|
||||||
$schema = sfYaml::load($file);
|
|
||||||
|
|
||||||
foreach ($schema as $className => $cd)
|
|
||||||
{
|
|
||||||
if (!isset($cd['tableName']) && !isset($cd['inheritance']))
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Class "%s" must have either a table or a parent', $className));
|
|
||||||
|
|
||||||
$class = new sfDoctrineClassSchema($className, $cd);
|
|
||||||
|
|
||||||
// add a table if necessary
|
|
||||||
if (isset($cd['tableName']))
|
|
||||||
{
|
|
||||||
// this top class is actually a table
|
|
||||||
$table = new sfDoctrineTableSchema($cd['tableName'], $package);
|
|
||||||
$table->addClass($class);
|
|
||||||
$this->tables[$cd['tableName']] = $table;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->classes[$className] = $class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function process()
|
|
||||||
{
|
|
||||||
$this->fixTables();
|
|
||||||
|
|
||||||
$this->addI18nFields();
|
|
||||||
|
|
||||||
$this->fixRelationships();
|
|
||||||
|
|
||||||
$this->addInheritanceFields();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineSchemaPropelLoader.class.php 3455 2007-02-14 16:17:48Z chtito $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineSchemaPropelLoader extends sfDoctrineDatabaseSchema
|
|
||||||
{
|
|
||||||
// get the attributes parsed by the sfPropelDatabaseSchema class
|
|
||||||
protected function getAttribute($tag, $attribute)
|
|
||||||
{
|
|
||||||
return isset($tag['_attributes'][$attribute]) ? $tag['_attributes'][$attribute] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($file, $package = null)
|
|
||||||
{
|
|
||||||
// we figure out what kind of file we are given
|
|
||||||
$type = array_pop(explode('.', $file));
|
|
||||||
$type2method = array('yml'=>'loadYAML', 'xml'=>'loadXML');
|
|
||||||
if (isset($type2method[$type]))
|
|
||||||
$method = $type2method[$type];
|
|
||||||
else
|
|
||||||
throw new sfDoctrineSchemaException(sprintf('Unkwnown method for extension "%s"', $type));
|
|
||||||
|
|
||||||
$propelDatabaseSchema = new sfPropelDatabaseSchema();
|
|
||||||
$propelDatabaseSchema->$method($file);
|
|
||||||
$data = $propelDatabaseSchema->asArray();
|
|
||||||
|
|
||||||
foreach ($propelDatabaseSchema->getTables() as $tb_name => $tableDesc)
|
|
||||||
{
|
|
||||||
// special table class
|
|
||||||
// propel has only such classes (no inheritance support)
|
|
||||||
$table = new sfDoctrineTableSchema($tb_name, $package);
|
|
||||||
$this->tables[$tb_name] = $table;
|
|
||||||
|
|
||||||
if (!($className = $this->getAttribute($tableDesc, 'phpName')))
|
|
||||||
$className = sfInflector::camelize($tb_name); // wild guess
|
|
||||||
|
|
||||||
$class = new sfDoctrineClassSchema($className);
|
|
||||||
$table->addClass($class);
|
|
||||||
|
|
||||||
// columns
|
|
||||||
foreach ($propelDatabaseSchema->getChildren($tableDesc) as $col_name => $columnDescription)
|
|
||||||
{
|
|
||||||
if (($col_name == 'id')) // id is automatically generated in doctrine
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$docCol = new sfDoctrineColumnSchema($col_name, $columnDescription, true);
|
|
||||||
$class->addColumn($docCol);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->classes[$class->getPhpName()] = $class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function process()
|
|
||||||
{
|
|
||||||
$this->fixRelationships();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: sfDoctrineTableSchema.class.php 3455 2007-02-14 16:17:48Z chtito $
|
|
||||||
*/
|
|
||||||
|
|
||||||
class sfDoctrineTableSchema extends sfDoctrineClassSchema
|
|
||||||
{
|
|
||||||
// the classes associated to that table
|
|
||||||
protected $classes;
|
|
||||||
|
|
||||||
// table name
|
|
||||||
protected $name;
|
|
||||||
|
|
||||||
// package of that table (usually either a plugin name, or a propel schema name)
|
|
||||||
protected $package;
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct($tableName, $package)
|
|
||||||
{
|
|
||||||
$this->setName($tableName);
|
|
||||||
$this->package = $package;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addClass($class)
|
|
||||||
{
|
|
||||||
// we add the class and try to avoid duplication
|
|
||||||
$this->classes[$class->getPhpName()] = $class;
|
|
||||||
$class->setTable($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClasses()
|
|
||||||
{
|
|
||||||
return $this->classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// exports this table in propel xml format
|
|
||||||
public function addPropelXmlClasses(&$node)
|
|
||||||
{
|
|
||||||
$t = $node->addChild('table');
|
|
||||||
$t->addAttribute('name', $this->getName());
|
|
||||||
$t->addAttribute('phpName', $this->getPhpName());
|
|
||||||
foreach($this->classes as $class)
|
|
||||||
{
|
|
||||||
$class->addPropelXmlColumns($t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPackage()
|
|
||||||
{
|
|
||||||
return $this->package;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
autoload:
|
|
||||||
# Doctrine:
|
|
||||||
# name: Doctrine classes
|
|
||||||
# ext: .php
|
|
||||||
# path: %SF_PLUGINS_DIR%/sfDoctrine/doctrine
|
|
||||||
# recursive: on
|
|
||||||
doctrine_model_classes:
|
|
||||||
name: Doctrine model classes
|
|
||||||
ext: .class.php
|
|
||||||
path: %SF_LIB_DIR%/model/doctrine
|
|
@ -1,5 +0,0 @@
|
|||||||
config/doctrine.yml:
|
|
||||||
class: sfDoctrineConfigHandler
|
|
||||||
|
|
||||||
config/schemas.yml:
|
|
||||||
class: sfDoctrineSchemasConfigHandler
|
|
@ -1,25 +0,0 @@
|
|||||||
all:
|
|
||||||
|
|
||||||
#doctrine attributes
|
|
||||||
attributes:
|
|
||||||
|
|
||||||
#automatic table creation (none, tables, constraints, all)
|
|
||||||
export: all
|
|
||||||
|
|
||||||
#default fetch mode (immediate, batch, lazy, offset, lazy_offset)
|
|
||||||
fetchmode: immediate
|
|
||||||
|
|
||||||
#collection limit (integer 1+)
|
|
||||||
coll_limit: 5
|
|
||||||
|
|
||||||
#global event listener
|
|
||||||
# listener: sfDoctrineEventListener
|
|
||||||
|
|
||||||
#locking (optimistic, pessimistic)
|
|
||||||
lockmode: pessimistic
|
|
||||||
|
|
||||||
#enable doctrine side validation (true, false)
|
|
||||||
vld: false
|
|
||||||
|
|
||||||
# enable quoting
|
|
||||||
quote_identifier: false
|
|
@ -1,3 +0,0 @@
|
|||||||
all:
|
|
||||||
orm: doctrine
|
|
||||||
# default_database: <your default connection here>
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ##MODULE_NAME## actions.
|
|
||||||
*
|
|
||||||
* @package ##PROJECT_NAME##
|
|
||||||
* @subpackage ##MODULE_NAME##
|
|
||||||
* @author ##AUTHOR_NAME##
|
|
||||||
* @version SVN: $Id: actions.class.php,v 1.1 2006/12/08 18:49:35 nathanael Exp $
|
|
||||||
*/
|
|
||||||
class ##MODULE_NAME##Actions extends auto##MODULE_NAME##Actions
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
generator:
|
|
||||||
class: sfDoctrineAdminGenerator
|
|
||||||
param:
|
|
||||||
model_class: ##MODEL_CLASS##
|
|
||||||
theme: crud
|
|
@ -1,104 +0,0 @@
|
|||||||
[?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <?php echo $this->getGeneratedModuleName() ?> actions.
|
|
||||||
*
|
|
||||||
* @package ##PROJECT_NAME##
|
|
||||||
* @subpackage <?php echo $this->getGeneratedModuleName() ?>
|
|
||||||
|
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: actions.class.php 3923 2007-05-03 19:42:33Z gnat $
|
|
||||||
*/
|
|
||||||
class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions
|
|
||||||
{
|
|
||||||
public function executeIndex ()
|
|
||||||
{
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeList ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getPluralName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeShow ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
|
|
||||||
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeCreate ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();
|
|
||||||
$this->setTemplate('edit');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeEdit ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
|
|
||||||
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeDelete ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
|
|
||||||
|
|
||||||
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?>->delete();
|
|
||||||
$this->redirect('<?php echo $this->getModuleName() ?>/list');
|
|
||||||
}
|
|
||||||
catch (Doctrine_Exception $e)
|
|
||||||
{
|
|
||||||
$this->getRequest()->setError('delete', 'Could not delete the selected <?php echo sfInflector::humanize($this->getSingularName()) ?>. Make sure it does not have any associated items.');
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeUpdate ()
|
|
||||||
{
|
|
||||||
if (<?php echo $this->getTestPksForGetOrCreate(false) ?>)
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction('') ?>);
|
|
||||||
$this->forward404Unless($<?php echo $this->getSingularName() ?>);
|
|
||||||
}
|
|
||||||
|
|
||||||
$formData = $this->getRequestParameter('<?php echo $this->getSingularName() ?>');
|
|
||||||
<?php foreach ($this->getColumns('') as $index => $column):
|
|
||||||
$type = $column->getDoctrineType();
|
|
||||||
$name = $column->getName(); ?>
|
|
||||||
<?php if($column->isPrimaryKey()) continue ?>
|
|
||||||
<?php if ($name == 'created_at' || $name == 'updated_at') continue ?>
|
|
||||||
<?php if ($type == 'boolean'): ?>
|
|
||||||
<?php $boolVar = "\$formData['$name']";
|
|
||||||
echo $this->getColumnSetter($column, "isset($boolVar) ? $boolVar : 0", false, '')?>;
|
|
||||||
<?php continue; ?>
|
|
||||||
<?php endif; // boolean case ?>
|
|
||||||
if ($newValue = $formData['<?php echo $name ?>'])
|
|
||||||
{
|
|
||||||
<?php if ($type == 'date' || $type == 'timestamp'): ?>
|
|
||||||
<?php $inputPattern = ($type == 'date' ? 'd' : 'g');
|
|
||||||
$outputPattern = ($type == 'date' ? 'i' : 'I'); ?>
|
|
||||||
$dateFormat = new sfDateFormat($this->getUser()->getCulture());
|
|
||||||
<?php echo $this->getColumnSetter($column, sprintf('$dateFormat->format($newValue, \'%s\', $dateFormat->getInputPattern(\'%s\'))', $outputPattern, $inputPattern), false, '');?>;
|
|
||||||
<?php elseif ($column->isForeignKey()): ?>
|
|
||||||
$<?php echo $this->getSingularName()?>->set('<?php echo $column->getColumnName()?>', (empty($newValue) ? null : $newValue));
|
|
||||||
<?php else: ?>
|
|
||||||
<?php echo $this->getColumnSetter($column, '$newValue', false, '');?>;
|
|
||||||
<?php endif; ?>
|
|
||||||
}
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
$<?php echo $this->getSingularName() ?>->save();
|
|
||||||
|
|
||||||
return $this->redirect('<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>);
|
|
||||||
<?php //' ?>
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
[?php use_helper('ObjectDoctrineAdmin', 'Object', 'Date') ?]
|
|
||||||
|
|
||||||
[?php echo form_tag('<?php echo $this->getModuleName() ?>/update', 'multipart=true') ?]
|
|
||||||
|
|
||||||
<?php foreach ($this->getPrimaryKey() as $pk): ?>
|
|
||||||
[?php echo object_input_hidden_tag($<?php echo $this->getSingularName() ?>, 'get<?php echo $pk->getPhpName() ?>') ?]
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<?php foreach ($this->getColumns('') as $index => $column): ?>
|
|
||||||
<?php if ($column->isPrimaryKey()) continue ?>
|
|
||||||
<?php if ($column->getName() == 'created_at' || $column->getName() == 'updated_at') continue ?>
|
|
||||||
<tr>
|
|
||||||
<th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>: </th>
|
|
||||||
<td>[?php echo <?php echo $this->getColumnEditTag($column) ?> ?]</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<hr />
|
|
||||||
[?php echo submit_tag('save') ?]
|
|
||||||
[?php if (<?php echo $this->getPrimaryKeyIsSet() ?>): ?]
|
|
||||||
[?php echo link_to('delete', '<?php echo $this->getModuleName() ?>/delete?<?php echo $this->getPrimaryKeyUrlParams() ?>, 'post=true&confirm=Are you sure?') ?]
|
|
||||||
[?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
|
|
||||||
[?php else: ?]
|
|
||||||
[?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/list') ?]
|
|
||||||
[?php endif; ?]
|
|
||||||
</form>
|
|
@ -1,27 +0,0 @@
|
|||||||
<h1><?php echo $this->getModuleName() ?></h1>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<?php foreach ($this->getColumns('') as $column): ?>
|
|
||||||
<th><?php echo sfInflector::humanize($column->getName()) ?></th>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
[?php foreach ($<?php echo $this->getPluralName() ?> as $<?php echo $this->getSingularName() ?>): ?]
|
|
||||||
<tr>
|
|
||||||
<?php foreach ($this->getColumns('') as $column): ?>
|
|
||||||
<?php if ($column->isPrimaryKey()): ?>
|
|
||||||
<td>[?php echo link_to($<?php echo $this->getSingularName() ?>->get('<?php echo $column->getPhpName() ?>'), '<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>); ?]</td>
|
|
||||||
<?php else: ?>
|
|
||||||
<td>[?php echo $<?php echo $this->getSingularName() ?>->get('<?php echo $column->getPhpName() ?>'); ?]</td>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tr>
|
|
||||||
[?php endforeach; ?]
|
|
||||||
<tr><td>Number of <?php echo $this->getPluralName() ?>: [?php echo count($<?php echo $this->getPluralName()?>) ?]</td></tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
[?php echo link_to ('create', '<?php echo $this->getModuleName() ?>/create') ?]
|
|
@ -1,13 +0,0 @@
|
|||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<?php foreach ($this->getAllColumns() as $column): ?>
|
|
||||||
<tr>
|
|
||||||
<th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>: </th>
|
|
||||||
<td>[?= $<?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>() ?]</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<hr />
|
|
||||||
[?php echo link_to('edit', '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
|
|
||||||
[?php echo link_to('list', '<?php echo $this->getModuleName() ?>/list') ?]
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ##MODULE_NAME## actions.
|
|
||||||
*
|
|
||||||
* @package ##PROJECT_NAME##
|
|
||||||
* @subpackage ##MODULE_NAME##
|
|
||||||
* @author Your name here
|
|
||||||
* @version SVN: $Id: actions.class.php 1415 2006-06-11 08:33:51Z fabien $
|
|
||||||
*/
|
|
||||||
class ##MODULE_NAME##Actions extends auto##MODULE_NAME##Actions
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
generator:
|
|
||||||
class: sfDoctrineAdminGenerator
|
|
||||||
param:
|
|
||||||
model_class: ##MODEL_CLASS##
|
|
||||||
theme: default
|
|
@ -1,422 +0,0 @@
|
|||||||
[?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <?php echo $this->getGeneratedModuleName() ?> actions.
|
|
||||||
*
|
|
||||||
* @package ##PROJECT_NAME##
|
|
||||||
* @subpackage <?php echo $this->getGeneratedModuleName() ?>
|
|
||||||
|
|
||||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @version SVN: $Id: actions.class.php 4836 2007-08-07 19:10:21Z Jonathan.Wage $
|
|
||||||
*/
|
|
||||||
class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions
|
|
||||||
{
|
|
||||||
public function preExecute ()
|
|
||||||
{
|
|
||||||
$this->getResponse()->addStylesheet('<?php echo $this->getParameterValue('css', sfConfig::get('sf_admin_web_dir').'/css/main') ?>');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeIndex ()
|
|
||||||
{
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeList ()
|
|
||||||
{
|
|
||||||
$this->processSort();
|
|
||||||
|
|
||||||
$this->processFilters();
|
|
||||||
|
|
||||||
<?php if ($this->getParameterValue('list.filters')): ?>
|
|
||||||
$this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/filters');
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
// pager
|
|
||||||
$this->pager = new sfDoctrinePager('<?php echo $this->getClassName() ?>', <?php echo $this->getParameterValue('list.max_per_page', 20) ?>);
|
|
||||||
|
|
||||||
<?php if ($peerMethod = $this->getParameterValue('list.peer_method')): ?>
|
|
||||||
$q = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')-><?php echo $peerMethod ?>();
|
|
||||||
$this->pager->setQuery($q);
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
$this->addSortCriteria($this->pager->getQuery());
|
|
||||||
$this->addFiltersCriteria($this->pager->getQuery());
|
|
||||||
|
|
||||||
$this->pager->setPage($this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'sf_admin/<?php echo $this->getSingularName() ?>')));
|
|
||||||
|
|
||||||
$this->pager->init();
|
|
||||||
// Save page
|
|
||||||
if ($this->getRequestParameter('page')) {
|
|
||||||
$this->getUser()->setAttribute('page', $this->getRequestParameter('page'), 'sf_admin/<?php echo $this->getSingularName() ?>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeCreate ()
|
|
||||||
{
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'edit');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeSave ()
|
|
||||||
{
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'edit');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeEdit ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate();
|
|
||||||
|
|
||||||
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
|
||||||
{
|
|
||||||
$this->update<?php echo $this->getClassName() ?>FromRequest();
|
|
||||||
|
|
||||||
$this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
|
|
||||||
$this->setFlash('notice', 'Your modifications have been saved');
|
|
||||||
|
|
||||||
if ($this->getRequestParameter('save_and_add'))
|
|
||||||
{
|
|
||||||
return $this->redirect('<?php echo $this->getModuleName() ?>/create');
|
|
||||||
}
|
|
||||||
else if ($this->getRequestParameter('save_and_list'))
|
|
||||||
{
|
|
||||||
return $this->redirect('<?php echo $this->getModuleName() ?>/list');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $this->redirect('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams('this->') ?>);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->addJavascriptsForEdit();
|
|
||||||
|
|
||||||
$this->labels = $this->getLabels();
|
|
||||||
}
|
|
||||||
|
|
||||||
// temporary fix to avoid using a distinct editSuccess.php template
|
|
||||||
sfLoader::loadHelpers(array('Helper', 'ObjectDoctrineAdmin'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeDelete ()
|
|
||||||
{
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>);
|
|
||||||
|
|
||||||
$this->forward404Unless($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$this->delete<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>);
|
|
||||||
}
|
|
||||||
catch (Doctrine_Exception $e)
|
|
||||||
{
|
|
||||||
$this->getRequest()->setError('delete', 'Could not delete the selected <?php echo sfInflector::humanize($this->getSingularName()) ?>. Make sure it does not have any associated items.');
|
|
||||||
return $this->forward('<?php echo $this->getModuleName() ?>', 'list');
|
|
||||||
}
|
|
||||||
|
|
||||||
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
|
|
||||||
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
|
|
||||||
<?php $input_type = $this->getParameterValue('edit.fields.'.$column->getName().'.type') ?>
|
|
||||||
<?php if ($input_type == 'admin_input_file_tag'): ?>
|
|
||||||
<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?>
|
|
||||||
$currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".<?php echo $this->getColumnGetter($column, true, 'this->')?>;
|
|
||||||
if (is_file($currentFile))
|
|
||||||
{
|
|
||||||
unlink($currentFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
return $this->redirect('<?php echo $this->getModuleName() ?>/list');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleErrorEdit()
|
|
||||||
{
|
|
||||||
$this->preExecute();
|
|
||||||
$this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate();
|
|
||||||
$this->update<?php echo $this->getClassName() ?>FromRequest();
|
|
||||||
|
|
||||||
$this->addJavascriptsForEdit();
|
|
||||||
|
|
||||||
$this->labels = $this->getLabels();
|
|
||||||
|
|
||||||
// temporary fix to avoid using a distinct editSuccess.php template
|
|
||||||
sfLoader::loadHelpers(array('Helper', 'ObjectDoctrineAdmin'));
|
|
||||||
|
|
||||||
return sfView::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function save<?php echo $this->getClassName() ?>($<?php echo $this->getSingularName() ?>)
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?>->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function delete<?php echo $this->getClassName() ?>($<?php echo $this->getSingularName() ?>)
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?>->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function update<?php echo $this->getClassName() ?>FromRequest()
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->getSingularName() ?>');
|
|
||||||
|
|
||||||
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
|
|
||||||
<?php foreach ($this->getColumns('edit.display', $category) as $column): $type = $column->getDoctrineType(); ?>
|
|
||||||
<?php $name = $column->getName(); ?>
|
|
||||||
<?php if ($column->isPrimaryKey()) continue ?>
|
|
||||||
<?php $credentials = $this->getParameterValue('edit.fields.'.$name.'.credentials') ?>
|
|
||||||
<?php $input_type = $this->getParameterValue('edit.fields.'.$name.'.type') ?>
|
|
||||||
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
|
|
||||||
if ($this->getUser()->hasCredential(<?php echo $credentials ?>))
|
|
||||||
{
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($input_type == 'admin_input_file_tag'): ?>
|
|
||||||
<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?>
|
|
||||||
$currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".<?php echo $this->getColumnGetter($column, true, 'this->')?>;
|
|
||||||
if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove']))
|
|
||||||
{
|
|
||||||
<?php echo $this->getColumnSetter($column, '', true) ?>;
|
|
||||||
if (is_file($currentFile))
|
|
||||||
{
|
|
||||||
unlink($currentFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->getRequest()->hasErrors() && $this->getRequest()->getFileSize('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]'))
|
|
||||||
{
|
|
||||||
<?php elseif ($type != 'boolean'): ?>
|
|
||||||
if (isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']))
|
|
||||||
{
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($input_type == 'admin_input_file_tag'): ?>
|
|
||||||
<?php if ($this->getParameterValue('edit.fields.'.$name.'.filename')): ?>
|
|
||||||
$fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.filename'))) ?>";
|
|
||||||
<?php else: ?>
|
|
||||||
$fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time());
|
|
||||||
<?php endif; ?>
|
|
||||||
$ext = $this->getRequest()->getFileExtension('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]');
|
|
||||||
if (is_file($currentFile))
|
|
||||||
{
|
|
||||||
unlink($currentFile);
|
|
||||||
}
|
|
||||||
$this->getRequest()->moveFile('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]', sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$fileName.$ext);
|
|
||||||
<?php echo $this->getColumnSetter($column, '$fileName.$ext')?>;
|
|
||||||
<?php elseif ($type == 'date' || $type == 'timestamp'): ?>
|
|
||||||
if ($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'])
|
|
||||||
{
|
|
||||||
$dateFormat = new sfDateFormat($this->getUser()->getCulture());
|
|
||||||
<?php
|
|
||||||
$inputPattern = ($type == 'date' ? 'd' : 'g');
|
|
||||||
$outputPattern = ($type == 'date' ? 'i' : 'I');
|
|
||||||
?>
|
|
||||||
// if this is a direct date input (rich == true)
|
|
||||||
if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$value = $dateFormat->format($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'], '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>'));
|
|
||||||
}
|
|
||||||
catch (sfException $e)
|
|
||||||
{
|
|
||||||
// not a valid date
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // rich == false
|
|
||||||
{
|
|
||||||
$value_array = $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'];
|
|
||||||
$value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : '');
|
|
||||||
}
|
|
||||||
<?php echo $this->getColumnSetter($column, '$value') ?>;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<?php echo $this->getColumnSetter($column, 'null') ?>;
|
|
||||||
}
|
|
||||||
<?php elseif ($type == 'boolean'): ?>
|
|
||||||
<?php $boolVar = "\${$this->getSingularName()}['$name']";
|
|
||||||
echo $this->getColumnSetter($column, "isset($boolVar) ? $boolVar : 0") ?>;
|
|
||||||
<?php elseif ($column->isForeignKey()): ?>
|
|
||||||
$foreignKey = $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'];
|
|
||||||
$foreignKey = empty($foreignKey) ? null : $foreignKey;
|
|
||||||
$this-><?php echo $this->getSingularName()?>->set('<?php echo $column->getColumnName()?>', $foreignKey);
|
|
||||||
<?php else: ?>
|
|
||||||
$this-><?php echo $this->getSingularName() ?>->set('<?php echo $column->getName() ?>', $<?php echo $this->getSingularName() ?>['<?php echo $name ?>']);
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($type != 'boolean'): ?>
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php // double lists
|
|
||||||
if (in_array($input_type, array('doctrine_admin_double_list', 'doctrine_admin_check_list', 'doctrine_admin_select_list'))): ?>
|
|
||||||
// Update many-to-many for "<?php echo $name ?>"
|
|
||||||
$<?php echo $name?>Table = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->getRelation('<?php echo $name ?>')->getTable();
|
|
||||||
|
|
||||||
$associationName = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->getRelation('<?php echo $name ?>')->getAssociationTable()->getOption('name');
|
|
||||||
$this-><?php echo $this->getSingularName()?>->$associationName->delete();
|
|
||||||
|
|
||||||
$ids = $this->getRequestParameter('associated_<?php echo $name ?>');
|
|
||||||
if (is_array($ids))
|
|
||||||
{
|
|
||||||
foreach ($ids as $id)
|
|
||||||
{
|
|
||||||
$id = explode('/', $id);
|
|
||||||
$this-><?php echo $this->getSingularName()?>->get('<?php echo $name ?>')->add($<?php echo $name?>Table->find($id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<?php endif; // double lists ?>
|
|
||||||
<?php if ($credentials): ?>
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function get<?php echo $this->getClassName() ?>OrCreate (<?php echo $this->getMethodParamsForGetOrCreate() ?>)
|
|
||||||
{
|
|
||||||
if (<?php echo $this->getTestPksForGetOrCreate() ?>)
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$<?php echo $this->getSingularName() ?> = sfDoctrine::getTable('<?php echo $this->getClassName() ?>')->find(array(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>));
|
|
||||||
|
|
||||||
$this->forward404Unless($<?php echo $this->getSingularName() ?>);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $<?php echo $this->getSingularName() ?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function processFilters ()
|
|
||||||
{
|
|
||||||
<?php if ($this->getParameterValue('list.filters')): ?>
|
|
||||||
if ($this->getRequest()->hasParameter('filter'))
|
|
||||||
{
|
|
||||||
$filters = $this->getRequestParameter('filters');
|
|
||||||
<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getDoctrineType() ?>
|
|
||||||
<?php if ($type == 'date' || $type == 'timestamp'):
|
|
||||||
$inputPattern = ($type == 'date' ? 'd' : 'g');
|
|
||||||
$outputPattern = ($type == 'date' ? 'i' : 'I'); ?>
|
|
||||||
$dateFormat = new sfDateFormat($this->getUser()->getCulture());
|
|
||||||
|
|
||||||
if (isset($filters['<?php echo $column->getName() ?>']['from']) && $filters['<?php echo $column->getName() ?>']['from'] !== '')
|
|
||||||
{
|
|
||||||
$filters['<?php echo $column->getName() ?>']['from'] = $dateFormat->format($filters['<?php echo $column->getName() ?>']['from'], '<?php echo $outputPattern?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>'));
|
|
||||||
}
|
|
||||||
if (isset($filters['<?php echo $column->getName() ?>']['to']) && $filters['<?php echo $column->getName() ?>']['to'] !== '')
|
|
||||||
{
|
|
||||||
$filters['<?php echo $column->getName() ?>']['to'] = $dateFormat->format($filters['<?php echo $column->getName() ?>']['to'], '<?php echo $outputPattern?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>'));
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/<?php echo $this->getSingularName() ?>');
|
|
||||||
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/<?php echo $this->getSingularName() ?>/filters');
|
|
||||||
$this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/<?php echo $this->getSingularName() ?>/filters');
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function processSort ()
|
|
||||||
{
|
|
||||||
if ($this->getRequestParameter('sort'))
|
|
||||||
{
|
|
||||||
$this->getUser()->setAttribute('sort', $this->getRequestParameter('sort'), 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
$this->getUser()->setAttribute('type', $this->getRequestParameter('type', 'asc'), 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->getUser()->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort'))
|
|
||||||
{
|
|
||||||
<?php if ($sort = $this->getParameterValue('list.sort')): ?>
|
|
||||||
<?php if (is_array($sort)): ?>
|
|
||||||
$this->getUser()->setAttribute('sort', '<?php echo $sort[0] ?>', 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
$this->getUser()->setAttribute('type', '<?php echo $sort[1] ?>', 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
<?php else: ?>
|
|
||||||
$this->getUser()->setAttribute('sort', '<?php echo $sort ?>', 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
$this->getUser()->setAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort');
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function addFiltersCriteria ($q)
|
|
||||||
{
|
|
||||||
<?php if ($this->getParameterValue('list.filters')): ?>
|
|
||||||
<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getDoctrineType() ?>
|
|
||||||
<?php if (($column->isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue ?>
|
|
||||||
<?php
|
|
||||||
$filterColumnName = $column->getName();
|
|
||||||
if ($column->isForeignKey())
|
|
||||||
$filterColumnName = $column->getColumnName();
|
|
||||||
$queryColumn = $this->getClassName().'.'.$filterColumnName;?>
|
|
||||||
if (isset($this->filters['<?php echo $column->getName() ?>_is_empty']))
|
|
||||||
{
|
|
||||||
$q->addWhere("<?php echo $queryColumn?> = '' OR <?php echo $queryColumn?> IS NULL");
|
|
||||||
}
|
|
||||||
<?php if ($type == 'date' || $type == 'timestamp'): ?>
|
|
||||||
else if (isset($this->filters['<?php echo $column->getName() ?>']))
|
|
||||||
{
|
|
||||||
if (isset($this->filters['<?php echo $column->getName() ?>']['from']) && $this->filters['<?php echo $column->getName() ?>']['from'] !== '')
|
|
||||||
{
|
|
||||||
<?php
|
|
||||||
$dateArg = "\$this->filters['{$column->getName()}']['%s']";
|
|
||||||
?>
|
|
||||||
$q->addWhere('<?php echo $queryColumn?> >= ?', <?php echo sprintf($dateArg, 'from') ?>);
|
|
||||||
}
|
|
||||||
if (isset($this->filters['<?php echo $column->getName() ?>']['to']) && $this->filters['<?php echo $column->getName() ?>']['to'] !== '')
|
|
||||||
{
|
|
||||||
$q->addWhere('<?php echo $queryColumn?> <= ?', <?php echo sprintf($dateArg, 'to') ?>);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
<?php else: ?>
|
|
||||||
else if (isset($this->filters['<?php echo $column->getName() ?>']) && $this->filters['<?php echo $column->getName() ?>'] !== '')
|
|
||||||
{
|
|
||||||
<?php if ($type == 'char' || $type == 'string'): ?>
|
|
||||||
$q->addWhere("<?php echo $queryColumn?> LIKE ?", '%'.$this->filters['<?php echo $column->getName() ?>'].'%');
|
|
||||||
<?php else: ?>
|
|
||||||
$q->addWhere("<?php echo $queryColumn?> = ?", $this->filters['<?php echo $column->getName() ?>']);
|
|
||||||
<?php endif; ?>
|
|
||||||
}
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function addSortCriteria ($q)
|
|
||||||
{
|
|
||||||
if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort'))
|
|
||||||
{
|
|
||||||
$table = sfDoctrine::getTable('<?php echo $this->getClassName()?>');
|
|
||||||
$colNames = array_keys($table->getColumns());
|
|
||||||
if (!in_array($sort_column, $colNames)) // illegal column name
|
|
||||||
return;
|
|
||||||
if ($this->getUser()->getAttribute('type', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == 'asc')
|
|
||||||
{
|
|
||||||
$q->orderBy('<?php echo $this->getClassName()?>.'.$sort_column);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$q->orderBy('<?php echo $this->getClassName()?>.'.$sort_column.' desc');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function addJavascriptsForEdit()
|
|
||||||
{
|
|
||||||
$this->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype');
|
|
||||||
$this->getResponse()->addJavascript(sfConfig::get('sf_admin_web_dir').'/js/collapse');
|
|
||||||
$this->getResponse()->addJavascript(sfConfig::get('sf_admin_web_dir').'/js/double_list');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getLabels()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
|
|
||||||
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
|
|
||||||
'<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}' => '<?php $label_name = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.name')); echo $label_name ?><?php if ($label_name): ?>:<?php endif; ?>',
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<ul class="sf_admin_actions">
|
|
||||||
<?php $editActions = $this->getParameterValue('edit.actions') ?>
|
|
||||||
<?php if (null !== $editActions): ?>
|
|
||||||
<?php foreach ((array) $editActions as $actionName => $params): ?>
|
|
||||||
<?php if ($actionName == '_delete') continue ?>
|
|
||||||
<?php echo $this->addCredentialCondition($this->getButtonToAction($actionName, $params, true), $params) ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<?php echo $this->getButtonToAction('_list', array(), true) ?>
|
|
||||||
<?php echo $this->getButtonToAction('_save', array(), true) ?>
|
|
||||||
<?php echo $this->getButtonToAction('_save_and_add', array(), true) ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</ul>
|
|
@ -1,86 +0,0 @@
|
|||||||
[?php echo form_tag('<?php echo $this->getModuleName() ?>/save', array(
|
|
||||||
'id' => 'sf_admin_edit_form',
|
|
||||||
'name' => 'sf_admin_edit_form',
|
|
||||||
'multipart' => true,
|
|
||||||
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
|
|
||||||
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
|
|
||||||
<?php if (false !== strpos($this->getParameterValue('edit.fields.'.$column->getName().'.type'), 'admin_double_list')): ?>
|
|
||||||
'onsubmit' => 'double_list_submit(); return true;'
|
|
||||||
<?php break 2; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
)) ?]
|
|
||||||
|
|
||||||
<?php foreach ($this->getPrimaryKey() as $pk): ?>
|
|
||||||
[?php echo object_input_hidden_tag($<?php echo $this->getSingularName() ?>, 'get<?php echo $pk->getPhpName() ?>') ?]
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
<?php $first = true ?>
|
|
||||||
<?php foreach ($this->getColumnCategories('edit.display') as $category): ?>
|
|
||||||
<?php
|
|
||||||
if ($category[0] == '-')
|
|
||||||
{
|
|
||||||
$category_name = substr($category, 1);
|
|
||||||
$collapse = true;
|
|
||||||
|
|
||||||
if ($first)
|
|
||||||
{
|
|
||||||
$first = false;
|
|
||||||
echo "[?php use_javascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype') ?]\n";
|
|
||||||
echo "[?php use_javascript(sfConfig::get('sf_admin_web_dir').'/js/collapse') ?]\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$category_name = $category;
|
|
||||||
$collapse = false;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<fieldset id="sf_fieldset_<?php echo preg_replace('/[^a-z0-9_]/', '_', strtolower($category_name)) ?>" class="<?php if ($collapse): ?> collapse<?php endif; ?>">
|
|
||||||
<?php if ($category != 'NONE'): ?><h2>[?php echo __('<?php echo $category_name ?>') ?]</h2>
|
|
||||||
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php $hides = $this->getParameterValue('edit.hide', array()) ?>
|
|
||||||
<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>
|
|
||||||
<?php if (in_array($column->getName(), $hides)) continue ?>
|
|
||||||
<?php if ($column->isPrimaryKey()) continue ?>
|
|
||||||
<?php $credentials = $this->getParameterValue('edit.fields.'.$column->getName().'.credentials') ?>
|
|
||||||
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
|
|
||||||
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<div class="form-row">
|
|
||||||
[?php echo label_for('<?php echo $this->getParameterValue("edit.fields.".$column->getName().".label_for", $this->getSingularName()."[".$column->getName()."]") ?>', __($labels['<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}']), '<?php if ($column->isNotNull()): ?>class="required" <?php endif; ?>') ?]
|
|
||||||
<div class="content[?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?] form-error[?php endif; ?]">
|
|
||||||
[?php if ($sf_request->hasError('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}')): ?]
|
|
||||||
[?php echo form_error('<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}', array('class' => 'form-error-msg')) ?]
|
|
||||||
[?php endif; ?]
|
|
||||||
|
|
||||||
[?php $value = <?php echo $this->getColumnEditTag($column); ?>; echo $value ? $value : ' ' ?]
|
|
||||||
<?php echo $this->getHelp($column, 'edit') ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php if ($credentials): ?>
|
|
||||||
[?php endif; ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</fieldset>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
[?php include_partial('edit_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
|
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<ul class="sf_admin_actions">
|
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
* WARNING: delete is a form, it must be outside the main form
|
|
||||||
*/
|
|
||||||
$editActions = $this->getParameterValue('edit.actions');
|
|
||||||
?>
|
|
||||||
<?php if (null === $editActions || (null !== $editActions && array_key_exists('_delete', $editActions))): ?>
|
|
||||||
<?php echo $this->addCredentialCondition($this->getButtonToAction('_delete', $editActions['_delete'], true), $editActions['_delete']) ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</ul>
|
|
@ -1,15 +0,0 @@
|
|||||||
[?php if ($sf_request->hasErrors()): ?]
|
|
||||||
<div class="form-errors">
|
|
||||||
<h2>[?php echo __('There are some errors that prevent the form to validate') ?]</h2>
|
|
||||||
<dl>
|
|
||||||
[?php foreach ($sf_request->getErrorNames() as $name): ?]
|
|
||||||
<dt>[?php echo __($labels[$name]) ?]</dt>
|
|
||||||
<dd>[?php echo $sf_request->getError($name) ?]</dd>
|
|
||||||
[?php endforeach; ?]
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
[?php elseif ($sf_flash->has('notice')): ?]
|
|
||||||
<div class="save-ok">
|
|
||||||
<h2>[?php echo __($sf_flash->get('notice')) ?]</h2>
|
|
||||||
</div>
|
|
||||||
[?php endif; ?]
|
|
@ -1,37 +0,0 @@
|
|||||||
[?php use_helper('Object') ?]
|
|
||||||
|
|
||||||
<?php if ($this->getParameterValue('list.filters')): ?>
|
|
||||||
<div class="sf_admin_filters">
|
|
||||||
[?php echo form_tag('<?php echo $this->getModuleName() ?>/list', array('method' => 'get')) ?]
|
|
||||||
|
|
||||||
<fieldset>
|
|
||||||
<h2>[?php echo __('filters') ?]</h2>
|
|
||||||
<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?>
|
|
||||||
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
|
|
||||||
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
|
|
||||||
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<div class="form-row">
|
|
||||||
<label for="<?php echo $column->getName() ?>">[?php echo __('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>:') ?]</label>
|
|
||||||
<div class="content">
|
|
||||||
[?php echo <?php echo $this->getColumnFilterTag($column) ?> ?]
|
|
||||||
<?php if ($this->getParameterValue('list.fields.'.$column->getName().'.filter_is_empty')): ?>
|
|
||||||
<div>[?php echo checkbox_tag('filters[<?php echo $column->getName() ?>_is_empty]', 1, isset($filters['<?php echo $column->getName() ?>_is_empty']) ? $filters['<?php echo $column->getName() ?>_is_empty'] : null) ?] <label for="filters[<?php echo $column->getName() ?>_is_empty]">[?php echo __('is empty') ?]</label></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php if ($credentials): ?>
|
|
||||||
[?php endif; ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<ul class="sf_admin_actions">
|
|
||||||
<li>[?php echo button_to(__('reset'), '<?php echo $this->getModuleName() ?>/list?filter=filter', 'class=sf_admin_action_reset_filter') ?]</li>
|
|
||||||
<li>[?php echo submit_tag(__('filter'), 'name=filter class=sf_admin_action_filter') ?]</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
@ -1,36 +0,0 @@
|
|||||||
<table cellspacing="0" class="sf_admin_list">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
[?php include_partial('list_th_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>') ?]
|
|
||||||
<?php if ($this->getParameterValue('list.object_actions')): ?>
|
|
||||||
<th id="sf_admin_list_th_sf_actions">[?php echo __('Actions') ?]</th>
|
|
||||||
<?php endif; ?>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
[?php $i = 1; foreach ($pager->getResults() as $<?php echo $this->getSingularName() ?>): $odd = fmod(++$i, 2) ?]
|
|
||||||
<tr class="sf_admin_row_[?php echo $odd ?]">
|
|
||||||
[?php include_partial('list_td_<?php echo $this->getParameterValue('list.layout', 'tabular') ?>', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
|
|
||||||
[?php include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
|
|
||||||
</tr>
|
|
||||||
[?php endforeach; ?]
|
|
||||||
</tbody>
|
|
||||||
<tfoot>
|
|
||||||
<tr><th colspan="<?php echo $this->getParameterValue('list.object_actions') ? count($this->getColumns('list.display')) + 1 : count($this->getColumns('list.display')) ?>">
|
|
||||||
<div class="float-right">
|
|
||||||
[?php if ($pager->haveToPaginate()): ?]
|
|
||||||
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/first.png', array('align' => 'absmiddle', 'alt' => __('First'), 'title' => __('First'))), '<?php echo $this->getModuleName() ?>/list?page=1') ?]
|
|
||||||
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', array('align' => 'absmiddle', 'alt' => __('Previous'), 'title' => __('Previous'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getPreviousPage()) ?]
|
|
||||||
|
|
||||||
[?php foreach ($pager->getLinks() as $page): ?]
|
|
||||||
[?php echo link_to_unless($page == $pager->getPage(), $page, '<?php echo $this->getModuleName() ?>/list?page='.$page) ?]
|
|
||||||
[?php endforeach; ?]
|
|
||||||
|
|
||||||
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', array('align' => 'absmiddle', 'alt' => __('Next'), 'title' => __('Next'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getNextPage()) ?]
|
|
||||||
[?php echo link_to(image_tag(sfConfig::get('sf_admin_web_dir').'/images/last.png', array('align' => 'absmiddle', 'alt' => __('Last'), 'title' => __('Last'))), '<?php echo $this->getModuleName() ?>/list?page='.$pager->getLastPage()) ?]
|
|
||||||
[?php endif; ?]
|
|
||||||
</div>
|
|
||||||
[?php echo format_number_choice('[0] no result|[1] 1 result|(1,+Inf] %1% results', array('%1%' => $pager->getNbResults()), $pager->getNbResults()) ?]
|
|
||||||
</th></tr>
|
|
||||||
</tfoot>
|
|
||||||
</table>
|
|
@ -1,10 +0,0 @@
|
|||||||
<ul class="sf_admin_actions">
|
|
||||||
<?php $listActions = $this->getParameterValue('list.actions') ?>
|
|
||||||
<?php if (null !== $listActions): ?>
|
|
||||||
<?php foreach ((array) $listActions as $actionName => $params): ?>
|
|
||||||
<?php echo $this->addCredentialCondition($this->getButtonToAction($actionName, $params, false), $params) ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<?php echo $this->getButtonToAction('_create', array(), false) ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</ul>
|
|
@ -1,8 +0,0 @@
|
|||||||
[?php if ($sf_request->getError('delete')): ?]
|
|
||||||
<div class="form-errors">
|
|
||||||
<h2>[?php echo __('Could not delete the selected %name%', array('%name%' => '<?php echo sfInflector::humanize($this->getSingularName()) ?>')) ?]</h2>
|
|
||||||
<ul>
|
|
||||||
<li>[?php echo $sf_request->getError('delete') ?]</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
[?php endif; ?]
|
|
@ -1,9 +0,0 @@
|
|||||||
<?php if ($this->getParameterValue('list.object_actions')): ?>
|
|
||||||
<td>
|
|
||||||
<ul class="sf_admin_td_actions">
|
|
||||||
<?php foreach ($this->getParameterValue('list.object_actions') as $actionName => $params): ?>
|
|
||||||
<?php echo $this->addCredentialCondition($this->getLinkToAction($actionName, $params, true), $params) ?>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</ul>
|
|
||||||
</td>
|
|
||||||
<?php endif; ?>
|
|
@ -1,16 +0,0 @@
|
|||||||
<td colspan="<?php echo count($this->getColumns('list.display')) ?>">
|
|
||||||
<?php if ($this->getParameterValue('list.params')): ?>
|
|
||||||
<?php echo $this->getI18NString('list.params') ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<?php $hides = $this->getParameterValue('list.hide', array()) ?>
|
|
||||||
<?php foreach ($this->getColumns('list.display') as $column): ?>
|
|
||||||
<?php if (in_array($column->getName(), $hides)) continue ?>
|
|
||||||
<?php if ($column->isLink()): ?>
|
|
||||||
[?php echo link_to(<?php echo $this->getColumnListTag($column) ?> ? <?php echo $this->getColumnListTag($column) ?> : __('-'), '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]
|
|
||||||
<?php else: ?>
|
|
||||||
[?php echo <?php echo $this->getColumnListTag($column) ?> ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
-
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</td>
|
|
@ -1,16 +0,0 @@
|
|||||||
<?php $hs = $this->getParameterValue('list.hide', array()) ?>
|
|
||||||
<?php foreach ($this->getColumns('list.display') as $column): ?>
|
|
||||||
<?php if (in_array($column->getName(), $hs)) continue ?>
|
|
||||||
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
|
|
||||||
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
|
|
||||||
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($column->isLink()): ?>
|
|
||||||
<td>[?php echo link_to(<?php echo $this->getColumnListTag($column) ?> ? <?php echo $this->getColumnListTag($column) ?> : __('-'), '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]</td>
|
|
||||||
<?php else: ?>
|
|
||||||
<td>[?php echo <?php echo $this->getColumnListTag($column) ?> ?]</td>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($credentials): ?>
|
|
||||||
[?php endif; ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
@ -1 +0,0 @@
|
|||||||
[?php include_partial('list_th_tabular') ?]
|
|
@ -1,24 +0,0 @@
|
|||||||
<?php $hides = $this->getParameterValue('list.hide', array()) ?>
|
|
||||||
<?php foreach ($this->getColumns('list.display') as $column): ?>
|
|
||||||
<?php if (in_array($column->getName(), $hides)) continue ?>
|
|
||||||
<?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?>
|
|
||||||
<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?>
|
|
||||||
[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<th id="sf_admin_list_th_<?php echo $column->getName() ?>">
|
|
||||||
<?php if ($column->isReal()): ?>
|
|
||||||
[?php if ($sf_user->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == '<?php echo $column->getName() ?>'): ?]
|
|
||||||
[?php echo link_to(__('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>'), '<?php echo $this->getModuleName() ?>/list?sort=<?php echo $column->getName() ?>&type='.($sf_user->getAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == 'asc' ? 'desc' : 'asc')) ?]
|
|
||||||
([?php echo __($sf_user->getAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort')) ?])
|
|
||||||
[?php else: ?]
|
|
||||||
[?php echo link_to(__('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>'), '<?php echo $this->getModuleName() ?>/list?sort=<?php echo $column->getName() ?>&type=asc') ?]
|
|
||||||
[?php endif; ?]
|
|
||||||
<?php else: ?>
|
|
||||||
[?php echo __('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>') ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php echo $this->getHelpAsIcon($column, 'list') ?>
|
|
||||||
</th>
|
|
||||||
<?php if ($credentials): ?>
|
|
||||||
[?php endif; ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php endforeach; ?>
|
|
@ -1,22 +0,0 @@
|
|||||||
[?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?]
|
|
||||||
|
|
||||||
[?php use_stylesheet('<?php echo $this->getParameterValue('css', sfConfig::get('sf_admin_web_dir').'/css/main') ?>') ?]
|
|
||||||
|
|
||||||
<div id="sf_admin_container">
|
|
||||||
|
|
||||||
<h1><?php echo $this->getI18NString('edit.title', 'edit '.$this->getModuleName()) ?></h1>
|
|
||||||
|
|
||||||
<div id="sf_admin_header">
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_header', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="sf_admin_content">
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_messages', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'labels' => $labels)) ?]
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_form', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'labels' => $labels)) ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="sf_admin_footer">
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/edit_footer', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,33 +0,0 @@
|
|||||||
[?php use_helper('I18N', 'Date') ?]
|
|
||||||
|
|
||||||
[?php use_stylesheet('<?php echo $this->getParameterValue('css', sfConfig::get('sf_admin_web_dir').'/css/main') ?>') ?]
|
|
||||||
|
|
||||||
<div id="sf_admin_container">
|
|
||||||
|
|
||||||
<h1><?php echo $this->getI18NString('list.title', $this->getModuleName().' list') ?></h1>
|
|
||||||
|
|
||||||
<div id="sf_admin_header">
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/list_header', array('pager' => $pager)) ?]
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/list_messages', array('pager' => $pager)) ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="sf_admin_bar">
|
|
||||||
<?php if ($this->getParameterValue('list.filters')): ?>
|
|
||||||
[?php include_partial('filters', array('filters' => $filters)) ?]
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="sf_admin_content">
|
|
||||||
[?php if (!$pager->getNbResults()): ?]
|
|
||||||
[?php echo __('no result') ?]
|
|
||||||
[?php else: ?]
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager)) ?]
|
|
||||||
[?php endif; ?]
|
|
||||||
[?php include_partial('list_actions') ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="sf_admin_footer">
|
|
||||||
[?php include_partial('<?php echo $this->getModuleName() ?>/list_footer', array('pager' => $pager)) ?]
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,897 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the sfDoctrine package.
|
|
||||||
* (c) 2006-2007 Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @package symfony.plugins
|
|
||||||
* @subpackage sfDoctrine
|
|
||||||
* @author Olivier Verdier <Olivier.Verdier@gmail.com>
|
|
||||||
* @author Nathanael D. Noblet <nathanael@gnat.ca>
|
|
||||||
* @version SVN: $Id: sfPakeDoctrine.php 4878 2007-08-17 17:45:54Z Jonathan.Wage $
|
|
||||||
*/
|
|
||||||
|
|
||||||
pake_desc('converts propel schema.*ml into doctrine schema');
|
|
||||||
pake_task('doctrine-import', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('exports doctrine schemas to sql');
|
|
||||||
pake_task('doctrine-build-sql', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('insert sql for doctrine schemas in to database');
|
|
||||||
pake_task('doctrine-insert-sql', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('build Doctrine classes');
|
|
||||||
pake_task('doctrine-build-model', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('Creates Doctrine CRUD Module');
|
|
||||||
pake_task('doctrine-generate-crud', 'app_exists');
|
|
||||||
|
|
||||||
pake_desc('initialize a new doctrine admin module');
|
|
||||||
pake_task('doctrine-init-admin', 'app_exists');
|
|
||||||
|
|
||||||
pake_desc('dump data to yaml fixtures file');
|
|
||||||
pake_task('doctrine-dump-data', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('load data from yaml fixtures file');
|
|
||||||
pake_task('doctrine-load-data', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('load doctrine nested set data from nested set fixtures file');
|
|
||||||
pake_task('doctrine-load-nested-set', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine build all - generate model and initialize database, drops current database if exists');
|
|
||||||
pake_task('doctrine-build-all', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine build all load - generate model, initialize database, and load data from fixtures. Drops current database if exists');
|
|
||||||
pake_task('doctrine-build-all-load', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine build schema - build schema from an existing database');
|
|
||||||
pake_task('doctrine-build-schema', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine drop all - drop all database tables');
|
|
||||||
pake_task('doctrine-drop-all-tables', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine build database - initialize database, drop current database if exists');
|
|
||||||
pake_task('doctrine-build-db', 'project_exists');
|
|
||||||
|
|
||||||
pake_desc('doctrine drop database - drops database');
|
|
||||||
pake_task('doctrine-drop-db', 'project_exists');
|
|
||||||
|
|
||||||
function run_doctrine_drop_all_tables($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
$env = empty($args[1]) ? 'dev' : $args[1];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
$sf_root_dir = sfConfig::get('sf_root_dir');
|
|
||||||
|
|
||||||
$declared = get_declared_classes();
|
|
||||||
|
|
||||||
$directory = sfConfig::get('sf_lib_dir').DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
if ($directory !== null)
|
|
||||||
{
|
|
||||||
foreach ((array) $directory as $dir)
|
|
||||||
{
|
|
||||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
|
||||||
RecursiveIteratorIterator::LEAVES_ONLY);
|
|
||||||
|
|
||||||
foreach ($it as $file)
|
|
||||||
{
|
|
||||||
$e = explode('.', $file->getFileName());
|
|
||||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false)
|
|
||||||
{
|
|
||||||
require_once $file->getPathName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$declared = array_diff(get_declared_classes(), $declared);
|
|
||||||
}
|
|
||||||
|
|
||||||
$parent = new ReflectionClass('Doctrine_Record');
|
|
||||||
|
|
||||||
$sql = array();
|
|
||||||
$fks = array();
|
|
||||||
|
|
||||||
// we iterate trhough the diff of previously declared classes
|
|
||||||
// and currently declared classes
|
|
||||||
foreach ($declared as $name)
|
|
||||||
{
|
|
||||||
$class = new ReflectionClass($name);
|
|
||||||
$conn = Doctrine_Manager::getInstance()->getConnectionForComponent($name);
|
|
||||||
|
|
||||||
// check if class is an instance of Doctrine_Record and not abstract
|
|
||||||
// class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord)
|
|
||||||
if ($class->isSubclassOf($parent) && ! $class->isAbstract() && method_exists($class->getName(), 'setTableDefinition'))
|
|
||||||
{
|
|
||||||
$record = new $name();
|
|
||||||
$table = $record->getTable();
|
|
||||||
|
|
||||||
try {
|
|
||||||
pake_echo_action('doctrine', "dropping table '".$table->getTableName()."'");
|
|
||||||
|
|
||||||
$table->getConnection()->export->dropTable($table->getTableName());
|
|
||||||
} catch(Exception $e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_load_data($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app))
|
|
||||||
{
|
|
||||||
throw new Exception('The app "'.$app.'" does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($args) > 1 && $args[count($args) - 1] == 'append')
|
|
||||||
{
|
|
||||||
array_pop($args);
|
|
||||||
$delete = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$delete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$env = empty($args[1]) ? 'dev' : $args[1];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
if (count($args) == 1)
|
|
||||||
{
|
|
||||||
if (!$pluginDirs = glob(sfConfig::get('sf_root_dir').'/plugins/*/data'))
|
|
||||||
{
|
|
||||||
$pluginDirs = array();
|
|
||||||
}
|
|
||||||
$fixtures_dirs = pakeFinder::type('dir')->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir'))));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$fixtures_dirs = array_slice($args, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = new sfDoctrineData();
|
|
||||||
$data->setDeleteCurrentData($delete);
|
|
||||||
|
|
||||||
foreach ($fixtures_dirs as $fixtures_dir)
|
|
||||||
{
|
|
||||||
if (!is_readable($fixtures_dir))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', sprintf('load data from "%s"', $fixtures_dir));
|
|
||||||
|
|
||||||
$data->loadData($fixtures_dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_import($task, $args)
|
|
||||||
{
|
|
||||||
$type = 'xml';
|
|
||||||
if (isset($args[0]))
|
|
||||||
$type = $args[0];
|
|
||||||
|
|
||||||
$schemas = _doctrine_load('propel', $type, false);
|
|
||||||
|
|
||||||
$doctrineSchemasDir = sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
pake_mkdirs($doctrineSchemasDir);
|
|
||||||
|
|
||||||
foreach($schemas as $schema)
|
|
||||||
{
|
|
||||||
$doctrineYml = $schema->asDoctrineYml();
|
|
||||||
$classes = $schema->getClasses();
|
|
||||||
$class = array_pop($classes);
|
|
||||||
$package = $class->getTable()->getPackage();
|
|
||||||
$filePath = $package.'.yml';
|
|
||||||
|
|
||||||
pake_echo_action('writing', $filePath);
|
|
||||||
|
|
||||||
file_put_contents($doctrineSchemasDir.$filePath, $doctrineYml['source']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_export($task, $args)
|
|
||||||
{
|
|
||||||
$schemas = _doctrine_load('doctrine', 'yml', false);
|
|
||||||
|
|
||||||
$configDir = sfConfig::get('sf_config_dir').DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
foreach($schemas as $schema)
|
|
||||||
{
|
|
||||||
$propelXml = $schema->asPropelXml();
|
|
||||||
|
|
||||||
// we do some tidying before echoing the xml
|
|
||||||
$source = preg_replace(array('#</database#', '#<(/?)table#', '#<column#', '#<(/?)foreign-key#', '#<reference#'), array("\n</database", "\n<\\1table", "\n <column", "\n <\\1foreign-key", "\n <reference",), $propelXml['source']);
|
|
||||||
|
|
||||||
$filePath = $propelXml['name'].'-schema.xml';
|
|
||||||
|
|
||||||
pake_echo_action('writing', $filePath);
|
|
||||||
|
|
||||||
file_put_contents($configDir.$filePath, $source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_insert_sql($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
$env = empty($args[1]) ? 'dev' : $args[1];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
$sf_root_dir = sfConfig::get('sf_root_dir');
|
|
||||||
|
|
||||||
$directories = sfFinder::type('dir')->maxdepth(0)->ignore_version_control()->in(sfConfig::get('sf_model_lib_dir').'/doctrine');
|
|
||||||
|
|
||||||
Doctrine::exportSchema($directories);
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', 'sql was inserted successfully');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_build_sql($task,$args)
|
|
||||||
{
|
|
||||||
if(count($args) < 1)
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide your app name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$sf_root_dir = sfConfig::get('sf_root_dir');
|
|
||||||
define('SF_APP', $args[0]);
|
|
||||||
$connection = isset($args[1])?$args[1]:'all';
|
|
||||||
|
|
||||||
simpleAutoloader::registerCallable(array('Doctrine','autoload'));
|
|
||||||
|
|
||||||
sfConfig::set('sf_app_module_dir',$sf_root_dir.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR);
|
|
||||||
|
|
||||||
$doctrineSchemaPathScheme = DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
$doctrineModelDir = sfConfig::get('sf_lib_dir').$doctrineSchemaPathScheme;
|
|
||||||
$generatedDir = $doctrineModelDir.'generated'.DIRECTORY_SEPARATOR;
|
|
||||||
|
|
||||||
$tmp_dir = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true));
|
|
||||||
|
|
||||||
$db_connections = sfYaml::load($sf_root_dir.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'databases.yml');
|
|
||||||
if(!isset($db_connections[$connection]))
|
|
||||||
{
|
|
||||||
throw new sfException('Unable to find connection: '.$connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
$connection = current($db_connections[$connection]);
|
|
||||||
$db = new sfDoctrineDatabase();
|
|
||||||
$db->initialize($connection['param']);
|
|
||||||
|
|
||||||
$directories = sfFinder::type('dir')->maxdepth(0)->ignore_version_control()->in(sfConfig::get('sf_model_lib_dir').'/doctrine');
|
|
||||||
|
|
||||||
foreach ($directories AS $directory)
|
|
||||||
{
|
|
||||||
$basename = basename($directory);
|
|
||||||
$name = $basename == 'generated' ? 'doctrine':'doctrine-'.$basename;
|
|
||||||
|
|
||||||
pake_echo_action("Building SQL", $name);
|
|
||||||
|
|
||||||
$sql = implode(";\n\n",Doctrine::exportSql($directory)).";\n";
|
|
||||||
$sql = str_replace(array(" (",") ",","),array("(\n ",")\n",",\n"),$sql);
|
|
||||||
|
|
||||||
if (!is_dir($sf_root_dir.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'sql'))
|
|
||||||
{
|
|
||||||
mkdir($sf_root_dir.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'sql');
|
|
||||||
}
|
|
||||||
|
|
||||||
$fd = fopen($sf_root_dir.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'sql'.DIRECTORY_SEPARATOR.$name.'.model.sql','w+');
|
|
||||||
fwrite($fd,$sql);
|
|
||||||
fclose($fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function run_doctrine_build_model($task, $args)
|
|
||||||
{
|
|
||||||
$schemas = _doctrine_load('doctrine', 'yml', true);
|
|
||||||
$doctrineSchemaPathScheme = DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
$doctrineModelDir = sfConfig::get('sf_lib_dir').$doctrineSchemaPathScheme;
|
|
||||||
|
|
||||||
$generatedDir = $doctrineModelDir.'generated'.DIRECTORY_SEPARATOR;
|
|
||||||
pake_mkdirs($generatedDir);
|
|
||||||
|
|
||||||
foreach($schemas as $db_schema)
|
|
||||||
{
|
|
||||||
foreach ($db_schema->getClasses() as $class)
|
|
||||||
{
|
|
||||||
foreach ($class->asPHP() as $cd)
|
|
||||||
{
|
|
||||||
$path = $doctrineModelDir;
|
|
||||||
|
|
||||||
$package = $class->getTable()->getPackage();
|
|
||||||
if ($package)
|
|
||||||
{
|
|
||||||
if (isset($cd['plugin']))
|
|
||||||
{
|
|
||||||
$path = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.$package.DIRECTORY_SEPARATOR.'lib'.$doctrineSchemaPathScheme;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$path.= $package.DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($cd['overwrite']))
|
|
||||||
{
|
|
||||||
$path .= 'generated'.DIRECTORY_SEPARATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
pake_mkdirs($path);
|
|
||||||
|
|
||||||
$filePath = $cd['className'].'.class.php';
|
|
||||||
|
|
||||||
// we overwrite only the base classes
|
|
||||||
if (isset($cd['overwrite']) || !file_exists($path.$filePath))
|
|
||||||
{
|
|
||||||
pake_echo_action('writing', $filePath);
|
|
||||||
file_put_contents($path.$filePath, $cd['source']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_build_all($task, $args)
|
|
||||||
{
|
|
||||||
run_doctrine_drop_db($task, $args);
|
|
||||||
run_doctrine_build_db($task, $args);
|
|
||||||
run_doctrine_build_model($task, $args);
|
|
||||||
//run_doctrine_insert_sql($task, $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_build_all_load($task, $args)
|
|
||||||
{
|
|
||||||
run_doctrine_build_all($task, $args);
|
|
||||||
run_doctrine_load_data($task, $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_build_schema($task, $args)
|
|
||||||
{
|
|
||||||
// This will build schema from an existing database
|
|
||||||
throw new Exception('Not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_drop_db($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
$env = empty($args[1]) ? 'dev' : $args[1];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
$databases = sfYaml::load(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'databases.yml');
|
|
||||||
|
|
||||||
$connectionBlockKey = $env;
|
|
||||||
|
|
||||||
if(!isset($databases[$connectionBlockKey]))
|
|
||||||
{
|
|
||||||
$connectionBlockKey = 'all';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$connections = $databases[$connectionBlockKey];
|
|
||||||
|
|
||||||
$manager = Doctrine_Manager::getInstance();
|
|
||||||
|
|
||||||
foreach ($connections AS $name => $info)
|
|
||||||
{
|
|
||||||
$dsnInfo = $manager->parseDsn($info['param']['dsn']);
|
|
||||||
$connection = $manager->getConnection($name);
|
|
||||||
|
|
||||||
try {
|
|
||||||
echo "Drop database '".$dsnInfo['database']."' are you sure Y/N ?";
|
|
||||||
$confirmation = strtolower(trim(fgets(STDIN)));
|
|
||||||
if ($confirmation!='y') {
|
|
||||||
pake_echo_action("cancelled");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', "dropping database '".$dsnInfo['database']."'");
|
|
||||||
|
|
||||||
$connection->export->dropDatabase($dsnInfo['database']);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
pake_echo_action('doctrine', "could not drop database '".$dsnInfo['database']."'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_doctrine_build_db($task, $args)
|
|
||||||
{
|
|
||||||
$connectionName = isset($args[0]) ? $args[0]:'all';
|
|
||||||
|
|
||||||
simpleAutoloader::registerCallable(array('Doctrine','autoload'));
|
|
||||||
|
|
||||||
$databases = sfYaml::load(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'databases.yml');
|
|
||||||
|
|
||||||
if(!isset($databases[$connectionName]))
|
|
||||||
{
|
|
||||||
$connectionName = 'all';
|
|
||||||
}
|
|
||||||
|
|
||||||
$connections = $databases[$connectionName];
|
|
||||||
|
|
||||||
foreach($connections AS $name => $connection)
|
|
||||||
{
|
|
||||||
$dsn = $connection['param']['dsn'];
|
|
||||||
$info = Doctrine_Manager::getInstance()->parseDsn($dsn);
|
|
||||||
|
|
||||||
$dsn = $info['scheme'].':host='.$info['host'];
|
|
||||||
$user = $info['user'];
|
|
||||||
$password = $info['pass'];
|
|
||||||
|
|
||||||
$connection = Doctrine_Manager::getInstance()->openConnection(new PDO($dsn, $user, $password), $name.'2');
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', "creating database '".$info['database']."'");
|
|
||||||
|
|
||||||
try {
|
|
||||||
$connection->export->createDatabase($info['database']);
|
|
||||||
} catch(Exception $e) {
|
|
||||||
pake_echo_action('doctrine', "could not create database '".$info['database']."'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: has to be rewritten to avoid code duplication
|
|
||||||
function run_doctrine_generate_crud($task,$args)
|
|
||||||
{
|
|
||||||
if (count($args) < 2)
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide your module name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($args) < 3)
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide your model class name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
$module = $args[1];
|
|
||||||
$model_class = $args[2];
|
|
||||||
$theme = isset($args[3]) ? $args[3] : 'crud';
|
|
||||||
|
|
||||||
// function variables
|
|
||||||
$doctrineModelDir = sfConfig::get('sf_lib_dir').DIRECTORY_SEPARATOR.'model'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
$sf_root_dir = sfConfig::get('sf_root_dir');
|
|
||||||
$sf_symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir');
|
|
||||||
$pluginDir = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..');
|
|
||||||
$doctrineLibDir =$pluginDir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.'Doctrine'.DIRECTORY_SEPARATOR;
|
|
||||||
$tmp_dir = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true));
|
|
||||||
|
|
||||||
sfConfig::set('sf_module_cache_dir', $tmp_dir);
|
|
||||||
sfConfig::set('sf_app_dir', $tmp_dir);
|
|
||||||
// add classes to autoload function
|
|
||||||
pake_echo_action('PluginDir', $pluginDir);
|
|
||||||
|
|
||||||
simpleAutoloader::registerCallable(array('Doctrine','autoload'));
|
|
||||||
|
|
||||||
// generate module
|
|
||||||
$generator_manager = new sfGeneratorManager();
|
|
||||||
$generator_manager->initialize();
|
|
||||||
$generator_manager->generate('sfDoctrineAdminGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme));
|
|
||||||
$moduleDir = $sf_root_dir.'/'.sfConfig::get('sf_apps_dir_name').'/'.$app.'/'.sfConfig::get('sf_app_module_dir_name').'/'.$module;
|
|
||||||
|
|
||||||
// copy our generated module
|
|
||||||
$finder = pakeFinder::type('any');
|
|
||||||
pake_mirror($finder, $tmp_dir.'/auto'.ucfirst($module), $moduleDir);
|
|
||||||
|
|
||||||
// change module name
|
|
||||||
pake_replace_tokens($moduleDir.'/actions/actions.class.php', getcwd(), '', '', array('auto'.ucfirst($module) => $module));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$author_name = $task->get_property('author', 'symfony');
|
|
||||||
}
|
|
||||||
catch (pakeException $e)
|
|
||||||
{
|
|
||||||
$author_name = 'Your name here';
|
|
||||||
}
|
|
||||||
|
|
||||||
$constants = array(
|
|
||||||
'PROJECT_NAME' => $task->get_property('name', 'symfony'),
|
|
||||||
'APP_NAME' => $app,
|
|
||||||
'MODULE_NAME' => $module,
|
|
||||||
'MODEL_CLASS' => $model_class,
|
|
||||||
'AUTHOR_NAME' => $author_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
// customize php files
|
|
||||||
$finder = pakeFinder::type('file')->name('*.php');
|
|
||||||
pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
|
|
||||||
|
|
||||||
// delete temp files
|
|
||||||
$finder = pakeFinder::type('any');
|
|
||||||
pake_remove($finder, $tmp_dir);
|
|
||||||
|
|
||||||
// for some reason the above does not remove the tmp dir as it should.
|
|
||||||
// delete temp dir
|
|
||||||
@rmdir($tmp_dir);
|
|
||||||
|
|
||||||
// delete cache/tmp
|
|
||||||
@rmdir(sfConfig::get('sf_cache_dir').'tmp');
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: has to be rewritten to avoid code duplication
|
|
||||||
function run_doctrine_init_admin($task, $args)
|
|
||||||
{
|
|
||||||
if (count($args) < 2)
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide your module name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($args) < 3)
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide your model class name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
$module = $args[1];
|
|
||||||
$model_class = $args[2];
|
|
||||||
$theme = isset($args[3]) ? $args[3] : 'default';
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$author_name = $task->get_property('author', 'symfony');
|
|
||||||
}
|
|
||||||
catch (pakeException $e)
|
|
||||||
{
|
|
||||||
$author_name = 'Your name here';
|
|
||||||
}
|
|
||||||
|
|
||||||
$constants = array(
|
|
||||||
'PROJECT_NAME' => $task->get_property('name', 'symfony'),
|
|
||||||
'APP_NAME' => $app,
|
|
||||||
'MODULE_NAME' => $module,
|
|
||||||
'MODEL_CLASS' => $model_class,
|
|
||||||
'AUTHOR_NAME' => $author_name,
|
|
||||||
'THEME' => $theme,
|
|
||||||
);
|
|
||||||
|
|
||||||
$moduleDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_apps_dir_name').DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.sfConfig::get('sf_app_module_dir_name').DIRECTORY_SEPARATOR.$module;
|
|
||||||
|
|
||||||
// create module structure
|
|
||||||
$finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
|
|
||||||
$dirs = sfLoader::getGeneratorSkeletonDirs('sfDoctrineAdmin', $theme);
|
|
||||||
foreach($dirs as $dir)
|
|
||||||
{
|
|
||||||
echo $dir;
|
|
||||||
if(is_dir($dir))
|
|
||||||
{
|
|
||||||
pake_mirror($finder, $dir, $moduleDir);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// customize php and yml files
|
|
||||||
$finder = pakeFinder::type('file')->name('*.php', '*.yml');
|
|
||||||
pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* run_doctrine_load_nested_set
|
|
||||||
*
|
|
||||||
* @param mixed $task
|
|
||||||
* @param mixed $args
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function run_doctrine_load_nested_set($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app))
|
|
||||||
{
|
|
||||||
throw new Exception('The app "'.$app.'" does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($args[1]))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide a filename.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $args[1];
|
|
||||||
|
|
||||||
$env = empty($args[2]) ? 'dev' : $args[2];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
$model = sfInflector::classify($args[1]);
|
|
||||||
$ymlName = sfInflector::tableize($args[1]);
|
|
||||||
|
|
||||||
$ymlPath = sfConfig::get('sf_data_dir').'/'.$ymlName.'.yml';
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', 'loading nested set data for '.$model);
|
|
||||||
pake_echo_action('doctrine', 'loading '.$ymlPath);
|
|
||||||
|
|
||||||
$nestedSetData = sfYaml::load($ymlPath);
|
|
||||||
|
|
||||||
_doctrine_load_nested_set_data($model, $nestedSetData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* run_doctrine_dump_data
|
|
||||||
*
|
|
||||||
* @param mixed $task
|
|
||||||
* @param mixed $args
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function run_doctrine_dump_data($task, $args)
|
|
||||||
{
|
|
||||||
if (!count($args))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide the app.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$app = $args[0];
|
|
||||||
|
|
||||||
if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app))
|
|
||||||
{
|
|
||||||
throw new Exception('The app "'.$app.'" does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($args[1]))
|
|
||||||
{
|
|
||||||
throw new Exception('You must provide a filename.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $args[1];
|
|
||||||
|
|
||||||
$env = empty($args[2]) ? 'dev' : $args[2];
|
|
||||||
|
|
||||||
_load_application_environment($app, $env);
|
|
||||||
|
|
||||||
if (!sfToolkit::isPathAbsolute($filename))
|
|
||||||
{
|
|
||||||
$dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures';
|
|
||||||
pake_mkdirs($dir);
|
|
||||||
$filename = $dir.DIRECTORY_SEPARATOR.$filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', sprintf('dumping data to "%s"', $filename));
|
|
||||||
|
|
||||||
$data = new sfDoctrineData();
|
|
||||||
$data->dumpData($filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* _doctrine_load_nested_set_data
|
|
||||||
*
|
|
||||||
* @param mixed $model
|
|
||||||
* @param mixed $nestedSetData
|
|
||||||
* @param mixed $parent
|
|
||||||
* @access protected
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function _doctrine_load_nested_set_data($model, $nestedSetData, $parent = null)
|
|
||||||
{
|
|
||||||
$manager = Doctrine_Manager::getInstance();
|
|
||||||
|
|
||||||
foreach($nestedSetData AS $name => $data)
|
|
||||||
{
|
|
||||||
$children = array();
|
|
||||||
$setters = array();
|
|
||||||
|
|
||||||
if( array_key_exists('children', $data) )
|
|
||||||
{
|
|
||||||
$children = $data['children'];
|
|
||||||
unset($data['children']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( array_key_exists('setters', $data) )
|
|
||||||
{
|
|
||||||
$setters = $data['setters'];
|
|
||||||
unset($data['setters']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$record = new $model();
|
|
||||||
|
|
||||||
if( is_array($setters) AND !empty($setters) )
|
|
||||||
{
|
|
||||||
foreach($setters AS $key => $value)
|
|
||||||
{
|
|
||||||
$record->set($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !$parent )
|
|
||||||
{
|
|
||||||
$manager->getTable($model)->getTree()->createRoot($record);
|
|
||||||
} else {
|
|
||||||
$parent->getNode()->addChild($record);
|
|
||||||
}
|
|
||||||
|
|
||||||
pake_echo_action('doctrine', 'loading '.str_repeat(' ', $record->getNode()->getLevel()).$name);
|
|
||||||
|
|
||||||
if( is_array($children) AND !empty($children) )
|
|
||||||
{
|
|
||||||
_doctrine_load_nested_set_data($model, $children, $record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _findPropelSchemas($type)
|
|
||||||
{
|
|
||||||
$preGlob = '*schema';
|
|
||||||
$root = 'config';
|
|
||||||
|
|
||||||
$extension = '.'.$type;
|
|
||||||
|
|
||||||
$schemas = pakeFinder::type('file')->name($preGlob.$extension)->in($root);
|
|
||||||
|
|
||||||
$schemasToLoad = array();
|
|
||||||
foreach ($schemas as $schema)
|
|
||||||
{
|
|
||||||
// we store the name of the file as "package"
|
|
||||||
$schemasToLoad[$schema] = basename($schema, $extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $schemasToLoad;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _findDoctrineSchemas()
|
|
||||||
{
|
|
||||||
$schemasToLoad = array();
|
|
||||||
|
|
||||||
// first we try with a connection mapping config file
|
|
||||||
$connectionMappingPath = 'config/schemas.yml';
|
|
||||||
if (file_exists($connectionMappingPath))
|
|
||||||
{
|
|
||||||
$connectionMapping = sfYaml::load($connectionMappingPath);
|
|
||||||
|
|
||||||
foreach ($connectionMapping as $connection => $schemas)
|
|
||||||
{
|
|
||||||
foreach ($schemas as $schema)
|
|
||||||
{
|
|
||||||
$components = explode('/', $schema);
|
|
||||||
$name = array_pop($components);
|
|
||||||
$schemaPath = 'config/doctrine/'.$name.'.yml';
|
|
||||||
if (!empty($components))
|
|
||||||
{
|
|
||||||
$packageName = $components[0];
|
|
||||||
$schemaPath = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.$packageName.DIRECTORY_SEPARATOR.$schemaPath;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$packageName = null;
|
|
||||||
|
|
||||||
if (file_exists($schemaPath))
|
|
||||||
{
|
|
||||||
$schemasToLoad[$schemaPath] = $packageName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // otherwise we load all the schemas in the doctrine directories
|
|
||||||
{
|
|
||||||
$preGlob = '*';
|
|
||||||
$root = 'config'.DIRECTORY_SEPARATOR.'doctrine';
|
|
||||||
|
|
||||||
$schemas = pakeFinder::type('file')->name($preGlob.'.yml')->in($root);
|
|
||||||
|
|
||||||
if(count($schemas))
|
|
||||||
$schemas = array_combine($schemas, array_fill(0, count($schemas), null));
|
|
||||||
|
|
||||||
// adding the plugin schemas
|
|
||||||
$pluginSchemas = array();
|
|
||||||
$pluginSchemas = pakeFinder::type('file')->name($preGlob.'.yml')->in(glob('plugins/*/'.$root));
|
|
||||||
$schemasToLoad = array();
|
|
||||||
foreach ($pluginSchemas as $pluginSchema)
|
|
||||||
{
|
|
||||||
// we get the plugin name from the path file; not very elegant...
|
|
||||||
$pluginName = basename(substr(dirname($pluginSchema), 0, -strlen($root)));
|
|
||||||
$schemasToLoad[$pluginSchema] = $pluginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
$schemasToLoad = array_merge($schemas, $schemasToLoad);
|
|
||||||
}
|
|
||||||
return $schemasToLoad;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _doctrine_load($mode, $type, $aggregate)
|
|
||||||
{
|
|
||||||
$schemasToLoad = array();
|
|
||||||
|
|
||||||
if ($mode == 'doctrine')
|
|
||||||
{
|
|
||||||
$schemasToLoad = _findDoctrineSchemas();
|
|
||||||
}
|
|
||||||
elseif ($mode == 'propel')
|
|
||||||
{
|
|
||||||
$schemasToLoad = _findPropelSchemas($type);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!count($schemasToLoad))
|
|
||||||
{
|
|
||||||
throw new Exception('No schemas were found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbSchemas = array();
|
|
||||||
|
|
||||||
// schema loader class
|
|
||||||
$schemaClass = 'sfDoctrineSchema'.ucfirst($mode).'Loader';
|
|
||||||
|
|
||||||
$db_schema = new $schemaClass();
|
|
||||||
$db_schemas = array();
|
|
||||||
|
|
||||||
foreach ($schemasToLoad as $schema => $package)
|
|
||||||
{
|
|
||||||
if (!$aggregate)
|
|
||||||
{
|
|
||||||
$db_schema = new $schemaClass();
|
|
||||||
}
|
|
||||||
$relativeSchema = substr($schema, strlen(sfConfig::get('sf_root_dir'))+1);
|
|
||||||
|
|
||||||
pake_echo_action('loading', 'Class descriptions from "'.$schema.'"');
|
|
||||||
$db_schema->load($schema, $package);
|
|
||||||
if (!$aggregate)
|
|
||||||
{
|
|
||||||
$db_schema->process();
|
|
||||||
$db_schemas[] = $db_schema;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($aggregate)
|
|
||||||
{
|
|
||||||
$db_schema->process();
|
|
||||||
$db_schemas = array($db_schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $db_schemas;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _load_application_environment($app, $env)
|
|
||||||
{
|
|
||||||
// define constants
|
|
||||||
define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
|
|
||||||
define('SF_APP', $app);
|
|
||||||
define('SF_ENVIRONMENT', $env);
|
|
||||||
define('SF_DEBUG', true);
|
|
||||||
|
|
||||||
// get configuration
|
|
||||||
require_once SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php';
|
|
||||||
|
|
||||||
sfContext::getInstance();
|
|
||||||
}
|
|
@ -1,548 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Doctrine.php 2255 2007-08-16 22:42:35Z Jonathan.Wage $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine
|
|
||||||
* the base class of Doctrine framework
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 2255 $
|
|
||||||
*/
|
|
||||||
final class Doctrine
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ERROR CONSTANTS
|
|
||||||
*/
|
|
||||||
const ERR = -1;
|
|
||||||
const ERR_SYNTAX = -2;
|
|
||||||
const ERR_CONSTRAINT = -3;
|
|
||||||
const ERR_NOT_FOUND = -4;
|
|
||||||
const ERR_ALREADY_EXISTS = -5;
|
|
||||||
const ERR_UNSUPPORTED = -6;
|
|
||||||
const ERR_MISMATCH = -7;
|
|
||||||
const ERR_INVALID = -8;
|
|
||||||
const ERR_NOT_CAPABLE = -9;
|
|
||||||
const ERR_TRUNCATED = -10;
|
|
||||||
const ERR_INVALID_NUMBER = -11;
|
|
||||||
const ERR_INVALID_DATE = -12;
|
|
||||||
const ERR_DIVZERO = -13;
|
|
||||||
const ERR_NODBSELECTED = -14;
|
|
||||||
const ERR_CANNOT_CREATE = -15;
|
|
||||||
const ERR_CANNOT_DELETE = -16;
|
|
||||||
const ERR_CANNOT_DROP = -17;
|
|
||||||
const ERR_NOSUCHTABLE = -18;
|
|
||||||
const ERR_NOSUCHFIELD = -19;
|
|
||||||
const ERR_NEED_MORE_DATA = -20;
|
|
||||||
const ERR_NOT_LOCKED = -21;
|
|
||||||
const ERR_VALUE_COUNT_ON_ROW = -22;
|
|
||||||
const ERR_INVALID_DSN = -23;
|
|
||||||
const ERR_CONNECT_FAILED = -24;
|
|
||||||
const ERR_EXTENSION_NOT_FOUND = -25;
|
|
||||||
const ERR_NOSUCHDB = -26;
|
|
||||||
const ERR_ACCESS_VIOLATION = -27;
|
|
||||||
const ERR_CANNOT_REPLACE = -28;
|
|
||||||
const ERR_CONSTRAINT_NOT_NULL = -29;
|
|
||||||
const ERR_DEADLOCK = -30;
|
|
||||||
const ERR_CANNOT_ALTER = -31;
|
|
||||||
const ERR_MANAGER = -32;
|
|
||||||
const ERR_MANAGER_PARSE = -33;
|
|
||||||
const ERR_LOADMODULE = -34;
|
|
||||||
const ERR_INSUFFICIENT_DATA = -35;
|
|
||||||
const ERR_CLASS_NAME = -36;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PDO derived constants
|
|
||||||
*/
|
|
||||||
const CASE_LOWER = 2;
|
|
||||||
const CASE_NATURAL = 0;
|
|
||||||
const CASE_UPPER = 1;
|
|
||||||
const CURSOR_FWDONLY = 0;
|
|
||||||
const CURSOR_SCROLL = 1;
|
|
||||||
const ERRMODE_EXCEPTION = 2;
|
|
||||||
const ERRMODE_SILENT = 0;
|
|
||||||
const ERRMODE_WARNING = 1;
|
|
||||||
const FETCH_ASSOC = 2;
|
|
||||||
const FETCH_BOTH = 4;
|
|
||||||
const FETCH_BOUND = 6;
|
|
||||||
const FETCH_CLASS = 8;
|
|
||||||
const FETCH_CLASSTYPE = 262144;
|
|
||||||
const FETCH_COLUMN = 7;
|
|
||||||
const FETCH_FUNC = 10;
|
|
||||||
const FETCH_GROUP = 65536;
|
|
||||||
const FETCH_INTO = 9;
|
|
||||||
const FETCH_LAZY = 1;
|
|
||||||
const FETCH_NAMED = 11;
|
|
||||||
const FETCH_NUM = 3;
|
|
||||||
const FETCH_OBJ = 5;
|
|
||||||
const FETCH_ORI_ABS = 4;
|
|
||||||
const FETCH_ORI_FIRST = 2;
|
|
||||||
const FETCH_ORI_LAST = 3;
|
|
||||||
const FETCH_ORI_NEXT = 0;
|
|
||||||
const FETCH_ORI_PRIOR = 1;
|
|
||||||
const FETCH_ORI_REL = 5;
|
|
||||||
const FETCH_SERIALIZE = 524288;
|
|
||||||
const FETCH_UNIQUE = 196608;
|
|
||||||
const NULL_EMPTY_STRING = 1;
|
|
||||||
const NULL_NATURAL = 0;
|
|
||||||
const NULL_TO_STRING = NULL;
|
|
||||||
const PARAM_BOOL = 5;
|
|
||||||
const PARAM_INPUT_OUTPUT = -2147483648;
|
|
||||||
const PARAM_INT = 1;
|
|
||||||
const PARAM_LOB = 3;
|
|
||||||
const PARAM_NULL = 0;
|
|
||||||
const PARAM_STMT = 4;
|
|
||||||
const PARAM_STR = 2;
|
|
||||||
/**
|
|
||||||
* ATTRIBUTE CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PDO derived attributes
|
|
||||||
*/
|
|
||||||
const ATTR_AUTOCOMMIT = 0;
|
|
||||||
const ATTR_PREFETCH = 1;
|
|
||||||
const ATTR_TIMEOUT = 2;
|
|
||||||
const ATTR_ERRMODE = 3;
|
|
||||||
const ATTR_SERVER_VERSION = 4;
|
|
||||||
const ATTR_CLIENT_VERSION = 5;
|
|
||||||
const ATTR_SERVER_INFO = 6;
|
|
||||||
const ATTR_CONNECTION_STATUS = 7;
|
|
||||||
const ATTR_CASE = 8;
|
|
||||||
const ATTR_CURSOR_NAME = 9;
|
|
||||||
const ATTR_CURSOR = 10;
|
|
||||||
const ATTR_ORACLE_NULLS = 11;
|
|
||||||
const ATTR_PERSISTENT = 12;
|
|
||||||
const ATTR_STATEMENT_CLASS = 13;
|
|
||||||
const ATTR_FETCH_TABLE_NAMES = 14;
|
|
||||||
const ATTR_FETCH_CATALOG_NAMES = 15;
|
|
||||||
const ATTR_DRIVER_NAME = 16;
|
|
||||||
const ATTR_STRINGIFY_FETCHES = 17;
|
|
||||||
const ATTR_MAX_COLUMN_LEN = 18;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine constants
|
|
||||||
*/
|
|
||||||
const ATTR_LISTENER = 100;
|
|
||||||
const ATTR_QUOTE_IDENTIFIER = 101;
|
|
||||||
const ATTR_FIELD_CASE = 102;
|
|
||||||
const ATTR_IDXNAME_FORMAT = 103;
|
|
||||||
const ATTR_SEQNAME_FORMAT = 104;
|
|
||||||
const ATTR_SEQCOL_NAME = 105;
|
|
||||||
const ATTR_CMPNAME_FORMAT = 118;
|
|
||||||
const ATTR_DBNAME_FORMAT = 117;
|
|
||||||
const ATTR_TBLCLASS_FORMAT = 119;
|
|
||||||
const ATTR_EXPORT = 140;
|
|
||||||
const ATTR_DECIMAL_PLACES = 141;
|
|
||||||
|
|
||||||
const ATTR_PORTABILITY = 106;
|
|
||||||
const ATTR_VLD = 107;
|
|
||||||
const ATTR_COLL_KEY = 108;
|
|
||||||
const ATTR_QUERY_LIMIT = 109;
|
|
||||||
const ATTR_AUTO_LENGTH_VLD = 110;
|
|
||||||
const ATTR_AUTO_TYPE_VLD = 111;
|
|
||||||
const ATTR_DEFAULT_TABLE_TYPE = 112;
|
|
||||||
const ATTR_DEF_TEXT_LENGTH = 113;
|
|
||||||
const ATTR_DEF_VARCHAR_LENGTH = 114;
|
|
||||||
const ATTR_DEF_TABLESPACE = 115;
|
|
||||||
const ATTR_EMULATE_DATABASE = 116;
|
|
||||||
const ATTR_DEFAULT_SEQUENCE = 133;
|
|
||||||
|
|
||||||
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
|
|
||||||
|
|
||||||
|
|
||||||
const ATTR_FETCHMODE = 118;
|
|
||||||
const ATTR_BATCH_SIZE = 119;
|
|
||||||
const ATTR_LOCKMODE = 120;
|
|
||||||
const ATTR_NAME_PREFIX = 121;
|
|
||||||
const ATTR_CREATE_TABLES = 122;
|
|
||||||
const ATTR_COLL_LIMIT = 123;
|
|
||||||
const ATTR_ACCESSORS = 124;
|
|
||||||
const ATTR_ACCESSOR_PREFIX_GET = 125;
|
|
||||||
const ATTR_ACCESSOR_PREFIX_SET = 126;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NESTED SET CONSTANTS
|
|
||||||
*/
|
|
||||||
const ATTR_NS_ROOT_COLUMN_NAME = 130;
|
|
||||||
const ATTR_NS_GAP_SIZE = 131;
|
|
||||||
const ATTR_NS_GAP_DECREASE_EXP = 132;
|
|
||||||
|
|
||||||
const ATTR_CACHE = 150;
|
|
||||||
const ATTR_CACHE_LIFESPAN = 151;
|
|
||||||
const ATTR_LOAD_REFERENCES = 153;
|
|
||||||
const ATTR_RECORD_LISTENER = 154;
|
|
||||||
const ATTR_THROW_EXCEPTIONS = 155;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LIMIT CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constant for row limiting
|
|
||||||
*/
|
|
||||||
const LIMIT_ROWS = 1;
|
|
||||||
/**
|
|
||||||
* constant for record limiting
|
|
||||||
*/
|
|
||||||
const LIMIT_RECORDS = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FETCHMODE CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IMMEDIATE FETCHING
|
|
||||||
* mode for immediate fetching
|
|
||||||
*/
|
|
||||||
const FETCH_IMMEDIATE = 0;
|
|
||||||
/**
|
|
||||||
* BATCH FETCHING
|
|
||||||
* mode for batch fetching
|
|
||||||
*/
|
|
||||||
const FETCH_BATCH = 1;
|
|
||||||
/**
|
|
||||||
* LAZY FETCHING
|
|
||||||
* mode for offset fetching
|
|
||||||
*/
|
|
||||||
const FETCH_OFFSET = 3;
|
|
||||||
/**
|
|
||||||
* LAZY OFFSET FETCHING
|
|
||||||
* mode for lazy offset fetching
|
|
||||||
*/
|
|
||||||
const FETCH_LAZY_OFFSET = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FETCH CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FETCH VALUEHOLDER
|
|
||||||
*/
|
|
||||||
const FETCH_VHOLDER = 1;
|
|
||||||
/**
|
|
||||||
* FETCH RECORD
|
|
||||||
*
|
|
||||||
* Specifies that the fetch method shall return Doctrine_Record
|
|
||||||
* objects as the elements of the result set.
|
|
||||||
*
|
|
||||||
* This is the default fetchmode.
|
|
||||||
*/
|
|
||||||
const FETCH_RECORD = 2;
|
|
||||||
/**
|
|
||||||
* FETCH ARRAY
|
|
||||||
*/
|
|
||||||
|
|
||||||
const FETCH_ARRAY = 3;
|
|
||||||
/**
|
|
||||||
* PORTABILITY CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Portability: turn off all portability features.
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_NONE = 0;
|
|
||||||
/**
|
|
||||||
* Portability: convert names of tables and fields to case defined in the
|
|
||||||
* "field_case" option when using the query*(), fetch*() methods.
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_FIX_CASE = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Portability: right trim the data output by query*() and fetch*().
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_RTRIM = 2;
|
|
||||||
/**
|
|
||||||
* Portability: force reporting the number of rows deleted.
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_DELETE_COUNT = 4;
|
|
||||||
/**
|
|
||||||
* Portability: convert empty values to null strings in data output by
|
|
||||||
* query*() and fetch*().
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_EMPTY_TO_NULL = 8;
|
|
||||||
/**
|
|
||||||
* Portability: removes database/table qualifiers from associative indexes
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
|
|
||||||
/**
|
|
||||||
* Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_EXPR = 32;
|
|
||||||
/**
|
|
||||||
* Portability: turn on all portability features.
|
|
||||||
* @see Doctrine::ATTR_PORTABILITY
|
|
||||||
*/
|
|
||||||
const PORTABILITY_ALL = 33;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LOCKMODE CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mode for optimistic locking
|
|
||||||
*/
|
|
||||||
const LOCK_OPTIMISTIC = 0;
|
|
||||||
/**
|
|
||||||
* mode for pessimistic locking
|
|
||||||
*/
|
|
||||||
const LOCK_PESSIMISTIC = 1;
|
|
||||||
/**
|
|
||||||
* EXPORT CONSTANTS
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* turns of exporting
|
|
||||||
*/
|
|
||||||
const EXPORT_NONE = 0;
|
|
||||||
/**
|
|
||||||
* export tables
|
|
||||||
*/
|
|
||||||
const EXPORT_TABLES = 1;
|
|
||||||
/**
|
|
||||||
* export constraints
|
|
||||||
*/
|
|
||||||
const EXPORT_CONSTRAINTS = 2;
|
|
||||||
/**
|
|
||||||
* export all
|
|
||||||
*/
|
|
||||||
const EXPORT_ALL = 3;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constant for auto_increment identifier
|
|
||||||
*/
|
|
||||||
const IDENTIFIER_AUTOINC = 1;
|
|
||||||
/**
|
|
||||||
* constant for sequence identifier
|
|
||||||
*/
|
|
||||||
const IDENTIFIER_SEQUENCE = 2;
|
|
||||||
/**
|
|
||||||
* constant for normal identifier
|
|
||||||
*/
|
|
||||||
const IDENTIFIER_NATURAL = 3;
|
|
||||||
/**
|
|
||||||
* constant for composite identifier
|
|
||||||
*/
|
|
||||||
const IDENTIFIER_COMPOSITE = 4;
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @var string $path doctrine root directory
|
|
||||||
*/
|
|
||||||
private static $path;
|
|
||||||
/**
|
|
||||||
* @var boolean $_debug
|
|
||||||
*/
|
|
||||||
private static $_debug = false;
|
|
||||||
|
|
||||||
public static function debug($bool = null)
|
|
||||||
{
|
|
||||||
if ($bool !== null) {
|
|
||||||
self::$_debug = (bool) $bool;
|
|
||||||
}
|
|
||||||
return self::$_debug;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getPath
|
|
||||||
* returns the doctrine root
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getPath()
|
|
||||||
{
|
|
||||||
if ( ! self::$path) {
|
|
||||||
self::$path = dirname(__FILE__);
|
|
||||||
}
|
|
||||||
return self::$path;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* loadAll
|
|
||||||
* loads all runtime classes
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function loadAll()
|
|
||||||
{
|
|
||||||
$classes = Doctrine_Compiler::getRuntimeClasses();
|
|
||||||
|
|
||||||
foreach ($classes as $class) {
|
|
||||||
Doctrine::autoload($class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* importSchema
|
|
||||||
* method for importing existing schema to Doctrine_Record classes
|
|
||||||
*
|
|
||||||
* @param string $directory
|
|
||||||
* @param array $info
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function importSchema($directory, array $databases = array())
|
|
||||||
{
|
|
||||||
return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* exportSchema
|
|
||||||
* method for exporting Doctrine_Record classes to a schema
|
|
||||||
*
|
|
||||||
* @param string $directory
|
|
||||||
*/
|
|
||||||
public static function exportSchema($directory = null)
|
|
||||||
{
|
|
||||||
return Doctrine_Manager::connection()->export->exportSchema($directory);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* exportSql
|
|
||||||
* method for exporting Doctrine_Record classes to a schema
|
|
||||||
*
|
|
||||||
* @param string $directory
|
|
||||||
*/
|
|
||||||
public static function exportSql($directory = null)
|
|
||||||
{
|
|
||||||
return Doctrine_Manager::connection()->export->exportSql($directory);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* compile
|
|
||||||
* method for making a single file of most used doctrine runtime components
|
|
||||||
* including the compiled file instead of multiple files (in worst
|
|
||||||
* cases dozens of files) can improve performance by an order of magnitude
|
|
||||||
*
|
|
||||||
* @param string $target
|
|
||||||
*
|
|
||||||
* @throws Doctrine_Exception
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function compile($target = null)
|
|
||||||
{
|
|
||||||
Doctrine_Compiler::compile($target);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* simple autoload function
|
|
||||||
* returns true if the class was loaded, otherwise false
|
|
||||||
*
|
|
||||||
* @param string $classname
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function autoload($classname)
|
|
||||||
{
|
|
||||||
if (class_exists($classname, false)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (! self::$path) {
|
|
||||||
self::$path = dirname(__FILE__);
|
|
||||||
}
|
|
||||||
$class = self::$path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
|
|
||||||
|
|
||||||
if ( ! file_exists($class)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once($class);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* dump
|
|
||||||
*
|
|
||||||
* dumps a given variable
|
|
||||||
*
|
|
||||||
* @param mixed $var a variable of any type
|
|
||||||
* @param boolean $output whether to output the content
|
|
||||||
* @return void|string
|
|
||||||
*/
|
|
||||||
public static function dump($var, $output = true)
|
|
||||||
{
|
|
||||||
$ret = array();
|
|
||||||
switch (gettype($var)) {
|
|
||||||
case 'array':
|
|
||||||
$ret[] = 'Array(';
|
|
||||||
foreach ($var as $k => $v) {
|
|
||||||
$ret[] = $k . ' : ' . Doctrine::dump($v, false);
|
|
||||||
}
|
|
||||||
$ret[] = ")";
|
|
||||||
break;
|
|
||||||
case 'object':
|
|
||||||
$ret[] = 'Object(' . get_class($var) . ')';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$ret[] = var_export($var, true);
|
|
||||||
}
|
|
||||||
if ($output) {
|
|
||||||
print implode("\n", $ret);
|
|
||||||
}
|
|
||||||
return implode("\n", $ret);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns table name from class name
|
|
||||||
*
|
|
||||||
* @param string $classname
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function tableize($classname)
|
|
||||||
{
|
|
||||||
return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns class name from table name
|
|
||||||
*
|
|
||||||
* @param string $tablename
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function classify($tablename)
|
|
||||||
{
|
|
||||||
return preg_replace('~(_?)(_)([\w])~e', '"$1".strtoupper("$3")', ucfirst($tablename));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* checks for valid class name (uses camel case and underscores)
|
|
||||||
*
|
|
||||||
* @param string $classname
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function isValidClassname($classname)
|
|
||||||
{
|
|
||||||
if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,141 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Access.php 1604 2007-06-08 19:07:32Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Access
|
|
||||||
*
|
|
||||||
* the purpose of Doctrine_Access is to provice array access
|
|
||||||
* and property overload interface for subclasses
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1604 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
abstract class Doctrine_Access extends Doctrine_Object implements ArrayAccess
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* setArray
|
|
||||||
*
|
|
||||||
* @param array $array an array of key => value pairs
|
|
||||||
* @since 1.0
|
|
||||||
* @return Doctrine_Access
|
|
||||||
*/
|
|
||||||
public function setArray(array $array)
|
|
||||||
{
|
|
||||||
foreach ($array as $k=>$v) {
|
|
||||||
$this->set($k,$v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __set an alias of set()
|
|
||||||
*
|
|
||||||
* @see set, offsetSet
|
|
||||||
* @param $name
|
|
||||||
* @param $value
|
|
||||||
* @since 1.0
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __set($name,$value)
|
|
||||||
{
|
|
||||||
$this->set($name,$value);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __get -- an alias of get()
|
|
||||||
*
|
|
||||||
* @see get, offsetGet
|
|
||||||
* @param mixed $name
|
|
||||||
* @since 1.0
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function __get($name)
|
|
||||||
{
|
|
||||||
return $this->get($name);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __isset()
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @since 1.0
|
|
||||||
* @return boolean whether or not this object contains $name
|
|
||||||
*/
|
|
||||||
public function __isset($name)
|
|
||||||
{
|
|
||||||
return $this->contains($name);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __unset()
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @since 1.0
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __unset($name)
|
|
||||||
{
|
|
||||||
return $this->remove($name);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param mixed $offset
|
|
||||||
* @return boolean whether or not this object contains $offset
|
|
||||||
*/
|
|
||||||
public function offsetExists($offset)
|
|
||||||
{
|
|
||||||
return $this->contains($offset);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* offsetGet an alias of get()
|
|
||||||
* @see get, __get
|
|
||||||
* @param mixed $offset
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function offsetGet($offset)
|
|
||||||
{
|
|
||||||
return $this->get($offset);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* sets $offset to $value
|
|
||||||
* @see set, __set
|
|
||||||
* @param mixed $offset
|
|
||||||
* @param mixed $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function offsetSet($offset, $value)
|
|
||||||
{
|
|
||||||
if ( ! isset($offset)) {
|
|
||||||
$this->add($value);
|
|
||||||
} else {
|
|
||||||
$this->set($offset, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* unset a given offset
|
|
||||||
* @see set, offsetSet, __set
|
|
||||||
* @param mixed $offset
|
|
||||||
*/
|
|
||||||
public function offsetUnset($offset)
|
|
||||||
{
|
|
||||||
return $this->remove($offset);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Adapter.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Doctrine_Adapter
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter
|
|
||||||
{
|
|
||||||
const ATTR_AUTOCOMMIT = 0;
|
|
||||||
const ATTR_CASE = 8;
|
|
||||||
const ATTR_CLIENT_VERSION = 5;
|
|
||||||
const ATTR_CONNECTION_STATUS = 7;
|
|
||||||
const ATTR_CURSOR = 10;
|
|
||||||
const ATTR_CURSOR_NAME = 9;
|
|
||||||
const ATTR_DRIVER_NAME = 16;
|
|
||||||
const ATTR_ERRMODE = 3;
|
|
||||||
const ATTR_FETCH_CATALOG_NAMES = 15;
|
|
||||||
const ATTR_FETCH_TABLE_NAMES = 14;
|
|
||||||
const ATTR_MAX_COLUMN_LEN = 18;
|
|
||||||
const ATTR_ORACLE_NULLS = 11;
|
|
||||||
const ATTR_PERSISTENT = 12;
|
|
||||||
const ATTR_PREFETCH = 1;
|
|
||||||
const ATTR_SERVER_INFO = 6;
|
|
||||||
const ATTR_SERVER_VERSION = 4;
|
|
||||||
const ATTR_STATEMENT_CLASS = 13;
|
|
||||||
const ATTR_STRINGIFY_FETCHES = 17;
|
|
||||||
const ATTR_TIMEOUT = 2;
|
|
||||||
const CASE_LOWER = 2;
|
|
||||||
const CASE_NATURAL = 0;
|
|
||||||
const CASE_UPPER = 1;
|
|
||||||
const CURSOR_FWDONLY = 0;
|
|
||||||
const CURSOR_SCROLL = 1;
|
|
||||||
const ERR_ALREADY_EXISTS = NULL;
|
|
||||||
const ERR_CANT_MAP = NULL;
|
|
||||||
const ERR_CONSTRAINT = NULL;
|
|
||||||
const ERR_DISCONNECTED = NULL;
|
|
||||||
const ERR_MISMATCH = NULL;
|
|
||||||
const ERR_NO_PERM = NULL;
|
|
||||||
const ERR_NONE = '00000';
|
|
||||||
const ERR_NOT_FOUND = NULL;
|
|
||||||
const ERR_NOT_IMPLEMENTED = NULL;
|
|
||||||
const ERR_SYNTAX = NULL;
|
|
||||||
const ERR_TRUNCATED = NULL;
|
|
||||||
const ERRMODE_EXCEPTION = 2;
|
|
||||||
const ERRMODE_SILENT = 0;
|
|
||||||
const ERRMODE_WARNING = 1;
|
|
||||||
const FETCH_ASSOC = 2;
|
|
||||||
const FETCH_BOTH = 4;
|
|
||||||
const FETCH_BOUND = 6;
|
|
||||||
const FETCH_CLASS = 8;
|
|
||||||
const FETCH_CLASSTYPE = 262144;
|
|
||||||
const FETCH_COLUMN = 7;
|
|
||||||
const FETCH_FUNC = 10;
|
|
||||||
const FETCH_GROUP = 65536;
|
|
||||||
const FETCH_INTO = 9;
|
|
||||||
const FETCH_LAZY = 1;
|
|
||||||
const FETCH_NAMED = 11;
|
|
||||||
const FETCH_NUM = 3;
|
|
||||||
const FETCH_OBJ = 5;
|
|
||||||
const FETCH_ORI_ABS = 4;
|
|
||||||
const FETCH_ORI_FIRST = 2;
|
|
||||||
const FETCH_ORI_LAST = 3;
|
|
||||||
const FETCH_ORI_NEXT = 0;
|
|
||||||
const FETCH_ORI_PRIOR = 1;
|
|
||||||
const FETCH_ORI_REL = 5;
|
|
||||||
const FETCH_SERIALIZE = 524288;
|
|
||||||
const FETCH_UNIQUE = 196608;
|
|
||||||
const NULL_EMPTY_STRING = 1;
|
|
||||||
const NULL_NATURAL = 0;
|
|
||||||
const NULL_TO_STRING = NULL;
|
|
||||||
const PARAM_BOOL = 5;
|
|
||||||
const PARAM_INPUT_OUTPUT = -2147483648;
|
|
||||||
const PARAM_INT = 1;
|
|
||||||
const PARAM_LOB = 3;
|
|
||||||
const PARAM_NULL = 0;
|
|
||||||
const PARAM_STMT = 4;
|
|
||||||
const PARAM_STR = 2;
|
|
||||||
}
|
|
@ -1,333 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Adapter');
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Db2
|
|
||||||
* IBM DB2 Adapter [BORROWED FROM ZEND FRAMEWORK]
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Adapter
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Db2 extends Doctrine_Adapter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* User-provided configuration.
|
|
||||||
*
|
|
||||||
* Basic keys are:
|
|
||||||
*
|
|
||||||
* username => (string) Connect to the database as this username.
|
|
||||||
* password => (string) Password associated with the username.
|
|
||||||
* host => (string) What host to connect to (default 127.0.0.1)
|
|
||||||
* dbname => (string) The name of the database to user
|
|
||||||
* protocol => (string) Protocol to use, defaults to "TCPIP"
|
|
||||||
* port => (integer) Port number to use for TCP/IP if protocol is "TCPIP"
|
|
||||||
* persistent => (boolean) Set TRUE to use a persistent connection (db2_pconnect)
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $_config = array(
|
|
||||||
'dbname' => null,
|
|
||||||
'username' => null,
|
|
||||||
'password' => null,
|
|
||||||
'host' => 'localhost',
|
|
||||||
'port' => '50000',
|
|
||||||
'protocol' => 'TCPIP',
|
|
||||||
'persistent' => false
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execution mode
|
|
||||||
*
|
|
||||||
* @var int execution flag (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected $_execute_mode = DB2_AUTOCOMMIT_ON;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table name of the last accessed table for an insert operation
|
|
||||||
* This is a DB2-Adapter-specific member variable with the utmost
|
|
||||||
* probability you might not find it in other adapters...
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected $_lastInsertTable = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* $config is an array of key/value pairs containing configuration
|
|
||||||
* options. These options are common to most adapters:
|
|
||||||
*
|
|
||||||
* dbname => (string) The name of the database to user
|
|
||||||
* username => (string) Connect to the database as this username.
|
|
||||||
* password => (string) Password associated with the username.
|
|
||||||
* host => (string) What host to connect to, defaults to localhost
|
|
||||||
* port => (string) The port of the database, defaults to 50000
|
|
||||||
* persistent => (boolean) Whether to use a persistent connection or not, defaults to false
|
|
||||||
* protocol => (string) The network protocol, defaults to TCPIP
|
|
||||||
* options => (array) Other database options such as autocommit, case, and cursor options
|
|
||||||
*
|
|
||||||
* @param array $config An array of configuration keys.
|
|
||||||
*/
|
|
||||||
public function __construct(array $config)
|
|
||||||
{
|
|
||||||
if ( ! isset($config['password'])) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception("Configuration array must have a key for 'password' for login credentials.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! isset($config['username'])) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception("Configuration array must have a key for 'username' for login credentials.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! isset($config['dbname'])) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception("Configuration array must have a key for 'dbname' that names the database instance.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep the config
|
|
||||||
$this->_config = array_merge($this->_config, (array) $config);
|
|
||||||
|
|
||||||
// create a profiler object
|
|
||||||
$enabled = false;
|
|
||||||
if (array_key_exists('profiler', $this->_config)) {
|
|
||||||
$enabled = (bool) $this->_config['profiler'];
|
|
||||||
unset($this->_config['profiler']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_profiler = new Doctrine_Profiler($enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a connection resource.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _connect()
|
|
||||||
{
|
|
||||||
if (is_resource($this->_connection)) {
|
|
||||||
// connection already exists
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! extension_loaded('ibm_db2')) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception('The IBM DB2 extension is required for this adapter but not loaded');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_config['persistent']) {
|
|
||||||
// use persistent connection
|
|
||||||
$conn_func_name = 'db2_pconnect';
|
|
||||||
} else {
|
|
||||||
// use "normal" connection
|
|
||||||
$conn_func_name = 'db2_connect';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->_config['options'])) {
|
|
||||||
// config options were not set, so set it to an empty array
|
|
||||||
$this->_config['options'] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->_config['options']['autocommit'])) {
|
|
||||||
// set execution mode
|
|
||||||
$this->_config['options']['autocommit'] = &$this->_execute_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_config['host'] !== 'localhost') {
|
|
||||||
// if the host isn't localhost, use extended connection params
|
|
||||||
$dbname = 'DRIVER={IBM DB2 ODBC DRIVER}' .
|
|
||||||
';DATABASE=' . $this->_config['dbname'] .
|
|
||||||
';HOSTNAME=' . $this->_config['host'] .
|
|
||||||
';PORT=' . $this->_config['port'] .
|
|
||||||
';PROTOCOL=' . $this->_config['protocol'] .
|
|
||||||
';UID=' . $this->_config['username'] .
|
|
||||||
';PWD=' . $this->_config['password'] .';';
|
|
||||||
$this->_connection = $conn_func_name(
|
|
||||||
$dbname,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
$this->_config['options']
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// host is localhost, so use standard connection params
|
|
||||||
$this->_connection = $conn_func_name(
|
|
||||||
$this->_config['dbname'],
|
|
||||||
$this->_config['username'],
|
|
||||||
$this->_config['password'],
|
|
||||||
$this->_config['options']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the connection
|
|
||||||
if (!$this->_connection) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception(db2_conn_errormsg(), db2_conn_error());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force the connection to close.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function closeConnection()
|
|
||||||
{
|
|
||||||
db2_close($this->_connection);
|
|
||||||
$this->_connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an SQL statement for preparation.
|
|
||||||
*
|
|
||||||
* @param string $sql The SQL statement with placeholders.
|
|
||||||
* @return Doctrine_Statement_Db2
|
|
||||||
*/
|
|
||||||
public function prepare($sql)
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$stmt = new Doctrine_Statement_Db2($this, $sql);
|
|
||||||
$stmt->setFetchMode($this->_fetchMode);
|
|
||||||
return $stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the execution mode
|
|
||||||
*
|
|
||||||
* @return int the execution mode (DB2_AUTOCOMMIT_ON or DB2_AUTOCOMMIT_OFF)
|
|
||||||
*/
|
|
||||||
public function _getExecuteMode()
|
|
||||||
{
|
|
||||||
return $this->_execute_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param integer $mode
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function _setExecuteMode($mode)
|
|
||||||
{
|
|
||||||
switch ($mode) {
|
|
||||||
case DB2_AUTOCOMMIT_OFF:
|
|
||||||
case DB2_AUTOCOMMIT_ON:
|
|
||||||
$this->_execute_mode = $mode;
|
|
||||||
db2_autocommit($this->_connection, $mode);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception("execution mode not supported");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quote a raw string.
|
|
||||||
*
|
|
||||||
* @param string $value Raw string
|
|
||||||
* @return string Quoted string
|
|
||||||
*/
|
|
||||||
protected function _quote($value)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Some releases of the IBM DB2 extension appear
|
|
||||||
* to be missing the db2_escape_string() method.
|
|
||||||
* The method was added in ibm_db2.c revision 1.53
|
|
||||||
* according to cvs.php.net. But the function is
|
|
||||||
* not present in my build of PHP 5.2.1.
|
|
||||||
*/
|
|
||||||
if (function_exists('db2_escape_string')) {
|
|
||||||
return db2_escape_string($value);
|
|
||||||
}
|
|
||||||
return parent::_quote($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getQuoteIdentifierSymbol()
|
|
||||||
{
|
|
||||||
$info = db2_server_info($this->_connection);
|
|
||||||
$identQuote = $info->IDENTIFIER_QUOTE_CHAR;
|
|
||||||
return $identQuote;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Begin a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _beginTransaction()
|
|
||||||
{
|
|
||||||
$this->_setExecuteMode(DB2_AUTOCOMMIT_OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _commit()
|
|
||||||
{
|
|
||||||
if (!db2_commit($this->_connection)) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception(
|
|
||||||
db2_conn_errormsg($this->_connection),
|
|
||||||
db2_conn_error($this->_connection));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rollback a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _rollBack()
|
|
||||||
{
|
|
||||||
if (!db2_rollback($this->_connection)) {
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception(
|
|
||||||
db2_conn_errormsg($this->_connection),
|
|
||||||
db2_conn_error($this->_connection));
|
|
||||||
}
|
|
||||||
$this->_setExecuteMode(DB2_AUTOCOMMIT_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the fetch mode.
|
|
||||||
*
|
|
||||||
* @param integer $mode
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setFetchMode($mode)
|
|
||||||
{
|
|
||||||
switch ($mode) {
|
|
||||||
case Doctrine::FETCH_NUM: // seq array
|
|
||||||
case Doctrine::FETCH_ASSOC: // assoc array
|
|
||||||
case Doctrine::FETCH_BOTH: // seq+assoc array
|
|
||||||
case Doctrine::FETCH_OBJ: // object
|
|
||||||
$this->_fetchMode = $mode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Adapter_Db2_Exception('Invalid fetch mode specified');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?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
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Adapter_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Db2_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Db2_Exception extends Doctrine_Adapter_Exception
|
|
||||||
{ }
|
|
@ -1,34 +0,0 @@
|
|||||||
<?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
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Exception extends Doctrine_Exception
|
|
||||||
{ }
|
|
@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Interface.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Interface
|
|
||||||
* This adapter interface should be implemented by all custom adapters
|
|
||||||
*
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
interface Doctrine_Adapter_Interface {
|
|
||||||
public function prepare($prepareString);
|
|
||||||
public function query($queryString);
|
|
||||||
public function quote($input);
|
|
||||||
public function exec($statement);
|
|
||||||
public function lastInsertId();
|
|
||||||
public function beginTransaction();
|
|
||||||
public function commit();
|
|
||||||
public function rollBack();
|
|
||||||
public function errorCode();
|
|
||||||
public function errorInfo();
|
|
||||||
}
|
|
@ -1,162 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1819 2007-06-25 17:48:44Z subzero2000 $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Mock
|
|
||||||
* This class is used for special testing purposes.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Adapter
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1819 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Mock implements Doctrine_Adapter_Interface, Countable
|
|
||||||
{
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
private $queries = array();
|
|
||||||
|
|
||||||
private $exception = array();
|
|
||||||
|
|
||||||
private $lastInsertIdFail = false;
|
|
||||||
|
|
||||||
public function __construct($name = null)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
public function pop()
|
|
||||||
{
|
|
||||||
return array_pop($this->queries);
|
|
||||||
}
|
|
||||||
public function forceException($name, $message = '', $code = 0)
|
|
||||||
{
|
|
||||||
$this->exception = array($name, $message, $code);
|
|
||||||
}
|
|
||||||
public function prepare($query)
|
|
||||||
{
|
|
||||||
$mock = new Doctrine_Adapter_Statement_Mock($this, $query);
|
|
||||||
$mock->queryString = $query;
|
|
||||||
|
|
||||||
return $mock;
|
|
||||||
}
|
|
||||||
public function addQuery($query)
|
|
||||||
{
|
|
||||||
$this->queries[] = $query;
|
|
||||||
}
|
|
||||||
public function query($query)
|
|
||||||
{
|
|
||||||
$this->queries[] = $query;
|
|
||||||
|
|
||||||
$e = $this->exception;
|
|
||||||
|
|
||||||
if( ! empty($e)) {
|
|
||||||
$name = $e[0];
|
|
||||||
|
|
||||||
$this->exception = array();
|
|
||||||
|
|
||||||
throw new $name($e[1], $e[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt = new Doctrine_Adapter_Statement_Mock($this, $query);
|
|
||||||
$stmt->queryString = $query;
|
|
||||||
|
|
||||||
return $stmt;
|
|
||||||
}
|
|
||||||
public function getAll()
|
|
||||||
{
|
|
||||||
return $this->queries;
|
|
||||||
}
|
|
||||||
public function quote($input)
|
|
||||||
{
|
|
||||||
return "'" . addslashes($input) . "'";
|
|
||||||
}
|
|
||||||
public function exec($statement)
|
|
||||||
{
|
|
||||||
$this->queries[] = $statement;
|
|
||||||
|
|
||||||
$e = $this->exception;
|
|
||||||
|
|
||||||
if( ! empty($e)) {
|
|
||||||
$name = $e[0];
|
|
||||||
|
|
||||||
$this->exception = array();
|
|
||||||
|
|
||||||
throw new $name($e[1], $e[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
public function forceLastInsertIdFail($fail = true)
|
|
||||||
{
|
|
||||||
if ($fail) {
|
|
||||||
$this->lastInsertIdFail = true;
|
|
||||||
} else {
|
|
||||||
$this->lastInsertIdFail = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function lastInsertId()
|
|
||||||
{
|
|
||||||
$this->queries[] = 'LAST_INSERT_ID()';
|
|
||||||
if ($this->lastInsertIdFail) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->queries);
|
|
||||||
}
|
|
||||||
public function beginTransaction()
|
|
||||||
{
|
|
||||||
$this->queries[] = 'BEGIN TRANSACTION';
|
|
||||||
}
|
|
||||||
public function commit()
|
|
||||||
{
|
|
||||||
$this->queries[] = 'COMMIT';
|
|
||||||
}
|
|
||||||
public function rollBack()
|
|
||||||
{
|
|
||||||
$this->queries[] = 'ROLLBACK';
|
|
||||||
}
|
|
||||||
public function errorCode()
|
|
||||||
{ }
|
|
||||||
public function errorInfo()
|
|
||||||
{ }
|
|
||||||
public function getAttribute($attribute)
|
|
||||||
{
|
|
||||||
if($attribute == Doctrine::ATTR_DRIVER_NAME)
|
|
||||||
return strtolower($this->name);
|
|
||||||
}
|
|
||||||
public function setAttribute($attribute, $value)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public function sqliteCreateFunction()
|
|
||||||
{ }
|
|
||||||
}
|
|
@ -1,141 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Mysqli
|
|
||||||
* This class is used for special testing purposes.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Adapter
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Mysqli extends Doctrine_Adapter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Creates a connection to the database.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Adapter_Mysqli_Exception
|
|
||||||
*/
|
|
||||||
protected function _connect()
|
|
||||||
{
|
|
||||||
if ($this->_connection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Suppress connection warnings here.
|
|
||||||
// Throw an exception instead.
|
|
||||||
@$this->_connection = new mysqli(
|
|
||||||
$this->_config['host'],
|
|
||||||
$this->_config['username'],
|
|
||||||
$this->_config['password'],
|
|
||||||
$this->_config['dbname']
|
|
||||||
);
|
|
||||||
if ($this->_connection === false || mysqli_connect_errno()) {
|
|
||||||
throw new Doctrine_Adapter_Mysqli_Exception(mysqli_connect_error());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force the connection to close.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function closeConnection()
|
|
||||||
{
|
|
||||||
$this->_connection->close();
|
|
||||||
$this->_connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepare a statement and return a PDOStatement-like object.
|
|
||||||
*
|
|
||||||
* @param string $sql SQL query
|
|
||||||
* @return Doctrine_Statement_Mysqli
|
|
||||||
*/
|
|
||||||
public function prepare($sql)
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$stmt = new Doctrine_Statement_Mysqli($this, $sql);
|
|
||||||
$stmt->setFetchMode($this->_fetchMode);
|
|
||||||
return $stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
|
|
||||||
*
|
|
||||||
* As a convention, on RDBMS brands that support sequences
|
|
||||||
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
|
|
||||||
* from the arguments and returns the last id generated by that sequence.
|
|
||||||
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
|
|
||||||
* returns the last value generated for such a column, and the table name
|
|
||||||
* argument is disregarded.
|
|
||||||
*
|
|
||||||
* MySQL does not support sequences, so $tableName and $primaryKey are ignored.
|
|
||||||
*
|
|
||||||
* @param string $tableName OPTIONAL Name of table.
|
|
||||||
* @param string $primaryKey OPTIONAL Name of primary key column.
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function lastInsertId($tableName = null, $primaryKey = null)
|
|
||||||
{
|
|
||||||
$mysqli = $this->_connection;
|
|
||||||
return $mysqli->insert_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Begin a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _beginTransaction()
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$this->_connection->autocommit(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commit a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _commit()
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$this->_connection->commit();
|
|
||||||
$this->_connection->autocommit(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Roll-back a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _rollBack()
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$this->_connection->rollback();
|
|
||||||
$this->_connection->autocommit(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,268 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Adapter');
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Oracle
|
|
||||||
* [BORROWED FROM ZEND FRAMEWORK]
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Adapter
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Oracle extends Doctrine_Adapter
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* User-provided configuration.
|
|
||||||
*
|
|
||||||
* Basic keys are:
|
|
||||||
*
|
|
||||||
* username => (string) Connect to the database as this username.
|
|
||||||
* password => (string) Password associated with the username.
|
|
||||||
* dbname => Either the name of the local Oracle instance, or the
|
|
||||||
* name of the entry in tnsnames.ora to which you want to connect.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $_config = array(
|
|
||||||
'dbname' => null,
|
|
||||||
'username' => null,
|
|
||||||
'password' => null,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
protected $_execute_mode = OCI_COMMIT_ON_SUCCESS;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* $config is an array of key/value pairs containing configuration
|
|
||||||
* options. These options are common to most adapters:
|
|
||||||
*
|
|
||||||
* username => (string) Connect to the database as this username.
|
|
||||||
* password => (string) Password associated with the username.
|
|
||||||
* dbname => Either the name of the local Oracle instance, or the
|
|
||||||
* name of the entry in tnsnames.ora to which you want to connect.
|
|
||||||
*
|
|
||||||
* @param array $config An array of configuration keys.
|
|
||||||
* @throws Doctrine_Adapter_Exception
|
|
||||||
*/
|
|
||||||
public function __construct(array $config)
|
|
||||||
{
|
|
||||||
if ( ! isset($config['password']) || ! isset($config['username'])) {
|
|
||||||
throw new Doctrine_Adapter_Exception('config array must have at least a username and a password');
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo Let this protect backward-compatibility for one release, then remove
|
|
||||||
if ( ! isset($config['database']) || ! isset($config['dbname'])) {
|
|
||||||
$config['dbname'] = $config['database'];
|
|
||||||
unset($config['database']);
|
|
||||||
trigger_error("Deprecated config key 'database', use 'dbname' instead.", E_USER_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep the config
|
|
||||||
$this->_config = array_merge($this->_config, (array) $config);
|
|
||||||
|
|
||||||
// create a profiler object
|
|
||||||
$enabled = false;
|
|
||||||
if (array_key_exists('profiler', $this->_config)) {
|
|
||||||
$enabled = (bool) $this->_config['profiler'];
|
|
||||||
unset($this->_config['profiler']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_profiler = new Doctrine_Profiler($enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a connection resource.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Adapter_Oracle_Exception
|
|
||||||
*/
|
|
||||||
protected function _connect()
|
|
||||||
{
|
|
||||||
if (is_resource($this->_connection)) {
|
|
||||||
// connection already exists
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!extension_loaded('oci8')) {
|
|
||||||
throw new Doctrine_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but not loaded');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->_config['dbname'])) {
|
|
||||||
$this->_connection = @oci_connect(
|
|
||||||
$this->_config['username'],
|
|
||||||
$this->_config['password'],
|
|
||||||
$this->_config['dbname']);
|
|
||||||
} else {
|
|
||||||
$this->_connection = oci_connect(
|
|
||||||
$this->_config['username'],
|
|
||||||
$this->_config['password']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the connection
|
|
||||||
if (!$this->_connection) {
|
|
||||||
throw new Doctrine_Adapter_Oracle_Exception(oci_error());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force the connection to close.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function closeConnection()
|
|
||||||
{
|
|
||||||
if (is_resource($this->_connection)) {
|
|
||||||
oci_close($this->_connection);
|
|
||||||
}
|
|
||||||
$this->_connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an SQL statement for preparation.
|
|
||||||
*
|
|
||||||
* @param string $sql The SQL statement with placeholders.
|
|
||||||
* @return Doctrine_Statement_Oracle
|
|
||||||
*/
|
|
||||||
public function prepare($sql)
|
|
||||||
{
|
|
||||||
$this->_connect();
|
|
||||||
$stmt = new Doctrine_Statement_Oracle($this, $sql);
|
|
||||||
$stmt->setFetchMode($this->_fetchMode);
|
|
||||||
return $stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quote a raw string.
|
|
||||||
*
|
|
||||||
* @param string $value Raw string
|
|
||||||
* @return string Quoted string
|
|
||||||
*/
|
|
||||||
protected function _quote($value)
|
|
||||||
{
|
|
||||||
$value = str_replace("'", "''", $value);
|
|
||||||
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quote a table identifier and alias.
|
|
||||||
*
|
|
||||||
* @param string|array|Doctrine_Expr $ident The identifier or expression.
|
|
||||||
* @param string $alias An alias for the table.
|
|
||||||
* @return string The quoted identifier and alias.
|
|
||||||
*/
|
|
||||||
public function quoteTableAs($ident, $alias)
|
|
||||||
{
|
|
||||||
// Oracle doesn't allow the 'AS' keyword between the table identifier/expression and alias.
|
|
||||||
return $this->_quoteIdentifierAs($ident, $alias, ' ');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Leave autocommit mode and begin a transaction.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function _beginTransaction()
|
|
||||||
{
|
|
||||||
$this->_setExecuteMode(OCI_DEFAULT);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Commit a transaction and return to autocommit mode.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Adapter_Oracle_Exception
|
|
||||||
*/
|
|
||||||
protected function _commit()
|
|
||||||
{
|
|
||||||
if (!oci_commit($this->_connection)) {
|
|
||||||
throw new Doctrine_Adapter_Oracle_Exception(oci_error($this->_connection));
|
|
||||||
}
|
|
||||||
$this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Roll back a transaction and return to autocommit mode.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Adapter_Oracle_Exception
|
|
||||||
*/
|
|
||||||
protected function _rollBack()
|
|
||||||
{
|
|
||||||
if (!oci_rollback($this->_connection)) {
|
|
||||||
throw new Doctrine_Adapter_Oracle_Exception(oci_error($this->_connection));
|
|
||||||
}
|
|
||||||
$this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the fetch mode.
|
|
||||||
*
|
|
||||||
* @todo Support FETCH_CLASS and FETCH_INTO.
|
|
||||||
*
|
|
||||||
* @param integer $mode A fetch mode.
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Adapter_Exception
|
|
||||||
*/
|
|
||||||
public function setFetchMode($mode)
|
|
||||||
{
|
|
||||||
switch ($mode) {
|
|
||||||
case Doctrine::FETCH_NUM: // seq array
|
|
||||||
case Doctrine::FETCH_ASSOC: // assoc array
|
|
||||||
case Doctrine::FETCH_BOTH: // seq+assoc array
|
|
||||||
case Doctrine::FETCH_OBJ: // object
|
|
||||||
$this->_fetchMode = $mode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Adapter_Exception('Invalid fetch mode specified');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param integer $mode
|
|
||||||
* @throws Doctrine_Adapter_Exception
|
|
||||||
*/
|
|
||||||
private function _setExecuteMode($mode)
|
|
||||||
{
|
|
||||||
switch($mode) {
|
|
||||||
case OCI_COMMIT_ON_SUCCESS:
|
|
||||||
case OCI_DEFAULT:
|
|
||||||
case OCI_DESCRIBE_ONLY:
|
|
||||||
$this->_execute_mode = $mode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Adapter_Exception('wrong execution mode specified');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public function _getExecuteMode()
|
|
||||||
{
|
|
||||||
return $this->_execute_mode;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Statement.php 1917 2007-07-01 11:27:45Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Statement
|
|
||||||
*
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1917 $
|
|
||||||
*/
|
|
||||||
abstract class Doctrine_Adapter_Statement
|
|
||||||
{
|
|
||||||
public function bindValue($no, $value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* fetch
|
|
||||||
*
|
|
||||||
* @see Doctrine::FETCH_* constants
|
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
|
||||||
*
|
|
||||||
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
|
||||||
* this value determines which row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
|
|
||||||
* Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
|
||||||
* Doctrine_Adapter_Statement_Interface object,
|
|
||||||
* you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
|
||||||
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
|
||||||
*
|
|
||||||
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
|
||||||
* $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
|
|
||||||
* the absolute number of the row in the result set that shall be fetched.
|
|
||||||
*
|
|
||||||
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
|
||||||
* which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
|
|
||||||
* specifies the row to fetch relative to the cursor position before
|
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function fetch()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function nextRowset()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function execute()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function errorCode()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function errorInfo()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function rowCount()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function setFetchMode($mode)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public function columnCount()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,275 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Interface.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Statement
|
|
||||||
*
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
interface Doctrine_Adapter_Statement_Interface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* bindColumn
|
|
||||||
* Bind a column to a PHP variable
|
|
||||||
*
|
|
||||||
* @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
|
|
||||||
* If using the column name, be aware that the name should match
|
|
||||||
* the case of the column, as returned by the driver.
|
|
||||||
* @param string $param Name of the PHP variable to which the column will be bound.
|
|
||||||
* @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure
|
|
||||||
*/
|
|
||||||
public function bindColumn($column, $param, $type = null);
|
|
||||||
/**
|
|
||||||
* bindValue
|
|
||||||
* Binds a value to a corresponding named or question mark
|
|
||||||
* placeholder in the SQL statement that was use to prepare the statement.
|
|
||||||
*
|
|
||||||
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
||||||
* this will be a parameter name of the form :name. For a prepared statement
|
|
||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
||||||
*
|
|
||||||
* @param mixed $value The value to bind to the parameter.
|
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function bindValue($param, $value, $type = null);
|
|
||||||
/**
|
|
||||||
* bindParam
|
|
||||||
* Binds a PHP variable to a corresponding named or question mark placeholder in the
|
|
||||||
* SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
|
|
||||||
* the variable is bound as a reference and will only be evaluated at the time
|
|
||||||
* that Doctrine_Adapter_Statement_Interface->execute() is called.
|
|
||||||
*
|
|
||||||
* Most parameters are input parameters, that is, parameters that are
|
|
||||||
* used in a read-only fashion to build up the query. Some drivers support the invocation
|
|
||||||
* of stored procedures that return data as output parameters, and some also as input/output
|
|
||||||
* parameters that both send in data and are updated to receive it.
|
|
||||||
*
|
|
||||||
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
||||||
* this will be a parameter name of the form :name. For a prepared statement
|
|
||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
||||||
*
|
|
||||||
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
|
||||||
*
|
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return
|
|
||||||
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
|
||||||
* Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
|
||||||
*
|
|
||||||
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
|
||||||
* from a stored procedure, you must explicitly set the length.
|
|
||||||
* @param mixed $driverOptions
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function bindParam($column, $variable, $type = null, $length = null, $driverOptions = array());
|
|
||||||
/**
|
|
||||||
* closeCursor
|
|
||||||
* Closes the cursor, enabling the statement to be executed again.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function closeCursor();
|
|
||||||
/**
|
|
||||||
* columnCount
|
|
||||||
* Returns the number of columns in the result set
|
|
||||||
*
|
|
||||||
* @return integer Returns the number of columns in the result set represented
|
|
||||||
* by the Doctrine_Adapter_Statement_Interface object. If there is no result set,
|
|
||||||
* this method should return 0.
|
|
||||||
*/
|
|
||||||
public function columnCount();
|
|
||||||
/**
|
|
||||||
* errorCode
|
|
||||||
* Fetch the SQLSTATE associated with the last operation on the statement handle
|
|
||||||
*
|
|
||||||
* @see Doctrine_Adapter_Interface::errorCode()
|
|
||||||
* @return string error code string
|
|
||||||
*/
|
|
||||||
public function errorCode();
|
|
||||||
/**
|
|
||||||
* errorInfo
|
|
||||||
* Fetch extended error information associated with the last operation on the statement handle
|
|
||||||
*
|
|
||||||
* @see Doctrine_Adapter_Interface::errorInfo()
|
|
||||||
* @return array error info array
|
|
||||||
*/
|
|
||||||
public function errorInfo();
|
|
||||||
/**
|
|
||||||
* execute
|
|
||||||
* Executes a prepared statement
|
|
||||||
*
|
|
||||||
* If the prepared statement included parameter markers, you must either:
|
|
||||||
* call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
|
|
||||||
* bound variables pass their value as input and receive the output value,
|
|
||||||
* if any, of their associated parameter markers or pass an array of input-only
|
|
||||||
* parameter values
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param array $params An array of values with as many elements as there are
|
|
||||||
* bound parameters in the SQL statement being executed.
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function execute($params = null);
|
|
||||||
/**
|
|
||||||
* fetch
|
|
||||||
*
|
|
||||||
* @see Doctrine::FETCH_* constants
|
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
|
||||||
*
|
|
||||||
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
|
||||||
* this value determines which row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
|
|
||||||
* Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
|
||||||
* Doctrine_Adapter_Statement_Interface object,
|
|
||||||
* you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
|
||||||
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
|
||||||
*
|
|
||||||
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
|
||||||
* $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
|
|
||||||
* the absolute number of the row in the result set that shall be fetched.
|
|
||||||
*
|
|
||||||
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
|
||||||
* which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
|
|
||||||
* specifies the row to fetch relative to the cursor position before
|
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function fetch($fetchStyle = Doctrine::FETCH_BOTH,
|
|
||||||
$cursorOrientation = Doctrine::FETCH_ORI_NEXT,
|
|
||||||
$cursorOffset = null);
|
|
||||||
/**
|
|
||||||
* fetchAll
|
|
||||||
* Returns an array containing all of the result set rows
|
|
||||||
*
|
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
|
||||||
*
|
|
||||||
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
|
||||||
* Doctrine::FETCH_COLUMN. Defaults to 0.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function fetchAll($fetchStyle = Doctrine::FETCH_BOTH);
|
|
||||||
/**
|
|
||||||
* fetchColumn
|
|
||||||
* Returns a single column from the next row of a
|
|
||||||
* result set or FALSE if there are no more rows.
|
|
||||||
*
|
|
||||||
* @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no
|
|
||||||
* value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn()
|
|
||||||
* fetches the first column.
|
|
||||||
*
|
|
||||||
* @return string returns a single column in the next row of a result set.
|
|
||||||
*/
|
|
||||||
public function fetchColumn($columnIndex = 0);
|
|
||||||
/**
|
|
||||||
* fetchObject
|
|
||||||
* Fetches the next row and returns it as an object.
|
|
||||||
*
|
|
||||||
* Fetches the next row and returns it as an object. This function is an alternative to
|
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style.
|
|
||||||
*
|
|
||||||
* @param string $className Name of the created class, defaults to stdClass.
|
|
||||||
* @param array $args Elements of this array are passed to the constructor.
|
|
||||||
*
|
|
||||||
* @return mixed an instance of the required class with property names that correspond
|
|
||||||
* to the column names or FALSE in case of an error.
|
|
||||||
*/
|
|
||||||
public function fetchObject($className = 'stdClass', $args = array());
|
|
||||||
/**
|
|
||||||
* getAttribute
|
|
||||||
* Retrieve a statement attribute
|
|
||||||
*
|
|
||||||
* @param integer $attribute
|
|
||||||
* @see Doctrine::ATTR_* constants
|
|
||||||
* @return mixed the attribute value
|
|
||||||
*/
|
|
||||||
public function getAttribute($attribute);
|
|
||||||
/**
|
|
||||||
* getColumnMeta
|
|
||||||
* Returns metadata for a column in a result set
|
|
||||||
*
|
|
||||||
* @param integer $column The 0-indexed column in the result set.
|
|
||||||
*
|
|
||||||
* @return array Associative meta data array with the following structure:
|
|
||||||
*
|
|
||||||
* native_type The PHP native type used to represent the column value.
|
|
||||||
* driver:decl_ type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta().
|
|
||||||
* flags Any flags set for this column.
|
|
||||||
* name The name of this column as returned by the database.
|
|
||||||
* len The length of this column. Normally -1 for types other than floating point decimals.
|
|
||||||
* precision The numeric precision of this column. Normally 0 for types other than floating point decimals.
|
|
||||||
* pdo_type The type of this column as represented by the PDO::PARAM_* constants.
|
|
||||||
*/
|
|
||||||
public function getColumnMeta($column);
|
|
||||||
/**
|
|
||||||
* nextRowset
|
|
||||||
* Advances to the next rowset in a multi-rowset statement handle
|
|
||||||
*
|
|
||||||
* Some database servers support stored procedures that return more than one rowset
|
|
||||||
* (also known as a result set). The nextRowset() method enables you to access the second
|
|
||||||
* and subsequent rowsets associated with a PDOStatement object. Each rowset can have a
|
|
||||||
* different set of columns from the preceding rowset.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function nextRowset();
|
|
||||||
/**
|
|
||||||
* rowCount
|
|
||||||
* rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
|
|
||||||
* executed by the corresponding object.
|
|
||||||
*
|
|
||||||
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
|
|
||||||
* some databases may return the number of rows returned by that statement. However,
|
|
||||||
* this behaviour is not guaranteed for all databases and should not be
|
|
||||||
* relied on for portable applications.
|
|
||||||
*
|
|
||||||
* @return integer Returns the number of rows.
|
|
||||||
*/
|
|
||||||
public function rowCount();
|
|
||||||
/**
|
|
||||||
* setAttribute
|
|
||||||
* Set a statement attribute
|
|
||||||
*
|
|
||||||
* @param integer $attribute
|
|
||||||
* @param mixed $value the value of given attribute
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function setAttribute($attribute, $value);
|
|
||||||
/**
|
|
||||||
* setFetchMode
|
|
||||||
* Set the default fetch mode for this statement
|
|
||||||
*
|
|
||||||
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
|
|
||||||
* @return boolean Returns 1 on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function setFetchMode($mode, $arg1 = null, $arg2 = null);
|
|
||||||
}
|
|
@ -1,334 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1917 2007-07-01 11:27:45Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Adapter_Statement_Mock
|
|
||||||
* This class is used for special testing purposes.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Adapter
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1917 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Adapter_Statement_Mock implements Doctrine_Adapter_Statement_Interface
|
|
||||||
{
|
|
||||||
private $mock;
|
|
||||||
|
|
||||||
public $queryString;
|
|
||||||
|
|
||||||
public function __construct($mock)
|
|
||||||
{
|
|
||||||
$this->mock = $mock;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* bindColumn
|
|
||||||
* Bind a column to a PHP variable
|
|
||||||
*
|
|
||||||
* @param mixed $column Number of the column (1-indexed) or name of the column in the result set.
|
|
||||||
* If using the column name, be aware that the name should match
|
|
||||||
* the case of the column, as returned by the driver.
|
|
||||||
* @param string $param Name of the PHP variable to which the column will be bound.
|
|
||||||
* @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure
|
|
||||||
*/
|
|
||||||
public function bindColumn($column, $param, $type = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* bindValue
|
|
||||||
* Binds a value to a corresponding named or question mark
|
|
||||||
* placeholder in the SQL statement that was use to prepare the statement.
|
|
||||||
*
|
|
||||||
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
||||||
* this will be a parameter name of the form :name. For a prepared statement
|
|
||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
||||||
*
|
|
||||||
* @param mixed $value The value to bind to the parameter.
|
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function bindValue($param, $value, $type = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* bindParam
|
|
||||||
* Binds a PHP variable to a corresponding named or question mark placeholder in the
|
|
||||||
* SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(),
|
|
||||||
* the variable is bound as a reference and will only be evaluated at the time
|
|
||||||
* that Doctrine_Adapter_Statement_Interface->execute() is called.
|
|
||||||
*
|
|
||||||
* Most parameters are input parameters, that is, parameters that are
|
|
||||||
* used in a read-only fashion to build up the query. Some drivers support the invocation
|
|
||||||
* of stored procedures that return data as output parameters, and some also as input/output
|
|
||||||
* parameters that both send in data and are updated to receive it.
|
|
||||||
*
|
|
||||||
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
|
||||||
* this will be a parameter name of the form :name. For a prepared statement
|
|
||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
|
||||||
*
|
|
||||||
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
|
||||||
*
|
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return
|
|
||||||
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
|
||||||
* Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
|
||||||
*
|
|
||||||
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
|
||||||
* from a stored procedure, you must explicitly set the length.
|
|
||||||
* @param mixed $driverOptions
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function bindParam($column, $variable, $type = null, $length = null, $driverOptions = array())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* closeCursor
|
|
||||||
* Closes the cursor, enabling the statement to be executed again.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function closeCursor()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* columnCount
|
|
||||||
* Returns the number of columns in the result set
|
|
||||||
*
|
|
||||||
* @return integer Returns the number of columns in the result set represented
|
|
||||||
* by the Doctrine_Adapter_Statement_Interface object. If there is no result set,
|
|
||||||
* this method should return 0.
|
|
||||||
*/
|
|
||||||
public function columnCount()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* errorCode
|
|
||||||
* Fetch the SQLSTATE associated with the last operation on the statement handle
|
|
||||||
*
|
|
||||||
* @see Doctrine_Adapter_Interface::errorCode()
|
|
||||||
* @return string error code string
|
|
||||||
*/
|
|
||||||
public function errorCode()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* errorInfo
|
|
||||||
* Fetch extended error information associated with the last operation on the statement handle
|
|
||||||
*
|
|
||||||
* @see Doctrine_Adapter_Interface::errorInfo()
|
|
||||||
* @return array error info array
|
|
||||||
*/
|
|
||||||
public function errorInfo()
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* fetch
|
|
||||||
*
|
|
||||||
* @see Doctrine::FETCH_* constants
|
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
|
||||||
*
|
|
||||||
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
|
||||||
* this value determines which row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
|
|
||||||
* Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
|
||||||
* Doctrine_Adapter_Statement_Interface object,
|
|
||||||
* you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
|
||||||
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
|
||||||
*
|
|
||||||
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
|
||||||
* $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
|
|
||||||
* the absolute number of the row in the result set that shall be fetched.
|
|
||||||
*
|
|
||||||
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
|
||||||
* which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
|
|
||||||
* specifies the row to fetch relative to the cursor position before
|
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function fetch($fetchStyle = Doctrine::FETCH_BOTH,
|
|
||||||
$cursorOrientation = Doctrine::FETCH_ORI_NEXT,
|
|
||||||
$cursorOffset = null)
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* fetchAll
|
|
||||||
* Returns an array containing all of the result set rows
|
|
||||||
*
|
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
|
||||||
*
|
|
||||||
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
|
||||||
* Doctrine::FETCH_COLUMN. Defaults to 0.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function fetchAll($fetchMode = Doctrine::FETCH_BOTH)
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* execute
|
|
||||||
* Executes a prepared statement
|
|
||||||
*
|
|
||||||
* If the prepared statement included parameter markers, you must either:
|
|
||||||
* call PDOStatement->bindParam() to bind PHP variables to the parameter markers:
|
|
||||||
* bound variables pass their value as input and receive the output value,
|
|
||||||
* if any, of their associated parameter markers or pass an array of input-only
|
|
||||||
* parameter values
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param array $params An array of values with as many elements as there are
|
|
||||||
* bound parameters in the SQL statement being executed.
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function execute($params = null)
|
|
||||||
{
|
|
||||||
if(is_object($this->mock)) {
|
|
||||||
$this->mock->addQuery($this->queryString);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* fetchColumn
|
|
||||||
* Returns a single column from the next row of a
|
|
||||||
* result set or FALSE if there are no more rows.
|
|
||||||
*
|
|
||||||
* @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no
|
|
||||||
* value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn()
|
|
||||||
* fetches the first column.
|
|
||||||
*
|
|
||||||
* @return string returns a single column in the next row of a result set.
|
|
||||||
*/
|
|
||||||
public function fetchColumn($columnIndex = 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* fetchObject
|
|
||||||
* Fetches the next row and returns it as an object.
|
|
||||||
*
|
|
||||||
* Fetches the next row and returns it as an object. This function is an alternative to
|
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style.
|
|
||||||
*
|
|
||||||
* @param string $className Name of the created class, defaults to stdClass.
|
|
||||||
* @param array $args Elements of this array are passed to the constructor.
|
|
||||||
*
|
|
||||||
* @return mixed an instance of the required class with property names that correspond
|
|
||||||
* to the column names or FALSE in case of an error.
|
|
||||||
*/
|
|
||||||
public function fetchObject($className = 'stdClass', $args = array())
|
|
||||||
{
|
|
||||||
return new $className();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* nextRowset
|
|
||||||
* Advances to the next rowset in a multi-rowset statement handle
|
|
||||||
*
|
|
||||||
* Some database servers support stored procedures that return more than one rowset
|
|
||||||
* (also known as a result set). The nextRowset() method enables you to access the second
|
|
||||||
* and subsequent rowsets associated with a PDOStatement object. Each rowset can have a
|
|
||||||
* different set of columns from the preceding rowset.
|
|
||||||
*
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function nextRowset()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* rowCount
|
|
||||||
* rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
|
|
||||||
* executed by the corresponding object.
|
|
||||||
*
|
|
||||||
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
|
|
||||||
* some databases may return the number of rows returned by that statement. However,
|
|
||||||
* this behaviour is not guaranteed for all databases and should not be
|
|
||||||
* relied on for portable applications.
|
|
||||||
*
|
|
||||||
* @return integer Returns the number of rows.
|
|
||||||
*/
|
|
||||||
public function rowCount()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getColumnMeta
|
|
||||||
* Returns metadata for a column in a result set
|
|
||||||
*
|
|
||||||
* @param integer $column The 0-indexed column in the result set.
|
|
||||||
*
|
|
||||||
* @return array Associative meta data array with the following structure:
|
|
||||||
*
|
|
||||||
* native_type The PHP native type used to represent the column value.
|
|
||||||
* driver:decl_ type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta().
|
|
||||||
* flags Any flags set for this column.
|
|
||||||
* name The name of this column as returned by the database.
|
|
||||||
* len The length of this column. Normally -1 for types other than floating point decimals.
|
|
||||||
* precision The numeric precision of this column. Normally 0 for types other than floating point decimals.
|
|
||||||
* pdo_type The type of this column as represented by the PDO::PARAM_* constants.
|
|
||||||
*/
|
|
||||||
public function getColumnMeta($column)
|
|
||||||
{ }
|
|
||||||
/**
|
|
||||||
* getAttribute
|
|
||||||
* Retrieve a statement attribute
|
|
||||||
*
|
|
||||||
* @param integer $attribute
|
|
||||||
* @see Doctrine::ATTR_* constants
|
|
||||||
* @return mixed the attribute value
|
|
||||||
*/
|
|
||||||
public function getAttribute($attribute)
|
|
||||||
{ }
|
|
||||||
/**
|
|
||||||
* setAttribute
|
|
||||||
* Set a statement attribute
|
|
||||||
*
|
|
||||||
* @param integer $attribute
|
|
||||||
* @param mixed $value the value of given attribute
|
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function setAttribute($attribute, $value)
|
|
||||||
{ }
|
|
||||||
/**
|
|
||||||
* setFetchMode
|
|
||||||
* Set the default fetch mode for this statement
|
|
||||||
*
|
|
||||||
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
|
|
||||||
* @return boolean Returns 1 on success or FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function setFetchMode($mode, $arg1 = null, $arg2 = null)
|
|
||||||
{ }
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
<?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
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_AuditLog
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_AuditLog
|
|
||||||
{
|
|
||||||
protected $_options = array(
|
|
||||||
'className' => '%CLASS%Version',
|
|
||||||
'versionColumn' => 'version',
|
|
||||||
'generateFiles' => false,
|
|
||||||
'table' => false,
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $_auditTable;
|
|
||||||
|
|
||||||
public function __construct($options)
|
|
||||||
{
|
|
||||||
$this->_options = array_merge($this->_options, $options);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __get
|
|
||||||
* an alias for getOption
|
|
||||||
*
|
|
||||||
* @param string $option
|
|
||||||
*/
|
|
||||||
public function __get($option)
|
|
||||||
{
|
|
||||||
if (isset($this->options[$option])) {
|
|
||||||
return $this->_options[$option];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* __isset
|
|
||||||
*
|
|
||||||
* @param string $option
|
|
||||||
*/
|
|
||||||
public function __isset($option)
|
|
||||||
{
|
|
||||||
return isset($this->_options[$option]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getOptions
|
|
||||||
* returns all options of this table and the associated values
|
|
||||||
*
|
|
||||||
* @return array all options and their values
|
|
||||||
*/
|
|
||||||
public function getOptions()
|
|
||||||
{
|
|
||||||
return $this->_options;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setOption
|
|
||||||
* sets an option and returns this object in order to
|
|
||||||
* allow flexible method chaining
|
|
||||||
*
|
|
||||||
* @see slef::$_options for available options
|
|
||||||
* @param string $name the name of the option to set
|
|
||||||
* @param mixed $value the value of the option
|
|
||||||
* @return Doctrine_AuditLog this object
|
|
||||||
*/
|
|
||||||
public function setOption($name, $value)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->_options[$name])) {
|
|
||||||
throw new Doctrine_Exception('Unknown option ' . $name);
|
|
||||||
}
|
|
||||||
$this->_options[$name] = $value;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getOption
|
|
||||||
* returns the value of given option
|
|
||||||
*
|
|
||||||
* @param string $name the name of the option
|
|
||||||
* @return mixed the value of given option
|
|
||||||
*/
|
|
||||||
public function getOption($name)
|
|
||||||
{
|
|
||||||
if (isset($this->_options[$name])) {
|
|
||||||
return $this->_options[$name];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getVersion(Doctrine_Record $record, $version)
|
|
||||||
{
|
|
||||||
$className = $this->_options['className'];
|
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
|
||||||
|
|
||||||
$values = array();
|
|
||||||
foreach ((array) $this->_options['table']->getIdentifier() as $id) {
|
|
||||||
$conditions[] = $className . '.' . $id . ' = ?';
|
|
||||||
$values[] = $record->get($id);
|
|
||||||
}
|
|
||||||
$where = implode(' AND ', $conditions) . ' AND ' . $className . '.' . $this->_options['versionColumn'] . ' = ?';
|
|
||||||
|
|
||||||
$values[] = $version;
|
|
||||||
|
|
||||||
$q->from($className)
|
|
||||||
->where($where);
|
|
||||||
|
|
||||||
return $q->execute($values, Doctrine_HYDRATE::HYDRATE_ARRAY);
|
|
||||||
}
|
|
||||||
public function buildDefinition(Doctrine_Table $table)
|
|
||||||
{
|
|
||||||
$this->_options['className'] = str_replace('%CLASS%',
|
|
||||||
$this->_options['table']->getComponentName(),
|
|
||||||
$this->_options['className']);
|
|
||||||
|
|
||||||
$name = $table->getComponentName();
|
|
||||||
|
|
||||||
$className = $name . 'Version';
|
|
||||||
|
|
||||||
if (class_exists($className)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$columns = $table->getColumns();
|
|
||||||
|
|
||||||
// the version column should be part of the primary key definition
|
|
||||||
$columns[$this->_options['versionColumn']]['primary'] = true;
|
|
||||||
|
|
||||||
$id = $table->getIdentifier();
|
|
||||||
|
|
||||||
$options = array('className' => $className);
|
|
||||||
|
|
||||||
$builder = new Doctrine_Import_Builder();
|
|
||||||
|
|
||||||
$def = $builder->buildDefinition($options, $columns);
|
|
||||||
|
|
||||||
if ( ! $this->_options['generateFiles']) {
|
|
||||||
eval($def);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
<?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
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Record_Listener');
|
|
||||||
/**
|
|
||||||
* Doctrine_AuditLog_Listener
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $_auditLog;
|
|
||||||
|
|
||||||
public function __construct(Doctrine_AuditLog $auditLog) {
|
|
||||||
$this->_auditLog = $auditLog;
|
|
||||||
}
|
|
||||||
public function preInsert(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
|
||||||
|
|
||||||
$event->getInvoker()->set($versionColumn, 1);
|
|
||||||
}
|
|
||||||
public function preDelete(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$class = $this->_auditLog->getOption('className');
|
|
||||||
|
|
||||||
$record = $event->getInvoker();
|
|
||||||
|
|
||||||
$version = new $class();
|
|
||||||
$version->merge($record->toArray());
|
|
||||||
$version->save();
|
|
||||||
|
|
||||||
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
|
||||||
$version = $record->get($versionColumn);
|
|
||||||
|
|
||||||
$record->set($versionColumn, ++$version);
|
|
||||||
}
|
|
||||||
public function preUpdate(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$class = $this->_auditLog->getOption('className');
|
|
||||||
$record = $event->getInvoker();
|
|
||||||
|
|
||||||
$version = new $class();
|
|
||||||
$version->merge($record->toArray());
|
|
||||||
$version->save();
|
|
||||||
|
|
||||||
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
|
||||||
|
|
||||||
$version = $record->get($versionColumn);
|
|
||||||
|
|
||||||
$record->set($versionColumn, ++$version);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,401 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Cache.php 1857 2007-06-26 22:30:23Z subzero2000 $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_EventListener');
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1857 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache extends Doctrine_EventListener implements Countable, IteratorAggregate
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $_options an array of general caching options
|
|
||||||
*/
|
|
||||||
protected $_options = array('size' => 1000,
|
|
||||||
'lifeTime' => 3600,
|
|
||||||
'addStatsPropability' => 0.25,
|
|
||||||
'savePropability' => 0.10,
|
|
||||||
'cleanPropability' => 0.01,
|
|
||||||
'statsFile' => '../data/stats.cache',
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* @var array $_queries query stack
|
|
||||||
*/
|
|
||||||
protected $_queries = array();
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Cache_Interface $_driver the cache driver object
|
|
||||||
*/
|
|
||||||
protected $_driver;
|
|
||||||
/**
|
|
||||||
* @var array $data current cache data array
|
|
||||||
*/
|
|
||||||
protected $_data = array();
|
|
||||||
/**
|
|
||||||
* @var boolean $success the success of last operation
|
|
||||||
*/
|
|
||||||
protected $_success = false;
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Cache_Interface|string $driver cache driver name or a driver object
|
|
||||||
* @param array $options cache driver options
|
|
||||||
*/
|
|
||||||
public function __construct($driver, $options = array())
|
|
||||||
{
|
|
||||||
if (is_object($driver)) {
|
|
||||||
if ( ! ($driver instanceof Doctrine_Cache_Interface)) {
|
|
||||||
throw new Doctrine_Cache_Exception('Driver should implement Doctrine_Cache_Interface.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_driver = $driver;
|
|
||||||
$this->_driver->setOptions($options);
|
|
||||||
} else {
|
|
||||||
$class = 'Doctrine_Cache_' . ucwords(strtolower($driver));
|
|
||||||
|
|
||||||
if ( ! class_exists($class)) {
|
|
||||||
throw new Doctrine_Cache_Exception('Cache driver ' . $driver . ' could not be found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_driver = new $class($options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getDriver
|
|
||||||
* returns the current cache driver
|
|
||||||
*
|
|
||||||
* @return Doctrine_Cache_Driver
|
|
||||||
*/
|
|
||||||
public function getDriver()
|
|
||||||
{
|
|
||||||
return $this->_driver;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setOption
|
|
||||||
*
|
|
||||||
* @param mixed $option the option name
|
|
||||||
* @param mixed $value option value
|
|
||||||
* @return boolean TRUE on success, FALSE on failure
|
|
||||||
*/
|
|
||||||
public function setOption($option, $value)
|
|
||||||
{
|
|
||||||
// sanity check (we need this since we are using isset() instead of array_key_exists())
|
|
||||||
if ($value === null) {
|
|
||||||
throw new Doctrine_Cache_Exception('Null values not accepted for options.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->_options[$option])) {
|
|
||||||
$this->_options[$option] = $value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getOption
|
|
||||||
*
|
|
||||||
* @param mixed $option the option name
|
|
||||||
* @return mixed option value
|
|
||||||
*/
|
|
||||||
public function getOption($option)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->_options[$option])) {
|
|
||||||
throw new Doctrine_Cache_Exception('Unknown option ' . $option);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_options[$option];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* add
|
|
||||||
* adds a query to internal query stack
|
|
||||||
*
|
|
||||||
* @param string|array $query sql query string
|
|
||||||
* @param string $namespace connection namespace
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function add($query, $namespace = null)
|
|
||||||
{
|
|
||||||
if (isset($namespace)) {
|
|
||||||
$this->_queries[$namespace][] = $query;
|
|
||||||
} else {
|
|
||||||
$this->_queries[] = $query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getQueries
|
|
||||||
*
|
|
||||||
* @param string $namespace optional query namespace
|
|
||||||
* @return array an array of sql query strings
|
|
||||||
*/
|
|
||||||
public function getAll($namespace = null)
|
|
||||||
{
|
|
||||||
if (isset($namespace)) {
|
|
||||||
if( ! isset($this->_queries[$namespace])) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_queries[$namespace];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_queries;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* pop
|
|
||||||
*
|
|
||||||
* pops a query from the stack
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function pop()
|
|
||||||
{
|
|
||||||
return array_pop($this->_queries);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* reset
|
|
||||||
*
|
|
||||||
* removes all queries from the query stack
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function reset()
|
|
||||||
{
|
|
||||||
$this->_queries = array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
*
|
|
||||||
* @return integer the number of queries in the stack
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->_queries);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getIterator
|
|
||||||
*
|
|
||||||
* @return ArrayIterator an iterator that iterates through the query stack
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->_queries);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return boolean whether or not the last cache operation was successful
|
|
||||||
*/
|
|
||||||
public function isSuccessful()
|
|
||||||
{
|
|
||||||
return $this->_success;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* save
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function clean()
|
|
||||||
{
|
|
||||||
$rand = (mt_rand() / mt_getrandmax());
|
|
||||||
|
|
||||||
if ($rand <= $this->_options['cleanPropability']) {
|
|
||||||
$queries = $this->readStats();
|
|
||||||
|
|
||||||
$stats = array();
|
|
||||||
|
|
||||||
foreach ($queries as $query) {
|
|
||||||
if (isset($stats[$query])) {
|
|
||||||
$stats[$query]++;
|
|
||||||
} else {
|
|
||||||
$stats[$query] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort($stats);
|
|
||||||
|
|
||||||
$i = $this->_options['size'];
|
|
||||||
|
|
||||||
while ($i--) {
|
|
||||||
$element = next($stats);
|
|
||||||
$query = key($stats);
|
|
||||||
|
|
||||||
$hash = md5($query);
|
|
||||||
|
|
||||||
$this->_driver->delete($hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* readStats
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function readStats()
|
|
||||||
{
|
|
||||||
if ($this->_options['statsFile'] !== false) {
|
|
||||||
$content = file_get_contents($this->_options['statsFile']);
|
|
||||||
|
|
||||||
$e = explode("\n", $content);
|
|
||||||
|
|
||||||
return array_map('unserialize', $e);
|
|
||||||
}
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* appendStats
|
|
||||||
*
|
|
||||||
* adds all queries to stats file
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function appendStats()
|
|
||||||
{
|
|
||||||
if ($this->_options['statsFile'] !== false) {
|
|
||||||
|
|
||||||
if ( ! file_exists($this->_options['statsFile'])) {
|
|
||||||
throw new Doctrine_Cache_Exception("Couldn't save cache statistics. Cache statistics file doesn't exists!");
|
|
||||||
}
|
|
||||||
|
|
||||||
$rand = (mt_rand() / mt_getrandmax());
|
|
||||||
|
|
||||||
if ($rand <= $this->_options['addStatsPropability']) {
|
|
||||||
file_put_contents($this->_options['statsFile'], implode("\n", array_map('serialize', $this->_queries)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* preQuery
|
|
||||||
* listens on the Doctrine_Event preQuery event
|
|
||||||
*
|
|
||||||
* adds the issued query to internal query stack
|
|
||||||
* and checks if cached element exists
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function preQuery(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$query = $event->getQuery();
|
|
||||||
|
|
||||||
$data = false;
|
|
||||||
// only process SELECT statements
|
|
||||||
if (strtoupper(substr(ltrim($query), 0, 6)) == 'SELECT') {
|
|
||||||
|
|
||||||
$this->add($query, $event->getInvoker()->getName());
|
|
||||||
|
|
||||||
$data = $this->_driver->fetch(md5(serialize($query)));
|
|
||||||
|
|
||||||
$this->success = ($data) ? true : false;
|
|
||||||
|
|
||||||
if ( ! $data) {
|
|
||||||
$rand = (mt_rand() / mt_getrandmax());
|
|
||||||
|
|
||||||
if ($rand < $this->_options['savePropability']) {
|
|
||||||
$stmt = $event->getInvoker()->getAdapter()->query($query);
|
|
||||||
|
|
||||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
|
||||||
|
|
||||||
$this->success = true;
|
|
||||||
|
|
||||||
$this->_driver->save(md5(serialize($query)), $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->success)
|
|
||||||
{
|
|
||||||
$this->_data = $data;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* preFetch
|
|
||||||
* listens the preFetch event of Doctrine_Connection_Statement
|
|
||||||
*
|
|
||||||
* advances the internal pointer of cached data and returns
|
|
||||||
* the current element
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function preFetch(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$ret = current($this->_data);
|
|
||||||
next($this->_data);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* preFetch
|
|
||||||
* listens the preFetchAll event of Doctrine_Connection_Statement
|
|
||||||
*
|
|
||||||
* returns the current cache data array
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function preFetchAll(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
return $this->_data;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* preExecute
|
|
||||||
* listens the preExecute event of Doctrine_Connection_Statement
|
|
||||||
*
|
|
||||||
* adds the issued query to internal query stack
|
|
||||||
* and checks if cached element exists
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function preExecute(Doctrine_Event $event)
|
|
||||||
{
|
|
||||||
$query = $event->getQuery();
|
|
||||||
|
|
||||||
$data = false;
|
|
||||||
|
|
||||||
// only process SELECT statements
|
|
||||||
if (strtoupper(substr(ltrim($query), 0, 6)) == 'SELECT') {
|
|
||||||
|
|
||||||
$this->add($query, $event->getInvoker()->getDbh()->getName());
|
|
||||||
|
|
||||||
$data = $this->_driver->fetch(md5(serialize(array($query, $event->getParams()))));
|
|
||||||
|
|
||||||
$this->success = ($data) ? true : false;
|
|
||||||
|
|
||||||
if ( ! $data) {
|
|
||||||
$rand = (mt_rand() / mt_getrandmax());
|
|
||||||
|
|
||||||
if ($rand <= $this->_options['savePropability']) {
|
|
||||||
|
|
||||||
$stmt = $event->getInvoker()->getStatement();
|
|
||||||
|
|
||||||
$stmt->execute($event->getParams());
|
|
||||||
|
|
||||||
$data = $stmt->fetchAll(Doctrine::FETCH_ASSOC);
|
|
||||||
|
|
||||||
$this->success = true;
|
|
||||||
|
|
||||||
$this->_driver->save(md5(serialize(array($query, $event->getParams()))), $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($this->success)
|
|
||||||
{
|
|
||||||
$this->_data = $data;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Apc.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Apc
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache_Apc extends Doctrine_Cache_Driver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param array $options associative array of cache driver options
|
|
||||||
*/
|
|
||||||
public function __construct($options = array())
|
|
||||||
{
|
|
||||||
if ( ! extension_loaded('apc')) {
|
|
||||||
throw new Doctrine_Cache_Exception('The apc extension must be loaded for using this backend !');
|
|
||||||
}
|
|
||||||
parent::__construct($options);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
|
||||||
*
|
|
||||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
*/
|
|
||||||
public function fetch($id, $testCacheValidity = true)
|
|
||||||
{
|
|
||||||
$tmp = apc_fetch($id);
|
|
||||||
if (is_array($tmp)) {
|
|
||||||
return $tmp[0];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available or not (for the given id)
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
||||||
*/
|
|
||||||
public function contains($id)
|
|
||||||
{
|
|
||||||
$tmp = apc_fetch($id);
|
|
||||||
if (is_array($tmp)) {
|
|
||||||
return $tmp[1];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Save some string datas into a cache record
|
|
||||||
*
|
|
||||||
* Note : $data is always saved as a string
|
|
||||||
*
|
|
||||||
* @param string $data data to cache
|
|
||||||
* @param string $id cache id
|
|
||||||
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function save($id, $data, $lifeTime = false)
|
|
||||||
{
|
|
||||||
$lifeTime = $this->getLifeTime($lifeTime);
|
|
||||||
|
|
||||||
return (bool) apc_store($id, array($data, time()), $lifeTime);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Remove a cache record
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
return apc_delete($id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Array.php 1495 2007-05-27 18:56:04Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Interface
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1495 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache_Array implements Countable, Doctrine_Cache_Interface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $data an array of cached data
|
|
||||||
*/
|
|
||||||
protected $data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
|
||||||
*
|
|
||||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
*/
|
|
||||||
public function fetch($id, $testCacheValidity = true)
|
|
||||||
{
|
|
||||||
if (isset($this->data[$id])) {
|
|
||||||
return $this->data[$id];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available or not (for the given id)
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
||||||
*/
|
|
||||||
public function contains($id)
|
|
||||||
{
|
|
||||||
return isset($this->data[$id]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Save some string datas into a cache record
|
|
||||||
*
|
|
||||||
* Note : $data is always saved as a string
|
|
||||||
*
|
|
||||||
* @param string $data data to cache
|
|
||||||
* @param string $id cache id
|
|
||||||
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function save($id, $data, $lifeTime = false)
|
|
||||||
{
|
|
||||||
$this->data[$id] = $data;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Remove a cache record
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
unset($this->data[$id]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Remove all cache record
|
|
||||||
*
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function deleteAll()
|
|
||||||
{
|
|
||||||
$this->data = array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->data);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,196 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Db.php 2258 2007-08-17 10:49:51Z jepso $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Db
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 2258 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache_Db extends Doctrine_Cache_Driver implements Countable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param array $_options an array of options
|
|
||||||
*/
|
|
||||||
public function __construct($options)
|
|
||||||
{
|
|
||||||
if ( ! isset($options['connection']) ||
|
|
||||||
! ($options['connection'] instanceof Doctrine_Connection)) {
|
|
||||||
|
|
||||||
throw new Doctrine_Cache_Exception('Connection option not set.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! isset($options['tableName']) ||
|
|
||||||
! is_string($options['tableName'])) {
|
|
||||||
|
|
||||||
throw new Doctrine_Cache_Exception('Table name option not set.');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$this->_options = $options;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getConnection
|
|
||||||
* returns the connection object associated with this cache driver
|
|
||||||
*
|
|
||||||
* @return Doctrine_Connection connection object
|
|
||||||
*/
|
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->_options['connection'];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
|
||||||
*
|
|
||||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
*/
|
|
||||||
public function fetch($id, $testCacheValidity = true)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT data, expire FROM ' . $this->_options['tableName']
|
|
||||||
. ' WHERE id = ?';
|
|
||||||
|
|
||||||
if ($testCacheValidity) {
|
|
||||||
$sql .= ' AND (expire=0 OR expire > ' . time() . ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->getConnection()->fetchAssoc($sql, array($id));
|
|
||||||
|
|
||||||
if ( ! isset($result[0])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return unserialize($result[0]['data']);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available or not (for the given id)
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
||||||
*/
|
|
||||||
public function contains($id)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT expire FROM ' . $this->_options['tableName']
|
|
||||||
. ' WHERE id = ? AND (expire=0 OR expire > ' . time() . ')';
|
|
||||||
|
|
||||||
return $this->getConnection()->fetchOne($sql, array($id));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Save some string datas into a cache record
|
|
||||||
*
|
|
||||||
* Note : $data is always saved as a string
|
|
||||||
*
|
|
||||||
* @param string $data data to cache
|
|
||||||
* @param string $id cache id
|
|
||||||
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function save($data, $id, $lifeTime = false)
|
|
||||||
{
|
|
||||||
$sql = 'INSERT INTO ' . $this->_options['tableName']
|
|
||||||
. ' (id, data, expire) VALUES (?, ?, ?)';
|
|
||||||
|
|
||||||
if ($lifeTime) {
|
|
||||||
$expire = time() + $lifeTime;
|
|
||||||
} else {
|
|
||||||
$expire = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = array($id, serialize($data), $expire);
|
|
||||||
|
|
||||||
return (bool) $this->getConnection()->exec($sql, $params);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Remove a cache record
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
$sql = 'DELETE FROM ' . $this->_options['tableName'] . ' WHERE id = ?';
|
|
||||||
|
|
||||||
return (bool) $this->getConnection()->exec($sql, array($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all cache records
|
|
||||||
*
|
|
||||||
* $return bool true on success, false on failure
|
|
||||||
*/
|
|
||||||
public function deleteAll()
|
|
||||||
{
|
|
||||||
$sql = 'DELETE FROM ' . $this->_options['tableName'];
|
|
||||||
|
|
||||||
return (bool) $this->getConnection()->exec($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
* returns the number of cached elements
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
$sql = 'SELECT COUNT(*) FROM ' . $this->_options['tableName'];
|
|
||||||
|
|
||||||
return (int) $this->getConnection()->fetchOne($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the cache table.
|
|
||||||
*/
|
|
||||||
public function createTable()
|
|
||||||
{
|
|
||||||
$name = $this->_options['tableName'];
|
|
||||||
|
|
||||||
$fields = array(
|
|
||||||
'id' => array(
|
|
||||||
'type' => 'string',
|
|
||||||
'length' => 255
|
|
||||||
),
|
|
||||||
'data' => array(
|
|
||||||
'type' => 'blob'
|
|
||||||
),
|
|
||||||
'expire' => array(
|
|
||||||
'type' => 'timestamp'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$options = array(
|
|
||||||
'primary' => array('id')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->getConnection()->export->createTable($name, $fields, $options);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Driver.php 1401 2007-05-20 17:54:22Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Driver
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1401 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
abstract class Doctrine_Cache_Driver implements Doctrine_Cache_Interface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $_options an array of options
|
|
||||||
*/
|
|
||||||
protected $_options = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param array $_options an array of options
|
|
||||||
*/
|
|
||||||
public function __construct($options)
|
|
||||||
{
|
|
||||||
$this->_options = $options;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setOption
|
|
||||||
*
|
|
||||||
* @param mixed $option the option name
|
|
||||||
* @param mixed $value option value
|
|
||||||
* @return boolean TRUE on success, FALSE on failure
|
|
||||||
*/
|
|
||||||
public function setOption($option, $value)
|
|
||||||
{
|
|
||||||
if (isset($this->_options[$option])) {
|
|
||||||
$this->_options[$option] = $value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getOption
|
|
||||||
*
|
|
||||||
* @param mixed $option the option name
|
|
||||||
* @return mixed option value
|
|
||||||
*/
|
|
||||||
public function getOption($option)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->_options[$option])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_options[$option];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache_Exception extends Doctrine_Exception
|
|
||||||
{ }
|
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Interface.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Interface
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
interface Doctrine_Cache_Interface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
|
||||||
*
|
|
||||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
*/
|
|
||||||
public function fetch($id, $testCacheValidity = true);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if a cache is available or not (for the given id)
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
||||||
*/
|
|
||||||
public function contains($id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save some string datas into a cache record
|
|
||||||
*
|
|
||||||
* Note : $data is always saved as a string
|
|
||||||
*
|
|
||||||
* @param string $data data to cache
|
|
||||||
* @param string $id cache id
|
|
||||||
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function save($data, $id, $lifeTime = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a cache record
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function delete($id);
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Memcache.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Cache_Driver');
|
|
||||||
/**
|
|
||||||
* Doctrine_Cache_Memcache
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Doctrine_Cache
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Cache_Memcache extends Doctrine_Cache_Driver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Memcache $_memcache memcache object
|
|
||||||
*/
|
|
||||||
protected $_memcache = null;
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param array $options associative array of cache driver options
|
|
||||||
*/
|
|
||||||
public function __construct($options = array())
|
|
||||||
{
|
|
||||||
if ( ! extension_loaded('memcache')) {
|
|
||||||
throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.');
|
|
||||||
}
|
|
||||||
parent::__construct($options);
|
|
||||||
|
|
||||||
if (isset($options['servers'])) {
|
|
||||||
$value= $options['servers'];
|
|
||||||
if (isset($value['host'])) {
|
|
||||||
// in this case, $value seems to be a simple associative array (one server only)
|
|
||||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
|
||||||
}
|
|
||||||
$this->setOption('servers', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_memcache = new Memcache;
|
|
||||||
|
|
||||||
foreach ($this->_options['servers'] as $server) {
|
|
||||||
if ( ! array_key_exists('persistent', $server)) {
|
|
||||||
$server['persistent'] = true;
|
|
||||||
}
|
|
||||||
if ( ! array_key_exists('port', $server)) {
|
|
||||||
$server['port'] = 11211;
|
|
||||||
}
|
|
||||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
|
||||||
*
|
|
||||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
|
||||||
*
|
|
||||||
* @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)
|
|
||||||
*/
|
|
||||||
public function fetch($id, $testCacheValidity = true)
|
|
||||||
{
|
|
||||||
$tmp = $this->_memcache->get($id);
|
|
||||||
|
|
||||||
if (is_array($tmp)) {
|
|
||||||
return $tmp[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Test if a cache is available or not (for the given id)
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
|
||||||
*/
|
|
||||||
public function contains($id)
|
|
||||||
{
|
|
||||||
return (bool) $this->_memcache->get($id);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Save some string datas into a cache record
|
|
||||||
*
|
|
||||||
* Note : $data is always saved as a string
|
|
||||||
*
|
|
||||||
* @param string $data data to cache
|
|
||||||
* @param string $id cache id
|
|
||||||
* @param int $lifeTime if != false, set a specific lifetime for this cache record (null => infinite lifeTime)
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function save($id, $data, $lifeTime = false)
|
|
||||||
{
|
|
||||||
if ($this->_options['compression']) {
|
|
||||||
$flag = MEMCACHE_COMPRESSED;
|
|
||||||
} else {
|
|
||||||
$flag = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->_memcache->set($id, $data, $flag, $lifeTime);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Remove a cache record
|
|
||||||
*
|
|
||||||
* @param string $id cache id
|
|
||||||
* @return boolean true if no problem
|
|
||||||
*/
|
|
||||||
public function delete($id)
|
|
||||||
{
|
|
||||||
return $this->_memcache->delete($id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,680 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Collection.php 2282 2007-08-28 16:45:22Z jackbravo $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Access');
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection
|
|
||||||
* Collection of Doctrine_Record objects.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 2282 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection extends Doctrine_Access implements Countable, IteratorAggregate, Serializable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $data an array containing the records of this collection
|
|
||||||
*/
|
|
||||||
protected $data = array();
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Table $table each collection has only records of specified table
|
|
||||||
*/
|
|
||||||
protected $_table;
|
|
||||||
/**
|
|
||||||
* @var array $_snapshot a snapshot of the fetched data
|
|
||||||
*/
|
|
||||||
protected $_snapshot = array();
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Record $reference collection can belong to a record
|
|
||||||
*/
|
|
||||||
protected $reference;
|
|
||||||
/**
|
|
||||||
* @var string $referenceField the reference field of the collection
|
|
||||||
*/
|
|
||||||
protected $referenceField;
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Relation the record this collection is related to, if any
|
|
||||||
*/
|
|
||||||
protected $relation;
|
|
||||||
/**
|
|
||||||
* @var string $keyColumn the name of the column that is used for collection key mapping
|
|
||||||
*/
|
|
||||||
protected $keyColumn;
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Null $null used for extremely fast null value testing
|
|
||||||
*/
|
|
||||||
protected static $null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Table|string $table
|
|
||||||
*/
|
|
||||||
public function __construct($table)
|
|
||||||
{
|
|
||||||
if ( ! ($table instanceof Doctrine_Table)) {
|
|
||||||
$table = Doctrine_Manager::getInstance()
|
|
||||||
->getTable($table);
|
|
||||||
}
|
|
||||||
$this->_table = $table;
|
|
||||||
|
|
||||||
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
|
|
||||||
if ($name !== null) {
|
|
||||||
$this->keyColumn = $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* initNullObject
|
|
||||||
* initializes the null object for this collection
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function initNullObject(Doctrine_Null $null)
|
|
||||||
{
|
|
||||||
self::$null = $null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getTable
|
|
||||||
* returns the table this collection belongs to
|
|
||||||
*
|
|
||||||
* @return Doctrine_Table
|
|
||||||
*/
|
|
||||||
public function getTable()
|
|
||||||
{
|
|
||||||
return $this->_table;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setData
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function setData(array $data)
|
|
||||||
{
|
|
||||||
$this->data = $data;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* this method is automatically called when this Doctrine_Collection is serialized
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function serialize()
|
|
||||||
{
|
|
||||||
$vars = get_object_vars($this);
|
|
||||||
|
|
||||||
unset($vars['reference']);
|
|
||||||
unset($vars['reference_field']);
|
|
||||||
unset($vars['relation']);
|
|
||||||
unset($vars['expandable']);
|
|
||||||
unset($vars['expanded']);
|
|
||||||
unset($vars['generator']);
|
|
||||||
|
|
||||||
$vars['_table'] = $vars['_table']->getComponentName();
|
|
||||||
|
|
||||||
return serialize($vars);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* unseralize
|
|
||||||
* this method is automatically called everytime a Doctrine_Collection object is unserialized
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function unserialize($serialized)
|
|
||||||
{
|
|
||||||
$manager = Doctrine_Manager::getInstance();
|
|
||||||
$connection = $manager->getCurrentConnection();
|
|
||||||
|
|
||||||
$array = unserialize($serialized);
|
|
||||||
|
|
||||||
foreach ($array as $name => $values) {
|
|
||||||
$this->$name = $values;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_table = $connection->getTable($this->_table);
|
|
||||||
|
|
||||||
|
|
||||||
$name = $this->_table->getAttribute(Doctrine::ATTR_COLL_KEY);
|
|
||||||
if ($name !== null) {
|
|
||||||
$this->keyColumn = $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setKeyColumn
|
|
||||||
* sets the key column for this collection
|
|
||||||
*
|
|
||||||
* @param string $column
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function setKeyColumn($column)
|
|
||||||
{
|
|
||||||
$this->keyColumn = $column;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getKeyColumn
|
|
||||||
* returns the name of the key column
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getKeyColumn()
|
|
||||||
{
|
|
||||||
return $this->column;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getData
|
|
||||||
* returns all the records as an array
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getData()
|
|
||||||
{
|
|
||||||
return $this->data;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getFirst
|
|
||||||
* returns the first record in the collection
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getFirst()
|
|
||||||
{
|
|
||||||
return reset($this->data);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getLast
|
|
||||||
* returns the last record in the collection
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getLast()
|
|
||||||
{
|
|
||||||
return end($this->data);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setReference
|
|
||||||
* sets a reference pointer
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setReference(Doctrine_Record $record, Doctrine_Relation $relation)
|
|
||||||
{
|
|
||||||
$this->reference = $record;
|
|
||||||
$this->relation = $relation;
|
|
||||||
|
|
||||||
if ($relation instanceof Doctrine_Relation_ForeignKey
|
|
||||||
|| $relation instanceof Doctrine_Relation_LocalKey
|
|
||||||
) {
|
|
||||||
|
|
||||||
$this->referenceField = $relation->getForeign();
|
|
||||||
|
|
||||||
$value = $record->get($relation->getLocal());
|
|
||||||
|
|
||||||
foreach ($this->data as $record) {
|
|
||||||
if ($value !== null) {
|
|
||||||
$record->set($this->referenceField, $value, false);
|
|
||||||
} else {
|
|
||||||
$record->set($this->referenceField, $this->reference, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($relation instanceof Doctrine_Relation_Association) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getReference
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getReference()
|
|
||||||
{
|
|
||||||
return $this->reference;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* remove
|
|
||||||
* removes a specified collection element
|
|
||||||
*
|
|
||||||
* @param mixed $key
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function remove($key)
|
|
||||||
{
|
|
||||||
$removed = $this->data[$key];
|
|
||||||
|
|
||||||
unset($this->data[$key]);
|
|
||||||
return $removed;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* contains
|
|
||||||
* whether or not this collection contains a specified element
|
|
||||||
*
|
|
||||||
* @param mixed $key the key of the element
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function contains($key)
|
|
||||||
{
|
|
||||||
return isset($this->data[$key]);
|
|
||||||
}
|
|
||||||
public function search(Doctrine_Record $record)
|
|
||||||
{
|
|
||||||
return array_search($record, $this->data, true);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* get
|
|
||||||
* returns a record for given key
|
|
||||||
*
|
|
||||||
* There are two special cases:
|
|
||||||
*
|
|
||||||
* 1. if null is given as a key a new record is created and attached
|
|
||||||
* at the end of the collection
|
|
||||||
*
|
|
||||||
* 2. if given key does not exist, then a new record is create and attached
|
|
||||||
* to the given key
|
|
||||||
*
|
|
||||||
* Collection also maps referential information to newly created records
|
|
||||||
*
|
|
||||||
* @param mixed $key the key of the element
|
|
||||||
* @return Doctrine_Record return a specified record
|
|
||||||
*/
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if ($key === null || ! isset($this->data[$key])) {
|
|
||||||
$record = $this->_table->create();
|
|
||||||
|
|
||||||
if (isset($this->referenceField)) {
|
|
||||||
$value = $this->reference->get($this->relation->getLocal());
|
|
||||||
|
|
||||||
if ($value !== null) {
|
|
||||||
$record->set($this->referenceField, $value, false);
|
|
||||||
} else {
|
|
||||||
$record->set($this->referenceField, $this->reference, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data[] = $record;
|
|
||||||
|
|
||||||
return $record;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->data[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array an array containing all primary keys
|
|
||||||
*/
|
|
||||||
public function getPrimaryKeys()
|
|
||||||
{
|
|
||||||
$list = array();
|
|
||||||
$name = $this->_table->getIdentifier();
|
|
||||||
|
|
||||||
foreach ($this->data as $record) {
|
|
||||||
if (is_array($record) && isset($record[$name])) {
|
|
||||||
$list[] = $record[$name];
|
|
||||||
} else {
|
|
||||||
$list[] = $record->getIncremented();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns all keys
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getKeys()
|
|
||||||
{
|
|
||||||
return array_keys($this->data);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
* this class implements interface countable
|
|
||||||
* returns the number of records in this collection
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->data);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* set
|
|
||||||
* @param integer $key
|
|
||||||
* @param Doctrine_Record $record
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function set($key, Doctrine_Record $record)
|
|
||||||
{
|
|
||||||
if (isset($this->referenceField)) {
|
|
||||||
$record->set($this->referenceField, $this->reference, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data[$key] = $record;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds a record to collection
|
|
||||||
* @param Doctrine_Record $record record to be added
|
|
||||||
* @param string $key optional key for the record
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function add(Doctrine_Record $record, $key = null)
|
|
||||||
{
|
|
||||||
if (isset($this->referenceField)) {
|
|
||||||
$value = $this->reference->get($this->relation->getLocal());
|
|
||||||
|
|
||||||
if ($value !== null) {
|
|
||||||
$record->set($this->referenceField, $value, false);
|
|
||||||
} else {
|
|
||||||
$record->set($this->referenceField, $this->reference, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* for some weird reason in_array cannot be used here (php bug ?)
|
|
||||||
*
|
|
||||||
* if used it results in fatal error : [ nesting level too deep ]
|
|
||||||
*/
|
|
||||||
foreach ($this->data as $val) {
|
|
||||||
if ($val === $record) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($key)) {
|
|
||||||
if (isset($this->data[$key])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->data[$key] = $record;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->keyColumn)) {
|
|
||||||
$value = $record->get($this->keyColumn);
|
|
||||||
if ($value === null) {
|
|
||||||
throw new Doctrine_Collection_Exception("Couldn't create collection index. Record field '".$this->keyColumn."' was null.");
|
|
||||||
}
|
|
||||||
$this->data[$value] = $record;
|
|
||||||
} else {
|
|
||||||
$this->data[] = $record;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* loadRelated
|
|
||||||
*
|
|
||||||
* @param mixed $name
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function loadRelated($name = null)
|
|
||||||
{
|
|
||||||
$list = array();
|
|
||||||
$query = new Doctrine_Query($this->_table->getConnection());
|
|
||||||
|
|
||||||
if ( ! isset($name)) {
|
|
||||||
foreach ($this->data as $record) {
|
|
||||||
$value = $record->getIncremented();
|
|
||||||
if ($value !== null) {
|
|
||||||
$list[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$query->from($this->_table->getComponentName() . '(' . implode(", ",$this->_table->getPrimaryKeys()) . ')');
|
|
||||||
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rel = $this->_table->getRelation($name);
|
|
||||||
|
|
||||||
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
|
|
||||||
foreach ($this->data as $record) {
|
|
||||||
$list[] = $record[$rel->getLocal()];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($this->data as $record) {
|
|
||||||
$value = $record->getIncremented();
|
|
||||||
if ($value !== null) {
|
|
||||||
$list[] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$dql = $rel->getRelationDql(count($list), 'collection');
|
|
||||||
|
|
||||||
$coll = $query->query($dql, $list);
|
|
||||||
|
|
||||||
$this->populateRelated($name, $coll);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* populateRelated
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param Doctrine_Collection $coll
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function populateRelated($name, Doctrine_Collection $coll)
|
|
||||||
{
|
|
||||||
$rel = $this->_table->getRelation($name);
|
|
||||||
$table = $rel->getTable();
|
|
||||||
$foreign = $rel->getForeign();
|
|
||||||
$local = $rel->getLocal();
|
|
||||||
|
|
||||||
if ($rel instanceof Doctrine_Relation_LocalKey) {
|
|
||||||
foreach ($this->data as $key => $record) {
|
|
||||||
foreach ($coll as $k => $related) {
|
|
||||||
if ($related[$foreign] == $record[$local]) {
|
|
||||||
$this->data[$key]->setRelated($name, $related);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
|
|
||||||
foreach ($this->data as $key => $record) {
|
|
||||||
if ( ! $record->exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$sub = new Doctrine_Collection($table);
|
|
||||||
|
|
||||||
foreach ($coll as $k => $related) {
|
|
||||||
if ($related[$foreign] == $record[$local]) {
|
|
||||||
$sub->add($related);
|
|
||||||
$coll->remove($k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->data[$key]->setRelated($name, $sub);
|
|
||||||
}
|
|
||||||
} elseif ($rel instanceof Doctrine_Relation_Association) {
|
|
||||||
$identifier = $this->_table->getIdentifier();
|
|
||||||
$asf = $rel->getAssociationFactory();
|
|
||||||
$name = $table->getComponentName();
|
|
||||||
|
|
||||||
foreach ($this->data as $key => $record) {
|
|
||||||
if ( ! $record->exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$sub = new Doctrine_Collection($table);
|
|
||||||
foreach ($coll as $k => $related) {
|
|
||||||
if ($related->get($local) == $record[$identifier]) {
|
|
||||||
$sub->add($related->get($name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->data[$key]->setRelated($name, $sub);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getNormalIterator
|
|
||||||
* returns normal iterator - an iterator that will not expand this collection
|
|
||||||
*
|
|
||||||
* @return Doctrine_Iterator_Normal
|
|
||||||
*/
|
|
||||||
public function getNormalIterator()
|
|
||||||
{
|
|
||||||
return new Doctrine_Collection_Iterator_Normal($this);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* takeSnapshot
|
|
||||||
* takes a snapshot from this collection
|
|
||||||
*
|
|
||||||
* snapshots are used for diff processing, for example
|
|
||||||
* when a fetched collection has three elements, then two of those
|
|
||||||
* are being removed the diff would contain one element
|
|
||||||
*
|
|
||||||
* Doctrine_Collection::save() attaches the diff with the help of last
|
|
||||||
* snapshot.
|
|
||||||
*
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function takeSnapshot()
|
|
||||||
{
|
|
||||||
$this->_snapshot = $this->data;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getSnapshot
|
|
||||||
* returns the data of the last snapshot
|
|
||||||
*
|
|
||||||
* @return array returns the data in last snapshot
|
|
||||||
*/
|
|
||||||
public function getSnapshot()
|
|
||||||
{
|
|
||||||
return $this->_snapshot;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* processDiff
|
|
||||||
* processes the difference of the last snapshot and the current data
|
|
||||||
*
|
|
||||||
* an example:
|
|
||||||
* Snapshot with the objects 1, 2 and 4
|
|
||||||
* Current data with objects 2, 3 and 5
|
|
||||||
*
|
|
||||||
* The process would remove object 4
|
|
||||||
*
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function processDiff()
|
|
||||||
{
|
|
||||||
foreach (array_diff($this->_snapshot, $this->data) as $record) {
|
|
||||||
$record->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* toArray
|
|
||||||
* Mimics the result of a $query->execute(array(), Doctrine::FETCH_ARRAY);
|
|
||||||
*
|
|
||||||
* @param boolean $deep
|
|
||||||
*/
|
|
||||||
public function toArray($deep = false)
|
|
||||||
{
|
|
||||||
if ($deep) {
|
|
||||||
$data = array();
|
|
||||||
foreach ($this->data as $key => $record) {
|
|
||||||
$data[$key] = $record->toArray($deep);
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
} else {
|
|
||||||
// this is preserved for backwards compatibility
|
|
||||||
// but could be replaced with above code
|
|
||||||
return $this->data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function getDeleteDiff()
|
|
||||||
{
|
|
||||||
return array_diff($this->_snapshot, $this->data);
|
|
||||||
}
|
|
||||||
public function getInsertDiff()
|
|
||||||
{
|
|
||||||
return array_diff($this->data, $this->_snapshot);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* save
|
|
||||||
* saves all records of this collection and processes the
|
|
||||||
* difference of the last snapshot and the current data
|
|
||||||
*
|
|
||||||
* @param Doctrine_Connection $conn optional connection parameter
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function save(Doctrine_Connection $conn = null)
|
|
||||||
{
|
|
||||||
if ($conn == null) {
|
|
||||||
$conn = $this->_table->getConnection();
|
|
||||||
}
|
|
||||||
$conn->beginTransaction();
|
|
||||||
$conn->transaction->addCollection($this);
|
|
||||||
|
|
||||||
$this->processDiff();
|
|
||||||
|
|
||||||
foreach ($this->getData() as $key => $record) {
|
|
||||||
$record->save($conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn->commit();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* delete
|
|
||||||
* single shot delete
|
|
||||||
* deletes all records from this collection
|
|
||||||
* and uses only one database query to perform this operation
|
|
||||||
*
|
|
||||||
* @return Doctrine_Collection
|
|
||||||
*/
|
|
||||||
public function delete(Doctrine_Connection $conn = null)
|
|
||||||
{
|
|
||||||
if ($conn == null) {
|
|
||||||
$conn = $this->_table->getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn->beginTransaction();
|
|
||||||
$conn->transaction->addCollection($this);
|
|
||||||
|
|
||||||
foreach ($this as $key => $record) {
|
|
||||||
$record->delete($conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn->commit();
|
|
||||||
|
|
||||||
$this->data = array();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getIterator
|
|
||||||
* @return object ArrayIterator
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
$data = $this->data;
|
|
||||||
return new ArrayIterator($data);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns a string representation of this object
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return Doctrine_Lib::getCollectionAsString($this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection_Exception extends Doctrine_Exception
|
|
||||||
{ }
|
|
@ -1,111 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Iterator.php 1323 2007-05-10 23:46:09Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Iterator
|
|
||||||
* iterates through Doctrine_Collection
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1323 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
abstract class Doctrine_Collection_Iterator implements Iterator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Collection $collection
|
|
||||||
*/
|
|
||||||
protected $collection;
|
|
||||||
/**
|
|
||||||
* @var array $keys
|
|
||||||
*/
|
|
||||||
protected $keys;
|
|
||||||
/**
|
|
||||||
* @var mixed $key
|
|
||||||
*/
|
|
||||||
protected $key;
|
|
||||||
/**
|
|
||||||
* @var integer $index
|
|
||||||
*/
|
|
||||||
protected $index;
|
|
||||||
/**
|
|
||||||
* @var integer $count
|
|
||||||
*/
|
|
||||||
protected $count;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
* @var Doctrine_Collection $collection
|
|
||||||
*/
|
|
||||||
public function __construct($collection)
|
|
||||||
{
|
|
||||||
$this->collection = $collection;
|
|
||||||
$this->keys = $this->collection->getKeys();
|
|
||||||
$this->count = $this->collection->count();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* rewinds the iterator
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
$this->index = 0;
|
|
||||||
$i = $this->index;
|
|
||||||
if (isset($this->keys[$i])) {
|
|
||||||
$this->key = $this->keys[$i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the current key
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->key;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns the current record
|
|
||||||
*
|
|
||||||
* @return Doctrine_Record
|
|
||||||
*/
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
return $this->collection->get($this->key);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* advances the internal pointer
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
$this->index++;
|
|
||||||
$i = $this->index;
|
|
||||||
if (isset($this->keys[$i])) {
|
|
||||||
$this->key = $this->keys[$i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Expandable.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Collection_Iterator');
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Iterator_Normal
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator
|
|
||||||
{
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
if ($this->index < $this->count) {
|
|
||||||
return true;
|
|
||||||
} elseif ($this->index == $this->count) {
|
|
||||||
$coll = $this->collection->expand($this->index);
|
|
||||||
|
|
||||||
if ($coll instanceof Doctrine_Collection) {
|
|
||||||
$count = count($coll);
|
|
||||||
if ($count > 0) {
|
|
||||||
$this->keys = array_merge($this->keys, $coll->getKeys());
|
|
||||||
$this->count += $count;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Normal.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Collection_Iterator');
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Iterator_Normal
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return boolean whether or not the iteration will continue
|
|
||||||
*/
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
return ($this->index < $this->count);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Offset.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Collection_Iterator');
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Iterator_Normal
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator
|
|
||||||
{
|
|
||||||
public function valid()
|
|
||||||
{ }
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Offset.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Collection_Offset');
|
|
||||||
/**
|
|
||||||
* Doctrine_Collection_Offset
|
|
||||||
* Collection of Doctrine_Record objects.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Collection_Offset extends Doctrine_Collection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var integer $limit
|
|
||||||
*/
|
|
||||||
private $limit;
|
|
||||||
/**
|
|
||||||
* @param Doctrine_Table $table
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Table $table)
|
|
||||||
{
|
|
||||||
parent::__construct($table);
|
|
||||||
$this->limit = $table->getAttribute(Doctrine::ATTR_COLL_LIMIT);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function getLimit()
|
|
||||||
{
|
|
||||||
return $this->limit;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return Doctrine_Collection_Iterator_Expandable
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new Doctrine_Collection_Iterator_Expandable($this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Column.php 1392 2007-05-19 17:29:43Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Column
|
|
||||||
* This class represents a database column
|
|
||||||
*
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @version $Revision: 1392 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Countable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $definition
|
|
||||||
*/
|
|
||||||
protected $_definition = array(
|
|
||||||
'type' => null,
|
|
||||||
'length' => 0,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* @var array $definition
|
|
||||||
*/
|
|
||||||
public function __construct(array $definition = array())
|
|
||||||
{
|
|
||||||
$this->_definition = $definition;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getDefinition()
|
|
||||||
{
|
|
||||||
return $this->_definition;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* contains
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function contains($name)
|
|
||||||
{
|
|
||||||
return isset($this->_definition[$name]);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* get
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function get($name)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->_definition[$name])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_definition[$name];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* set
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function set($name, $value)
|
|
||||||
{
|
|
||||||
$this->_definition[$name] = $value;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param string $field
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getEnumValues()
|
|
||||||
{
|
|
||||||
if (isset($this->_definition['values'])) {
|
|
||||||
return $this->_definition['values'];
|
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* enumValue
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param integer $index
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function enumValue($index)
|
|
||||||
{
|
|
||||||
if ($index instanceof Doctrine_Null) {
|
|
||||||
return $index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isset($this->_definition['values'][$index]) ? $this->_definition['values'][$index] : $index;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* enumIndex
|
|
||||||
*
|
|
||||||
* @param string $field
|
|
||||||
* @param mixed $value
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function enumIndex($field, $value)
|
|
||||||
{
|
|
||||||
$values = $this->getEnumValues($field);
|
|
||||||
|
|
||||||
return array_search($value, $values);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->_definition);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getIterator
|
|
||||||
*
|
|
||||||
* @return ArrayIterator
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->_definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Compiler.php 1768 2007-06-19 22:55:34Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Compiler
|
|
||||||
* This class can be used for compiling the entire Doctrine framework into a single file
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1768 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Compiler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* method for making a single file of most used doctrine runtime components
|
|
||||||
* including the compiled file instead of multiple files (in worst
|
|
||||||
* cases dozens of files) can improve performance by an order of magnitude
|
|
||||||
*
|
|
||||||
* @throws Doctrine_Compiler_Exception if something went wrong during the compile operation
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function compile($target = null)
|
|
||||||
{
|
|
||||||
$path = Doctrine::getPath();
|
|
||||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY);
|
|
||||||
|
|
||||||
foreach ($it as $file) {
|
|
||||||
$e = explode('.', $file->getFileName());
|
|
||||||
|
|
||||||
// we don't want to require versioning files
|
|
||||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
|
||||||
require_once $file->getPathName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array_merge(get_declared_classes(), get_declared_interfaces());
|
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
foreach ($classes as $class) {
|
|
||||||
$e = explode('_', $class);
|
|
||||||
|
|
||||||
if ($e[0] !== 'Doctrine') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$refl = new ReflectionClass($class);
|
|
||||||
$file = $refl->getFileName();
|
|
||||||
|
|
||||||
print 'Adding ' . $file . PHP_EOL;
|
|
||||||
|
|
||||||
$lines = file($file);
|
|
||||||
|
|
||||||
$start = $refl->getStartLine() - 1;
|
|
||||||
$end = $refl->getEndLine();
|
|
||||||
|
|
||||||
$ret = array_merge($ret, array_slice($lines, $start, ($end - $start)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($target == null) {
|
|
||||||
$target = $path . DIRECTORY_SEPARATOR . 'Doctrine.compiled.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
// first write the 'compiled' data to a text file, so
|
|
||||||
// that we can use php_strip_whitespace (which only works on files)
|
|
||||||
$fp = @fopen($target, 'w');
|
|
||||||
|
|
||||||
if ($fp === false) {
|
|
||||||
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
|
|
||||||
}
|
|
||||||
fwrite($fp, "<?php ". implode('', $ret));
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
$stripped = php_strip_whitespace($target);
|
|
||||||
$fp = @fopen($target, 'w');
|
|
||||||
if ($fp === false) {
|
|
||||||
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
|
|
||||||
}
|
|
||||||
fwrite($fp, $stripped);
|
|
||||||
fclose($fp);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Compiler_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Compiler_Exception extends Doctrine_Exception
|
|
||||||
{ }
|
|
@ -1,363 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Configurable.php 2153 2007-08-03 11:52:24Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Configurable
|
|
||||||
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 2153 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
abstract class Doctrine_Configurable extends Doctrine_Object
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $attributes an array of containing all attributes
|
|
||||||
*/
|
|
||||||
protected $attributes = array();
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Configurable $parent the parent of this component
|
|
||||||
*/
|
|
||||||
protected $parent;
|
|
||||||
/**
|
|
||||||
* @var array $_impl an array containing concrete implementations for class templates
|
|
||||||
* keys as template names and values as names of the concrete
|
|
||||||
* implementation classes
|
|
||||||
*/
|
|
||||||
protected $_impl = array();
|
|
||||||
/**
|
|
||||||
* setAttribute
|
|
||||||
* sets a given attribute
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* $manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL);
|
|
||||||
*
|
|
||||||
* // or
|
|
||||||
*
|
|
||||||
* $manager->setAttribute('portability', Doctrine::PORTABILITY_ALL);
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param mixed $attribute either a Doctrine::ATTR_* integer constant or a string
|
|
||||||
* corresponding to a constant
|
|
||||||
* @param mixed $value the value of the attribute
|
|
||||||
* @see Doctrine::ATTR_* constants
|
|
||||||
* @throws Doctrine_Exception if the value is invalid
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setAttribute($attribute,$value)
|
|
||||||
{
|
|
||||||
if (is_string($attribute)) {
|
|
||||||
$upper = strtoupper($attribute);
|
|
||||||
|
|
||||||
$const = 'Doctrine::ATTR_' . $attribute;
|
|
||||||
if (defined($const)) {
|
|
||||||
$this->_state = constant($const);
|
|
||||||
} else {
|
|
||||||
throw new Doctrine_Exception('Unknown attribute ' . $attribute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch ($attribute) {
|
|
||||||
case Doctrine::ATTR_FETCHMODE:
|
|
||||||
if ($value < 0) {
|
|
||||||
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_LISTENER:
|
|
||||||
$this->setEventListener($value);
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_LOCKMODE:
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_CREATE_TABLES:
|
|
||||||
throw new Doctrine_Exception("ATTR_CREATE_TABLES has been deprecated. See exporting in the first chapter of the manual.");
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_ACCESSORS:
|
|
||||||
throw new Doctrine_Exception("Get / Set filtering is deprecated (slowed down Doctrine too much).");
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_COLL_LIMIT:
|
|
||||||
if ($value < 1) {
|
|
||||||
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_COLL_KEY:
|
|
||||||
if ( ! ($this instanceof Doctrine_Table)) {
|
|
||||||
throw new Doctrine_Exception("This attribute can only be set at table level.");
|
|
||||||
}
|
|
||||||
if ($value !== null && ! $this->hasColumn($value)) {
|
|
||||||
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_CACHE:
|
|
||||||
if ($value !== null) {
|
|
||||||
if ( ! ($value instanceof Doctrine_Cache_Interface)) {
|
|
||||||
throw new Doctrine_Exception('Cache driver should implement Doctrine_Cache_Interface');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_VLD:
|
|
||||||
case Doctrine::ATTR_AUTO_LENGTH_VLD:
|
|
||||||
case Doctrine::ATTR_AUTO_TYPE_VLD:
|
|
||||||
case Doctrine::ATTR_QUERY_LIMIT:
|
|
||||||
case Doctrine::ATTR_QUOTE_IDENTIFIER:
|
|
||||||
case Doctrine::ATTR_PORTABILITY:
|
|
||||||
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
|
|
||||||
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
|
|
||||||
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
|
|
||||||
case Doctrine::ATTR_EMULATE_DATABASE:
|
|
||||||
case Doctrine::ATTR_DEFAULT_SEQUENCE:
|
|
||||||
case Doctrine::ATTR_EXPORT:
|
|
||||||
case Doctrine::ATTR_DECIMAL_PLACES:
|
|
||||||
case Doctrine::ATTR_LOAD_REFERENCES:
|
|
||||||
case Doctrine::ATTR_RECORD_LISTENER:
|
|
||||||
case Doctrine::ATTR_THROW_EXCEPTIONS:
|
|
||||||
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_SEQCOL_NAME:
|
|
||||||
if ( ! is_string($value)) {
|
|
||||||
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_FIELD_CASE:
|
|
||||||
if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
|
|
||||||
throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.');
|
|
||||||
break;
|
|
||||||
case Doctrine::ATTR_SEQNAME_FORMAT:
|
|
||||||
case Doctrine::ATTR_IDXNAME_FORMAT:
|
|
||||||
if ($this instanceof Doctrine_Table) {
|
|
||||||
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
|
|
||||||
. 'at table level (only at connection or global level).');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Exception("Unknown attribute.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->attributes[$attribute] = $value;
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setImpl
|
|
||||||
* binds given class to given template name
|
|
||||||
*
|
|
||||||
* this method is the base of Doctrine dependency injection
|
|
||||||
*
|
|
||||||
* @param string $template name of the class template
|
|
||||||
* @param string $class name of the class to be bound
|
|
||||||
* @return Doctrine_Configurable this object
|
|
||||||
*/
|
|
||||||
public function setImpl($template, $class)
|
|
||||||
{
|
|
||||||
$this->_impl[$template] = $class;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getImpl
|
|
||||||
* returns the implementation for given class
|
|
||||||
*
|
|
||||||
* @return string name of the concrete implementation
|
|
||||||
*/
|
|
||||||
public function getImpl($template)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->_impl[$template])) {
|
|
||||||
if (isset($this->parent)) {
|
|
||||||
return $this->parent->getImpl($template);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->_impl[$template];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getCacheDriver
|
|
||||||
*
|
|
||||||
* @return Doctrine_Cache_Interface
|
|
||||||
*/
|
|
||||||
public function getCacheDriver()
|
|
||||||
{
|
|
||||||
if ( ! isset($this->attributes[Doctrine::ATTR_CACHE])) {
|
|
||||||
throw new Doctrine_Exception('Cache driver not initialized.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->attributes[Doctrine::ATTR_CACHE];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @param Doctrine_EventListener $listener
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setEventListener($listener)
|
|
||||||
{
|
|
||||||
return $this->setListener($listener);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* addRecordListener
|
|
||||||
*
|
|
||||||
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
|
|
||||||
* @return mixed this object
|
|
||||||
*/
|
|
||||||
public function addRecordListener($listener, $name = null)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->attributes[Doctrine::ATTR_RECORD_LISTENER]) ||
|
|
||||||
! ($this->attributes[Doctrine::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) {
|
|
||||||
|
|
||||||
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain();
|
|
||||||
}
|
|
||||||
$this->attributes[Doctrine::ATTR_RECORD_LISTENER]->add($listener, $name);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getListener
|
|
||||||
*
|
|
||||||
* @return Doctrine_EventListener_Interface|Doctrine_Overloadable
|
|
||||||
*/
|
|
||||||
public function getRecordListener()
|
|
||||||
{
|
|
||||||
if ( ! isset($this->attributes[Doctrine::ATTR_RECORD_LISTENER])) {
|
|
||||||
if (isset($this->parent)) {
|
|
||||||
return $this->parent->getRecordListener();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->attributes[Doctrine::ATTR_RECORD_LISTENER];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setListener
|
|
||||||
*
|
|
||||||
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
|
|
||||||
* @return Doctrine_Configurable this object
|
|
||||||
*/
|
|
||||||
public function setRecordListener($listener)
|
|
||||||
{
|
|
||||||
if ( ! ($listener instanceof Doctrine_Record_Listener_Interface)
|
|
||||||
&& ! ($listener instanceof Doctrine_Overloadable)
|
|
||||||
) {
|
|
||||||
throw new Doctrine_Exception("Couldn't set eventlistener. Record listeners should implement either Doctrine_Record_Listener_Interface or Doctrine_Overloadable");
|
|
||||||
}
|
|
||||||
$this->attributes[Doctrine::ATTR_RECORD_LISTENER] = $listener;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* addListener
|
|
||||||
*
|
|
||||||
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
|
|
||||||
* @return mixed this object
|
|
||||||
*/
|
|
||||||
public function addListener($listener, $name = null)
|
|
||||||
{
|
|
||||||
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER]) ||
|
|
||||||
! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
|
|
||||||
|
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
|
|
||||||
}
|
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getListener
|
|
||||||
*
|
|
||||||
* @return Doctrine_EventListener_Interface|Doctrine_Overloadable
|
|
||||||
*/
|
|
||||||
public function getListener()
|
|
||||||
{
|
|
||||||
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
|
|
||||||
if (isset($this->parent)) {
|
|
||||||
return $this->parent->getListener();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->attributes[Doctrine::ATTR_LISTENER];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setListener
|
|
||||||
*
|
|
||||||
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
|
|
||||||
* @return Doctrine_Configurable this object
|
|
||||||
*/
|
|
||||||
public function setListener($listener)
|
|
||||||
{
|
|
||||||
if ( ! ($listener instanceof Doctrine_EventListener_Interface)
|
|
||||||
&& ! ($listener instanceof Doctrine_Overloadable)
|
|
||||||
) {
|
|
||||||
throw new Doctrine_EventListener_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
|
|
||||||
}
|
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns the value of an attribute
|
|
||||||
*
|
|
||||||
* @param integer $attribute
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getAttribute($attribute)
|
|
||||||
{
|
|
||||||
$attribute = (int) $attribute;
|
|
||||||
|
|
||||||
if ($attribute < 0) {
|
|
||||||
throw new Doctrine_Exception('Unknown attribute.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! isset($this->attributes[$attribute])) {
|
|
||||||
if (isset($this->parent)) {
|
|
||||||
return $this->parent->getAttribute($attribute);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $this->attributes[$attribute];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getAttributes
|
|
||||||
* returns all attributes as an array
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getAttributes()
|
|
||||||
{
|
|
||||||
return $this->attributes;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* sets a parent for this configurable component
|
|
||||||
* the parent must be configurable component itself
|
|
||||||
*
|
|
||||||
* @param Doctrine_Configurable $component
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setParent(Doctrine_Configurable $component)
|
|
||||||
{
|
|
||||||
$this->parent = $component;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getParent
|
|
||||||
* returns the parent of this component
|
|
||||||
*
|
|
||||||
* @return Doctrine_Configurable
|
|
||||||
*/
|
|
||||||
public function getParent()
|
|
||||||
{
|
|
||||||
return $this->parent;
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Common.php 1794 2007-06-24 20:11:41Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* standard connection, the parent of pgsql, mysql and sqlite
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1794 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Common extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
|
||||||
*
|
|
||||||
* @param string $query
|
|
||||||
* @param mixed $limit
|
|
||||||
* @param mixed $offset
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit = false,$offset = false,$isManip=false)
|
|
||||||
{
|
|
||||||
$limit = (int) $limit;
|
|
||||||
$offset = (int) $offset;
|
|
||||||
|
|
||||||
if ($limit && $offset) {
|
|
||||||
$query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
|
|
||||||
} elseif ($limit && ! $offset) {
|
|
||||||
$query .= ' LIMIT ' . $limit;
|
|
||||||
} elseif ( ! $limit && $offset) {
|
|
||||||
$query .= ' LIMIT 999999999999 OFFSET ' . $offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Db2.php 1181 2007-03-20 23:22:51Z gnat $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Db2
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1181 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Db2 extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
|
||||||
*
|
|
||||||
* @param string $query query to modify
|
|
||||||
* @param integer $limit limit the number of rows
|
|
||||||
* @param integer $offset start reading from given offset
|
|
||||||
* @return string the modified query
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit, $offset)
|
|
||||||
{
|
|
||||||
if ($limit <= 0)
|
|
||||||
return $query;
|
|
||||||
|
|
||||||
if ($offset == 0) {
|
|
||||||
return $query . ' FETCH FIRST '. $limit .' ROWS ONLY';
|
|
||||||
} else {
|
|
||||||
$sqlPieces = explode('from', $query);
|
|
||||||
$select = $sqlPieces[0];
|
|
||||||
$table = $sqlPieces[1];
|
|
||||||
|
|
||||||
$col = explode('select', $select);
|
|
||||||
|
|
||||||
$sql = 'WITH OFFSET AS(' . $select . ', ROW_NUMBER() ' .
|
|
||||||
'OVER(ORDER BY ' . $col[1] . ') AS dctrn_rownum FROM ' . $table . ')' .
|
|
||||||
$select . 'FROM OFFSET WHERE dctrn_rownum BETWEEN ' . $offset .
|
|
||||||
'AND ' . ($offset + $limit - 1);
|
|
||||||
return $sql;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1345 2007-05-14 13:00:14Z meus $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1345 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Exception extends Doctrine_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorMessages an array containing messages for portable error codes
|
|
||||||
*/
|
|
||||||
static protected $errorMessages = array(
|
|
||||||
Doctrine::ERR => 'unknown error',
|
|
||||||
Doctrine::ERR_ALREADY_EXISTS => 'already exists',
|
|
||||||
Doctrine::ERR_CANNOT_CREATE => 'can not create',
|
|
||||||
Doctrine::ERR_CANNOT_ALTER => 'can not alter',
|
|
||||||
Doctrine::ERR_CANNOT_REPLACE => 'can not replace',
|
|
||||||
Doctrine::ERR_CANNOT_DELETE => 'can not delete',
|
|
||||||
Doctrine::ERR_CANNOT_DROP => 'can not drop',
|
|
||||||
Doctrine::ERR_CONSTRAINT => 'constraint violation',
|
|
||||||
Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
|
|
||||||
Doctrine::ERR_DIVZERO => 'division by zero',
|
|
||||||
Doctrine::ERR_INVALID => 'invalid',
|
|
||||||
Doctrine::ERR_INVALID_DATE => 'invalid date or time',
|
|
||||||
Doctrine::ERR_INVALID_NUMBER => 'invalid number',
|
|
||||||
Doctrine::ERR_MISMATCH => 'mismatch',
|
|
||||||
Doctrine::ERR_NODBSELECTED => 'no database selected',
|
|
||||||
Doctrine::ERR_NOSUCHFIELD => 'no such field',
|
|
||||||
Doctrine::ERR_NOSUCHTABLE => 'no such table',
|
|
||||||
Doctrine::ERR_NOT_CAPABLE => 'Doctrine backend not capable',
|
|
||||||
Doctrine::ERR_NOT_FOUND => 'not found',
|
|
||||||
Doctrine::ERR_NOT_LOCKED => 'not locked',
|
|
||||||
Doctrine::ERR_SYNTAX => 'syntax error',
|
|
||||||
Doctrine::ERR_UNSUPPORTED => 'not supported',
|
|
||||||
Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row',
|
|
||||||
Doctrine::ERR_INVALID_DSN => 'invalid DSN',
|
|
||||||
Doctrine::ERR_CONNECT_FAILED => 'connect failed',
|
|
||||||
Doctrine::ERR_NEED_MORE_DATA => 'insufficient data supplied',
|
|
||||||
Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found',
|
|
||||||
Doctrine::ERR_NOSUCHDB => 'no such database',
|
|
||||||
Doctrine::ERR_ACCESS_VIOLATION => 'insufficient permissions',
|
|
||||||
Doctrine::ERR_LOADMODULE => 'error while including on demand module',
|
|
||||||
Doctrine::ERR_TRUNCATED => 'truncated',
|
|
||||||
Doctrine::ERR_DEADLOCK => 'deadlock detected',
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* @see Doctrine::ERR_* constants
|
|
||||||
* @since 1.0
|
|
||||||
* @var integer $portableCode portable error code
|
|
||||||
*/
|
|
||||||
protected $portableCode;
|
|
||||||
/**
|
|
||||||
* getPortableCode
|
|
||||||
* returns portable error code
|
|
||||||
*
|
|
||||||
* @return integer portable error code
|
|
||||||
*/
|
|
||||||
public function getPortableCode()
|
|
||||||
{
|
|
||||||
return $this->portableCode;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getPortableMessage
|
|
||||||
* returns portable error message
|
|
||||||
*
|
|
||||||
* @return string portable error message
|
|
||||||
*/
|
|
||||||
public function getPortableMessage()
|
|
||||||
{
|
|
||||||
return self::errorMessage($this->portableCode);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Return a textual error message for a Doctrine error code
|
|
||||||
*
|
|
||||||
* @param int|array integer error code,
|
|
||||||
* null to get the current error code-message map,
|
|
||||||
* or an array with a new error code-message map
|
|
||||||
*
|
|
||||||
* @return string error message, or false if the error code was
|
|
||||||
* not recognized
|
|
||||||
*/
|
|
||||||
public function errorMessage($value = null)
|
|
||||||
{
|
|
||||||
return isset(self::$errorMessages[$value]) ?
|
|
||||||
self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Firebird.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Firebird
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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)
|
|
||||||
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Firebird extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Firebird';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO $pdo database handle
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => true,
|
|
||||||
'indexes' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'savepoints' => true,
|
|
||||||
'current_id' => true,
|
|
||||||
'limit_queries' => 'emulated',
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => 'emulated',
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => true,
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => true,
|
|
||||||
'prepared_statements' => true,
|
|
||||||
'identifier_quoting' => false,
|
|
||||||
'pattern_escaping' => true
|
|
||||||
);
|
|
||||||
// initialize all driver options
|
|
||||||
/**
|
|
||||||
$this->options['DBA_username'] = false;
|
|
||||||
$this->options['DBA_password'] = false;
|
|
||||||
$this->options['database_path'] = '';
|
|
||||||
$this->options['database_extension'] = '.gdb';
|
|
||||||
$this->options['server_version'] = '';
|
|
||||||
*/
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the charset on the current connection
|
|
||||||
*
|
|
||||||
* @param string charset
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setCharset($charset)
|
|
||||||
{
|
|
||||||
$query = 'SET NAMES '.$this->dbh->quote($charset);
|
|
||||||
$this->exec($query);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
|
||||||
*
|
|
||||||
* @param string $query query to modify
|
|
||||||
* @param integer $limit limit the number of rows
|
|
||||||
* @param integer $offset start reading from given offset
|
|
||||||
* @return string modified query
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit, $offset)
|
|
||||||
{
|
|
||||||
if ($limit > 0) {
|
|
||||||
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
|
|
||||||
"SELECT FIRST $limit SKIP $offset", $query);
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Firebird_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
|
|
||||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorCodeMap an array that is used for determining portable
|
|
||||||
* error code from a native database error code
|
|
||||||
*/
|
|
||||||
protected static $errorCodeMap = array(
|
|
||||||
-104 => Doctrine::ERR_SYNTAX,
|
|
||||||
-150 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
-151 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
-155 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
-157 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
-158 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
-170 => Doctrine::ERR_MISMATCH,
|
|
||||||
-171 => Doctrine::ERR_MISMATCH,
|
|
||||||
-172 => Doctrine::ERR_INVALID,
|
|
||||||
// -204 => // Covers too many errors, need to use regex on msg
|
|
||||||
-205 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
-206 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
-208 => Doctrine::ERR_INVALID,
|
|
||||||
-219 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
-297 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
-303 => Doctrine::ERR_INVALID,
|
|
||||||
-413 => Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
-530 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
-551 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
-552 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
// -607 => // Covers too many errors, need to use regex on msg
|
|
||||||
-625 => Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
-803 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
-804 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
-904 => Doctrine::ERR_CONNECT_FAILED,
|
|
||||||
-922 => Doctrine::ERR_NOSUCHDB,
|
|
||||||
-923 => Doctrine::ERR_CONNECT_FAILED,
|
|
||||||
-924 => Doctrine::ERR_CONNECT_FAILED
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* @var array $errorRegexps an array that is used for determining portable
|
|
||||||
* error code from a native database error message
|
|
||||||
*/
|
|
||||||
protected static $errorRegexps = array(
|
|
||||||
'/generator .* is not defined/'
|
|
||||||
=> Doctrine::ERR_SYNTAX, // for compat. w ibase_errcode()
|
|
||||||
'/table.*(not exist|not found|unknown)/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
'/table .* already exists/i'
|
|
||||||
=> Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
'/unsuccessful metadata update .* failed attempt to store duplicate value/i'
|
|
||||||
=> Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
'/unsuccessful metadata update .* not found/i'
|
|
||||||
=> Doctrine::ERR_NOT_FOUND,
|
|
||||||
'/validation error for column .* value "\*\*\* null/i'
|
|
||||||
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/violation of [\w ]+ constraint/i'
|
|
||||||
=> Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/conversion error from string/i'
|
|
||||||
=> Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
'/no permission for/i'
|
|
||||||
=> Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
'/arithmetic exception, numeric overflow, or string truncation/i'
|
|
||||||
=> Doctrine::ERR_INVALID,
|
|
||||||
'/table unknown/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to errorInfo array and returns the modified array
|
|
||||||
*
|
|
||||||
* the portable error code is added at the end of array
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
// todo: are the following lines needed?
|
|
||||||
// memo for the interbase php module hackers: we need something similar
|
|
||||||
// to mysql_errno() to retrieve error codes instead of this ugly hack
|
|
||||||
if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_msg, $m)) {
|
|
||||||
$native_code = (int)$m[2];
|
|
||||||
} else {
|
|
||||||
$native_code = null;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
foreach (self::$errorRegexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errorInfo[2])) {
|
|
||||||
$errorInfo[3] = $code;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset(self::$errorCodeMap[$errorInfo[1]])) {
|
|
||||||
$errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
|
|
||||||
}
|
|
||||||
return $errorInfo;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Informix.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mysql
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Informix extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Informix';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO $pdo database handle
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
// initialize all driver options
|
|
||||||
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Informix_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Informix_Exception extends Doctrine_Connection_Exception
|
|
||||||
{ }
|
|
@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mock.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Common');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mysql
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Mock extends Doctrine_Connection_Common
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Mock';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO|Doctrine_Adapter $adapter database handler
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Module.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Module
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Module
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Doctrine_Connection $conn Doctrine_Connection object, every connection
|
|
||||||
* module holds an instance of Doctrine_Connection
|
|
||||||
*/
|
|
||||||
protected $conn;
|
|
||||||
/**
|
|
||||||
* @var string $moduleName the name of this module
|
|
||||||
*/
|
|
||||||
protected $moduleName;
|
|
||||||
/**
|
|
||||||
* @param Doctrine_Connection $conn Doctrine_Connection object, every connection
|
|
||||||
* module holds an instance of Doctrine_Connection
|
|
||||||
*/
|
|
||||||
public function __construct($conn = null)
|
|
||||||
{
|
|
||||||
if ( ! ($conn instanceof Doctrine_Connection)) {
|
|
||||||
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
|
|
||||||
}
|
|
||||||
$this->conn = $conn;
|
|
||||||
|
|
||||||
$e = explode('_', get_class($this));
|
|
||||||
|
|
||||||
$this->moduleName = $e[1];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getConnection
|
|
||||||
* returns the connection object this module uses
|
|
||||||
*
|
|
||||||
* @return Doctrine_Connection
|
|
||||||
*/
|
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->conn;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getModuleName
|
|
||||||
* returns the name of this module
|
|
||||||
*
|
|
||||||
* @return string the name of this module
|
|
||||||
*/
|
|
||||||
public function getModuleName()
|
|
||||||
{
|
|
||||||
return $this->moduleName;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,189 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mssql.php 1178 2007-03-18 20:00:45Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mssql
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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: 1178 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Mssql extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Mssql';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO $pdo database handle
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
// initialize all driver options
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => 'emulated',
|
|
||||||
'indexes' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'current_id' => 'emulated',
|
|
||||||
'limit_queries' => 'emulated',
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => 'emulated',
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => true,
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => true,
|
|
||||||
'prepared_statements' => 'emulated',
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* quoteIdentifier
|
|
||||||
* Quote a string so it can be safely used as a table / column name
|
|
||||||
*
|
|
||||||
* Quoting style depends on which database driver is being used.
|
|
||||||
*
|
|
||||||
* @param string $identifier identifier name to be quoted
|
|
||||||
* @param bool $checkOption check the 'quote_identifier' option
|
|
||||||
*
|
|
||||||
* @return string quoted identifier string
|
|
||||||
*/
|
|
||||||
public function quoteIdentifier($identifier, $checkOption = false)
|
|
||||||
{
|
|
||||||
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
|
|
||||||
return $identifier;
|
|
||||||
}
|
|
||||||
return '[' . str_replace(']', ']]', $identifier) . ']';
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds an adapter-specific LIMIT clause to the SELECT statement.
|
|
||||||
* [ borrowed from Zend Framework ]
|
|
||||||
*
|
|
||||||
* @param string $query
|
|
||||||
* @param mixed $limit
|
|
||||||
* @param mixed $offset
|
|
||||||
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit, $offset, $isManip = false)
|
|
||||||
{
|
|
||||||
if ($limit > 0) {
|
|
||||||
$count = intval($limit);
|
|
||||||
|
|
||||||
$offset = intval($offset);
|
|
||||||
if ($offset < 0) {
|
|
||||||
throw new Doctrine_Connection_Exception("LIMIT argument offset=$offset is not valid");
|
|
||||||
}
|
|
||||||
|
|
||||||
$orderby = stristr($query, 'ORDER BY');
|
|
||||||
if ($orderby !== false) {
|
|
||||||
$sort = (stripos($orderby, 'desc') !== false) ? 'desc' : 'asc';
|
|
||||||
$order = str_ireplace('ORDER BY', '', $orderby);
|
|
||||||
$order = trim(preg_replace('/ASC|DESC/i', '', $order));
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count+$offset) . ' ', $query);
|
|
||||||
|
|
||||||
$query = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $query . ') AS inner_tbl';
|
|
||||||
if ($orderby !== false) {
|
|
||||||
$query .= ' ORDER BY ' . $order . ' ';
|
|
||||||
$query .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
|
|
||||||
}
|
|
||||||
$query .= ') AS outer_tbl';
|
|
||||||
if ($orderby !== false) {
|
|
||||||
$query .= ' ORDER BY ' . $order . ' ' . $sort;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return version information about the server
|
|
||||||
*
|
|
||||||
* @param bool $native determines if the raw version string should be returned
|
|
||||||
* @return mixed array/string with version information or MDB2 error object
|
|
||||||
*/
|
|
||||||
public function getServerVersion($native = false)
|
|
||||||
{
|
|
||||||
if ($this->serverInfo) {
|
|
||||||
$serverInfo = $this->serverInfo;
|
|
||||||
} else {
|
|
||||||
$query = 'SELECT @@VERSION';
|
|
||||||
$serverInfo = $this->fetchOne($query);
|
|
||||||
}
|
|
||||||
// cache server_info
|
|
||||||
$this->serverInfo = $serverInfo;
|
|
||||||
if ( ! $native) {
|
|
||||||
if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $serverInfo, $tmp)) {
|
|
||||||
$serverInfo = array(
|
|
||||||
'major' => $tmp[1],
|
|
||||||
'minor' => $tmp[2],
|
|
||||||
'patch' => $tmp[3],
|
|
||||||
'extra' => null,
|
|
||||||
'native' => $serverInfo,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$serverInfo = array(
|
|
||||||
'major' => null,
|
|
||||||
'minor' => null,
|
|
||||||
'patch' => null,
|
|
||||||
'extra' => null,
|
|
||||||
'native' => $serverInfo,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $serverInfo;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Checks if there's a sequence that exists.
|
|
||||||
*
|
|
||||||
* @param string $seq_name The sequence name to verify.
|
|
||||||
* @return boolean The value if the table exists or not
|
|
||||||
*/
|
|
||||||
public function checkSequence($seqName)
|
|
||||||
{
|
|
||||||
$query = 'SELECT * FROM ' . $seqName;
|
|
||||||
try {
|
|
||||||
$this->exec($query);
|
|
||||||
} catch(Doctrine_Connection_Exception $e) {
|
|
||||||
if ($e->getPortableCode() == Doctrine::ERR_NOSUCHTABLE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mssql_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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)
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorCodeMap an array that is used for determining portable
|
|
||||||
* error code from a native database error code
|
|
||||||
*/
|
|
||||||
protected static $errorCodeMap = array(
|
|
||||||
110 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
155 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
170 => Doctrine::ERR_SYNTAX,
|
|
||||||
207 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
208 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
245 => Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
515 => Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
547 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
1913 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
2627 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
2714 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
3701 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
8134 => Doctrine::ERR_DIVZERO,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to $portableCode field
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @return boolean whether or not the error info processing was successfull
|
|
||||||
* (the process is successfull if portable error code was found)
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
$code = $errorInfo[1];
|
|
||||||
if (isset(self::$errorCodeMap[$code])) {
|
|
||||||
$this->portableCode = self::$errorCodeMap[$code];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,207 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Mysql.php 1773 2007-06-19 23:33:04Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Common');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mysql
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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: 1773 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Mysql';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO|Doctrine_Adapter $adapter database handler
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
$this->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
|
||||||
$this->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
|
|
||||||
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => 'emulated',
|
|
||||||
'indexes' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'savepoints' => false,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'current_id' => 'emulated',
|
|
||||||
'limit_queries' => true,
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => true,
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => true,
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => true,
|
|
||||||
'prepared_statements' => 'emulated',
|
|
||||||
'identifier_quoting' => true,
|
|
||||||
'pattern_escaping' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->properties['string_quoting'] = array('start' => "'",
|
|
||||||
'end' => "'",
|
|
||||||
'escape' => '\\',
|
|
||||||
'escape_pattern' => '\\');
|
|
||||||
|
|
||||||
$this->properties['identifier_quoting'] = array('start' => '`',
|
|
||||||
'end' => '`',
|
|
||||||
'escape' => '`');
|
|
||||||
|
|
||||||
$this->properties['sql_comments'] = array(
|
|
||||||
array('start' => '-- ', 'end' => "\n", 'escape' => false),
|
|
||||||
array('start' => '#', 'end' => "\n", 'escape' => false),
|
|
||||||
array('start' => '/*', 'end' => '*/', 'escape' => false),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->properties['varchar_max_length'] = 255;
|
|
||||||
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the charset on the current connection
|
|
||||||
*
|
|
||||||
* @param string charset
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setCharset($charset)
|
|
||||||
{
|
|
||||||
$query = 'SET NAMES '.$this->dbh->quote($charset);
|
|
||||||
$this->exec($query);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
|
|
||||||
* query, except that if there is already a row in the table with the same
|
|
||||||
* key field values, the REPLACE query just updates its values instead of
|
|
||||||
* inserting a new row.
|
|
||||||
*
|
|
||||||
* The REPLACE type of query does not make part of the SQL standards. Since
|
|
||||||
* practically only MySQL implements it natively, this type of query is
|
|
||||||
* emulated through this method for other DBMS using standard types of
|
|
||||||
* queries inside a transaction to assure the atomicity of the operation.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param string $table name of the table on which the REPLACE query will
|
|
||||||
* be executed.
|
|
||||||
* @param array $fields associative array that describes the fields and the
|
|
||||||
* values that will be inserted or updated in the specified table. The
|
|
||||||
* indexes of the array are the names of all the fields of the table. The
|
|
||||||
* values of the array are also associative arrays that describe the
|
|
||||||
* values and other properties of the table fields.
|
|
||||||
*
|
|
||||||
* Here follows a list of field properties that need to be specified:
|
|
||||||
*
|
|
||||||
* value:
|
|
||||||
* Value to be assigned to the specified field. This value may be
|
|
||||||
* of specified in database independent type format as this
|
|
||||||
* function can perform the necessary datatype conversions.
|
|
||||||
*
|
|
||||||
* Default:
|
|
||||||
* this property is required unless the Null property
|
|
||||||
* is set to 1.
|
|
||||||
*
|
|
||||||
* type
|
|
||||||
* Name of the type of the field. Currently, all types Metabase
|
|
||||||
* are supported except for clob and blob.
|
|
||||||
*
|
|
||||||
* Default: no type conversion
|
|
||||||
*
|
|
||||||
* null
|
|
||||||
* Boolean property that indicates that the value for this field
|
|
||||||
* should be set to null.
|
|
||||||
*
|
|
||||||
* The default value for fields missing in INSERT queries may be
|
|
||||||
* specified the definition of a table. Often, the default value
|
|
||||||
* is already null, but since the REPLACE may be emulated using
|
|
||||||
* an UPDATE query, make sure that all fields of the table are
|
|
||||||
* listed in this function argument array.
|
|
||||||
*
|
|
||||||
* Default: 0
|
|
||||||
*
|
|
||||||
* key
|
|
||||||
* Boolean property that indicates that this field should be
|
|
||||||
* handled as a primary key or at least as part of the compound
|
|
||||||
* unique index of the table that will determine the row that will
|
|
||||||
* updated if it exists or inserted a new row otherwise.
|
|
||||||
*
|
|
||||||
* This function will fail if no key field is specified or if the
|
|
||||||
* value of a key field is set to null because fields that are
|
|
||||||
* part of unique index they may not be null.
|
|
||||||
*
|
|
||||||
* Default: 0
|
|
||||||
*
|
|
||||||
* @return integer the number of affected rows
|
|
||||||
*/
|
|
||||||
public function replace($table, array $fields, array $keys)
|
|
||||||
{
|
|
||||||
$count = count($fields);
|
|
||||||
$query = $values = '';
|
|
||||||
$keys = $colnum = 0;
|
|
||||||
|
|
||||||
for (reset($fields); $colnum < $count; next($fields), $colnum++) {
|
|
||||||
$name = key($fields);
|
|
||||||
|
|
||||||
if ($colnum > 0) {
|
|
||||||
$query .= ',';
|
|
||||||
$values.= ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
$query .= $name;
|
|
||||||
|
|
||||||
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
|
|
||||||
$value = 'NULL';
|
|
||||||
} else {
|
|
||||||
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
|
|
||||||
$value = $this->quote($fields[$name]['value'], $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
$values .= $value;
|
|
||||||
|
|
||||||
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
|
|
||||||
if ($value === 'NULL') {
|
|
||||||
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
|
|
||||||
}
|
|
||||||
$keys++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($keys == 0) {
|
|
||||||
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
|
|
||||||
}
|
|
||||||
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
|
|
||||||
|
|
||||||
return $this->exec($query);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Mysql_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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)
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorCodeMap an array that is used for determining portable
|
|
||||||
* error code from a native database error code
|
|
||||||
*/
|
|
||||||
protected static $errorCodeMap = array(
|
|
||||||
1004 => Doctrine::ERR_CANNOT_CREATE,
|
|
||||||
1005 => Doctrine::ERR_CANNOT_CREATE,
|
|
||||||
1006 => Doctrine::ERR_CANNOT_CREATE,
|
|
||||||
1007 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1008 => Doctrine::ERR_CANNOT_DROP,
|
|
||||||
1022 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1044 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
1046 => Doctrine::ERR_NODBSELECTED,
|
|
||||||
1048 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
1049 => Doctrine::ERR_NOSUCHDB,
|
|
||||||
1050 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1051 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
1054 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
1061 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1062 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1064 => Doctrine::ERR_SYNTAX,
|
|
||||||
1091 => Doctrine::ERR_NOT_FOUND,
|
|
||||||
1100 => Doctrine::ERR_NOT_LOCKED,
|
|
||||||
1136 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
1142 => Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
1146 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
1216 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
1217 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to $portableCode field
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @return boolean whether or not the error info processing was successfull
|
|
||||||
* (the process is successfull if portable error code was found)
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
$code = $errorInfo[1];
|
|
||||||
if (isset(self::$errorCodeMap[$code])) {
|
|
||||||
$this->portableCode = self::$errorCodeMap[$code];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,116 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Oracle.php 1798 2007-06-24 21:05:12Z zYne $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Oracle
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1798 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Oracle extends Doctrine_Connection
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Oracle';
|
|
||||||
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => true,
|
|
||||||
'indexes' => true,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'current_id' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'savepoints' => true,
|
|
||||||
'limit_queries' => true,
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => 'emulated',
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => false, // implementation is broken
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => true,
|
|
||||||
'prepared_statements' => true,
|
|
||||||
'identifier_quoting' => true,
|
|
||||||
'pattern_escaping' => true,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
$this->options['DBA_username'] = false;
|
|
||||||
$this->options['DBA_password'] = false;
|
|
||||||
$this->options['database_name_prefix'] = false;
|
|
||||||
$this->options['emulate_database'] = true;
|
|
||||||
$this->options['default_tablespace'] = false;
|
|
||||||
$this->options['default_text_field_length'] = 2000;
|
|
||||||
$this->options['result_prefetching'] = false;
|
|
||||||
*/
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Sets up the date/time format
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS')
|
|
||||||
{
|
|
||||||
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
|
||||||
*
|
|
||||||
* @param string $query query to modify
|
|
||||||
* @param integer $limit limit the number of rows
|
|
||||||
* @param integer $offset start reading from given offset
|
|
||||||
* @return string the modified query
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit, $offset)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
$e = explode("select ",strtolower($query));
|
|
||||||
$e2 = explode(" from ",$e[1]);
|
|
||||||
$fields = $e2[0];
|
|
||||||
*/
|
|
||||||
$limit = (int) $limit;
|
|
||||||
$offset = (int) $offset;
|
|
||||||
if (preg_match('/^\s*SELECT/i', $query)) {
|
|
||||||
if ( ! preg_match('/\sFROM\s/i', $query)) {
|
|
||||||
$query .= " FROM dual";
|
|
||||||
}
|
|
||||||
if ($limit > 0) {
|
|
||||||
// taken from http://svn.ez.no/svn/ezcomponents/packages/Database
|
|
||||||
$max = $offset + $limit;
|
|
||||||
if ($offset > 0) {
|
|
||||||
$min = $offset + 1;
|
|
||||||
$query = 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' . $query
|
|
||||||
. ') a WHERE ROWNUM <= ' . $max . ') WHERE dctrn_rownum >= ' . $min;
|
|
||||||
} else {
|
|
||||||
$query = 'SELECT a.* FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Oracle_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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)
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorCodeMap an array that is used for determining portable
|
|
||||||
* error code from a native database error code
|
|
||||||
*/
|
|
||||||
protected static $errorCodeMap = array(
|
|
||||||
1 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
900 => Doctrine::ERR_SYNTAX,
|
|
||||||
904 => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
913 => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
921 => Doctrine::ERR_SYNTAX,
|
|
||||||
923 => Doctrine::ERR_SYNTAX,
|
|
||||||
942 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
955 => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
1400 => Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
1401 => Doctrine::ERR_INVALID,
|
|
||||||
1407 => Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
1418 => Doctrine::ERR_NOT_FOUND,
|
|
||||||
1476 => Doctrine::ERR_DIVZERO,
|
|
||||||
1722 => Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
2289 => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
2291 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
2292 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
2449 => Doctrine::ERR_CONSTRAINT,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to $portableCode field
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @return boolean whether or not the error info processing was successfull
|
|
||||||
* (the process is successfull if portable error code was found)
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
$code = $errorInfo[1];
|
|
||||||
if (isset(self::$errorCodeMap[$code])) {
|
|
||||||
$this->portableCode = self::$errorCodeMap[$code];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,190 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Pgsql.php 2113 2007-07-31 05:50:41Z lukenukem $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload("Doctrine_Connection_Common");
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Pgsql
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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: 2113 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Pgsql';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO $pdo database handle
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
// initialize all driver options
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => true,
|
|
||||||
'indexes' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'savepoints' => true,
|
|
||||||
'current_id' => true,
|
|
||||||
'limit_queries' => true,
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => 'emulated',
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => 'emulated',
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => true,
|
|
||||||
'prepared_statements' => true,
|
|
||||||
'identifier_quoting' => true,
|
|
||||||
'pattern_escaping' => true,
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->properties['string_quoting'] = array('start' => "'",
|
|
||||||
'end' => "'",
|
|
||||||
'escape' => "'",
|
|
||||||
'escape_pattern' => '\\');
|
|
||||||
|
|
||||||
$this->properties['identifier_quoting'] = array('start' => '"',
|
|
||||||
'end' => '"',
|
|
||||||
'escape' => '"');
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the charset on the current connection
|
|
||||||
*
|
|
||||||
* @param string charset
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setCharset($charset)
|
|
||||||
{
|
|
||||||
$query = 'SET NAMES '.$this->dbh->quote($charset);
|
|
||||||
$this->exec($query);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* convertBoolean
|
|
||||||
* some drivers need the boolean values to be converted into integers
|
|
||||||
* when using DQL API
|
|
||||||
*
|
|
||||||
* This method takes care of that conversion
|
|
||||||
*
|
|
||||||
* @param array $item
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function convertBooleans($item)
|
|
||||||
{
|
|
||||||
if (is_array($item)) {
|
|
||||||
foreach ($item as $key => $value) {
|
|
||||||
if (is_bool($value)) {
|
|
||||||
$item[$key] = ($value) ? 'true' : 'false';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (is_bool($item)) {
|
|
||||||
$item = ($item) ? 'true' : 'false';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Changes a query string for various DBMS specific reasons
|
|
||||||
*
|
|
||||||
* @param string $query query to modify
|
|
||||||
* @param integer $limit limit the number of rows
|
|
||||||
* @param integer $offset start reading from given offset
|
|
||||||
* @param boolean $isManip if the query is a DML query
|
|
||||||
* @return string modified query
|
|
||||||
*/
|
|
||||||
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
|
|
||||||
{
|
|
||||||
if ($limit > 0) {
|
|
||||||
$query = rtrim($query);
|
|
||||||
|
|
||||||
if (substr($query, -1) == ';') {
|
|
||||||
$query = substr($query, 0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isManip) {
|
|
||||||
$manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query);
|
|
||||||
$from = $match[2];
|
|
||||||
$where = $match[3];
|
|
||||||
$query = $manip . ' ' . $from . ' WHERE ctid=(SELECT ctid FROM '
|
|
||||||
. $from . ' ' . $where . ' LIMIT ' . $limit . ')';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if ( ! empty($limit)) {
|
|
||||||
$query .= ' LIMIT ' . $limit;
|
|
||||||
}
|
|
||||||
if ( ! empty($offset)) {
|
|
||||||
$query .= ' OFFSET ' . $offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return version information about the server
|
|
||||||
*
|
|
||||||
* @param string $native determines if the raw version string should be returned
|
|
||||||
* @return array|string an array or string with version information
|
|
||||||
*/
|
|
||||||
public function getServerVersion($native = false)
|
|
||||||
{
|
|
||||||
$query = 'SHOW SERVER_VERSION';
|
|
||||||
|
|
||||||
$serverInfo = $this->fetchOne($query);
|
|
||||||
|
|
||||||
if ( ! $native) {
|
|
||||||
$tmp = explode('.', $serverInfo, 3);
|
|
||||||
|
|
||||||
if (empty($tmp[2]) && isset($tmp[1])
|
|
||||||
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
|
|
||||||
) {
|
|
||||||
$serverInfo = array(
|
|
||||||
'major' => $tmp[0],
|
|
||||||
'minor' => $tmp2[1],
|
|
||||||
'patch' => null,
|
|
||||||
'extra' => $tmp2[2],
|
|
||||||
'native' => $serverInfo,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$serverInfo = array(
|
|
||||||
'major' => isset($tmp[0]) ? $tmp[0] : null,
|
|
||||||
'minor' => isset($tmp[1]) ? $tmp[1] : null,
|
|
||||||
'patch' => isset($tmp[2]) ? $tmp[2] : null,
|
|
||||||
'extra' => null,
|
|
||||||
'native' => $serverInfo,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $serverInfo;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Pgsql_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @author Paul Cooper <pgc@ucecom.com> (PEAR MDB2 Pgsql driver)
|
|
||||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorRegexps an array that is used for determining portable
|
|
||||||
* error code from a native database error message
|
|
||||||
*/
|
|
||||||
protected static $errorRegexps = array(
|
|
||||||
'/parser: parse error at or near/i'
|
|
||||||
=> Doctrine::ERR_SYNTAX,
|
|
||||||
'/syntax error at/'
|
|
||||||
=> Doctrine::ERR_SYNTAX,
|
|
||||||
'/column reference .* is ambiguous/i'
|
|
||||||
=> Doctrine::ERR_SYNTAX,
|
|
||||||
'/column .* (of relation .*)?does not exist/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
'/attribute .* not found|relation .* does not have attribute/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
'/column .* specified in USING clause does not exist in (left|right) table/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
'/(relation|sequence|table).*does not exist|class .* not found/i'
|
|
||||||
=> Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
'/index .* does not exist/'
|
|
||||||
=> Doctrine::ERR_NOT_FOUND,
|
|
||||||
'/relation .* already exists/i'
|
|
||||||
=> Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
'/(divide|division) by zero$/i'
|
|
||||||
=> Doctrine::ERR_DIVZERO,
|
|
||||||
'/pg_atoi: error in .*: can\'t parse /i'
|
|
||||||
=> Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
'/invalid input syntax for( type)? (integer|numeric)/i'
|
|
||||||
=> Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
'/value .* is out of range for type \w*int/i'
|
|
||||||
=> Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
'/integer out of range/i'
|
|
||||||
=> Doctrine::ERR_INVALID_NUMBER,
|
|
||||||
'/value too long for type character/i'
|
|
||||||
=> Doctrine::ERR_INVALID,
|
|
||||||
'/permission denied/'
|
|
||||||
=> Doctrine::ERR_ACCESS_VIOLATION,
|
|
||||||
'/violates [\w ]+ constraint/'
|
|
||||||
=> Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/referential integrity violation/'
|
|
||||||
=> Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/violates not-null constraint/'
|
|
||||||
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/more expressions than target columns/i'
|
|
||||||
=> Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to $portableCode field
|
|
||||||
*
|
|
||||||
* the portable error code is added at the end of array
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @see Doctrine::ERR_* constants
|
|
||||||
* @see Doctrine_Connection::$portableCode
|
|
||||||
* @return boolean whether or not the error info processing was successfull
|
|
||||||
* (the process is successfull if portable error code was found)
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
foreach (self::$errorRegexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errorInfo[2])) {
|
|
||||||
$this->portableCode = $code;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,174 +0,0 @@
|
|||||||
<?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
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Overloadable');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Profiler
|
|
||||||
*
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @package Doctrine
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAggregate, Countable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param array $listeners an array containing all availible listeners
|
|
||||||
*/
|
|
||||||
private $listeners = array('query',
|
|
||||||
'prepare',
|
|
||||||
'commit',
|
|
||||||
'rollback',
|
|
||||||
'connect',
|
|
||||||
'begintransaction',
|
|
||||||
'exec',
|
|
||||||
'execute',
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* @param array $events an array containing all listened events
|
|
||||||
*/
|
|
||||||
private $events = array();
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setFilterQueryType
|
|
||||||
*
|
|
||||||
* @param integer $filter
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function setFilterQueryType() {
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* method overloader
|
|
||||||
* this method is used for invoking different listeners, for the full
|
|
||||||
* list of availible listeners, see Doctrine_EventListener
|
|
||||||
*
|
|
||||||
* @param string $m the name of the method
|
|
||||||
* @param array $a method arguments
|
|
||||||
* @see Doctrine_EventListener
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function __call($m, $a)
|
|
||||||
{
|
|
||||||
// first argument should be an instance of Doctrine_Event
|
|
||||||
if ( ! ($a[0] instanceof Doctrine_Event)) {
|
|
||||||
throw new Doctrine_Connection_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Event.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (substr($m, 0, 3) === 'pre') {
|
|
||||||
// pre-event listener found
|
|
||||||
$a[0]->start();
|
|
||||||
|
|
||||||
if( ! in_array($a[0], $this->events, true)) {
|
|
||||||
$this->events[] = $a[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// after-event listener found
|
|
||||||
$a[0]->end();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* If filtering by query type is enabled, only keep the query if
|
|
||||||
* it was one of the allowed types.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
if ( ! is_null($this->filterTypes)) {
|
|
||||||
if ( ! ($a[0]->getQueryType() & $this->_filterTypes)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* get
|
|
||||||
*
|
|
||||||
* @param mixed $key
|
|
||||||
* @return Doctrine_Event
|
|
||||||
*/
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if (isset($this->events[$key])) {
|
|
||||||
return $this->events[$key];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getAll
|
|
||||||
* returns all profiled events as an array
|
|
||||||
*
|
|
||||||
* @return array all events in an array
|
|
||||||
*/
|
|
||||||
public function getAll()
|
|
||||||
{
|
|
||||||
return $this->events;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getIterator
|
|
||||||
* returns an iterator that iterates through the logged events
|
|
||||||
*
|
|
||||||
* @return ArrayIterator
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->events);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* count
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->events);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* pop the last event from the event stack
|
|
||||||
*
|
|
||||||
* @return Doctrine_Event
|
|
||||||
*/
|
|
||||||
public function pop()
|
|
||||||
{
|
|
||||||
return array_pop($this->events);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Get the Doctrine_Event object for the last query that was run, regardless if it has
|
|
||||||
* ended or not. If the event has not ended, it's end time will be Null.
|
|
||||||
*
|
|
||||||
* @return Doctrine_Event
|
|
||||||
*/
|
|
||||||
public function lastEvent()
|
|
||||||
{
|
|
||||||
if (empty($this->events)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
end($this->events);
|
|
||||||
return current($this->events);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1345 2007-05-14 13:00:14Z meus $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Profiler_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Profiler_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1345 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Profiler_Exception extends Doctrine_Exception
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Sqlite.php 2271 2007-08-25 00:14:14Z jackbravo $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload("Doctrine_Connection_Common");
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Sqlite
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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: 2271 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string $driverName the name of this connection driver
|
|
||||||
*/
|
|
||||||
protected $driverName = 'Sqlite';
|
|
||||||
/**
|
|
||||||
* the constructor
|
|
||||||
*
|
|
||||||
* @param Doctrine_Manager $manager
|
|
||||||
* @param PDO $pdo database handle
|
|
||||||
*/
|
|
||||||
public function __construct(Doctrine_Manager $manager, $adapter)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->supported = array(
|
|
||||||
'sequences' => 'emulated',
|
|
||||||
'indexes' => true,
|
|
||||||
'affected_rows' => true,
|
|
||||||
'summary_functions' => true,
|
|
||||||
'order_by_text' => true,
|
|
||||||
'current_id' => 'emulated',
|
|
||||||
'limit_queries' => true,
|
|
||||||
'LOBs' => true,
|
|
||||||
'replace' => true,
|
|
||||||
'transactions' => true,
|
|
||||||
'savepoints' => false,
|
|
||||||
'sub_selects' => true,
|
|
||||||
'auto_increment' => true,
|
|
||||||
'primary_key' => true,
|
|
||||||
'result_introspection' => false, // not implemented
|
|
||||||
'prepared_statements' => 'emulated',
|
|
||||||
'identifier_quoting' => true,
|
|
||||||
'pattern_escaping' => false,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
$this->options['base_transaction_name'] = '___php_Doctrine_sqlite_auto_commit_off';
|
|
||||||
$this->options['fixed_float'] = 0;
|
|
||||||
$this->options['database_path'] = '';
|
|
||||||
$this->options['database_extension'] = '';
|
|
||||||
$this->options['server_version'] = '';
|
|
||||||
*/
|
|
||||||
parent::__construct($manager, $adapter);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* initializes database functions missing in sqlite
|
|
||||||
*
|
|
||||||
* @see Doctrine_Expression
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function connect()
|
|
||||||
{
|
|
||||||
parent::connect();
|
|
||||||
|
|
||||||
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
|
|
||||||
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
|
|
||||||
$this->dbh->sqliteCreateFunction('md5', 'md5', 1);
|
|
||||||
$this->dbh->sqliteCreateFunction('sha1', 'sha1', 1);
|
|
||||||
$this->dbh->sqliteCreateFunction('locate', 'strpos', 2);
|
|
||||||
$this->dbh->sqliteCreateFunction('rtrim', 'rtrim', 1);
|
|
||||||
$this->dbh->sqliteCreateFunction('ltrim', 'ltrim', 1);
|
|
||||||
$this->dbh->sqliteCreateFunction('trim', 'trim', 1);
|
|
||||||
$this->dbh->sqliteCreateFunction('now', 'time', 0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* getDatabaseFile
|
|
||||||
*
|
|
||||||
* @param string $name the name of the database
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getDatabaseFile($name)
|
|
||||||
{
|
|
||||||
return $name . '.db';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many individuals
|
|
||||||
* and is licensed under the LGPL. For more information, see
|
|
||||||
* <http://www.phpdoctrine.com>.
|
|
||||||
*/
|
|
||||||
Doctrine::autoload('Doctrine_Connection_Exception');
|
|
||||||
/**
|
|
||||||
* Doctrine_Connection_Sqlite_Exception
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @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)
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 1080 $
|
|
||||||
* @category Object Relational Mapping
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
*/
|
|
||||||
class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var array $errorRegexps an array that is used for determining portable
|
|
||||||
* error code from a native database error message
|
|
||||||
*/
|
|
||||||
protected static $errorRegexps = array(
|
|
||||||
'/^no such table:/' => Doctrine::ERR_NOSUCHTABLE,
|
|
||||||
'/^no such index:/' => Doctrine::ERR_NOT_FOUND,
|
|
||||||
'/^(table|index) .* already exists$/' => Doctrine::ERR_ALREADY_EXISTS,
|
|
||||||
'/PRIMARY KEY must be unique/i' => Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/is not unique/' => Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/columns .* are not unique/i' => Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/uniqueness constraint failed/' => Doctrine::ERR_CONSTRAINT,
|
|
||||||
'/may not be NULL/' => Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
|
||||||
'/^no such column:/' => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
'/column not present in both tables/i' => Doctrine::ERR_NOSUCHFIELD,
|
|
||||||
'/^near ".*": syntax error$/' => Doctrine::ERR_SYNTAX,
|
|
||||||
'/[0-9]+ values for [0-9]+ columns/i' => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* This method checks if native error code/message can be
|
|
||||||
* converted into a portable code and then adds this
|
|
||||||
* portable error code to $portableCode field
|
|
||||||
*
|
|
||||||
* @param array $errorInfo error info array
|
|
||||||
* @since 1.0
|
|
||||||
* @see Doctrine::ERR_* constants
|
|
||||||
* @see Doctrine_Connection::$portableCode
|
|
||||||
* @return boolean whether or not the error info processing was successfull
|
|
||||||
* (the process is successfull if portable error code was found)
|
|
||||||
*/
|
|
||||||
public function processErrorInfo(array $errorInfo)
|
|
||||||
{
|
|
||||||
foreach (self::$errorRegexps as $regexp => $code) {
|
|
||||||
if (preg_match($regexp, $errorInfo[2])) {
|
|
||||||
|
|
||||||
$this->portableCode = $code;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user