public function loadData() { $data = $this->provider->fetch($this->entityName, $this->options); if (is_array($data) && count($data)) { $this->entity->{'set' . $this->extras['prefix'] . ucfirst(ucfirst(Transformer::pluralize($this->entityName)))}(array()); foreach ($data as $item) { $this->entity->{'add' . $this->extras['prefix'] . ucfirst($this->entityName)}($item); } } else { $this->entity->{'set' . $this->extras['prefix'] . ucfirst(ucfirst(Transformer::pluralize($this->entityName)))}(array()); } }
protected function createEntitySource($entityName) { $header = $use = $class = $body = $footer = ""; $header = "<?php\n\n"; $header .= "namespace " . $this->entityNamespace . ";\n\n"; if (array_key_exists('abstract', $this->model[$entityName])) { $class .= "abstract "; } $class .= "class " . ucfirst($entityName) . " "; if (isset($this->model[$entityName]['extends'])) { $class .= "extends " . ucfirst($this->model[$entityName]['extends']) . " "; $useStringToBeAdded = "use " . $this->entityNamespace . "\\" . ucfirst($this->model[$entityName]['extends']) . ";"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } } $class .= "{\n\n"; /// primary key helper /// setter $body .= "\tpublic function setPrimaryKey(\$primaryKey){\n"; $body .= "\t\t\$this->" . $this->getPrimaryKeyForEntity($entityName) . " = \$primaryKey;\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function getPrimaryKey(){\n"; $body .= "\t\treturn \$this->" . $this->getPrimaryKeyForEntity($entityName) . ";\n"; $body .= "\t}\n\n"; if (isset($this->model[$entityName]['properties'])) { foreach ($this->model[$entityName]['properties'] as $property => $options) { /// declaration $class .= "\tprotected \$" . $property . ";\n"; /// setter $body .= "\tpublic function set" . ucfirst($property) . "(\$" . $property . "){\n"; $body .= "\t\t\$this->" . $property . " = \$" . $property . ";\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function get" . ucfirst($property) . "(){\n"; $body .= "\t\treturn \$this->" . $property . ";\n"; $body .= "\t}\n\n"; } } /// loggable if (true === isset($this->model[$entityName]['blameable'])) { if (true === isset($this->model[$entityName]['blameable']['targetEntity'])) { /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\Provider\\Changelog;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// declaration $class .= "\tprotected \$changelog;\n"; /// setter $body .= "\tpublic function setChangelog(Changelog \$changelog){\n"; $body .= "\t\t\$this->changelog = \$changelog;\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function getChangelog(){\n"; $body .= "\t\treturn \$this->changelog;\n"; $body .= "\t}\n\n"; } } /// blameable if (true === isset($this->model[$entityName]['blameable'])) { if (true === isset($this->model[$entityName]['blameable']['targetEntity'])) { /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\LazyLoader\\SingleLazyLoader;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// declaration $class .= "\tprotected \$blame;\n"; /// setter $body .= "\tpublic function setBlame(\$blame){\n"; $body .= "\t\t\$this->blame = \$blame;\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function getBlame(){\n"; $body .= "\t\tif(\$this->blame instanceof SingleLazyLoader){\n"; $body .= "\t\t\t\$this->blame = \$this->blame->getData();\n"; $body .= "\t\t}\n"; $body .= "\t\treturn \$this->blame;\n"; $body .= "\t}\n\n"; } } /// relations if (isset($this->model[$entityName]['relations'])) { foreach ($this->model[$entityName]['relations'] as $relatedEntity => $cardinality) { /// use if ($relatedEntity !== $entityName) { $useStringToBeAdded = "use " . $this->entityNamespace . "\\" . ucfirst($relatedEntity) . ";"; } /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } switch ($cardinality) { case 'ONE_TO_ONE': case '<<ONE_TO_ONE': case 'MANY_TO_ONE': /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\LazyLoader\\SingleLazyLoader;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// declaration $class .= "\tprotected \$" . $relatedEntity . ";\n"; /// setter $body .= "\tpublic function set" . ucfirst($relatedEntity) . "(\$" . $relatedEntity . "){\n"; $body .= "\t\t\$this->" . $relatedEntity . " = \$" . $relatedEntity . ";\n"; /// if an abstract entity is the relation set discriminator value if (true === array_key_exists('abstract', $this->model[$relatedEntity])) { $body .= "\t\tif(\$this->" . $relatedEntity . " instanceof SingleLazyLoader){\n"; $body .= "\t\t\t\$this->" . $relatedEntity . " = \$this->" . $relatedEntity . "->getData();\n"; $body .= "\t\t}\n"; $body .= "\t\t\$this->set" . ucfirst($relatedEntity) . "Class(get_class(\$this->" . $relatedEntity . "));\n"; } $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function get" . ucfirst($relatedEntity) . "(){\n"; $body .= "\t\tif(\$this->" . $relatedEntity . " instanceof SingleLazyLoader){\n"; $body .= "\t\t\t\$this->" . $relatedEntity . " = \$this->" . $relatedEntity . "->getData();\n"; $body .= "\t\t}\n"; $body .= "\t\treturn \$this->" . $relatedEntity . ";\n"; $body .= "\t}\n\n"; /// if an abstract entity is the relation add discriminator if (true === array_key_exists('abstract', $this->model[$relatedEntity])) { $class .= "\tprotected \$" . $relatedEntity . "Class;\n"; /// setter $body .= "\tpublic function set" . ucfirst($relatedEntity) . "Class(\$" . $relatedEntity . "Class){\n"; $body .= "\t\t\$this->" . $relatedEntity . "Class = \$" . $relatedEntity . "Class;\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function get" . ucfirst($relatedEntity) . "Class(){\n"; $body .= "\t\treturn \$this->" . $relatedEntity . "Class;\n"; $body .= "\t}\n\n"; } break; case 'SELF::ONE_TO_MANY': case 'SELF::MANY_TO_ONE': /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\LazyLoader\\SingleLazyLoader;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// declaration $class .= "\tprotected \$parent" . ucfirst($relatedEntity) . ";\n"; /// setter $body .= "\tpublic function setParent" . ucfirst($relatedEntity) . "(\$parent" . ucfirst($relatedEntity) . "){\n"; $body .= "\t\t\$this->parent" . ucfirst($relatedEntity) . " = \$parent" . ucfirst($relatedEntity) . ";\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getter $body .= "\tpublic function getParent" . ucfirst($relatedEntity) . "(){\n"; $body .= "\t\tif(\$this->parent" . ucfirst($relatedEntity) . " instanceof SingleLazyLoader){\n"; $body .= "\t\t\t\$this->parent" . ucfirst($relatedEntity) . " = \$this->parent" . ucfirst($relatedEntity) . "->getData();\n"; $body .= "\t\t}\n"; $body .= "\t\treturn \$this->parent" . ucfirst($relatedEntity) . ";\n"; $body .= "\t}\n\n"; /// no break here as we also need the 'to-many' methods /// no break here as we also need the 'to-many' methods case 'ONE_TO_MANY': case 'MANY_TO_MANY': case '<<MANY_TO_MANY': /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\LazyLoader\\MultipleLazyLoader;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// declaration $class .= "\tprotected \$" . Transformer::pluralize($relatedEntity) . ";\n"; /// setters $body .= "\tpublic function add" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$" . $relatedEntity . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'add" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->add" . ucfirst($relatedEntity) . "BeforeListener(\$" . $relatedEntity . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->load" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(null !== \$" . $relatedEntity . "->getId()){\n"; $body .= "\t\t\t\$this->" . Transformer::pluralize($relatedEntity) . "[\$" . $relatedEntity . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()] = \$" . $relatedEntity . ";\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\t\$this->" . Transformer::pluralize($relatedEntity) . "[] = \$" . $relatedEntity . ";\n"; $body .= "\t\t}\n\n"; $body .= "\t\tif(true === method_exists(\$this,'add" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->add" . ucfirst($relatedEntity) . "AfterListener(\$" . $relatedEntity . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function remove" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$" . $relatedEntity . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'remove" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->remove" . ucfirst($relatedEntity) . "BeforeListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->load" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->" . Transformer::pluralize($relatedEntity) . "[\$" . $relatedEntity . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()])){\n"; $body .= "\t\t\tunset(\$this->" . Transformer::pluralize($relatedEntity) . "[\$" . $relatedEntity . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()]);\n"; $body .= "\t\t}\n"; $body .= "\t\tif(true === method_exists(\$this,'remove" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->remove" . ucfirst($relatedEntity) . "AfterListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function set" . ucfirst(Transformer::pluralize($relatedEntity)) . "(\$" . Transformer::pluralize($relatedEntity) . "){\n"; $body .= "\t\t\$this->" . Transformer::pluralize($relatedEntity) . " = \$" . Transformer::pluralize($relatedEntity) . ";\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getters $body .= "\tpublic function get" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->load" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\treturn \$this->" . Transformer::pluralize($relatedEntity) . ";\n"; $body .= "\t}\n\n"; $body .= "\tpublic function get" . ucfirst($relatedEntity) . "(\$key){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->load" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->" . Transformer::pluralize($relatedEntity) . "[\$key])){\n"; $body .= "\t\t\treturn \$this->" . Transformer::pluralize($relatedEntity) . "[\$key];\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\treturn null;\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; /// loader $body .= "\tpublic function load" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\tif(\$this->" . Transformer::pluralize($relatedEntity) . " instanceof MultipleLazyLoader){\n"; $body .= "\t\t\t\$this->" . Transformer::pluralize($relatedEntity) . "->loadData();\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; break; case 'SELF::MANY_TO_MANY': /// use $useStringToBeAdded = "use WernerDweight\\Dobee\\LazyLoader\\MultipleLazyLoader;"; /// check for duplicity if (false === strpos($use, $useStringToBeAdded)) { $use .= $useStringToBeAdded . "\n"; } /// MASTER /// declaration $class .= "\tprotected \$master" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; /// setters $body .= "\tpublic function addMaster" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$master" . ucfirst($relatedEntity) . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'addMaster" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->addMaster" . ucfirst($relatedEntity) . "BeforeListener(\$" . $relatedEntity . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(null !== \$master" . ucfirst($relatedEntity) . "->getId()){\n"; $body .= "\t\t\t\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$master" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()] = \$master" . ucfirst($relatedEntity) . ";\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\t\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[] = \$master" . ucfirst($relatedEntity) . ";\n"; $body .= "\t\t}\n\n"; $body .= "\t\tif(true === method_exists(\$this,'addMaster" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->addMaster" . ucfirst($relatedEntity) . "AfterListener(\$master" . ucfirst($relatedEntity) . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function removeMaster" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$master" . ucfirst($relatedEntity) . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'removeMaster" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->removeMaster" . ucfirst($relatedEntity) . "BeforeListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$master" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()])){\n"; $body .= "\t\t\tunset(\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$salve" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()]);\n"; $body .= "\t\t}\n"; $body .= "\t\tif(true === method_exists(\$this,'removeMaster" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->removeMaster" . ucfirst($relatedEntity) . "AfterListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function setMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "(\$master" . ucfirst(Transformer::pluralize($relatedEntity)) . "){\n"; $body .= "\t\t\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . " = \$master" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getters $body .= "\tpublic function getMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\treturn \$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; $body .= "\t}\n\n"; $body .= "\tpublic function getMaster" . ucfirst($relatedEntity) . "(\$key){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$key])){\n"; $body .= "\t\t\treturn \$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$key];\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\treturn null;\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; /// loader $body .= "\tpublic function loadMaster" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\tif(\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . " instanceof MultipleLazyLoader){\n"; $body .= "\t\t\t\$this->master" . ucfirst(Transformer::pluralize($relatedEntity)) . "->loadData();\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; /// SLAVE /// declaration $class .= "\tprotected \$slave" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; /// setters $body .= "\tpublic function addSlave" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$slave" . ucfirst($relatedEntity) . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'addSlave" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->addSlave" . ucfirst($relatedEntity) . "BeforeListener(\$" . $relatedEntity . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(null !== \$slave" . ucfirst($relatedEntity) . "->getId()){\n"; $body .= "\t\t\t\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$slave" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()] = \$slave" . ucfirst($relatedEntity) . ";\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\t\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[] = \$slave" . ucfirst($relatedEntity) . ";\n"; $body .= "\t\t}\n\n"; $body .= "\t\tif(true === method_exists(\$this,'addSlave" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->addSlave" . ucfirst($relatedEntity) . "AfterListener(\$slave" . ucfirst($relatedEntity) . ");\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function removeSlave" . ucfirst($relatedEntity) . "(" . ucfirst($relatedEntity) . " \$slave" . ucfirst($relatedEntity) . "){\n"; $body .= "\t\tif(true === method_exists(\$this,'removeSlave" . ucfirst($relatedEntity) . "BeforeListener')){\n"; $body .= "\t\t\t\$this->removeSlave" . ucfirst($relatedEntity) . "BeforeListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$slave" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()])){\n"; $body .= "\t\t\tunset(\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$salve" . ucfirst($relatedEntity) . "->get" . ucfirst($this->getPrimaryKeyForEntity($relatedEntity)) . "()]);\n"; $body .= "\t\t}\n"; $body .= "\t\tif(true === method_exists(\$this,'removeSlave" . ucfirst($relatedEntity) . "AfterListener')){\n"; $body .= "\t\t\t\$this->removeSlave" . ucfirst($relatedEntity) . "AfterListener();\n"; $body .= "\t\t}\n\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; $body .= "\tpublic function setSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "(\$slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "){\n"; $body .= "\t\t\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . " = \$slave" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; $body .= "\t\treturn \$this;\n"; $body .= "\t}\n\n"; /// getters $body .= "\tpublic function getSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\treturn \$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . ";\n"; $body .= "\t}\n\n"; $body .= "\tpublic function getSlave" . ucfirst($relatedEntity) . "(\$key){\n"; $body .= "\t\t/// check that items are loaded (if not load them)\n"; $body .= "\t\t\$this->loadSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "();\n\n"; $body .= "\t\tif(isset(\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$key])){\n"; $body .= "\t\t\treturn \$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "[\$key];\n"; $body .= "\t\t}\n"; $body .= "\t\telse{\n"; $body .= "\t\t\treturn null;\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; /// loader $body .= "\tpublic function loadSlave" . ucfirst(Transformer::pluralize($relatedEntity)) . "(){\n"; $body .= "\t\tif(\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . " instanceof MultipleLazyLoader){\n"; $body .= "\t\t\t\$this->slave" . ucfirst(Transformer::pluralize($relatedEntity)) . "->loadData();\n"; $body .= "\t\t}\n"; $body .= "\t}\n\n"; break; } } } $footer .= "\t/// write your own logic below this point\n\n"; $footer .= "}\n\n"; $footer .= "?>\n"; return $header . $use . "\n" . $class . "\n" . $body . $footer; }