public function testPluralize() { $this->assertSame(String::pluralize('cat'), 'cats'); $this->assertSame(String::pluralize('pony'), 'ponies'); $this->assertSame(String::pluralize('bass'), 'basses'); $this->assertSame(String::pluralize('case'), 'cases'); }
function init() { $this->name_many = String::pluralize($this->name); $this->class_name = String::convertToCamelCase($this->name); $this->class_name_many = String::pluralize($this->class_name); $this->repository_class = 'Storage\\Repository\\' . $this->class_name . 'Repository'; $this->model_class = 'Storage\\Model\\' . $this->class_name . 'Base'; $model_file = $this->application->getProject()->getPath('src php Model ' . $this->class_name . '.php'); if (file_exists($model_file)) { $this->model_class = 'Model\\' . $this->class_name; } $repository_file = $this->application->getProject()->getPath('src php Repository ' . $this->class_name . '.php'); if (file_exists($repository_file)) { $this->repository_class = 'Repository\\' . $this->class_name; } if (count($this->properties)) { $properties = $this->properties; $this->properties = array(); foreach ($properties as $key => $config) { if ($config instanceof Model) { $reference = $this->hasOne($config); if (is_string($key)) { $reference->usingAlias($key); } } else { $this->addProperty($key, $config); } } } if (!$this->getPk()) { $this->addBehaviour('id'); } }
/** * Init Fenom engine with modifiers and functions * @param $fenom */ private function initEngine($fenom) { $fenom->addModifier('pluralize', function ($string) { return String::pluralize($string); }); $fenom->addModifier('camelcase', function ($string) { return String::convertToCamelCase($string); }); }
public function renderGetterAndSetter() { $reference = $this->reference; $property_name = String::pluralize($reference->getReferencedBy()); $getter = 'get' . String::convertToCamelCase($property_name); $source = $this->schema->getModel($reference->getSource()); $destination = $this->schema->getModel($reference->getDestination()); $finder = array(); foreach ($reference->getProperties() as $property) { $finder[] = "'" . $property->getName() . "' => \$this->" . $destination->getProperty($property->getForeignName())->getGetter() . "(),"; } $finder = implode(PHP_EOL . ' ', $finder); $source_model_class = $source->getModelClass(); $source_name = $reference->getSource(); $repository_getter = 'get' . String::pluralize(String::convertToCamelCase($source->getName())); $result = <<<PROPERTY /** * get {$property_name} * @return {$source_model_class} */ public function {$getter}() { if(is_null(\$this->{$property_name})) { \$this->{$property_name} = \$this->getRepository()->getMaster()->{$repository_getter}()->findAll(array( {$finder} )); } return \$this->{$property_name}; } PROPERTY; if ($this->schema->getModel($source_name)->hasBehaviour('link')) { $link = $this->schema->getModel($source_name); $foreign = $link->getBehaviour('link')->getForeignModel($destination); foreach ($link->getOutReferences() as $relation) { if ($relation->getDestination() == $foreign->getName()) { break; } } $relation_property_name = String::pluralize($relation->getDestinationAlias()); $relation_getter = 'get' . String::convertToCamelCase($relation_property_name); $link_getter = 'get' . String::convertToCamelCase($relation->getDestinationAlias()); $foreign_model_class = $foreign->getModelClass(); $result .= <<<PROPERTY /** * get {$relation_property_name} * @return {$foreign_model_class}[] */ public function {$relation_getter}() { if(is_null(\$this->{$relation_property_name})) { \$this->{$relation_property_name} = array(); foreach(\$this->{$getter}() as \$link) { \$this->{$relation_property_name}[] = \$link->{$link_getter}(); } } return \$this->{$relation_property_name}; } PROPERTY; } return $result; }