CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,144 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Data object to describe a joined hydration in a Model Query
* ModelWith objects are used by formatters to hydrate related objects
*
* @author Francois Zaninotto (Propel)
* @package propel.runtime.query
*/
class ModelWith
{
protected $modelName = '';
protected $modelPeerName = '';
protected $isSingleTableInheritance = false;
protected $isAdd = false;
protected $relationName = '';
protected $relationMethod = '';
protected $relatedClass;
public function __construct(ModelJoin $join = null)
{
if (null !== $join) {
$this->init($join);
}
}
/**
* Define the joined hydration schema based on a join object.
* Fills the ModelWith properties using a ModelJoin as source
*
* @param ModelJoin $join
*/
public function init(ModelJoin $join)
{
$tableMap = $join->getTableMap();
$this->modelName = $tableMap->getClassname();
$this->modelPeerName = $tableMap->getPeerClassname();
$this->isSingleTableInheritance = $tableMap->isSingleTableInheritance();
$relation = $join->getRelationMap();
if ($relation->getType() == RelationMap::ONE_TO_MANY) {
$this->isAdd = true;
$this->relationName = $relation->getName() . 's';
$this->relationMethod = 'add' . $relation->getName();
} else {
$this->relationName = $relation->getName();
$this->relationMethod = 'set' . $relation->getName();
}
if (!$join->isPrimary()) {
$this->relatedClass = $join->hasLeftTableAlias() ? $join->getLeftTableAlias() : $relation->getLeftTable()->getPhpName();
}
}
// DataObject getters & setters
public function setModelName($modelName)
{
$this->modelName = $modelName;
}
public function getModelName()
{
return $this->modelName;
}
public function setModelPeerName($modelPeerName)
{
$this->modelPeerName = $modelPeerName;
}
public function getModelPeerName()
{
return $this->modelPeerName;
}
public function setIsSingleTableInheritance($isSingleTableInheritance)
{
$this->isSingleTableInheritance = $isSingleTableInheritance;
}
public function isSingleTableInheritance()
{
return $this->isSingleTableInheritance;
}
public function setIsAdd($isAdd)
{
$this->isAdd = $isAdd;;
}
public function isAdd()
{
return $this->isAdd;
}
public function setRelationName($relationName)
{
$this->relationName = $relationName;
}
public function getRelationName()
{
return $this->relationName;
}
public function setRelationMethod($relationMethod)
{
$this->relationMethod = $relationMethod;
}
public function getRelationMethod()
{
return $this->relationMethod;
}
public function setRelatedClass($relatedClass)
{
$this->relatedClass = $relatedClass;
}
public function getRelatedClass()
{
return $this->relatedClass;
}
// Utility methods
public function isPrimary()
{
return null === $this->relatedClass;
}
public function __toString()
{
return sprintf("modelName: %s, relationName: %s, relationMethod: %s, relatedClass: %s", $this->modelName, $this->relationName, $this->relationMethod, $this->relatedClass);
}
}

View file

@ -0,0 +1,170 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Array formatter for Propel query
* format() returns a PropelArrayCollection of associative arrays
*
* @author Francois Zaninotto
* @version $Revision: 1796 $
* @package propel.runtime.formatter
*/
class PropelArrayFormatter extends PropelFormatter
{
protected $collectionName = 'PropelArrayCollection';
protected $alreadyHydratedObjects = array();
protected $emptyVariable;
public function format(PDOStatement $stmt)
{
$this->checkInit();
if($class = $this->collectionName) {
$collection = new $class();
$collection->setModel($this->class);
$collection->setFormatter($this);
} else {
$collection = array();
}
if ($this->isWithOneToMany() && $this->hasLimit) {
throw new PropelException('Cannot use limit() in conjunction with with() on a one-to-many relationship. Please remove the with() call, or the limit() call.');
}
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
if ($object = &$this->getStructuredArrayFromRow($row)) {
$collection[] = $object;
}
}
$this->currentObjects = array();
$this->alreadyHydratedObjects = array();
$stmt->closeCursor();
return $collection;
}
public function formatOne(PDOStatement $stmt)
{
$this->checkInit();
$result = null;
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
if ($object = &$this->getStructuredArrayFromRow($row)) {
$result = &$object;
}
}
$this->currentObjects = array();
$this->alreadyHydratedObjects = array();
$stmt->closeCursor();
return $result;
}
/**
* Formats an ActiveRecord object
*
* @param BaseObject $record the object to format
*
* @return array The original record turned into an array
*/
public function formatRecord($record = null)
{
return $record ? $record->toArray() : array();
}
public function isObjectFormatter()
{
return false;
}
/**
* Hydrates a series of objects from a result row
* The first object to hydrate is the model of the Criteria
* The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one
*
* @param array $row associative array indexed by column number,
* as returned by PDOStatement::fetch(PDO::FETCH_NUM)
*
* @return Array
*/
public function &getStructuredArrayFromRow($row)
{
$col = 0;
// hydrate main object or take it from registry
$mainObjectIsNew = false;
$mainKey = call_user_func(array($this->peer, 'getPrimaryKeyHashFromRow'), $row);
// we hydrate the main object even in case of a one-to-many relationship
// in order to get the $col variable increased anyway
$obj = $this->getSingleObjectFromRow($row, $this->class, $col);
if (!isset($this->alreadyHydratedObjects[$this->class][$mainKey])) {
$this->alreadyHydratedObjects[$this->class][$mainKey] = $obj->toArray();
$mainObjectIsNew = true;
}
$hydrationChain = array();
// related objects added using with()
foreach ($this->getWith() as $relAlias => $modelWith) {
// determine class to use
if ($modelWith->isSingleTableInheritance()) {
$class = call_user_func(array($modelWith->getModelPeerName(), 'getOMClass'), $row, $col, false);
$refl = new ReflectionClass($class);
if ($refl->isAbstract()) {
$col += constant($class . 'Peer::NUM_COLUMNS');
continue;
}
} else {
$class = $modelWith->getModelName();
}
// hydrate related object or take it from registry
$key = call_user_func(array($modelWith->getModelPeerName(), 'getPrimaryKeyHashFromRow'), $row, $col);
// we hydrate the main object even in case of a one-to-many relationship
// in order to get the $col variable increased anyway
$secondaryObject = $this->getSingleObjectFromRow($row, $class, $col);
if (!isset($this->alreadyHydratedObjects[$relAlias][$key])) {
if ($secondaryObject->isPrimaryKeyNull()) {
$this->alreadyHydratedObjects[$relAlias][$key] = array();
} else {
$this->alreadyHydratedObjects[$relAlias][$key] = $secondaryObject->toArray();
}
}
if ($modelWith->isPrimary()) {
$arrayToAugment = &$this->alreadyHydratedObjects[$this->class][$mainKey];
} else {
$arrayToAugment = &$hydrationChain[$modelWith->getRelatedClass()];
}
if ($modelWith->isAdd()) {
if (!isset($arrayToAugment[$modelWith->getRelationName()]) || !in_array($this->alreadyHydratedObjects[$relAlias][$key], $arrayToAugment[$modelWith->getRelationName()])) {
$arrayToAugment[$modelWith->getRelationName()][] = &$this->alreadyHydratedObjects[$relAlias][$key];
}
} else {
$arrayToAugment[$modelWith->getRelationName()] = &$this->alreadyHydratedObjects[$relAlias][$key];
}
$hydrationChain[$relAlias] = &$this->alreadyHydratedObjects[$relAlias][$key];
}
// columns added using withColumn()
foreach ($this->getAsColumns() as $alias => $clause) {
$this->alreadyHydratedObjects[$this->class][$mainKey][$alias] = $row[$col];
$col++;
}
if ($mainObjectIsNew) {
return $this->alreadyHydratedObjects[$this->class][$mainKey];
} else {
// we still need to return a reference to something to avoid a warning
return $emptyVariable;
}
}
}

View file

