if (is_array($options) && !empty($options)) {
$optionsPhp = self::varExport($options);
- $build .= " \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
+ $build .= " \$this->getTable()->addTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
} else {
if (isset($templates[0])) {
- $build .= " \$this->loadTemplate('" . $options . "');" . PHP_EOL;
+ $build .= " \$this->getTable()->addTemplate('" . $options . "');" . PHP_EOL;
} else {
- $build .= " \$this->loadTemplate('" . $name . "');" . PHP_EOL;
+ $build .= " \$this->getTable()->addTemplate('" . $name . "');" . PHP_EOL;
}
}
}
private function emitActAs($level, $name)
{
- return " \$this->actAs(\$" . strtolower($name) . "$level);" . PHP_EOL;
+ return " \$this->getTable()->addTemplate(\$" . strtolower($name) . "$level);" . PHP_EOL;
}
private function buildActAs($actAs)
}
}
- public function loadTemplate($template, array $options = array())
- {
- $this->actAs($template, $options);
- }
-
public function bindQueryParts(array $queryParts)
{
$this->_table->bindQueryParts($queryParts);
$this->_table->addGenerator($generator, get_class($generator));
}
- public function actAs($tpl, array $options = array())
- {
- if ( ! is_object($tpl)) {
- $className = 'IPF_ORM_Template_' . $tpl;
-
- if (class_exists($className, true)) {
- $tpl = new $className($options);
- } else if (class_exists($tpl, true)) {
- $tpl = new $tpl($options);
- } else {
- throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
- }
- }
-
- if ( ! ($tpl instanceof IPF_ORM_Template)) {
- throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
- }
-
- $className = get_class($tpl);
-
- $this->_table->addTemplate($className, $tpl);
-
- $tpl->setTable($this->_table);
- $tpl->setUp();
- $tpl->setTableDefinition();
-
- return $this;
- }
-
public function check($constraint, $name = null)
{
if (is_array($constraint)) {
return isset($this->_templates[$template]);
}
- public function addTemplate($template, IPF_ORM_Template $impl)
+ public function addTemplate($tpl, array $options=array())
{
- $this->_templates[$template] = $impl;
+ if (!is_object($tpl)) {
+ $className = 'IPF_ORM_Template_' . $tpl;
- return $this;
+ if (class_exists($className, true)) {
+ $tpl = new $className($options);
+ } else if (class_exists($tpl, true)) {
+ $tpl = new $tpl($options);
+ } else {
+ throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
+ }
+ }
+
+ if (!($tpl instanceof IPF_ORM_Template)) {
+ throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
+ }
+
+ $className = get_class($tpl);
+ $this->_templates[$className] = $tpl;
+
+ $tpl->setTable($this);
+ $tpl->setUp();
+ $tpl->setTableDefinition();
}
public function getGenerators()