/** * @param QC|mixed $criteria * @return ModelCollection */ public static function loadList($criteria = null) { /** * @var Model $object */ $object = self::getModel(get_called_class()); $customCollectionClassName = Inflector::pluralize($object->_name) . 'Collection'; $collectionClass = class_exists($customCollectionClassName) ? $customCollectionClassName : '\\Solve\\Database\\Models\\ModelCollection'; return call_user_func(array($collectionClass, 'loadList'), $criteria, $object); }
/** * @param $data * @param bool $one * @return array * @throws \Exception */ public static function fixYamlStructures($data, $one = false) { if ($one) { $data = array('structure' => $data); } foreach ($data as $model_name => $structure) { if (!isset($structure['columns']) || !empty($structure['manual'])) { continue; } foreach (array_keys($structure) as $key) { if (!in_array($key, self::$_allowedStructureKeys)) { throw new \Exception('Unexpected key in model ' . $model_name . ': ' . $key); } } $pk_field = false; foreach ($structure['columns'] as $field => $info) { if (!is_array($info)) { $info = array('type' => $info); } if (isset($info['auto_increment'])) { $pk_field = $field; } $structure['columns'][$field] = $info; } if (!isset($structure['table'])) { $structure['table'] = strtolower(Inflector::pluralize($model_name)); } if (!isset($structure['indexes']['primary'])) { if (!$pk_field) { if (!isset($structure['columns']['id'])) { $structure['columns'] = array_merge(array('id' => array('type' => 'int(11) unsigned', 'auto_increment' => true, 'not_null' => true)), $structure['columns']); } $pk_field = 'id'; } $structure['indexes']['primary'] = array('columns' => array($pk_field), 'type' => 'primary'); } if (isset($structure['relations'])) { // @todo auto constraints generation from relations foreach ($structure['relations'] as $key => $item) { } } if (empty($structure['constraints'])) { unset($structure['constraints']); } if (!empty($structure['character_set']) && $structure['character_set'] == 'utf8') { unset($structure['character_set']); } if (!empty($structure['collation']) && $structure['collation'] == 'utf8_unicode_ci') { unset($structure['collation']); } $data[$model_name] = $structure; } return $one ? $data['structure'] : $data; }
/** * @param Model $caller * @return string */ private function _getObjectFolder($caller) { $id = $caller->getID(); if (!intval($id)) { $int = ord($id[0]) . ord($id[1]); } else { $int = $id > 9 ? $id[0] . $id[1] : '0' . $id; } return Inflector::pluralize(Inflector::underscore($this->_modelName)) . '/' . $int . '/' . (int) $id % 100; }
public function testPluralize() { $this->assertEquals('winners', Inflector::pluralize('winner'), 'simple pluralization'); $this->assertEquals('men', Inflector::pluralize('man'), 'the \'man\' word'); $this->assertEquals('people', Inflector::pluralize('people'), 'the exceptions word'); }