Doctrine 1.2.4
Doctrine_Table Class Reference

Inherits Doctrine_Configurable, and Countable.

Public Member Functions

 __construct ($name, Doctrine_Connection $conn, $initDefinition=false)
 
 __call ($method, $arguments)
 
 __get ($option)
 
 __isset ($option)
 
 __toString ()
 
 addCheckConstraint ($definition, $name)
 
 addForeignKey (array $definition)
 
 addGenerator (Doctrine_Record_Generator $generator, $name=null)
 
 addIndex ($index, array $definition)
 
 addListener ($listener, $name=null)
 
 addNamedQuery ($queryKey, $query)
 
 addRecord (Doctrine_Record $record)
 
 addRecordListener ($listener, $name=null)
 
 addTemplate ($template, Doctrine_Template $impl)
 
 applyInheritance ($where)
 
 bind ($args, $type)
 
 bindQueryPart ($queryPart, $value)
 
 bindQueryParts (array $queryParts)
 
 clear ()
 
 construct ()
 
 count ()
 
 create (array $array=array())
 
 createNamedQuery ($queryKey)
 
 createQuery ($alias= '')
 
 enumIndex ($fieldName, $value)
 
 enumValue ($fieldName, $index)
 
 execute ($queryKey, $params=array(), $hydrationMode=Doctrine_Core::HYDRATE_RECORD)
 
 executeOne ($queryKey, $params=array(), $hydrationMode=Doctrine_Core::HYDRATE_RECORD)
 
 export ()
 
 find ()
 
 findAll ($hydrationMode=null)
 
 findBy ($fieldName, $value, $hydrationMode=null)
 
 findByDql ($dql, $params=array(), $hydrationMode=null)
 
 findBySql ($dql, $params=array(), $hydrationMode=null)
 
 findOneBy ($fieldName, $value, $hydrationMode=null)
 
 getAttribute ($attribute)
 
 getAttributes ()
 
 getBoundQueryPart ($queryPart)
 
 getCharset ()
 
 getClassnameToReturn ()
 
 getCollate ()
 
 getColumnCount ()
 
 getColumnDefinition ($columnName)
 
 getColumnName ($fieldName)
 
 getColumnNames (array $fieldNames=null)
 
 getColumnOwner ($columnName)
 
 getColumns ()
 
 getComponentName ()
 
 getConnection ()
 
 getData ()
 
 getDefaultValueOf ($fieldName)
 
 getDefinitionOf ($fieldName)
 
 getEnumValues ($fieldName)
 
 getExportableFormat ($parseForeignKeys=true)
 
 getFieldLength ($fieldName)
 
 getFieldName ($columnName)
 
 getFieldNames ()
 
 getFieldValidators ($fieldName)
 
 getFilters ()
 
 getGenerator ($generator)
 
 getGenerators ()
 
 getIdentifier ()
 
 getIdentifierColumnNames ()
 
 getIdentifierType ()
 
 getImpl ($template)
 
 getIndex ($index)
 
 getListener ()
 
 getLocator ()
 
 getMethodOwner ($method)
 
 getOption ($name)
 
 getOptions ()
 
 getOrderByStatement ($alias=null, $columnNames=false)
 
 getParent ()
 
 getParentGenerator ()
 
 getProxy ($id=null)
 
 getQueryObject ()
 
 getRecord ()
 
 getRecordInstance ()
 
 getRecordListener ()
 
 getRelation ($alias, $recursive=true)
 
 getRelationParser ()
 
 getRelations ()
 
 getRepository ()
 
 getTableName ()
 
 getTemplate ($template)
 
 getTemplates ()
 
 getTree ()
 
 getTypeOf ($fieldName)
 
 getTypeOfColumn ($columnName)
 
 getUniques ()
 
 hasColumn ($columnName)
 
 hasDefaultValues ()
 
 hasField ($fieldName)
 
 hasGenerator ($generator)
 
 hasMany ()
 
 hasOne ()
 
 hasRelation ($alias)
 
 hasTemplate ($template)
 
 initDefinition ()
 
 initIdentifier ()
 
 isGenerator ()
 
 isIdentifier ($fieldName)
 
 isIdentifierAutoincrement ()
 
 isIdentifierComposite ()
 
 isInheritedColumn ($columnName)
 
 isTree ()
 
 locate ($name)
 
 prepareValue ($fieldName, $value, $typeHint=null)
 
 processOrderBy ($alias, $orderBy, $columnNames=false)
 
 removeColumn ($fieldName)
 
 removeRecord (Doctrine_Record $record)
 
 setAttribute ($attribute, $value)
 
 setCharset ($charset)
 
 setCollate ($collate)
 
 setColumn ($name, $type=null, $length=null, $options=array(), $prepend=false)
 
 setColumnOption ($columnName, $option, $value)
 
 setColumnOptions ($columnName, array $options)
 
 setColumns (array $definitions)
 
 setConnection (Doctrine_Connection $conn)
 
 setData (array $data)
 
 setEventListener ($listener)
 
 setGenerator (Doctrine_Record_Generator $generator)
 
 setImpl ($template, $class)
 
 setListener ($listener)
 
 setLocator (Doctrine_Locator $locator)
 
 setMethodOwner ($method, $class)
 
 setOption ($name, $value)
 
 setOptions ($options)
 
 setParent (Doctrine_Configurable $component)
 
 setRecordListener ($listener)
 
 setTableName ($tableName)
 
 unique ($fields, $options=array(), $createdUniqueIndex=true)
 
 unsetAttribute ($attribute)
 
 unshiftFilter (Doctrine_Record_Filter $filter)
 
 validateField ($fieldName, $value, Doctrine_Record $record=null)
 
 validateUniques (Doctrine_Record $record)
 

Static Public Member Functions

static getNullObject ()
 
static initNullObject (Doctrine_Null $null)
 

Protected Member Functions

 _checkForeignKeyExists ($def, $foreignKeys)
 
 _resolveFindByFieldName ($name)
 

Protected Attributes

 $_uniques = array()
 

Detailed Description

Definition at line 37 of file Table.php.

Constructor & Destructor Documentation

Doctrine_Table::__construct (   $name,
Doctrine_Connection  $conn,
  $initDefinition = false 
)

the constructor

Exceptions
Doctrine_Connection_Exceptionif there are no opened connections
Parameters
string$namethe name of the component
Doctrine_Connection$connthe connection associated with this table
boolean$initDefinitionwhether to init the in-memory schema

Definition at line 238 of file Table.php.

{
$this->_conn = $conn;
$this->_options['name'] = $name;
$this->setParent($this->_conn);
$this->_conn->addTable($this);
$this->_parser = new Doctrine_Relation_Parser($this);
if ($charset = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET)) {
$this->_options['charset'] = $charset;
}
if ($collate = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE)) {
$this->_options['collate'] = $collate;
}
if ($initDefinition) {
$this->record = $this->initDefinition();
$this->initIdentifier();
$this->record->setUp();
// if tree, set up tree
if ($this->isTree()) {
$this->getTree()->setUp();
}
} else {
if ( ! isset($this->_options['tableName'])) {
$this->setTableName(Doctrine_Inflector::tableize($this->_options['name']));
}
}
$this->_filters[] = new Doctrine_Record_Filter_Standard();
$this->_repository = new Doctrine_Table_Repository($this);
$this->construct();
}

Member Function Documentation

Doctrine_Table::__call (   $method,
  $arguments 
)

Adds support for magic finders.

This method add support for calling methods not defined in code, such as: findByColumnName, findByRelationAlias findById, findByContactId, etc.

Returns
the result of the finder

Definition at line 2805 of file Table.php.

