public function __call($name, $args) { if (StringUtil::startsWith($name, 'set') && !StringUtil::endsWith($name, 'Id')) { $property = strtolower(preg_replace('/([a-z])([A-Z])/', '${1}_${2}', substr($name, 3))); if (property_exists($this, $property) && count($args) == 1) { $this->{$property} = $args[0]; return $this; } } throw new ModelException(sprintf('The method %s does not exist on the model %s, and cannot be magically created', $name, get_class($this))); }
public function testEndsWith() { $string = 'ah !'; $this->assertTrue(StringUtil::endsWith($string, '')); $this->assertTrue(StringUtil::endsWith($string, '!')); $this->assertTrue(StringUtil::endsWith($string, ' !')); $this->assertTrue(StringUtil::endsWith($string, 'h !')); $this->assertTrue(StringUtil::endsWith($string, 'ah !')); $this->assertFalse(StringUtil::endsWith($string, ' ')); $this->assertFalse(StringUtil::endsWith($string, 'ah ')); $this->assertFalse(StringUtil::endsWith($string, false)); $this->assertFalse(StringUtil::endsWith($string, true)); }
/** * Scan all the given folders (not recursive), and extract models * This function expects all the php files in the folders to be models, * if this is not true for your application generate the list of models * and call createFromModels() instead */ public function createFromModelFolders(array $folders) { $models = array(); foreach ($folders as $folder) { $files = scandir($folder); foreach ($files as $file) { $path = "{$folder}/{$file}"; if (is_file($path) && StringUtil::endsWith($file, ".php")) { require_once $path; $models = array_merge($models, self::extractClassFromFile($path)); } } } $this->createFromModels($models); }