public function createMapper($singularName) { $name = Inflect::pluralize($singularName); $class = "{$name}Mapper"; $path = $this->getRmePath($name) . "/{$class}.php"; $this->buildPhpFromTemplate($path, 'rme_mapper', ['class' => $class]); return $path; }
public function testPluralize() { $inflections = array('oxen' => 'ox', 'cats' => 'cat', 'cats' => 'cat', 'purses' => 'purse', 'analyses' => 'analysis', 'houses' => 'house', 'sheep' => 'sheep', 'buses' => 'bus', 'axes' => 'axis', 'uses' => 'use', 'databases' => 'database', 'quizzes' => 'quiz', 'matrices' => 'matrix', 'vertices' => 'vertex', 'aliases' => 'aliases', 'aliases' => 'alias', 'octopi' => 'octopus', 'axes' => 'axis', 'crises' => 'crisis', 'crises' => 'crises', 'shoes' => 'shoe', 'foes' => 'foe', 'pianos' => 'piano', 'wierdos' => 'wierdo', 'toes' => 'toe', 'banjos' => 'banjo', 'vetoes' => 'veto', 'cows' => 'cow'); foreach ($inflections as $key => $value) { print "Testing {$value} pluralizes to: {$key}\n"; $this->assertEquals($key, Inflect::pluralize($value)); } print "\n"; }
public function __construct($client) { $this->_client = $client; if (!isset($this->_resourceName)) { $this->_resourceName = $this->getResourceNameFromClass(); } if (!isset($this->objectName)) { $this->_objectName = Inflect::singularize($this->_resourceName); } if (!isset($this->_objectNamePlural)) { $this->_objectNamePlural = Inflect::pluralize($this->_resourceName); } }
/** * @param HttpClient $client */ public function __construct(HttpClient $client) { $this->client = $client; if (!isset($this->resourceName)) { $this->resourceName = $this->getResourceNameFromClass(); } if (!isset($this->objectName)) { $this->objectName = Inflect::singularize($this->resourceName); } if (!isset($this->objectNamePlural)) { $this->objectNamePlural = Inflect::pluralize($this->resourceName); } $this->setUpRoutes(); }
public function invoke(Scaffolding $scaffolding) { $name = ucFirst($this->in->getArgument('entityName')); $file = $scaffolding->createRepository($name); $this->writeCreatedFilesHeader(); $this->writeCreatedFile($file); $file = $scaffolding->createMapper($name); $this->writeCreatedFile($file); $params = []; foreach ($this->in->getVariadics() as $arg) { list($param, $type) = explode(':', $arg) + [NULL, 'mixed']; $params[$param] = $type; } $file = $scaffolding->createEntity($name, $params); $this->writeCreatedFile($file); $this->out->writeln("\n<comment>Don't forget to add repository to your Model class</comment>"); $plural = Inflect::pluralize($name); $repoClass = 'Rme\\' . ucFirst($plural) . 'Repository'; $param = lcFirst($plural); $this->out->writeln(" * @property-read {$repoClass} \${$param}"); }
/** * Add trait variables * * @param array $values * @param array $trait * * @return mixed */ private function applyTraitVariables(array $values, array $trait) { $variables = implode('|', array_keys($values)); $newTrait = []; foreach ($trait as $key => &$value) { $newKey = preg_replace_callback('/<<(' . $variables . ')([\\s]*\\|[\\s]*!(singularize|pluralize))?>>/', function ($matches) use($values) { $transformer = isset($matches[3]) ? $matches[3] : ''; switch ($transformer) { case 'singularize': return Inflect::singularize($values[$matches[1]]); break; case 'pluralize': return Inflect::pluralize($values[$matches[1]]); break; default: return $values[$matches[1]]; } }, $key); if (is_array($value)) { $value = $this->applyTraitVariables($values, $value); } else { $value = preg_replace_callback('/<<(' . $variables . ')([\\s]*\\|[\\s]*!(singularize|pluralize))?>>/', function ($matches) use($values) { $transformer = isset($matches[3]) ? $matches[3] : ''; switch ($transformer) { case 'singularize': return Inflect::singularize($values[$matches[1]]); break; case 'pluralize': return Inflect::pluralize($values[$matches[1]]); break; default: return $values[$matches[1]]; } }, $value); } $newTrait[$newKey] = $value; } return $newTrait; }
public function slug($delimiter = '-') { $this->string = trim(Inflect::urlify($this->string, $delimiter), $delimiter); return $this; }
/** @inheritdoc */ public static function getEntityClassNames() { $class = str_replace('Repository', '', get_called_class()); return [Inflect::singularize($class)]; }
protected function getPropertyNamePlural($arg) { return $arg ? ltrim($arg, '$') : Inflect::pluralize(lcfirst($this->reflection->getShortName())); }
public static function getEntityClassNames() { $class = substr(get_called_class(), 0, -10); return [Inflect::singularize($class)]; }