{
$lcMethod = strtolower($method);
if (substr($lcMethod, 0, 6) == 'findby') {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
} else if (substr($lcMethod, 0, 9) == 'findoneby') {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
}
if (isset($by)) {
if ( ! isset($arguments[0])) {
throw new Doctrine_Table_Exception('You must specify the value to ' . $method);
}
$fieldName = $this->_resolveFindByFieldName($by);
$count = count(explode('Or', $by)) + (count(explode('And', $by)) - 1);
if (count($arguments) > $count)
{
$hydrationMode = end($arguments);
unset($arguments[count($arguments) - 1]);
} else {
$hydrationMode = null;
}
if ($this->hasField($fieldName)) {
return $this->$method($fieldName, $arguments[0], $hydrationMode);
} else if ($this->hasRelation($by)) {
$relation = $this->getRelation($by);
if ($relation['type'] === Doctrine_Relation::MANY) {
throw new Doctrine_Table_Exception('Cannot findBy many relationship.');
}
return $this->$method($relation['local'], $arguments[0], $hydrationMode);
} else {
return $this->$method($by, $arguments, $hydrationMode);
}
}
// Forward the method on to the record instance and see if it has anything or one of its behaviors
try {
return call_user_func_array(array($this->getRecordInstance(), $method . 'TableProxy'), $arguments);
throw new Doctrine_Table_Exception(sprintf('Unknown method %s::%s', get_class($this), $method));
}
Doctrine_Table::__get (   $option)

Magic method for accessing to object properties.

This method is an alias for getOption. foreach ($table->indexes as $name => $definition) { // ... }

Parameters
string$option
Returns
mixed

Definition at line 773 of file Table.php.

{
if (isset($this->_options[$option])) {
return $this->_options[$option];
}
return null;
}
Doctrine_Table::__isset (   $option)

Magic method for testing object properties existence.

This method tests if an option exists. if (isset($table->tableName)) { // ... }

Parameters
string$option

Definition at line 793 of file Table.php.

{
return isset($this->_options[$option]);
}
Doctrine_Table::__toString ( )

Generates a string representation of this object.

This method is useful for debugging purposes, or it can be overriden in Doctrine_Record to provide a value when Record is casted to (string).

Returns
string

Definition at line 2704 of file Table.php.

{
}
Doctrine_Table::_checkForeignKeyExists (   $def,
  $foreignKeys 
)
protected

Check if a foreign definition already exists in the fks array for a foreign table, local and foreign key

Parameters
array$defForeign key definition to check for
array$foreignKeysArray of existing foreign key definitions to check in
Returns
boolean $result Whether or not the foreign key was found

Definition at line 740 of file Table.php.

{
foreach ($foreignKeys as $key => $foreignKey) {
if ($def['local'] == $foreignKey['local'] && $def['foreign'] == $foreignKey['foreign'] && $def['foreignTable'] == $foreignKey['foreignTable']) {
return $key;
}
}
return false;
}
Doctrine_Table::_resolveFindByFieldName (   $name)
protected

Resolves the passed find by field name inflecting the parameter.

This method resolves the appropriate field name regardless of whether the user passes a column name, field name, or a Doctrine_Inflector::classified() version of their column name. It will be inflected with Doctrine_Inflector::tableize() to get the column or field name.

Parameters
string$name
Returns
string $fieldName

Definition at line 2784 of file Table.php.

{
$fieldName = Doctrine_Inflector::tableize($name);
if ($this->hasColumn($name) || $this->hasField($name)) {
return $this->getFieldName($this->getColumnName($name));
} else if ($this->hasColumn($fieldName) || $this->hasField($fieldName)) {
return $this->getFieldName($this->getColumnName($fieldName));
} else {
return false;
}
}
Doctrine_Table::addCheckConstraint (   $definition,
  $name 
)

Adds a check constraint to the table in-memory definition.

This method adds a CHECK constraint to the schema definition. It does not add the constraint to the physical table in the db;

See Also
export().
Parameters
$definition
mixed$nameif string used as name for the constraint. Otherwise it is indexed numerically.
Returns
void

Definition at line 850 of file Table.php.

{
if (is_string($name)) {
$this->_options['checks'][$name] = $definition;
} else {
$this->_options['checks'][] = $definition;
}
return $this;
}
Doctrine_Table::addForeignKey ( array  $definition)

Adds a foreignKey to the table in-memory definition.

This method adds a foreign key to the schema definition. It does not add the key to the physical table in the db;

See Also
export().
Parameters
array$definitiondefinition of the foreign key
Returns
void

Definition at line 833 of file Table.php.

{
$this->_options['foreignKeys'][] = $definition;
}
Doctrine_Table::addGenerator ( Doctrine_Record_Generator  $generator,
  $name = null 
)

Adds a generate to the table instance.

Parameters
Doctrine_Record_Generator$generator
string$name
Returns
Doctrine_Table

Definition at line 2524 of file Table.php.

{
if ($name === null) {
$this->_generators[] = $generator;
} else {
$this->_generators[$name] = $generator;
}
return $this;
}
Doctrine_Table::addIndex (   $index,
array  $definition 
)

Adds an index to this table in-memory definition.

This method adds an INDEX to the schema definition. It does not add the index to the physical table in the db;

See Also
export().
Parameters
string$indexindex name
array$definitionkeys are type, fields
Returns
void

Definition at line 871 of file Table.php.

{
if (isset($definition['fields'])) {
foreach ((array) $definition['fields'] as $key => $field) {
if (is_numeric($key)) {
$definition['fields'][$key] = $this->getColumnName($field);
} else {
$columnName = $this->getColumnName($key);
unset($definition['fields'][$key]);
$definition['fields'][$columnName] = $field;
}
}
}
$this->_options['indexes'][$index] = $definition;
}
Doctrine_Configurable::addListener (   $listener,
  $name = null 
)
inherited

addListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Configurable this object

Definition at line 277 of file Configurable.php.

{
if ( ! isset($this->attributes[Doctrine_Core::ATTR_LISTENER]) ||
! ($this->attributes[Doctrine_Core::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine_Core::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
}
$this->attributes[Doctrine_Core::ATTR_LISTENER]->add($listener, $name);
return $this;
}
Doctrine_Table::addNamedQuery (   $queryKey,
  $query 
)

Adds a named query in the query registry.

This methods register a query object with a name to use in the future.

See Also
createNamedQuery()
Parameters
$queryKeyquery key name to use for storage
string | Doctrine_Query$queryDQL string or object
Returns
void

Definition at line 1535 of file Table.php.

{
$registry = Doctrine_Manager::getInstance()->getQueryRegistry();
$registry->add($this->getComponentName() . '/' . $queryKey, $query);
}
Doctrine_Table::addRecord ( Doctrine_Record  $record)

Adds a record to the first level cache (identity map).

This method is used internally to cache records, ensuring that only one object that represents a sql record exists in all scopes.

Parameters
Doctrine_Record$recordrecord to be added
Returns
boolean true if record was not present in the map
Todo:
Better name? registerRecord?

Definition at line 1769 of file Table.php.

{
$id = implode(' ', $record->identifier());
if (isset($this->_identityMap[$id])) {
return false;
}
$this->_identityMap[$id] = $record;
return true;
}
Doctrine_Configurable::addRecordListener (   $listener,
  $name = null 
)
inherited

addRecordListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Configurable this object

Definition at line 225 of file Configurable.php.

{
if ( ! isset($this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER]) ||
! ($this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) {
$this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain();
}
$this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER]->add($listener, $name);
return $this;
}
Doctrine_Table::addTemplate (   $template,
Doctrine_Template  $impl 
)

Adds a template to this table.

Parameters
string$templatetemplate name
Doctrine_Template$implbehavior to attach
Returns
Doctrine_Table

Definition at line 2474 of file Table.php.

{
$this->_templates[$template] = $impl;
return $this;
}
Doctrine_Table::applyInheritance (   $where)
final

applyInheritance

Parameters
$wherequery where part to be modified
Returns
string query where part with column aggregation inheritance added

Definition at line 1931 of file Table.php.

{
if ( ! empty($this->_options['inheritanceMap'])) {
$a = array();
foreach ($this->_options['inheritanceMap'] as $field => $value) {
$a[] = $this->getColumnName($field) . ' = ?';
}
$i = implode(' AND ', $a);
$where .= ' AND ' . $i;
}
return $where;
}
Doctrine_Table::bind (   $args,
  $type 
)

Adds a relation to the table.

This method defines a relation on this table, that will be present on every record belonging to this component.

Parameters
array$argsfirst value is a string, name of related component; second value is array, options for the relation.
See Also
Doctrine_Relation::_$definition
Parameters
integer$typeDoctrine_Relation::ONE or Doctrine_Relation::MANY
Returns
void
Todo:
Name proposal: addRelation

Definition at line 943 of file Table.php.

{
$options = ( ! isset($args[1])) ? array() : $args[1];
$options['type'] = $type;
$this->_parser->bind($args[0], $options);
}
Doctrine_Table::bindQueryPart (   $queryPart,
  $value 
)

Adds default query parts to the selects executed on this table.

This method binds given value to given query part. Every query created by this table will have this part set by default.

Parameters
string$queryPart
mixed$value
Returns
Doctrine_Record this object

Definition at line 2589 of file Table.php.

{
$this->_options['queryParts'][$queryPart] = $value;
return $this;
}
Doctrine_Table::bindQueryParts ( array  $queryParts)

Binds query parts to this component.

See Also
bindQueryPart()
Parameters
array$queryPartsan array of pre-bound query parts
Returns
Doctrine_Table this object

Definition at line 2572 of file Table.php.

{
$this->_options['queryParts'] = $queryParts;
return $this;
}
Doctrine_Table::clear ( )

Clears the first level cache (identityMap).

This method ensures that records are reloaded from the db.

Returns
void
Todo:
what about a more descriptive name? clearIdentityMap?

Definition at line 1754 of file Table.php.

{
$this->_identityMap = array();
}
Doctrine_Table::construct ( )

Construct template method.

This method provides concrete Table classes with the possibility to hook into the constructor procedure. It is called after the Doctrine_Table construction process is finished.

Returns
void

Definition at line 287 of file Table.php.

{ }
Doctrine_Table::count ( )

Implements Countable interface.

Returns
integer number of records in the table

Definition at line 1949 of file Table.php.

{
return $this->createQuery()->count();
}
Doctrine_Table::create ( array  $array = array())

Creates a new record.

This method create a new instance of the model defined by this table. The class of this record is the subclass of Doctrine_Record defined by this component. The record is not created in the database until you call ().

Parameters
$arrayan array where keys are field names and values representing field values. Can contain also related components;
See Also
Doctrine_Record::fromArray()
Returns
Doctrine_Record the created record object

Definition at line 1518 of file Table.php.

{
$record = new $this->_options['name']($this, true);
$record->fromArray($array);
return $record;
}
Doctrine_Table::createNamedQuery (   $queryKey)

Creates a named query from one in the query registry.

This method clones a new query object from a previously registered one.

See Also
addNamedQuery()
Parameters
string$queryKeyquery key name
Returns
Doctrine_Query

Definition at line 1550 of file Table.php.

{
$queryRegistry = Doctrine_Manager::getInstance()->getQueryRegistry();
if (strpos($queryKey, '/') !== false) {
$e = explode('/', $queryKey);
return $queryRegistry->get($e[1], $e[0]);
}
return $queryRegistry->get($queryKey, $this->getComponentName());
}
Doctrine_Table::createQuery (   $alias = '')

Creates a query on this table.

This method returns a new Doctrine_Query object and adds the component name of this table as the query 'from' part. $table = Doctrine_Core::getTable('User'); $table->createQuery('myuser') ->where('myuser.Phonenumber = ?', '5551234');

Parameters
string$aliasname for component aliasing
Returns
Doctrine_Query

Definition at line 1028 of file Table.php.

{
if ( ! empty($alias)) {
$alias = ' ' . trim($alias);
}
$class = $this->getAttribute(Doctrine_Core::ATTR_QUERY_CLASS);
return Doctrine_Query::create($this->_conn, $class)
->from($this->getComponentName() . $alias);
}
Doctrine_Table::enumIndex (   $fieldName,
  $value 
)

Retrieves an enum index.

See Also
enumValue()
Parameters
string$fieldName
mixed$valuevalue of the enum considered
Returns
integer can be string if native enums are used.

Definition at line 2013 of file Table.php.

{
$values = $this->getEnumValues($fieldName);
if ($this->_conn->getAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM)) {
return $value;
}
return array_search($value, $values);
}
Doctrine_Table::enumValue (   $fieldName,
  $index 
)

Retrieves an enum value.

This method finds a enum string value. If ATTR_USE_NATIVE_ENUM is set on the connection, index and value are the same thing.

Parameters
string$fieldName
integer$indexnumeric index of the enum
Returns
mixed

Definition at line 1990 of file Table.php.

{
if ($index instanceof Doctrine_Null) {
return false;
}
if ($this->_conn->getAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM)) {
return $index;
}
$columnName = $this->getColumnName($fieldName);
return isset($this->_columns[$columnName]['values'][$index]) ? $this->_columns[$columnName]['values'][$index] : false;
}
Doctrine_Table::execute (   $queryKey,
  $params = array(),
  $hydrationMode = Doctrine_Core::HYDRATE_RECORD 
)

Finds result of a named query.

This method fetches data using the provided $queryKey to choose a named query in the query registry.

Parameters
string$queryKeythe query key
array$paramsprepared statement params (if any)
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Exceptions
Doctrine_Query_Registryif no query for given queryKey is found
Returns
Doctrine_Collection|array

Definition at line 1724 of file Table.php.

{
return $this->createNamedQuery($queryKey)->execute($params, $hydrationMode);
}
Doctrine_Table::executeOne (   $queryKey,
  $params = array(),
  $hydrationMode = Doctrine_Core::HYDRATE_RECORD 
)

Fetches one record with a named query.

This method uses the provided $queryKey to clone and execute the associated named query in the query registry.

Parameters
string$queryKeythe query key
array$paramsprepared statement params (if any)
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Exceptions
Doctrine_Query_Registryif no query for given queryKey is found
Returns
Doctrine_Record|array

Definition at line 1741 of file Table.php.

{
return $this->createNamedQuery($queryKey)->fetchOne($params, $hydrationMode);
}
Doctrine_Table::export ( )

Exports this table to database based on the schema definition.

This method create a physical table in the database, using the definition that comes from the component Doctrine_Record instance.

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Returns
boolean whether or not the export operation was successful false if table already existed in the database

Definition at line 635 of file Table.php.

{
$this->_conn->export->exportTable($this);
}
Doctrine_Table::find ( )

Finds a record by its identifier.

$table->find(11); $table->find(11, Doctrine_Core::HYDRATE_RECORD); $table->find('namedQueryForYearArchive', array(2009), Doctrine_Core::HYDRATE_ARRAY);

Parameters
mixed$nameDatabase Row ID or Query Name defined previously as a NamedQuery
mixed$paramsThis argument is the hydration mode (Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD) if first param is a Database Row ID. Otherwise this argument expect an array of query params.
int$hydrationModeOptional Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD if first argument is a NamedQuery
Returns
mixed Doctrine_Collection, array, Doctrine_Record or false if no result

Definition at line 1580 of file Table.php.

{
$num_args = func_num_args();
// Named Query or IDs
$name = func_get_arg(0);
if (is_null($name)) {
return false;
}
$ns = $this->getComponentName();
$m = $name;
// Check for possible cross-access
if ( ! is_array($name) && strpos($name, '/') !== false) {
list($ns, $m) = explode('/', $name);
}
// Define query to be used
if (
! is_array($name) &&
Doctrine_Manager::getInstance()->getQueryRegistry()->has($m, $ns)
) {
// We're dealing with a named query
$q = $this->createNamedQuery($name);
// Parameters construction
$params = ($num_args >= 2) ? func_get_arg(1) : array();
// Hydration mode
$hydrationMode = ($num_args == 3) ? func_get_arg(2) : null;
// Executing query
$res = $q->execute($params, $hydrationMode);
} else {
// We're passing a single ID or an array of IDs
$q = $this->createQuery('dctrn_find')
->where('dctrn_find.' . implode(' = ? AND dctrn_find.', (array) $this->getIdentifier()) . ' = ?')
->limit(1);
// Parameters construction
$params = is_array($name) ? array_values($name) : array($name);
// Hydration mode
$hydrationMode = ($num_args == 2) ? func_get_arg(1) : null;
// Executing query
$res = $q->fetchOne($params, $hydrationMode);
}
$q->free();
return $res;
}
Doctrine_Table::findAll (   $hydrationMode = null)

Retrieves all the records stored in this table.

Parameters
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Returns
Doctrine_Collection|array

Definition at line 1642 of file Table.php.

{
return $this->createQuery('dctrn_find')
->execute(array(), $hydrationMode);
}
Doctrine_Table::findBy (   $fieldName,
  $value,
  $hydrationMode = null 
)

Find records basing on a field.

Parameters
string$columnfield for the WHERE clause
string$valueprepared statement parameter
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Returns
Doctrine_Collection|array

Definition at line 1689 of file Table.php.

{
return $this->createQuery('dctrn_find')
->where($this->buildFindByWhere($fieldName), (array) $value)
->execute(array(), $hydrationMode);
}
Doctrine_Table::findByDql (   $dql,
  $params = array(),
  $hydrationMode = null 
)

Finds records in this table with a given DQL where clause.

Parameters
string$dqlDQL WHERE clause
array$paramspreparated statement parameters
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Returns
Doctrine_Collection|array

Definition at line 1673 of file Table.php.

{
$parser = $this->createQuery();
$query = 'FROM ' . $this->getComponentName() . ' dctrn_find WHERE ' . $dql;
return $parser->query($query, $params, $hydrationMode);
}
Doctrine_Table::findBySql (   $dql,
  $params = array(),
  $hydrationMode = null 
)

Finds records in this table with a given SQL where clause.

Parameters
string$dqlDQL WHERE clause to use
array$paramsquery parameters (a la PDO)
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Returns
Doctrine_Collection|array
Todo:
This actually takes DQL, not SQL, but it requires column names instead of field names. This should be fixed to use raw SQL instead.

Definition at line 1659 of file Table.php.

{
return $this->createQuery('dctrn_find')
->where($dql)->execute($params, $hydrationMode);
}
Doctrine_Table::findOneBy (   $fieldName,
  $value,
  $hydrationMode = null 
)

Finds the first record that satisfy the clause.

Parameters
string$columnfield for the WHERE clause
string$valueprepared statement parameter
int$hydrationModeDoctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
Returns
Doctrine_Record

Definition at line 1704 of file Table.php.

{
return $this->createQuery('dctrn_find')
->where($this->buildFindByWhere($fieldName), (array) $value)
->limit(1)
->fetchOne(array(), $hydrationMode);
}
Doctrine_Configurable::getAttribute (   $attribute)
inherited

returns the value of an attribute

Parameters
integer$attribute
Returns
mixed

Definition at line 329 of file Configurable.php.

{
if (isset($this->attributes[$attribute])) {
return $this->attributes[$attribute];
}
if (isset($this->parent)) {
return $this->parent->getAttribute($attribute);
}
return null;
}
Doctrine_Configurable::getAttributes ( )
inherited

getAttributes returns all attributes as an array

Returns
array

Definition at line 360 of file Configurable.php.

{
return $this->attributes;
}
Doctrine_Table::getBoundQueryPart (   $queryPart)

Retrieves a bound query part.

See Also
bindQueryPart()
Parameters
string$queryPartfield interested
Returns
string value of the bind

Definition at line 2660 of file Table.php.

{
if ( ! isset($this->_options['queryParts'][$queryPart])) {
return null;
}
return $this->_options['queryParts'][$queryPart];
}
Doctrine_Configurable::getCharset ( )
inherited

Get the charset

Returns
mixed

Definition at line 380 of file Configurable.php.

{
return $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET);
}
Doctrine_Table::getClassnameToReturn ( )

Get the classname to return. Most often this is just the options['name'].

Check the subclasses option and the inheritanceMap for each subclass to see if all the maps in a subclass is met. If this is the case return that subclass name. If no subclasses match or if there are no subclasses defined return the name of the class for this tables record.

Todo:
this function could use reflection to check the first time it runs if the subclassing option is not set.
Returns
string The name of the class to create
Deprecated:

Definition at line 1880 of file Table.php.

{
if ( ! isset($this->_options['subclasses'])) {
return $this->_options['name'];
}
foreach ($this->_options['subclasses'] as $subclass) {
$table = $this->_conn->getTable($subclass);
$inheritanceMap = $table->getOption('inheritanceMap');
$nomatch = false;
foreach ($inheritanceMap as $key => $value) {
if ( ! isset($this->_data[$key]) || $this->_data[$key] != $value) {
$nomatch = true;
break;
}
}
if ( ! $nomatch) {
return $table->getComponentName();
}
}
return $this->_options['name'];
}
Doctrine_Configurable::getCollate ( )
inherited

Get the collate

Returns
mixed $collate

Definition at line 400 of file Configurable.php.

{
return $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE);
}
Doctrine_Table::getColumnCount ( )
Returns
integer the number of columns in this table