@ -0,0 +1,202 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Abstract class for query formatter
*
* @author Francois Zaninotto
* @version $Revision: 1796 $
* @package propel.runtime.formatter
*/
abstract class PropelFormatter
{
protected
$dbName,
$class,
$peer,
$with = array(),
$asColumns = array(),
$hasLimit = false,
$currentObjects = array();
public function __construct(ModelCriteria $criteria = null)
{
if (null !== $criteria) {
$this->init($criteria);
}
}
/**
* Define the hydration schema based on a query object.
* Fills the Formatter's properties using a Criteria as source
*
* @param ModelCriteria $criteria
*
* @return PropelFormatter The current formatter object
*/
public function init(ModelCriteria $criteria)
{
$this->dbName = $criteria->getDbName();
$this->class = $criteria->getModelName();
$this->peer = $criteria->getModelPeerName();
$this->setWith($criteria->getWith());
$this->asColumns = $criteria->getAsColumns();
$this->hasLimit = $criteria->getLimit() != 0;
return $this;
}
// DataObject getters & setters
public function setDbName($dbName)
{
$this->dbName = $dbName;
}
public function getDbName()
{
return $this->dbName;
}
public function setClass($class)
{
$this->class = $class;
}
public function getClass()
{
return $this->class;
}
public function setPeer($peer)
{
$this->peer = $peer;
}
public function getPeer()
{
return $this->peer;
}
public function setWith($withs = array())
{
$this->with = array();
foreach ($withs as $relation => $join) {
$this->with[$relation] = new ModelWith($join);
}
}
public function getWith()
{
return $this->with;
}
public function setAsColumns($asColumns = array())
{
$this->asColumns = $asColumns;
}
public function getAsColumns()
{
return $this->asColumns;
}
public function setHasLimit($hasLimit = false)
{
$this->hasLimit = $hasLimit;
}
public function hasLimit()
{
return $this->hasLimit;
}
/**
* Formats an ActiveRecord object
*
* @param BaseObject $record the object to format
*
* @return BaseObject The original record
*/
public function formatRecord($record = null)
{
return $record;
}
abstract public function format(PDOStatement $stmt);
abstract public function formatOne(PDOStatement $stmt);
abstract public function isObjectFormatter();
public function checkInit()
{
if (null === $this->peer) {
throw new PropelException('You must initialize a formatter object before calling format() or formatOne()');
}
}
public function getTableMap()
{
return Propel::getDatabaseMap($this->dbName)->getTableByPhpName($this->class);
}
protected function isWithOneToMany()
{
foreach ($this->with as $modelWith) {
if ($modelWith->isAdd()) {
return true;
}
}
return false;
}
/**
* Gets the worker object for the class.
* To save memory, we don't create a new object for each row,
* But we keep hydrating a single object per class.
* The column offset in the row is used to index the array of classes
* As there may be more than one object of the same class in the chain
*
* @param int $col Offset of the object in the list of objects to hydrate
* @param string $class Propel model object class
*
* @return BaseObject
*/
protected function getWorkerObject($col, $class)
{
if(isset($this->currentObjects[$col])) {
$this->currentObjects[$col]->clear();
} else {
$this->currentObjects[$col] = new $class();
}
return $this->currentObjects[$col];
}
/**
* Gets a Propel object hydrated from a selection of columns in statement row
*
* @param array $row associative array indexed by column number,
* as returned by PDOStatement::fetch(PDO::FETCH_NUM)
* @param string $class The classname of the object to create
* @param int $col The start column for the hydration (modified)
*
* @return BaseObject
*/
public function getSingleObjectFromRow($row, $class, &$col = 0)
{
$obj = $this->getWorkerObject($col, $class);
$col = $obj->hydrate($row, $col);
return $obj;
}
}

View file

@ -0,0 +1,112 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Object formatter for Propel query
* format() returns a PropelObjectCollection of Propel model objects
*
* @author Francois Zaninotto
* @version $Revision: 1733 $
* @package propel.runtime.formatter
*/
class PropelObjectFormatter extends PropelFormatter
{
protected $collectionName = 'PropelObjectCollection';
public function format(PDOStatement $stmt)
{
$this->checkInit();
if($class = $this->collectionName) {
$collection = new $class();
$collection->setModel($this->class);
$collection->setFormatter($this);
} else {
$collection = array();
}
if ($this->isWithOneToMany()) {
if ($this->hasLimit) {
throw new PropelException('Cannot use limit() in conjunction with with() on a one-to-many relationship. Please remove the with() call, or the limit() call.');
}
$pks = array();
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$object = $this->getAllObjectsFromRow($row);
$pk = $object->getPrimaryKey();
if (!in_array($pk, $pks)) {
$collection[] = $object;
$pks[] = $pk;
}
}
} else {
// only many-to-one relationships
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$collection[] = $this->getAllObjectsFromRow($row);
}
}
$stmt->closeCursor();
return $collection;
}
public function formatOne(PDOStatement $stmt)
{
$this->checkInit();
$result = null;
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$result = $this->getAllObjectsFromRow($row);
}
$stmt->closeCursor();
return $result;
}
public function isObjectFormatter()
{
return true;
}
/**
* Hydrates a series of objects from a result row
* The first object to hydrate is the model of the Criteria
* The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one
*
* @param array $row associative array indexed by column number,
* as returned by PDOStatement::fetch(PDO::FETCH_NUM)
*
* @return BaseObject
*/
public function getAllObjectsFromRow($row)
{
// main object
list($obj, $col) = call_user_func(array($this->peer, 'populateObject'), $row);
// related objects added using with()
foreach ($this->getWith() as $class => $modelWith) {
list($endObject, $col) = call_user_func(array($modelWith->getModelPeerName(), 'populateObject'), $row, $col);
// as we may be in a left join, the endObject may be empty
// in which case it should not be related to the previous object
if (null === $endObject || $endObject->isPrimaryKeyNull()) {
continue;
}
if (isset($hydrationChain)) {
$hydrationChain[$class] = $endObject;
} else {
$hydrationChain = array($class => $endObject);
}
$startObject = $modelWith->isPrimary() ? $obj : $hydrationChain[$modelWith->getRelatedClass()];
call_user_func(array($startObject, $modelWith->getRelationMethod()), $endObject);
}
// columns added using withColumn()
foreach ($this->getAsColumns() as $alias => $clause) {
$obj->setVirtualColumn($alias, $row[$col]);
$col++;
}
return $obj;
}
}

