public function __call($method, $arguments) { $this->checkWhetherRecordOperateable(); if (strpos($method, 'init_') === 0) { $relationship = ltrim($method, 'init_'); $relationshipMetadata = $this->relationship->getMetadata($relationship); if ($relationshipMetadata === null) { $relationship = Helper::pluralize($relationship); $relationshipMetadata = $this->relationship->getMetadata($relationship); if ($relationship === null) { throw new UndefinedMethodException($method, get_called_class()); } } $this->{$relationship} = new $relationshipMetadata['class']($arguments[0]); return true; } if (preg_match('/_was_changed$/', $method)) { $attribute = preg_replace('/_was_changed$/', '', $method); if (array_key_exists($attribute, $this->_attributes)) { return array_key_exists($attribute, $this->_changedAttributes); } } throw new UndefinedMethodException($method, get_called_class()); }
public function testPluralize() { $this->assertEquals('Users', Helper::pluralize('User')); }