Definition at line 2143 of file Table.php.

{
return $this->columnCount;
}
Doctrine_Table::getColumnDefinition (   $columnName)

Retrieves a column definition from this table schema.

Parameters
string$columnName
Returns
array column definition;
See Also
$_columns

Definition at line 1176 of file Table.php.

{
if ( ! isset($this->_columns[$columnName])) {
return false;
}
return $this->_columns[$columnName];
}
Doctrine_Table::getColumnName (   $fieldName)

Returns a column name for a column alias.

If the actual name for the alias cannot be found this method returns the given alias.

Parameters
string$aliascolumn alias
Returns
string column name

Definition at line 1157 of file Table.php.

{
// FIX ME: This is being used in places where an array is passed, but it should not be an array
// For example in places where Doctrine should support composite foreign/primary keys
$fieldName = is_array($fieldName) ? $fieldName[0]:$fieldName;
if (isset($this->_columnNames[$fieldName])) {
return $this->_columnNames[$fieldName];
}
return strtolower($fieldName);
}
Doctrine_Table::getColumnNames ( array  $fieldNames = null)

Returns an array containing all the column names.

Returns
array numeric array

Definition at line 2183 of file Table.php.

{
if ($fieldNames === null) {
return array_keys($this->_columns);
} else {
$columnNames = array();
foreach ($fieldNames as $fieldName) {
$columnNames[] = $this->getColumnName($fieldName);
}
return $columnNames;
}
}
Doctrine_Table::getColumnOwner (   $columnName)