View file

@ -0,0 +1,96 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* Object formatter for Propel query
* format() returns a PropelOnDemandCollection that hydrates objects as the use iterates on the collection
* This formatter consumes less memory than the PropelObjectFormatter, but doesn't use Instance Pool
*
* @author Francois Zaninotto
* @version $Revision: 1733 $
* @package propel.runtime.formatter
*/
class PropelOnDemandFormatter extends PropelObjectFormatter
{
protected $collectionName = 'PropelOnDemandCollection';
protected $isSingleTableInheritance = false;
public function init(ModelCriteria $criteria)
{
parent::init($criteria);
$this->isSingleTableInheritance = $criteria->getTableMap()->isSingleTableInheritance();
return $this;
}
public function format(PDOStatement $stmt)
{
$this->checkInit();
if ($this->isWithOneToMany()) {
throw new PropelException('PropelOnDemandFormatter cannot hydrate related objects using a one-to-many relationship. Try removing with() from your query.');
}
$class = $this->collectionName;
$collection = new $class();
$collection->setModel($this->class);
$collection->initIterator($this, $stmt);
return $collection;
}
/**
* Hydrates a series of objects from a result row
* The first object to hydrate is the model of the Criteria
* The following objects (the ones added by way of ModelCriteria::with()) are linked to the first one
*
* @param array $row associative array indexed by column number,
* as returned by PDOStatement::fetch(PDO::FETCH_NUM)
*
* @return BaseObject
*/
public function getAllObjectsFromRow($row)
{
$col = 0;
// main object
$class = $this->isSingleTableInheritance ? call_user_func(array($his->peer, 'getOMClass'), $row, $col, false) : $this->class;
$obj = $this->getSingleObjectFromRow($row, $class, $col);
// related objects using 'with'
foreach ($this->getWith() as $modelWith) {
if ($modelWith->isSingleTableInheritance()) {
$class = call_user_func(array($modelWith->getModelPeerName(), 'getOMClass'), $row, $col, false);
$refl = new ReflectionClass($class);
if ($refl->isAbstract()) {
$col += constant($class . 'Peer::NUM_COLUMNS');
continue;
}
} else {
$class = $modelWith->getModelName();
}
$endObject = $this->getSingleObjectFromRow($row, $class, $col);
// as we may be in a left join, the endObject may be empty
// in which case it should not be related to the previous object
if (null === $endObject || $endObject->isPrimaryKeyNull()) {
continue;
}
if (isset($hydrationChain)) {
$hydrationChain[$class] = $endObject;
} else {
$hydrationChain = array($class => $endObject);
}
$startObject = $modelWith->isPrimary() ? $obj : $hydrationChain[$modelWith->getRelatedClass()];
call_user_func(array($startObject, $modelWith->getRelationMethod()), $endObject);
}
foreach ($this->getAsColumns() as $alias => $clause) {
$obj->setVirtualColumn($alias, $row[$col]);
$col++;
}
return $obj;
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* statement formatter for Propel query
* format() returns a PDO statement
*
* @author Francois Zaninotto
* @version $Revision: 1796 $
* @package propel.runtime.formatter
*/
class PropelStatementFormatter extends PropelFormatter
{
public function format(PDOStatement $stmt)
{
return $stmt;
}
public function formatOne(PDOStatement $stmt)
{
if ($stmt->rowCount() == 0) {
return null;
} else {
return $stmt;
}
}
public function formatRecord($record = null)
{
throw new PropelException('The Statement formatter cannot transform a record into a statement');
}
public function isObjectFormatter()
{
return false;
}
}