public function __call($m, $a) { if (fnmatch('set*', $m)) { $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3)))); $v = empty($a) ? true : current($a); self::$__events[$this->__ns][$k] = $v; return $this; } elseif (fnmatch('get*', $m)) { $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3)))); if (isset(self::$__events[$this->__ns][$k])) { return self::$__events[$this->__ns][$k]; } $default = empty($a) ? null : current($args); return $default; } elseif (fnmatch('has*', $m)) { $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 3)))); return isset(self::$__events[$this->__ns][$k]); } elseif (fnmatch('clear*', $m)) { $k = Inflector::lower(Inflector::uncamelize(lcfirst(substr($m, 5)))); unset(self::$__events[$this->__ns][$k]); return $this; } else { if (isset(self::$__events[$this->__ns][$m])) { $v = self::$__events[$this->__ns][$m]; if (is_callable($v)) { return call_user_func_array($v, $a); } else { return $v; } } } }
public function __call($func, $argv) { if (substr($func, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); if (isset($argv[0])) { $environment = $argv[0]; } else { $environment = APPLICATION_ENV; } return getConfig($key, $environment); } elseif (substr($func, 0, 3) == 'set') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); $value = Arrays::first($argv); if (isset($argv[1])) { $environment = $argv[1]; } else { $environment = 'all'; } setConfig($key, $value, $environment); return $this; } elseif (substr($func, 0, 3) == 'has') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); if (isset($argv[0])) { $environment = $argv[0]; } else { $environment = APPLICATION_ENV; } return null !== getConfig($key, $environment); } }
function libProject($lib, $args = null) { $lib = strtolower(Inflector::uncamelize($lib)); $script = str_replace('_', DS, $lib) . '.php'; if (fnmatch('*_*', $lib)) { $class = 'Thin\\' . str_replace('_', '\\', $lib); $tab = explode('\\', $class); $first = $tab[1]; $class = str_replace('Thin\\' . $first, 'Thin\\' . ucfirst($first) . 'Project', $class); if (count($tab) > 2) { for ($i = 2; $i < count($tab); $i++) { $seg = trim($tab[$i]); $class = str_replace('\\' . $seg, '\\' . ucfirst($seg), $class); } } } else { $class = 'Thin\\' . ucfirst($lib) . 'Project'; } $file = path('module') . DS . 'classes' . DS . $script; if (file_exists($file)) { require_once $file; if (empty($args)) { return new $class(); } else { if (!is_array($args)) { if (is_string($args)) { if (fnmatch('*,*', $args)) { $args = explode(',', str_replace(', ', ',', $args)); } else { $args = [$args]; } } else { $args = [$args]; } } $methods = get_class_methods($class); if (in_array('instance', $methods)) { $check = new \ReflectionMethod($class, 'instance'); if ($check->isStatic()) { return call_user_func_array([$class, 'instance'], $args); } } else { return construct($class, $args); } } } if (class_exists('Thin\\' . $lib)) { $c = 'Thin\\' . $lib; return new $c(); } if (class_exists($lib)) { return new $lib(); } throw new Exception("The Project {$class} does not exist."); }
static function initialize_association_options($class_name, $plural_name, &$options) { parent::initialize_association_options($class_name, $plural_name, $options); if (!isset($options['join_table'])) { $tableized_class = Inflector::tableize($class_name); $tableized_foreign_class = Inflector::tableize($options['class_name']); $options['join_table'] = $tableized_class < $tableized_foreign_class ? $tableized_class . '_' . $tableized_foreign_class : $tableized_foreign_class . '_' . $tableized_class; } if (!isset($options['association_foreign_key'])) { $options['association_foreign_key'] = Inflector::uncamelize($options['class_name']) . '_id'; } }
static function initialize_association_options($class_name, $plural_name, &$options) { if (!isset($options['class_name'])) { $options['class_name'] = Inflector::classify($plural_name); } if (!isset($options['foreign_key'])) { $options['foreign_key'] = Inflector::uncamelize($class_name) . '_id'; } if (!isset($options['validate'])) { $options['validate'] = true; } }
public function __call($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } $connection = $this->start(); $odm = $connection->database(SITE_NAME); return $odm->collection("{$database}.{$table}"); }
public static function __callStatic($method, $args) { $table = Inflector::uncamelize($method); $database = 'system'; if (empty($args)) { return core('fast')->instanciate($database, $table); } elseif (count($args) == 1) { $id = current($args); if (is_numeric($id)) { return core('fast')->instanciate($database, $table)->find((int) $id); } } }
public static function __callStatic($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } if (empty($args)) { return lib('mysql')->table($table, $database); } }
public static function __callstatic($method, $args) { if (substr($method, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); $return = static::get($var); return $return; } elseif (substr($method, 0, 3) == 'set') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); $value = current($args); return static::set($var, $value); } }
public function __call($m, $a) { $action = array_shift($a); if (!empty($a)) { $success = array_shift($a); } else { $success = null; } if (!empty($a)) { $error = array_shift($a); } else { $error = null; } return $this->step(Inflector::uncamelize($m), $action, $success, $error, $a); }
static function initialize_association_options($class_name, $singular_name, &$options) { if (!isset($options['class_name'])) { $options['class_name'] = Inflector::camelize($singular_name); } if (!isset($options['foreign_key'])) { $options['foreign_key'] = Inflector::uncamelize($options['class_name']) . '_id'; } if (isset($options['polymorphic']) && $options['polymorphic']) { if (!isset($options['foreign_type'])) { $options['foreign_type'] = Inflector::uncamelize($options['class_name']) . '_type'; } } if (!isset($options['validate'])) { $options['validate'] = true; } }
public function __construct($db = null, $table = null) { $this->db = is_null($db) ? SITE_NAME : $db; $this->table = is_null($table) ? 'core' : $table; $dir = Config::get('dir.flat.store', session_save_path()); if (!is_dir($dir)) { File::mkdir($dir); } $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db)); if (!is_dir($dir)) { File::mkdir($dir); } $this->file = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table)) . '.flat'; if (!file_exists($this->file)) { File::put($this->file, serialize([])); } Now::set('flat.collection.' . $this->db . '.' . $this->table, lib('sessy', [$this->db, $this->table, unserialize(File::read($this->file))])); }
public static function __callStatic($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } if (empty($args)) { return core('fast')->instanciate($database, $table); } elseif (count($args) == 1) { $id = current($args); if (is_numeric($id)) { return core('fast')->instanciate($database, $table)->find((int) $id); } } }
public function __call($func, $argv) { if (substr($func, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); return getMeta($key); } elseif (substr($func, 0, 3) == 'set') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); $value = Arrays::first($argv); setMeta($key, $value); return $this; } elseif (substr($func, 0, 3) == 'has') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $key = Inflector::lower($uncamelizeMethod); return null !== getMeta($key); } }
public static function __callStatic($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } if (!count($args)) { return Moo\Db::instance($database, $table); } elseif (count($args) == 1) { $id = Arrays::first($args); if (is_numeric($id)) { return Moo\Db::instance($database, $table)->find($id); } } }
public function __call($m, $a) { if (fnmatch('get*', $m)) { $key = Inflector::uncamelize(substr($m, 3)); $default = empty($a) ? null : current($a); return $this->get($key, $default); } elseif (fnmatch('set*', $m)) { $key = Inflector::uncamelize(substr($m, 3)); return $this->set($key, current($a)); } elseif (fnmatch('has*', $m)) { $key = Inflector::uncamelize(substr($m, 3)); return $this->has($key); } elseif (fnmatch('del*', $m)) { $key = Inflector::uncamelize(substr($m, 3)); return $this->remove($key); } else { return empty($a) ? $this->get($m) : $this->set($m, current($a)); } }
public function __call($event, $args) { if (substr($event, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3))); $key = Inflector::lower($uncamelizeMethod); return $this->get($key); } elseif (substr($event, 0, 3) == 'set') { $value = Arrays::first($args); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3))); $key = Inflector::lower($uncamelizeMethod); if ($key == '__object') { throw new Exception("The key {$key} is protected."); } return $this->set($key, $value); } if (true === $this->__has($event)) { return $this->__fire($event, $args); } else { $value = Arrays::first($args); if (method_exists($this, $event)) { throw new Exception("The method {$event} is a native class' method. Please choose an other name."); } if (!is_callable($value)) { $closure = function () use($value) { return $value; }; $value = $closure; } $obj = $this->instance(); $share = function () use($obj, $value) { $args = func_get_args(); $args[] = $obj; return call_user_func_array($value, $args); }; $eventable = $this->__event($event, $share); return $this; } }
public function __call($m, $a) { if (fnmatch('get*', $m)) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 3))); $key = Inflector::lower($uncamelizeMethod); $args = [$key]; if (!empty($a)) { $args[] = current($a); } return call_user_func_array([$this, 'get'], $args); } elseif (fnmatch('set*', $m)) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 3))); $key = Inflector::lower($uncamelizeMethod); $args = [$key]; $args[] = current($a); return call_user_func_array([$this, 'set'], $args); } elseif (fnmatch('forget*', $m)) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($m, 6))); $key = Inflector::lower($uncamelizeMethod); $args = [$key]; return call_user_func_array([$this, 'forget'], $args); } }
public static function autoload($className) { $found = false; foreach (static::$_paths as $ns => $path) { $file = $path . preg_replace('#\\\\|_(?!.+\\\\)#', DS, str_replace($ns, '', $className)) . '.php'; if (is_readable($file)) { require_once $file; static::$_classes[$className] = true; $found = true; break; } } if (fnmatch('Thin\\\\Db*', $className) && !class_exists($className)) { $db = Inflector::uncamelize(str_replace(['Thin\\Db', 'Thin\\Db\\'], '', $className)); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } jdb($database, $table); $found = true; } }
public function __call($method, $parameters) { if (substr($method, 0, 6) == 'findBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value); } elseif (substr($method, 0, strlen('findObjectsBy')) == 'findObjectsBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, strlen('findObjectsBy')))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, false, true); } elseif (substr($method, 0, 9) == 'findOneBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, true); } }
public function __call($func, $argv) { if (substr($func, 0, 3) == 'get') { $data = $this->_session->getData(); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (isset($data->{$var})) { $this->checkTimeout(); return $data->{$var}; } else { return null; } } elseif (substr($func, 0, 3) == 'set') { $data = $this->_session->getData(); $value = $argv[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (false === $this->_isLocked) { $data->{$var} = $value; } return $this->save(); } elseif (substr($func, 0, 6) == 'forget') { $data = $this->_session->getData(); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (false === $this->_isLocked) { $this->erase($var); return $data; } return $this->save(); } if (!is_callable($func) || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get') { throw new \BadMethodCallException(__CLASS__ . ' => ' . $func); } }
<?php namespace Thin; $tablesModels = glob(APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . '*.php'); $tables = array(); if (count($tablesModels)) { foreach ($tablesModels as $tm) { $tab = explode(DS, $tm); $table = lcfirst(Inflector::uncamelize(repl('.php', '', Arrays::last($tab)))); $tables[$table] = (include $tm); } } return array('tables' => $tables);
public function __call($method, $parameters) { if (substr($method, 0, 6) == 'findBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value); } elseif (substr($method, 0, strlen('findObjectsBy')) == 'findObjectsBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, strlen('findObjectsBy')))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, false, true); } elseif (substr($method, 0, 9) == 'findOneBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, true); } elseif (substr($method, 0, 15) == 'findOneObjectBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 15))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, true, true); } else { $settings = isAke(self::$configs, $this->entity); $event = isAke($settings, $method); if (!empty($event)) { if (is_callable($event)) { if (version_compare(PHP_VERSION, '5.4.0', ">=")) { $event = $event->bindTo($this); } return call_user_func_array($event, $parameters); } } else { if (count($parameters) == 1) { $c = $this; $cb = function () use($c) { return $c; }; return self::configs($this->entity, $method, Arrays::first($parameters), $cb); } else { return $this->__fire($method, $parameters); } } } }
public function __call($func, $argv) { if (substr($func, 0, 3) == 'get' && strlen($func) > 3) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (isset($this->{$var})) { $this->checkTimeout(); return $this->{$var}; } else { return count($argv) == 1 ? current($argv) : null; } } elseif (substr($func, 0, 3) == 'set' && strlen($func) > 3) { $value = count($argv) == 1 ? current($argv) : null; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (false === $this->_isLocked) { $this->{$var} = $value; } return $this->save(); } elseif (substr($func, 0, 6) == 'forget' && strlen($func) > 6) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 6))); $var = Inflector::lower($uncamelizeMethod); if (false === $this->_isLocked) { $this->erase($var); return $this; } return $this->save(); } $id = sha1($func); if (isset($this->{$id})) { if ($this->{$id} instanceof \Closure) { return call_user_func_array($this->{$id}, $argv); } } if (!is_callable($func) || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get') { throw new \BadMethodCallException(__CLASS__ . ' => ' . $func); } }
public function __call($method, $args) { if (empty($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array(); } if (!Arrays::is($this->_datas['foreignFields'])) { $this->_datas['foreignFields'] = array($this->_datas['foreignFields']); } if (substr($method, 0, 3) == 'get') { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) && 'true' != $this->_datas['foreignFields'][$var]) { return $this->_datas['foreignFields'][$var]; } $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $field = $rs['fieldName']; $classModel = $this->_datas['classModel']; $obj = new $classModel(); if (Arrays::inArray($field, $this->_datas['keys'])) { $modelField = $rs['foreignTable']; if (isset($this->_datas['configModel']['relationship']) && ake($field, $this->_datas['configModel']['relationship'])) { $m = $this->_datas['configModel']['relationship'][$field]; if (ake("entity", $rs)) { $entity = $rs['entity']; } else { $entity = $obj->_entity; } if (null !== $m['type']) { switch ($m['type']) { case 'manyToOne': case 'oneToOne': $nObj = new self($entity, $modelField); if (ake("relationshipKeys", $rs)) { $field = $rs['relationshipKeys']; } if (!is_null($this->{$field})) { if (false === $this->_cache) { $result = $nObj->find($this->{$field}); } else { $result = $nObj->cache($this->_cache)->find($this->{$field}); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; } break; case 'manyToMany': case 'oneToMany': $nObj = new self($entity, $modelField); $getter = $this->pk(); $fk = ake("relationshipKeys", $rs) ? $rs['relationshipKeys'][$field] : $rs['foreignKey']; if (false === $this->_cache) { $result = $nObj->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); } else { $result = $nObj->cache($this->_cache)->where($nObj->_dbName . '.' . $nObj->_tableName . "." . $fk . " = " . $nObj->quote($this->{$getter}))->select(); $this->_cache = false; } $this->_datas['foreignFields'][$var] = $result; return $result; break; } } } } } if (isset($this->{$var}) || is_null($this->{$var})) { return $this->{$var}; } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } return null; } elseif (substr($method, 0, 3) == 'set') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $this->_datas['foreignFields'][$var] = $value; $rs = $this->_datas['configModel']['relationship'][$var]; $setField = $rs['fieldName']; $getter = $rs['foreignKey']; if (Arrays::in($setField, $vars) && isset($value->{$getter})) { $this->{$setField} = $value->{$getter}; return $this; } else { return $this; } } else { $this->{$var} = $value; return $this; } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } elseif (substr($method, 0, 3) == 'min') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->min($var); } } elseif (substr($method, 0, 3) == 'max') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->max($var); } } elseif (substr($method, 0, 3) == 'avg') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::in($var, $vars)) { return $this->avg($var); } } elseif (substr($method, 0, 3) == 'sum') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->sum($var); } } elseif (substr($method, 0, 5) == 'count') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $vars = array_values($this->fields()); if (Arrays::inArray($var, $vars)) { return $this->count($var); } } elseif (substr($method, 0, 6) == 'findBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (is_object($value) && null !== $this->_datas['configModel']['relationship'][$var]) { switch ($this->_datas['configModel']['relationship'][$var]) { case 'manyToOne': case 'oneToOne': $field = $rs['fieldName']; $q = $this->_dbName . '.' . $this->_tableName . "." . $field . " = " . $this->quote($value->{$field}); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } case 'oneToMany': case 'manyToMany': $field = $rs['fieldName']; $pk = $this->pk(); $pkValue = $value->{$pk}; $q = $this->_dbName . '.' . $this->_tableName . "." . $pk . " = " . $this->quote($pkValue); if (false === $this->_cache) { return $this->where($q)->select(); } else { return $this->cache($this->_cache)->where($q)->select(); $this->_cache = false; } } } else { if (Arrays::in($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } } elseif (substr($method, 0, 5) == 'where' && strlen($method) > 5) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 5))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } $var = $this->_dbName . '.' . $this->_tableName . '.' . $var; $condition = $args[0]; $operator = isset($args[1]) ? $args[1] : 'AND'; return $this->where("{$var} {$condition}", $operator); } elseif (substr($method, 0, 7) == 'groupBy' && strlen($method) > 7) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); if ($var == 'id') { $var = $this->pk(); } return $this->groupBy($var); } elseif (substr($method, 0, 7) == 'orderBy') { $direction = count($args) ? $args[0] : 'ASC'; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 7))); $var = Inflector::lower($uncamelizeMethod); return $this->order($var, $direction); } elseif (substr($method, 0, 9) == 'findOneBy') { $vars = array_values($this->fields()); $value = $args[0]; $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $var = Inflector::lower($uncamelizeMethod); if (Arrays::inArray($var, $vars) || $var == 'id') { if ($var != 'id') { return $this->findBy($var, $value, true); } else { return $this->find($value); } } else { throw new Exception("Unknown field {$var} in " . get_class($this) . " class."); } } else { $vars = array_values($this->fields()); $uncamelizeMethod = Inflector::uncamelize(lcfirst($method)); $var = Inflector::lower($uncamelizeMethod); $var = true === $this->hasForeignRelation($var) ? $this->fkFieldName($var) : $var; $rs = $this->_datas['configModel']['relationship'][$var]; $this->_datas['foreignFields'][$var] = $value; if (Arrays::in($var, $vars) || ake($var, $this->_datas['foreignFields']) || true === $this->hasForeignRelation($var)) { if (ake($var, $this->_datas['foreignFields'])) { return $this->_datas['foreignFields'][$var]; } if (isset($this->{$var})) { return $this->{$var}; } else { if (!method_exists($this, $method)) { $this->{$method} = $args[0]; } } } } }
public function getClass() { return Inflector::uncamelize(repl('Thin\\', '', get_called_class())); }
function __autoload($class_name) { $file_name = YARR_APP_PATH . '/models/' . Inflector::uncamelize($class_name) . '.php'; if (file_exists($file_name)) { require_once $file_name; } }
public function __call($func, $argv) { if (substr($func, 0, 3) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); if (isset($this->{$var})) { return $this->{$var}; } else { return null; } } elseif (substr($func, 0, 3) == 'set') { $value = Arrays::first($argv); $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, 3))); $var = Inflector::lower($uncamelizeMethod); $this->{$var} = $value; return $this; } if (!is_callable($func) || substr($func, 0, 3) !== 'set' || substr($func, 0, 3) !== 'get') { throw new \BadMethodCallException(__CLASS__ . ' => ' . $func); } }
public function __call($method, $parameters) { if (substr($method, 0, 6) == 'findBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 6))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value); } elseif (substr($method, 0, strlen('findObjectsBy')) == 'findObjectsBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, strlen('findObjectsBy')))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, false, true); } elseif (substr($method, 0, 9) == 'findOneBy') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 9))); $field = Inflector::lower($uncamelizeMethod); $value = Arrays::first($parameters); return $this->findBy($field, $value, true); } else { $settings = isAke(self::$configs, $this->entity); $event = isAke($settings, $method); if (!empty($event)) { if (is_callable($event)) { if (version_compare(PHP_VERSION, '5.4.0', ">=")) { $event = $event->bindTo($this); } return call_user_func_array($event, $parameters); } } else { throw new Exception("The method '{$method}' is not callable."); } } }
public static function __callStatic($method, $args) { $db = new self(); if (substr($method, 0, 3) == 'get' && strlen($method) > 3) { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); if (count($args) == 1) { $default = Arrays::first($args); } else { $default = null; } return $db->get($var, $default); } elseif (substr($method, 0, 3) == 'set' && strlen($method) > 3) { if (count($args) == 2) { $ttl = Arrays::last($args); } else { $ttl = 0; } $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($method, 3))); $var = Inflector::lower($uncamelizeMethod); return $db->set($var, Arrays::first($args), $ttl); } else { throw new \BadMethodCallException(__CLASS__ . ' => ' . $func); } }