Gets the owner of a column.

The owner of a column is the name of the component in a hierarchy that defines the column.

Parameters
string$columnNamethe column name
Returns
string the name of the owning/defining component

Definition at line 523 of file Table.php.

{
if (isset($this->_columns[$columnName]['owner'])) {
return $this->_columns[$columnName]['owner'];
} else {
return $this->getComponentName();
}
}
Doctrine_Table::getColumns ( )

Retrieves all columns of the table.

See Also
$_columns;
Returns
array keys are column names and values are definition

Definition at line 2154 of file Table.php.

{
return $this->_columns;
}
Doctrine_Table::getComponentName ( )

Gets the subclass of Doctrine_Record that belongs to this table.

Returns
string

Definition at line 2388 of file Table.php.

{
return $this->_options['name'];
}
Doctrine_Table::getConnection ( )

Returns the connection associated with this table (if any).

Returns
Doctrine_Connection|null the connection object

Definition at line 1499 of file Table.php.

{
return $this->_conn;
}
Doctrine_Table::getData ( )

Returns internal data.

This method is used by Doctrine_Record instances when retrieving data from database.

Returns
array

Definition at line 2285 of file Table.php.

{
return $this->_data;
}
Doctrine_Table::getDefaultValueOf (   $fieldName)

Retrieves the default value (if any) for a given column.

Parameters
string$fieldNamecolumn name
Returns
mixed default value as set in definition

Definition at line 1419 of file Table.php.

{
$columnName = $this->getColumnName($fieldName);
if ( ! isset($this->_columns[$columnName])) {
throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$columnName." doesn't exist.");
}
if (isset($this->_columns[$columnName]['default'])) {
return $this->_columns[$columnName]['default'];
} else {
return null;
}
}
Doctrine_Table::getDefinitionOf (   $fieldName)

Retrieves the definition of a field.

This method retrieves the definition of the column, basing of $fieldName which can be a column name or a field name (alias).

Parameters
string$fieldName
Returns
array false on failure

Definition at line 2236 of file Table.php.

{
$columnName = $this->getColumnName($fieldName);
return $this->getColumnDefinition($columnName);
}
Doctrine_Table::getEnumValues (   $fieldName)

Retrieves the enum values for a given field.

Parameters
string$fieldName
Returns
array

Definition at line 1970 of file Table.php.

{
$columnName = $this->getColumnName($fieldName);
if (isset($this->_columns[$columnName]['values'])) {
return $this->_columns[$columnName]['values'];
} else {
return array();
}
}
Doctrine_Table::getExportableFormat (   $parseForeignKeys = true)

Returns an exportable representation of this object.

This method produces a array representation of the table schema, where keys are tableName, columns (

See Also
$_columns) and options. The options subarray contains 'primary' and 'foreignKeys'.
Parameters
boolean$parseForeignKeyswhether to include foreign keys definition in the options
Returns
array

Definition at line 650 of file Table.php.

{
$columns = array();
$primary = array();
foreach ($this->getColumns() as $name => $definition) {
if (isset($definition['owner'])) {
continue;
}
switch ($definition['type']) {
case 'boolean':
if (isset($definition['default'])) {
$definition['default'] = $this->getConnection()->convertBooleans($definition['default']);
}
break;
}
$columns[$name] = $definition;
if (isset($definition['primary']) && $definition['primary']) {
$primary[] = $name;
}
}
$options['foreignKeys'] = isset($this->_options['foreignKeys']) ?
$this->_options['foreignKeys'] : array();
if ($parseForeignKeys && $this->getAttribute(Doctrine_Core::ATTR_EXPORT) & Doctrine_Core::EXPORT_CONSTRAINTS) {
$constraints = array();
$emptyIntegrity = array('onUpdate' => null,
'onDelete' => null);
foreach ($this->getRelations() as $name => $relation) {
$fk = $relation->toArray();
$fk['foreignTable'] = $relation->getTable()->getTableName();
// do not touch tables that have EXPORT_NONE attribute
if ($relation->getTable()->getAttribute(Doctrine_Core::ATTR_EXPORT) === Doctrine_Core::EXPORT_NONE) {
continue;
}
if ($relation->getTable() === $this && in_array($relation->getLocal(), $primary)) {
if ($relation->hasConstraint()) {
throw new Doctrine_Table_Exception("Badly constructed integrity constraints. Cannot define constraint of different fields in the same table.");
}
continue;
}
$integrity = array('onUpdate' => $fk['onUpdate'],
'onDelete' => $fk['onDelete']);
$fkName = $relation->getForeignKeyName();
if ($relation instanceof Doctrine_Relation_LocalKey) {
$def = array('name' => $fkName,
'local' => $relation->getLocalColumnName(),
'foreign' => $relation->getForeignColumnName(),
'foreignTable' => $relation->getTable()->getTableName());
if ($integrity !== $emptyIntegrity) {
$def = array_merge($def, $integrity);
}
if (($key = $this->_checkForeignKeyExists($def, $options['foreignKeys'])) === false) {
$options['foreignKeys'][$fkName] = $def;
} else {
unset($def['name']);
$options['foreignKeys'][$key] = array_merge($options['foreignKeys'][$key], $def);
}
}
}
}
$options['primary'] = $primary;
return array('tableName' => $this->getOption('tableName'),
'columns' => $columns,
'options' => array_merge($this->getOptions(), $options));
}
Doctrine_Table::getFieldLength (   $fieldName)

Gets the maximum length of a field. For integer fields, length is bytes occupied. For decimal fields, it is the total number of cyphers

Parameters
string$fieldName
Returns
integer

Definition at line 2648 of file Table.php.

{
return $this->_columns[$this->getColumnName($fieldName)]['length'];
}
Doctrine_Table::getFieldName (   $columnName)

Returns a column alias for a column name.

If no alias can be found the column name is returned.

Parameters
string$columnNamecolumn name
Returns
string column alias

Definition at line 1192 of file Table.php.

{
if (isset($this->_fieldNames[$columnName])) {
return $this->_fieldNames[$columnName];
}
return $columnName;
}
Doctrine_Table::getFieldNames ( )

Returns an array containing all the field names.

Returns
array numeric array

Definition at line 2222 of file Table.php.

{
return array_values($this->_fieldNames);
}
Doctrine_Table::getFieldValidators (   $fieldName)

Gets the names of all validators being applied on a field.

Parameters
string$fieldName
Returns
array names of validators

Definition at line 2602 of file Table.php.

{
$validators = array();
$columnName = $this->getColumnName($fieldName);
// this loop is a dirty workaround to get the validators filtered out of
// the options, since everything is squeezed together currently
foreach ($this->_columns[$columnName] as $name => $args) {
if (empty($name)
|| $name == 'primary'
|| $name == 'protected'
|| $name == 'autoincrement'
|| $name == 'default'
|| $name == 'values'
|| $name == 'sequence'
|| $name == 'zerofill'
|| $name == 'owner'
|| $name == 'scale'
|| $name == 'type'
|| $name == 'length'
|| $name == 'fixed'
|| $name == 'comment'
|| $name == 'extra') {
continue;
}
if ($name == 'notnull' && isset($this->_columns[$columnName]['autoincrement'])
&& $this->_columns[$columnName]['autoincrement'] === true) {
continue;
}
// skip it if it's explicitly set to FALSE (i.e. notnull => false)
if ($args === false) {
continue;
}
$validators[$name] = $args;
}
return $validators;
}
Doctrine_Table::getFilters ( )

getFilters

Returns
array $filters

Definition at line 2691 of file Table.php.

{
return $this->_filters;
}
Doctrine_Table::getGenerator (   $generator)

Gets generator instance for a passed name.

Parameters
string$generator
Returns
Doctrine_Record_Generator $generator

Definition at line 2497 of file Table.php.

{
if ( ! isset($this->_generators[$generator])) {
throw new Doctrine_Table_Exception('Generator ' . $generator . ' not loaded');
}
return $this->_generators[$generator];
}
Doctrine_Table::getGenerators ( )

Gets all the generators for this table.

Returns
array $generators

Definition at line 2486 of file Table.php.

{
return $this->_generators;
}
Doctrine_Table::getIdentifier ( )

Returns the definition of the identifier key.

Returns
string can be array if a multi-column primary key is used.

Definition at line 1436 of file Table.php.

{
return $this->_identifier;
}
Doctrine_Table::getIdentifierColumnNames ( )

Returns an array with all the identifier column names.

Returns
array numeric array

Definition at line 2201 of file Table.php.

{
return $this->getColumnNames((array) $this->getIdentifier());
}
Doctrine_Table::getIdentifierType ( )

Retrieves the type of primary key.

This method finds out if the primary key is multifield.

See Also
Doctrine_Identifier constants
Returns
integer

Definition at line 1448 of file Table.php.

{
return $this->_identifierType;
}
Doctrine_Configurable::getImpl (   $template)
inherited

getImpl returns the implementation for given class

Returns
string name of the concrete implementation

Definition at line 187 of file Configurable.php.

{
if ( ! isset($this->_impl[$template])) {
if (isset($this->parent)) {
return $this->parent->getImpl($template);
}
return null;
}
return $this->_impl[$template];
}
Doctrine_Table::getIndex (   $index)

Retrieves an index definition.

This method returns a given index definition:

See Also
addIndex().
Parameters
string$indexindex name;
See Also
addIndex()
Returns
array|boolean array on success, FALSE on failure

Definition at line 898 of file Table.php.

{
if (isset($this->_options['indexes'][$index])) {
return $this->_options['indexes'][$index];
}
return false;
}
Doctrine_Configurable::getListener ( )
inherited

getListener

Returns
Doctrine_EventListener_Interface|Doctrine_Overloadable

