Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2012 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3917050 to your computer and use it in GitHub Desktop.
Save anonymous/3917050 to your computer and use it in GitHub Desktop.
DynamicCollectionObjectFormatter class
/**
* 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 one of the following
* - a custom ObjectCollection for a given modal name if the class exists ( ex InvoiceObjectCollection class )
* - the default PropelObjectCollection of Propel model objects
*
* @author Lee Leathers
* @author Marius Ghita
* @package propel.runtime.collection
*/
class DynamicCollectionObjectFormatter extends PropelObjectFormatter
{
public function setModalName($modalName)
{
$this->collectionName = $modalName . "ObjectCollection";
if(false === class_exists($this->collectionName))
{
$this->collectionName = "PropelObjectCollection";
}
elseif(false === is_subclass_of($this->collectionName, "PropelObjectCollection"))
{
throw new LogicException(sprintf(
"%s class must be a subclass of PropelObjectCollection",
$this->collectionName)
);
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment