public function testSingularize() { $inflections = array('ox' => 'ox', 'cats' => 'cat', 'oxen' => 'ox', 'cats' => 'cat', 'purses' => 'purse', 'analyses' => 'analysis', 'houses' => 'house', 'sheep' => 'sheep', 'buses' => 'bus', 'uses' => 'use', 'databases' => 'database', 'quizzes' => 'quiz', 'matrices' => 'matrix', 'vertices' => 'vertex', 'alias' => 'alias', 'aliases' => 'alias', 'octopi' => 'octopus', 'axes' => 'axis', 'axis' => 'axis', 'crises' => 'crisis', 'crisis' => 'crisis', 'shoes' => 'shoe', 'foes' => 'foe', 'pianos' => 'piano', 'wierdos' => 'wierdo', 'toes' => 'toe', 'banjoes' => 'banjo', 'vetoes' => 'veto', 'cows' => 'cow'); foreach ($inflections as $key => $value) { print "Testing {$key} singularizes to: {$value}\n"; $this->assertEquals($value, Inflect::singularize($key)); } 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(); }
/** * 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 singular() { $this->string = Inflect::singularize($this->string); return $this; }
/** @inheritdoc */ public static function getEntityClassNames() { $class = str_replace('Repository', '', get_called_class()); return [Inflect::singularize($class)]; }
public static function getEntityClassNames() { $class = substr(get_called_class(), 0, -10); return [Inflect::singularize($class)]; }