Definition at line 294 of file Configurable.php.

{
if ( ! isset($this->attributes[Doctrine_Core::ATTR_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getListener();
}
return null;
}
return $this->attributes[Doctrine_Core::ATTR_LISTENER];
}
Doctrine_Locator_Injectable::getLocator ( )
inherited

getLocator returns the locator associated with this object

if there are no locator locally associated then this method tries to fetch the current global locator

Returns
Doctrine_Locator

Definition at line 75 of file Injectable.php.

{
if ( ! isset($this->_locator)) {
$this->_locator = Doctrine_Locator::instance();
}
return $this->_locator;
}
Doctrine_Table::getMethodOwner (   $method)

getMethodOwner

Parameters
string$method
Returns
void

Definition at line 607 of file Table.php.

{
return (isset($this->_invokedMethods[$method])) ?
$this->_invokedMethods[$method] : false;
}
static Doctrine_Locator_Injectable::getNullObject ( )
staticinherited

getNullObject returns the null object associated with this object

Returns
Doctrine_Null

Definition at line 145 of file Injectable.php.

{
return self::$_null;
}
Doctrine_Table::getOption (   $name)

Returns the value of a given option.

See Also
Doctrine_Table::$_options for available options
Parameters
string$namethe name of the option
Returns
mixed the value of given option

Definition at line 1086 of file Table.php.

{
if (isset($this->_options[$name])) {
return $this->_options[$name];
}
return null;
}
Doctrine_Table::getOptions ( )

Retrieves all options of this table and the associated values.

Returns
array all options and their values

Definition at line 803 of file Table.php.

{
return $this->_options;
}
Doctrine_Table::getOrderByStatement (   $alias = null,
  $columnNames = false 
)

Get the table orderby statement

Parameters
string$aliasThe alias to use
boolean$columnNamesWhether or not to use column names instead of field names
Returns
string $orderByStatement

Definition at line 1102 of file Table.php.

{
if (isset($this->_options['orderBy'])) {
return $this->processOrderBy($alias, $this->_options['orderBy']);
}
}
Doctrine_Configurable::getParent ( )
inherited

getParent returns the parent of this component

Returns
Doctrine_Configurable

Definition at line 423 of file Configurable.php.

{
return $this->parent;
}
Doctrine_Table::getParentGenerator ( )

Get the parent generator responsible for this table instance

Returns
Doctrine_Record_Generator

Definition at line 2560 of file Table.php.

{
return $this->_generator;
}
Doctrine_Table::getProxy (   $id = null)
final
Parameters
$iddatabase row id
Exceptions
Doctrine_Find_Exception
Returns
Doctrine_Record

Definition at line 1907 of file Table.php.

{
if ($id !== null) {
$identifierColumnNames = $this->getIdentifierColumnNames();
$query = 'SELECT ' . implode(', ', (array) $identifierColumnNames)
. ' FROM ' . $this->getTableName()
. ' WHERE ' . implode(' = ? && ', (array) $identifierColumnNames) . ' = ?';
$query = $this->applyInheritance($query);
$params = array_merge(array($id), array_values($this->_options['inheritanceMap']));
$this->_data = $this->_conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC);
if ($this->_data === false)
return false;
}
return $this->getRecord();
}
Doctrine_Table::getQueryObject ( )
Returns
Doctrine_Query a Doctrine_Query object

Definition at line 1957 of file Table.php.

{
$graph = $this->createQuery();
$graph->load($this->getComponentName());
return $graph;
}
Doctrine_Table::getRecord ( )

Returns a new record.

This method checks if a internal record exists in identityMap, if does not exist it creates a new one.

Returns
Doctrine_Record

Definition at line 1812 of file Table.php.

{
if ( ! empty($this->_data)) {
$identifierFieldNames = $this->getIdentifier();
if ( ! is_array($identifierFieldNames)) {
$identifierFieldNames = array($identifierFieldNames);
}
$found = false;
foreach ($identifierFieldNames as $fieldName) {
if ( ! isset($this->_data[$fieldName])) {
// primary key column not found return new record
$found = true;
break;
}
$id[] = $this->_data[$fieldName];
}
if ($found) {
$recordName = $this->getComponentName();
$record = new $recordName($this, true);
$this->_data = array();
return $record;
}
$id = implode(' ', $id);
if (isset($this->_identityMap[$id])) {
$record = $this->_identityMap[$id];
if ($record->getTable()->getAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE)) {
$record->hydrate($this->_data);
if ($record->state() == Doctrine_Record::STATE_PROXY) {
if (!$record->isInProxyState()) {
}
}
} else {
$record->hydrate($this->_data, false);
}
} else {
$recordName = $this->getComponentName();
$record = new $recordName($this);
$this->_identityMap[$id] = $record;
}
$this->_data = array();
} else {
$recordName = $this->getComponentName();
$record = new $recordName($this, true);
}
return $record;
}
Doctrine_Table::getRecordInstance ( )

Gets the record instance for this table.

The Doctrine_Table instance always holds at least one instance of a model so that it can be reused for several things, but primarily it is first used to instantiate all the internal in memory schema definition.

Returns
Doctrine_Record Empty instance of the record

Definition at line 542 of file Table.php.

{
if ( ! $this->record) {
$this->record = new $this->_options['name'];
}
return $this->record;
}
Doctrine_Configurable::getRecordListener ( )
inherited

getListener

Returns
Doctrine_EventListener_Interface|Doctrine_Overloadable

Definition at line 242 of file Configurable.php.

{
if ( ! isset($this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getRecordListener();
}
return null;
}
return $this->attributes[Doctrine_Core::ATTR_RECORD_LISTENER];
}
Doctrine_Table::getRelation (   $alias,
  $recursive = true 
)

Retrieves a relation object for this component.

Parameters
string$aliasrelation alias;
See Also
hasRelation()
Returns
Doctrine_Relation

Definition at line 999 of file Table.php.

{
return $this->_parser->getRelation($alias, $recursive);
}
Doctrine_Table::getRelationParser ( )

Retrieves the relation parser associated with this table.

Returns
Doctrine_Relation_Parser relation parser object

Definition at line 755 of file Table.php.

{
return $this->_parser;
}
Doctrine_Table::getRelations ( )

Retrieves all relation objects defined on this table.

Returns
array

Definition at line 1009 of file Table.php.

{
return $this->_parser->getRelations();
}
Doctrine_Table::getRepository ( )

Gets the internal record repository.

Returns
Doctrine_Table_Repository

Definition at line 1045 of file Table.php.

{
return $this->_repository;
}
Doctrine_Table::getTableName ( )

Gets the table name in the db.

Returns
string

Definition at line 2398 of file Table.php.

{
return $this->_options['tableName'];
}
Doctrine_Table::getTemplate (   $template)

Retrieves a particular template by class name.

This method retrieves a behavior/template object attached to the table. For Doctrine_Template_* classes, the base name can be used.

Parameters
string$templatename of the behavior
Exceptions
Doctrine_Table_Exceptionif the given template is not set on this table
Returns
Doctrine_Template

Definition at line 2445 of file Table.php.

{
if (isset($this->_templates['Doctrine_Template_' . $template])) {
return $this->_templates['Doctrine_Template_' . $template];
} else if (isset($this->_templates[$template])) {
return $this->_templates[$template];
}
throw new Doctrine_Table_Exception('Template ' . $template . ' not loaded');
}
Doctrine_Table::getTemplates ( )

Retrieves all templates (behaviors) attached to this table.

Returns
array an array containing all templates

Definition at line 2429 of file Table.php.

{
return $this->_templates;
}
Doctrine_Table::getTree ( )

Gets associated tree. This method returns the associated Tree object (if any exists). Normally implemented by NestedSet behavior.

Returns
Doctrine_Tree false if not a tree

Definition at line 2368 of file Table.php.

{
if (isset($this->_options['treeImpl'])) {
if ( ! $this->_tree) {
$options = isset($this->_options['treeOptions']) ? $this->_options['treeOptions'] : array();
$this->_tree = Doctrine_Tree::factory($this,
$this->_options['treeImpl'],
$options
);
}
return $this->_tree;
}
return false;
}
Doctrine_Table::getTypeOf (   $fieldName)

Retrieves the type of a field.

Parameters
string$fieldName
Returns
string false on failure

Definition at line 2248 of file Table.php.

{
return $this->getTypeOfColumn($this->getColumnName($fieldName));
}
Doctrine_Table::getTypeOfColumn (   $columnName)

Retrieves the type of a column.

Parameters
string$columnName
Returns
string false if column is not found

Definition at line 2259 of file Table.php.

{
return isset($this->_columns[$columnName]) ? $this->_columns[$columnName]['type'] : false;
}
Doctrine_Table::getUniques ( )

Gets the array of unique fields sets.

See Also
$_uniques;
Returns
array numeric array

Definition at line 2212 of file Table.php.

{
}
Doctrine_Table::hasColumn (   $columnName)

Finds out whether the table definition contains a given column.

Parameters
string$columnName
Returns
boolean

Definition at line 1458 of file Table.php.

{
return isset($this->_columns[strtolower($columnName)]);
}
Doctrine_Table::hasDefaultValues ( )

Finds out whether this table has default values for columns.

Returns
boolean

Definition at line 1408 of file Table.php.

{
return $this->hasDefaultValues;
}
Doctrine_Table::hasField (   $fieldName)

Finds out whether the table definition has a given field.

This method returns true if

See Also
hasColumn() returns true or if an alias named $fieldName exists.
Parameters
string$fieldName
Returns
boolean

Definition at line 1471 of file Table.php.

{
return isset($this->_columnNames[$fieldName]);
}
Doctrine_Table::hasGenerator (   $generator)

Checks if a generator name exists.

Parameters
string$generator
Returns
void

Definition at line 2512 of file Table.php.

{
return isset($this->_generators[$generator]);
}
Doctrine_Table::hasMany ( )

Binds One-to-Many / Many-to-Many aggregate relation

Parameters
string$componentNamethe name of the related component
string$optionsrelation options
See Also
Doctrine_Relation::_$definition
Returns
Doctrine_Record this object

