public static function table() { static $table = null; if ($table !== null) { return $table; } if (!empty(static::$table)) { return static::$table; } $parts = explode('\\', get_called_class()); $table = Helper::pluralize(Helper::underscore(array_pop($parts))); return $table; }
public function __construct($model) { $this->_model = $model; $namespaces = explode('\\', get_called_class()); $type = Helper::underscore(array_pop($namespaces)); $properties = get_class_vars(get_class($model)); if (!empty($properties[$type])) { foreach ($properties[$type] as $metadata) { $name = array_shift($metadata); if (empty($metadata['class'])) { $metadata['class'] = ucfirst(Helper::singularize($name)); } $metadata['class'] = '\\' . ltrim($metadata['class'], '\\'); $this->_metadata[$name] = $metadata; } } }
public function testUnderscore() { $this->assertEquals('string_to_underscore', Helper::underscore('string_to_underscore')); $this->assertEquals('string_to_underscore', Helper::underscore('StringToUnderscore')); }