Definition at line 972 of file Table.php.

{
$this->bind(func_get_args(), Doctrine_Relation::MANY);
}
Doctrine_Table::hasOne ( )

Binds One-to-One aggregate relation

Parameters
string$componentNamethe name of the related component
string$optionsrelation options
See Also
Doctrine_Relation::_$definition
Returns
Doctrine_Record this object

Definition at line 959 of file Table.php.

{
$this->bind(func_get_args(), Doctrine_Relation::ONE);
}
Doctrine_Table::hasRelation (   $alias)

Tests if a relation exists.

This method queries the table definition to find out if a relation is defined for this component. Alias defined with foreignAlias are not recognized as there's only one Doctrine_Relation object on the owning side.

Parameters
string$aliasthe relation alias to search for.
Returns
boolean true if the relation exists. Otherwise false.

Definition at line 988 of file Table.php.

{
return $this->_parser->hasRelation($alias);
}
Doctrine_Table::hasTemplate (   $template)

Checks if the table has a given template.

Parameters
string$templatename of template;
See Also
getTemplate()
Returns
boolean

Definition at line 2462 of file Table.php.

{
return isset($this->_templates[$template]) || isset($this->_templates['Doctrine_Template_' . $template]);
}
Doctrine_Table::initDefinition ( )

Initializes the in-memory table definition.

Parameters
string$name

Definition at line 295 of file Table.php.

{
$name = $this->_options['name'];
if ( ! class_exists($name) || empty($name)) {
throw new Doctrine_Exception("Couldn't find class " . $name);
}
$record = new $name($this);
$names = array();
$class = $name;
// get parent classes
do {
if ($class === 'Doctrine_Record') {
break;
}
$name = $class;
$names[] = $name;
} while ($class = get_parent_class($class));
if ($class === false) {
throw new Doctrine_Table_Exception('Class "' . $name . '" must be a child class of Doctrine_Record');
}
// reverse names
$names = array_reverse($names);
// save parents
array_pop($names);
$this->_options['parents'] = $names;
// create database table
if (method_exists($record, 'setTableDefinition')) {
$record->setTableDefinition();
// get the declaring class of setTableDefinition method
$method = new ReflectionMethod($this->_options['name'], 'setTableDefinition');
$class = $method->getDeclaringClass();
} else {
$class = new ReflectionClass($class);
}
$this->_options['joinedParents'] = array();
foreach (array_reverse($this->_options['parents']) as $parent) {
if ($parent === $class->getName()) {
continue;
}
$ref = new ReflectionClass($parent);
if ($ref->isAbstract() || ! $class->isSubClassOf($parent)) {
continue;
}
$parentTable = $this->_conn->getTable($parent);
$found = false;
$parentColumns = $parentTable->getColumns();
foreach ($parentColumns as $columnName => $definition) {
if ( ! isset($definition['primary']) || $definition['primary'] === false) {
if (isset($this->_columns[$columnName])) {
$found = true;
break;
} else {
if ( ! isset($parentColumns[$columnName]['owner'])) {
$parentColumns[$columnName]['owner'] = $parentTable->getComponentName();
}
$this->_options['joinedParents'][] = $parentColumns[$columnName]['owner'];
}
} else {
unset($parentColumns[$columnName]);
}
}
if ($found) {
continue;
}
foreach ($parentColumns as $columnName => $definition) {
$fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName);
$this->setColumn($fullName, $definition['type'], $definition['length'], $definition, true);
}
break;
}
$this->_options['joinedParents'] = array_values(array_unique($this->_options['joinedParents']));
$this->_options['declaringClass'] = $class;
// set the table definition for the given tree implementation
if ($this->isTree()) {
$this->getTree()->setTableDefinition();
}
$this->columnCount = count($this->_columns);
if ( ! isset($this->_options['tableName'])) {
$this->setTableName(Doctrine_Inflector::tableize($class->getName()));
}
return $record;
}
Doctrine_Table::initIdentifier ( )

Initializes the primary key.

Called in the construction process, builds the identifier definition copying in the schema the list of the fields which constitutes the primary key.

Returns
void

Definition at line 412 of file Table.php.

{
switch (count($this->_identifier)) {
case 0:
if ( ! empty($this->_options['joinedParents'])) {
$root = current($this->_options['joinedParents']);
$table = $this->_conn->getTable($root);
$this->_identifier = $table->getIdentifier();
$this->_identifierType = ($table->getIdentifierType() !== Doctrine_Core::IDENTIFIER_AUTOINC)
? $table->getIdentifierType() : Doctrine_Core::IDENTIFIER_NATURAL;
// add all inherited primary keys
foreach ((array) $this->_identifier as $id) {
$definition = $table->getDefinitionOf($id);
// inherited primary keys shouldn't contain autoinc
// and sequence definitions
unset($definition['autoincrement']);
unset($definition['sequence']);
// add the inherited primary key column
$fullName = $id . ' as ' . $table->getFieldName($id);
$this->setColumn($fullName, $definition['type'], $definition['length'],
$definition, true);
}
} else {
$identifierOptions = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_IDENTIFIER_OPTIONS);
$name = (isset($identifierOptions['name']) && $identifierOptions['name']) ? $identifierOptions['name']:'id';
$name = sprintf($name, $this->getTableName());
$definition = array('type' => (isset($identifierOptions['type']) && $identifierOptions['type']) ? $identifierOptions['type']:'integer',
'length' => (isset($identifierOptions['length']) && $identifierOptions['length']) ? $identifierOptions['length']:8,
'autoincrement' => isset($identifierOptions['autoincrement']) ? $identifierOptions['autoincrement']:true,
'primary' => isset($identifierOptions['primary']) ? $identifierOptions['primary']:true);
unset($identifierOptions['name'], $identifierOptions['type'], $identifierOptions['length']);
foreach ($identifierOptions as $key => $value) {
if ( ! isset($definition[$key]) || ! $definition[$key]) {
$definition[$key] = $value;
}
}
$this->setColumn($name, $definition['type'], $definition['length'], $definition, true);
$this->_identifier = $name;
$this->_identifierType = Doctrine_Core::IDENTIFIER_AUTOINC;
}
$this->columnCount++;
break;
case 1:
foreach ($this->_identifier as $pk) {
$e = $this->getDefinitionOf($pk);
$found = false;
foreach ($e as $option => $value) {
if ($found) {
break;
}
$e2 = explode(':', $option);
switch (strtolower($e2[0])) {
case 'autoincrement':
case 'autoinc':
if ($value !== false) {
$this->_identifierType = Doctrine_Core::IDENTIFIER_AUTOINC;
$found = true;
}
break;
case 'seq':
case 'sequence':
$this->_identifierType = Doctrine_Core::IDENTIFIER_SEQUENCE;
$found = true;
if (is_string($value)) {
$this->_options['sequenceName'] = $value;
} else {
if (($sequence = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_SEQUENCE)) !== null) {
$this->_options['sequenceName'] = $sequence;
} else {
$this->_options['sequenceName'] = $this->_conn->formatter->getSequenceName($this->_options['tableName']);
}
}
break;
}
}
if ( ! isset($this->_identifierType)) {
$this->_identifierType = Doctrine_Core::IDENTIFIER_NATURAL;
}
}
$this->_identifier = $pk;
break;
default:
$this->_identifierType = Doctrine_Core::IDENTIFIER_COMPOSITE;
}
}
static Doctrine_Locator_Injectable::initNullObject ( Doctrine_Null  $null)
staticinherited

initNullObject initializes the null object

Parameters
Doctrine_Null$null
Returns
void

Definition at line 134 of file Injectable.php.

{
self::$_null = $null;
}
Doctrine_Table::isGenerator ( )

Check whether this table was created by a record generator or not

Returns
boolean

Definition at line 2550 of file Table.php.

{
return isset($this->_generator) ? true : false;
}
Doctrine_Table::isIdentifier (   $fieldName)

Checks whether a field is in the primary key.

Checks if $fieldName is part of the table identifier, which defines the one-column or multi-column primary key.

Parameters
string$fieldNameThe field name
Returns
boolean TRUE if the field is part of the table identifier/primary key field(s),

Definition at line 570 of file Table.php.

{
return ($fieldName === $this->getIdentifier() ||
in_array($fieldName, (array) $this->getIdentifier()));
}
Doctrine_Table::isIdentifierAutoincrement ( )

Checks whether a field identifier is of type autoincrement.

This method checks if the primary key is a AUTOINCREMENT column or if the table uses a natural key.

Returns
boolean TRUE if the identifier is autoincrement FALSE otherwise

Definition at line 585 of file Table.php.

Doctrine_Table::isIdentifierComposite ( )

Checks whether a field identifier is a composite key.

Returns
boolean TRUE if the identifier is a composite key, FALSE otherwise

Definition at line 596 of file Table.php.

Doctrine_Table::isInheritedColumn (   $columnName)

Checks whether a column is inherited from a component further up in the hierarchy.

Parameters
$columnNameThe column name
Returns
boolean TRUE if column is inherited, FALSE otherwise.

Definition at line 556 of file Table.php.

{
return (isset($this->_columns[$columnName]['owner']));
}
Doctrine_Table::isTree ( )

Determines if table acts as tree.

Returns
boolean if tree return true, otherwise returns false

Definition at line 2419 of file Table.php.

{
return ( ! is_null($this->_options['treeImpl'])) ? true : false;
}
Doctrine_Locator_Injectable::locate (   $name)
inherited

locate locates a resource by given name and returns it

if the resource cannot be found locally this method tries to use the global locator for finding the resource

See Also
Doctrine_Locator::locate()
Exceptions
Doctrine_Locator_Exceptionif the resource could not be found
Parameters
string$namethe name of the resource
Returns
mixed the located resource

Definition at line 96 of file Injectable.php.

{
if (isset($this->_resources[$name])) {
if (is_object($this->_resources[$name])) {
return $this->_resources[$name];
} else {
// get the name of the concrete implementation
$concreteImpl = $this->_resources[$name];
return $this->getLocator()->locate($concreteImpl);
}
} else {
return $this->getLocator()->locate($name);
}
}
Doctrine_Table::prepareValue (   $fieldName,
  $value,
  $typeHint = null 
)

Performs special data preparation.

This method returns a representation of a field data, depending on the type of the given column.

  1. It unserializes array and object typed columns
  2. Uncompresses gzip typed columns
  3. Initializes special null object pointer for null values (for fast column existence checking purposes)

example: $field = 'name'; $value = null; $table->prepareValue($field, $value); // Doctrine_Null

Exceptions
Doctrine_Table_Exceptionif unserialization of array/object typed column fails or
Doctrine_Table_Exceptionif uncompression of gzip typed column fails *
Parameters
string$fieldthe name of the field
string$valuefield value
string$typeHintType hint used to pass in the type of the value to prepare if it is already known. This enables the method to skip the type determination. Used i.e. during hydration.
Returns
mixed prepared value

Definition at line 2316 of file Table.php.

{
if ($value === self::$_null) {
return self::$_null;
} else if ($value === null) {
return null;
} else {
$type = is_null($typeHint) ? $this->getTypeOf($fieldName) : $typeHint;
switch ($type) {
case 'enum':
case 'integer':
case 'string';
// don't do any casting here PHP INT_MAX is smaller than what the databases support
break;
case 'set':
return explode(',', $value);
break;
case 'boolean':
return (boolean) $value;
break;
case 'array':
case 'object':
if (is_string($value)) {
$value = empty($value) ? null:unserialize($value);
if ($value === false) {
throw new Doctrine_Table_Exception('Unserialization of ' . $fieldName . ' failed.');
}
return $value;
}
break;
case 'gzip':
$value = gzuncompress($value);
if ($value === false) {
throw new Doctrine_Table_Exception('Uncompressing of ' . $fieldName . ' failed.');
}
return $value;
break;
}
}
return $value;
}
Doctrine_Table::processOrderBy (   $alias,
  $orderBy,
  $columnNames = false 
)

Process an order by statement to be prefixed with the passed alias and field names converted to column names if the 3rd argument is true.

Parameters
string$aliasThe alias to prefix columns with
string$orderByThe order by to process
string$columnNamesWhether or not to convert field names to column names
Returns
string $orderBy

Definition at line 1118 of file Table.php.

{
if ( ! $alias) {
$alias = $this->getComponentName();
}
if ( ! is_array($orderBy)) {
$e1 = explode(',', $orderBy);
} else {
$e1 = $orderBy;
}
$e1 = array_map('trim', $e1);
foreach ($e1 as $k => $v) {
$e2 = explode(' ', $v);
if ($columnNames) {
$e2[0] = $this->getColumnName($e2[0]);
}
if ($this->hasField($this->getFieldName($e2[0]))) {
$e1[$k] = $alias . '.' . $e2[0];
} else {
$e1[$k] = $e2[0];
}
if (isset($e2[1])) {
$e1[$k] .= ' ' . $e2[1];
}
}
return implode(', ', $e1);
}
Doctrine_Table::removeColumn (   $fieldName)

Removes a field name from the table schema information.

Parameters
string$fieldName
Returns
boolean true if the field is found and removed. False otherwise.

Definition at line 2166 of file Table.php.

{
if ( ! $this->hasField($fieldName)) {
return false;
}
$columnName = $this->getColumnName($fieldName);
unset($this->_columnNames[$fieldName], $this->_fieldNames[$columnName], $this->_columns[$columnName]);
$this->columnCount = count($this->_columns);
return true;
}
Doctrine_Table::removeRecord ( Doctrine_Record  $record)

Removes a record from the identity map.

This method deletes from the cache the given record; can be used to force reloading of an object from database.

Parameters
Doctrine_Record$recordrecord to remove from cache
Returns
boolean true if the record was found and removed, false if the record wasn't found.

Definition at line 1792 of file Table.php.

{
$id = implode(' ', $record->identifier());
if (isset($this->_identityMap[$id])) {
unset($this->_identityMap[$id]);
return true;
}
return false;
}
Doctrine_Configurable::setAttribute (   $attribute,
  $value 
)
inherited

setAttribute sets a given attribute

$manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_ALL);

Parameters
mixed$attributeeither a Doctrine_Core::ATTR_* integer constant or a string corresponding to a constant
mixed$valuethe value of the attribute
See Also
Doctrine_Core::ATTR_* constants
Exceptions
Doctrine_Exceptionif the value is invalid
Returns
void

Definition at line 73 of file Configurable.php.

{
switch ($attribute) {
$this->setEventListener($value);
break;
case Doctrine_Core::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->hasField($value)) {
throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'.");
}
break;
case Doctrine_Core::ATTR_CACHE:
case Doctrine_Core::ATTR_RESULT_CACHE:
case Doctrine_Core::ATTR_QUERY_CACHE:
if ($value !== null) {
if ( ! ($value instanceof Doctrine_Cache_Interface)) {
throw new Doctrine_Exception('Cache driver should implement Doctrine_Cache_Interface');
}
}
break;
case Doctrine_Core::ATTR_SEQCOL_NAME:
if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break;
case Doctrine_Core::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_Core::ATTR_SEQNAME_FORMAT:
case Doctrine_Core::ATTR_IDXNAME_FORMAT:
case Doctrine_Core::ATTR_TBLNAME_FORMAT:
case Doctrine_Core::ATTR_FKNAME_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;
}
$this->attributes[$attribute] = $value;
}
Doctrine_Configurable::setCharset (   $charset)
inherited

Set the charset

Parameters
string$charset

Definition at line 370 of file Configurable.php.

{
$this->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET, $charset);
}
Doctrine_Configurable::setCollate (   $collate)
inherited

Set the collate

Parameters
string$collate

Definition at line 390 of file Configurable.php.

{
$this->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE, $collate);
}
Doctrine_Table::setColumn (   $name,
  $type = null,
  $length = null,
  $options = array(),
  $prepend = false 
)

Adds a column to the schema.

This method does not alter the database table;

See Also
export();
$_columns;
Parameters
string$namecolumn physical name
string$typetype of data
integer$lengthmaximum length
mixed$options
boolean$prependWhether to prepend or append the new column to the column list. By default the column gets appended.
Exceptions
Doctrine_Table_Exceptionif trying use wrongly typed parameter
Returns
void

Definition at line 1286 of file Table.php.

{
if (is_string($options)) {
$options = explode('|', $options);
}
foreach ($options as $k => $option) {
if (is_numeric($k)) {
if ( ! empty($option)) {
$options[$option] = true;
}
unset($options[$k]);
}
}
// extract column name & field name
if (stripos($name, ' as '))
{
if (strpos($name, ' as ')) {
$parts = explode(' as ', $name);
} else {
$parts = explode(' AS ', $name);
}
if (count($parts) > 1) {
$fieldName = $parts[1];
} else {
$fieldName = $parts[0];
}
$name = strtolower($parts[0]);
} else {
$fieldName = $name;
$name = strtolower($name);
}
$name = trim($name);
$fieldName = trim($fieldName);
if ($prepend) {
$this->_columnNames = array_merge(array($fieldName => $name), $this->_columnNames);
$this->_fieldNames = array_merge(array($name => $fieldName), $this->_fieldNames);
} else {
$this->_columnNames[$fieldName] = $name;
$this->_fieldNames[$name] = $fieldName;
}
$defaultOptions = $this->getAttribute(Doctrine_Core::ATTR_DEFAULT_COLUMN_OPTIONS);
if (isset($defaultOptions['length']) && $defaultOptions['length'] && $length == null) {
$length = $defaultOptions['length'];
}
if ($length == null) {
switch ($type) {
case 'integer':
$length = 8;
break;
case 'decimal':
$length = 18;
break;
case 'string':
case 'clob':
case 'float':
case 'integer':
case 'array':
case 'object':
case 'blob':
case 'gzip':
//$length = 2147483647;
//All the DataDict driver classes have work-arounds to deal
//with unset lengths.
$length = null;
break;
case 'boolean':
$length = 1;
case 'date':
// YYYY-MM-DD ISO 8601
$length = 10;
case 'time':
// HH:NN:SS+00:00 ISO 8601
$length = 14;
case 'timestamp':
// YYYY-MM-DDTHH:MM:SS+00:00 ISO 8601
$length = 25;
}
}
$options['type'] = $type;
$options['length'] = $length;
foreach ($defaultOptions as $key => $value) {
if ( ! array_key_exists($key, $options) || is_null($options[$key])) {
$options[$key] = $value;
}
}
if ($prepend) {
$this->_columns = array_merge(array($name => $options), $this->_columns);
} else {
$this->_columns[$name] = $options;
}
if (isset($options['primary']) && $options['primary']) {
if (isset($this->_identifier)) {
$this->_identifier = (array) $this->_identifier;
}
if ( ! in_array($fieldName, $this->_identifier)) {
$this->_identifier[] = $fieldName;
}
}
if (isset($options['default'])) {
$this->hasDefaultValues = true;
}
}
Doctrine_Table::setColumnOption (   $columnName,
  $option,
  $value 
)

Set an individual column option

Parameters
string$columnName
string$option
string$value
Returns
void

Definition at line 1239 of file Table.php.

{
if ($option == 'primary') {
if (isset($this->_identifier)) {
$this->_identifier = (array) $this->_identifier;
}
if ($value && ! in_array($columnName, $this->_identifier)) {
$this->_identifier[] = $columnName;
} else if (!$value && in_array($columnName, $this->_identifier)) {
$key = array_search($columnName, $this->_identifier);
unset($this->_identifier[$key]);
}
}
$columnName = $this->getColumnName($columnName);
$this->_columns[$columnName][$option] = $value;
}
Doctrine_Table::setColumnOptions (   $columnName,
array  $options 
)

Customize the array of options for a column or multiple columns. First argument can be a single field/column name or an array of them. The second argument is an array of options.

[php]
public function setTableDefinition()
{
    parent::setTableDefinition();
    $this->setColumnOptions('username', array(
        'unique' => true
    ));
}
Parameters
string$columnName
array$validators
Returns
void

Definition at line 1218 of file Table.php.

{
if (is_array($columnName)) {
foreach ($columnName as $name) {
$this->setColumnOptions($name, $options);
}
} else {
foreach ($options as $option => $value) {
$this->setColumnOption($columnName, $option, $value);
}
}
}
Doctrine_Table::setColumns ( array  $definitions)

Set multiple column definitions at once

Parameters
array$definitions
Returns
void

Definition at line 1264 of file Table.php.

{
foreach ($definitions as $name => $options) {
$this->setColumn($name, $options['type'], $options['length'], $options);
}
}
Doctrine_Table::setConnection ( Doctrine_Connection  $conn)

Sets the default connection for this table.

This method assign the connection which this table will use to create queries.

Doctrine_Connection a connection object

Returns
Doctrine_Table this object; fluent interface

Definition at line 1485 of file Table.php.

{
$this->_conn = $conn;
$this->setParent($this->_conn);
return $this;
}
Doctrine_Table::setData ( array  $data)

Doctrine uses this function internally. Users are strongly discouraged to use this function.

private

Parameters
array$datainternal data
Returns
void

Definition at line 2272 of file Table.php.

{
$this->_data = $data;
}
Doctrine_Configurable::setEventListener (   $listener)
inherited
Parameters
Doctrine_EventListener$listener
Returns
void

Definition at line 214 of file Configurable.php.

{
return $this->setListener($listener);
}
Doctrine_Table::setGenerator ( Doctrine_Record_Generator  $generator)

Set the generator responsible for creating this table

Parameters
Doctrine_Record_Generator$generator
Returns
void

Definition at line 2540 of file Table.php.

{
$this->_generator = $generator;
}
Doctrine_Configurable::setImpl (   $template,
  $class 
)
inherited

setImpl binds given class to given template name

this method is the base of Doctrine dependency injection

Parameters
string$templatename of the class template
string$classname of the class to be bound
Returns
Doctrine_Configurable this object

Definition at line 174 of file Configurable.php.

{
$this->_impl[$template] = $class;
return $this;
}
Doctrine_Configurable::setListener (   $listener)
inherited

setListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Configurable this object

Definition at line 311 of file Configurable.php.

{
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_Core::ATTR_LISTENER] = $listener;
return $this;
}
Doctrine_Locator_Injectable::setLocator ( Doctrine_Locator  $locator)
inherited

setLocator this method can be used for setting the locator object locally

Parameters
Doctrine_Locatorthe locator object
Returns
Doctrine_Locator_Injectable this instance

Definition at line 60 of file Injectable.php.

{
$this->_locator = $locator;
return $this;
}
Doctrine_Table::setMethodOwner (   $method,
  $class 
)

setMethodOwner

Parameters
string$method
string$class

Definition at line 619 of file Table.php.

{
$this->_invokedMethods[$method] = $class;
}
Doctrine_Table::setOption (   $name,
  $value 
)

Sets an option for the table.

This method sets an option and returns this object in order to allow flexible method chaining.

See Also
Doctrine_Table::$_options for available options
Parameters
string$namethe name of the option to set
mixed$valuethe value of the option
Returns
Doctrine_Table this object

Definition at line 1061 of file Table.php.

{
switch ($name) {
case 'name':
case 'tableName':
break;
case 'enumMap':
case 'inheritanceMap':
case 'index':
case 'treeOptions':
if ( ! is_array($value)) {
throw new Doctrine_Table_Exception($name . ' should be an array.');
}
break;
}
$this->_options[$name] = $value;
}
Doctrine_Table::setOptions (   $options)

Sets all the options.

This method sets options of the table that are specified in the argument. It has no effect on other options.

Parameters
array$optionskeys are option names
Returns
void

Definition at line 817 of file Table.php.

{
foreach ($options as $key => $value) {
$this->setOption($key, $value);
}
}
Doctrine_Configurable::setParent ( Doctrine_Configurable  $component)
inherited

sets a parent for this configurable component the parent must be configurable component itself

Parameters
Doctrine_Configurable$component
Returns
void

Definition at line 412 of file Configurable.php.

{
$this->parent = $component;
}
Doctrine_Configurable::setRecordListener (   $listener)
inherited

setListener

Parameters
Doctrine_EventListener_Interface | Doctrine_Overloadable$listener
Returns
Doctrine_Configurable this object

Definition at line 259 of file Configurable.php.

{
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_Core::ATTR_RECORD_LISTENER] = $listener;
return $this;
}
Doctrine_Table::setTableName (   $tableName)

sets the table name in the schema definition.

Parameters
string$tableName
Returns
void

Definition at line 2409 of file Table.php.

{
$this->setOption('tableName', $this->_conn->formatter->getTableName($tableName));
}
Doctrine_Table::unique (   $fields,
  $options = array(),
  $createdUniqueIndex = true 
)

Defines a n-uple of fields that must be unique for every record.

This method Will automatically add UNIQUE index definition and validate the values on save. The UNIQUE index is not created in the database until you use

See Also
export().
Parameters
array$fieldsvalues are fieldnames
array$optionsarray of options for unique validator
bool$createUniqueIndexWhether or not to create a unique index in the database
Returns
void

Definition at line 919 of file Table.php.

{
if ($createdUniqueIndex) {
$name = implode('_', $fields) . '_unqidx';
$definition = array('type' => 'unique', 'fields' => $fields);
$this->addIndex($name, $definition);
}
$this->_uniques[] = array($fields, $options);
}
Doctrine_Configurable::unsetAttribute (   $attribute)
inherited

Unset an attribute from this levels attributes

Parameters
integer$attribute
Returns
void

Definition at line 347 of file Configurable.php.

{
if (isset($this->attributes[$attribute])) {
unset($this->attributes[$attribute]);
}
}
Doctrine_Table::unshiftFilter ( Doctrine_Record_Filter  $filter)

unshiftFilter

Parameters
Doctrine_Record_Filter$filter
Returns
Doctrine_Table this object (provides a fluent interface)

Definition at line 2675 of file Table.php.

{
$filter->setTable($this);
$filter->init();
array_unshift($this->_filters, $filter);
return $this;
}
Doctrine_Table::validateField (   $fieldName,
  $value,
Doctrine_Record  $record = null 
)

Validates a given field using table ATTR_VALIDATE rules.

See Also
Doctrine_Core::ATTR_VALIDATE
Parameters
string$fieldName
string$value
Doctrine_Record$recordrecord to consider; if it does not exists, it is created
Returns
Doctrine_Validator_ErrorStack $errorStack

Definition at line 2032 of file Table.php.

{
if ($record instanceof Doctrine_Record) {
$errorStack = $record->getErrorStack();
} else {
$record = $this->create();
$errorStack = new Doctrine_Validator_ErrorStack($this->getOption('name'));
}
if ($value === self::$_null) {
$value = null;
} else if ($value instanceof Doctrine_Record && $value->exists()) {
$value = $value->getIncremented();
} else if ($value instanceof Doctrine_Record && ! $value->exists()) {
foreach($this->getRelations() as $relation) {
if ($fieldName == $relation->getLocalFieldName() && (get_class($value) == $relation->getClass() || is_subclass_of($value, $relation->getClass()))) {
return $errorStack;
}
}
}
$dataType = $this->getTypeOf($fieldName);
// Validate field type, if type validation is enabled
if ($this->getAttribute(Doctrine_Core::ATTR_VALIDATE) & Doctrine_Core::VALIDATE_TYPES) {
if ( ! Doctrine_Validator::isValidType($value, $dataType)) {
$errorStack->add($fieldName, 'type');
}
if ($dataType == 'enum') {
$enumIndex = $this->enumIndex($fieldName, $value);
if ($enumIndex === false && $value !== null) {
$errorStack->add($fieldName, 'enum');
}
}
if ($dataType == 'set') {
$values = $this->_columns[$fieldName]['values'];
// Convert string to array
if (is_string($value)) {
$value = explode(',', $value);
$value = array_map('trim', $value);
$record->set($fieldName, $value);
}
// Make sure each set value is valid
foreach ($value as $k => $v) {
if ( ! in_array($v, $values)) {
$errorStack->add($fieldName, 'set');
}
}
}
}
// Validate field length, if length validation is enabled
if ($this->getAttribute(Doctrine_Core::ATTR_VALIDATE) & Doctrine_Core::VALIDATE_LENGTHS) {
if ( ! Doctrine_Validator::validateLength($value, $dataType, $this->getFieldLength($fieldName))) {
$errorStack->add($fieldName, 'length');
}
}
// Run all custom validators
foreach ($this->getFieldValidators($fieldName) as $validatorName => $args) {
if ( ! is_string($validatorName)) {
$validatorName = $args;
$args = array();
}
$validator = Doctrine_Validator::getValidator($validatorName);
$validator->invoker = $record;
$validator->field = $fieldName;
$validator->args = $args;
if ( ! $validator->validate($value)) {
$errorStack->add($fieldName, $validator);
}
}
return $errorStack;
}
Doctrine_Table::validateUniques ( Doctrine_Record  $record)

Validates all the unique indexes.

This methods validates 'unique' sets of fields for the given Doctrine_Record instance. Pushes error to the record error stack if they are generated.

Parameters
Doctrine_Record$record

Definition at line 2117 of file Table.php.

{
$errorStack = $record->getErrorStack();
$validator = Doctrine_Validator::getValidator('unique');
$validator->invoker = $record;
foreach ($this->_uniques as $unique)
{
list($fields, $options) = $unique;
$validator->args = $options;
$validator->field = $fields;
$values = array();
foreach ($fields as $field) {
$values[] = $record->$field;
}
if ( ! $validator->validate($values)) {
foreach ($fields as $field) {
$errorStack->add($field, $validator);
}
}
}
}

Field Documentation

array Doctrine_Table::$_uniques = array()
protected

Array of unique sets of fields. These values are validated on save

Definition at line 92 of file Table.php.


The documentation for this class was generated from the following file: