当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::camelize方法代码示例

本文整理汇总了PHP中Thin\Inflector::camelize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::camelize方法的具体用法?PHP Inflector::camelize怎么用?PHP Inflector::camelize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thin\Inflector的用法示例。


在下文中一共展示了Inflector::camelize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     if (fnmatch('*cli*', php_sapi_name())) {
         $dir = Config::get('dir.schedules', APPLICATION_PATH . DS . 'schedules');
         if (is_dir($dir)) {
             Timer::start();
             Cli::show("Start of execution", 'COMMENT');
             $files = glob($dir . DS . '*.php');
             foreach ($files as $file) {
                 require_once $file;
                 $object = str_replace('.php', '', Arrays::last(explode(DS, $file)));
                 $class = 'Thin\\' . ucfirst(Inflector::camelize($object . '_schedule'));
                 $instance = lib('app')->make($class);
                 $methods = get_class_methods($instance);
                 Cli::show("Start schedule '{$object}'", 'COMMENT');
                 foreach ($methods as $method) {
                     $when = $this->getWhen($instance, $method);
                     $isDue = $this->isDue($object, $method, $when);
                     if (true === $isDue) {
                         Cli::show("Execution of {$object}->{$method}", 'INFO');
                         $instance->{$method}();
                     } else {
                         Cli::show("No need to execute {$object}->{$method}", 'QUESTION');
                     }
                 }
             }
             Cli::show("Time of execution [" . Timer::get() . " s.]", 'SUCCESS');
             Cli::show("end of execution", 'COMMENT');
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:31,代码来源:schedule.php

示例2: _related

 public function _related()
 {
     $fields = array_keys($this->_data);
     $obj = $this;
     foreach ($fields as $field) {
         if (fnmatch('*_id', $field)) {
             if (is_string($field)) {
                 $value = $this->{$field};
                 if (!is_callable($value)) {
                     $fk = str_replace('_id', '', $field);
                     $ns = $this->_db->db;
                     $cb = function ($object = false) use($value, $fk, $ns) {
                         $db = Db::instance($ns, $fk);
                         return $db->find($value, $object);
                     };
                     $this->_event($fk, $cb);
                     $setter = lcfirst(Inflector::camelize("link_{$fk}"));
                     $cb = function (Model $fkObject) use($obj, $field, $fk) {
                         $obj->{$field} = $fkObject->id;
                         $newCb = function () use($fkObject) {
                             return $fkObject;
                         };
                         $obj->_event($fk, $newCb);
                         return $obj;
                     };
                     $this->_event($setter, $cb);
                 }
             }
         }
     }
     return $this;
 }
开发者ID:schpill,项目名称:standalone,代码行数:32,代码来源:Model.php

示例3: __construct

 public function __construct($type)
 {
     $this->type = $type;
     $dbFile = STORAGE_PATH . DS . Inflector::camelize('value_' . $type) . '.store';
     $this->db = new SQLite3($dbFile);
     $q = "SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'datas'";
     $res = $this->db->query($q);
     if (false === $res->fetchArray()) {
         $this->db->exec('CREATE TABLE datas (key, value, expiration)');
     }
     $this->clean();
 }
开发者ID:schpill,项目名称:thin,代码行数:12,代码来源:Value.php

示例4: __construct

 public function __construct(Database $model)
 {
     $this->model = $model->inCache(false);
     $fileConfig = APPLICATION_PATH . DS . 'models' . DS . 'CrudNosql' . DS . ucfirst(Inflector::camelize($model->db)) . DS . ucfirst(Inflector::camelize($model->table)) . '.php';
     if (File::exists($fileConfig)) {
         $this->config = (include $fileConfig);
     } else {
         $this->config = [];
     }
     if (!empty($this->config)) {
         $this->prepareFields();
     }
     if (get_magic_quotes_gpc()) {
         $_REQUEST = $this->stripslashes($_REQUEST);
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:16,代码来源:Crud.php

示例5: __construct

 public function __construct($type)
 {
     $this->type = $type;
     $this->fields = Arrays::exists($type, Data::$_fields) ? Data::$_fields[$type] : Data::noConfigFields($type);
     $this->settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : Data::defaultConfig($type);
     $this->session = session(Inflector::camelize('store_' . $type));
     $data = $this->session->getData();
     if (empty($data)) {
         $data = array();
         $this->session->setData($data);
     }
     $dbFile = STORAGE_PATH . DS . Inflector::camelize('store_' . $type) . '.store';
     $this->db = new SQLite3($dbFile);
     $q = "SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'datas'";
     $res = $this->db->query($q);
     if (false === $res->fetchArray()) {
         $this->db->exec('CREATE TABLE datas (id VARCHAR PRIMARY KEY, datecreate, datemodify, value)');
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:19,代码来源:Store.php

示例6: __callStatic

 /**
  * Magic method for handling API methods.
  *
  * @since   PHP 5.3
  * @param   string  $method
  * @param   array   $args
  * @return  array
  */
 public static function __callStatic($method, $args)
 {
     // if production mode...
     if (Config::get('paypal.production_mode') === true) {
         // use production credentials
         $credentials = Config::get('paypal.production');
         // use production endpoint
         $endpoint = 'https://api-3t.paypal.com/nvp';
     } else {
         // use sandbox credentials
         $credentials = Config::get('paypal.sandbox');
         // use sandbox endpoint
         $endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
     }
     // build credentials
     $params = array('VERSION' => '74.0', 'USER' => $credentials['username'], 'PWD' => $credentials['password'], 'SIGNATURE' => $credentials['signature'], 'METHOD' => Inflector::camelize($method));
     // build post data
     $fields = http_build_query($params + $args[0]);
     // curl request
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $endpoint);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     $response = curl_exec($ch);
     // if errors...
     if (curl_errno($ch)) {
         #$errors = curl_error($ch);
         curl_close($ch);
         // return false
         return false;
     } else {
         curl_close($ch);
         // return array
         parse_str($response, $result);
         return $result;
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:49,代码来源:Paypal.php

示例7: __construct

 public function __construct($type, $entity = 'db')
 {
     $this->type = $type;
     $this->entity = $entity;
     $this->fields = Arrays::exists($type, Data::$_fields) ? Data::$_fields[$type] : Data::noConfigFields($type);
     $this->settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : Data::defaultConfig($type);
     $this->session = session(Inflector::camelize('storeSQL_' . $type));
     $data = $this->session->getData();
     if (empty($data)) {
         $data = array();
         $this->session->setData($data);
     }
     $this->db = $this->connect();
     if (false === $this->checkTable()) {
         $q = 'CREATE TABLE IF NOT EXISTS `datas_' . $this->type . '` (
               `id` varchar(9) NOT NULL,
               `datecreate` int(11) unsigned NOT NULL,
               `datemodify` int(11) unsigned NOT NULL,
               `value` longtext NOT NULL
             ) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
         $this->_query($q);
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:23,代码来源:Sql.php

示例8: make

 public static function make($db, $what)
 {
     if (is_string($what)) {
         $file = APPLICATION_PATH . DS . 'models' . DS . 'Bigdata' . DS . 'views' . DS . $db->db . DS . ucfirst(I::lower($db->table)) . DS . I::camelize($what) . '.php';
         if (files()->exists($file)) {
             require_once $file;
             $class = '\\Thin\\' . ucfirst(I::lower($db->db)) . ucfirst(I::lower($db->table)) . 'View';
             return $class::make($db);
         } else {
             return $db;
         }
     } elseif (A::is($what)) {
         $nameview = 'view_' . $db->db . '_' . $db->table . '_' . sha1(serialize($what));
         $ageDb = $db->getage();
         $viewDb = Db::instance($db->db, $nameview);
         $ageView = $db->getage();
         $exists = strlen($db->cache()->get('dbRedis.views.' . $nameview)) ? true : false;
         if ($ageView < $ageDb || !$exists) {
             $viewDb->getCollection()->remove();
             foreach ($what as $wh) {
                 $op = 'AND';
                 if (count($wh) == 4) {
                     $op = $wh[3];
                     unset($wh[3]);
                 }
                 $db = $db->where($wh);
             }
             $res = $db->exec();
             foreach ($res as $row) {
                 $viewDb->saveView($row);
             }
             $db->cache()->set('dbRedis.views.' . $nameview, 1);
         }
         return $viewDb;
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:36,代码来源:View.php

示例9: raw

 function raw($db, $table)
 {
     if ($db != SITE_NAME) {
         $fn = Inflector::camelize($db . '_' . $table);
     } else {
         $fn = ucfirst(strtolower($table));
     }
     $code = 'namespace Thin; function ' . $fn . '() {return \\Thin\\Raw::' . $fn . '();}';
     if (!function_exists('\\Thin\\' . $fn)) {
         eval($code);
     } else {
         throw new Exception('The function ' . $fn . ' ever exists.');
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:14,代码来源:functions.php

示例10: __callStatic

 public static function __callStatic($fn, $args)
 {
     $method = Inflector::uncamelize($fn);
     $tab = explode('_', $method);
     $table = array_shift($tab);
     $function = implode('_', $tab);
     $function = lcfirst(Inflector::camelize($function));
     $instance = self::instance(SITE_NAME, $table);
     return call_user_func_array([$instance, $function], $args);
 }
开发者ID:schpill,项目名称:standalone,代码行数:10,代码来源:Db.php

示例11: generate

 public static function generate($model, $overwrite = false)
 {
     $file = APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . ucfirst(Inflector::camelize($model)) . '.php';
     if (!File::exists($file) || $overwrite) {
         $db = model($model);
         $crud = new Crud($db);
         File::delete($file);
         $tplModel = fgc(__DIR__ . DS . 'Model.tpl');
         $tplField = fgc(__DIR__ . DS . 'Field.tpl');
         $fields = $crud->fields();
         $singular = ucfirst($model);
         $plural = $singular . 's';
         $default_order = $crud->pk();
         $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel);
         $fieldsSection = '';
         foreach ($fields as $field) {
             if ($field != $crud->pk()) {
                 $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
                 $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:25,代码来源:Tools.php

示例12: __call

 public function __call($func, $args)
 {
     if (substr($func, 0, strlen('get')) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('get'))));
         $field = Inflector::lower($uncamelizeMethod);
         $method = lcfirst(Inflector::camelize('get_' . $field . '_attribute'));
         $methods = get_class_methods($this);
         if (in_array($method, $methods)) {
             return $this->{$method}();
         }
         $default = count($args) == 1 ? current($args) : null;
         $res = isAke($this->_data, $field, false);
         if (false !== $res) {
             return $res;
         } else {
             $resFk = isAke($this->_data, $field . '_id', false);
             if (false !== $resFk) {
                 $db = Db::instance($this->_db->db, $field);
                 $object = count($args) == 1 ? $args[0] : false;
                 if (!is_bool($object)) {
                     $object = false;
                 }
                 return $db->find($resFk, $object);
             } else {
                 if ($field[strlen($field) - 1] == 's' && isset($this->_data['id']) && $field[0] != '_') {
                     $db = Db::instance($this->_db->db, substr($field, 0, -1));
                     $object = count($args) == 1 ? $args[0] : false;
                     if (!is_bool($object)) {
                         $object = false;
                     }
                     $hasPivot = $this->hasPivot($db);
                     if (true === $hasPivot) {
                         $model = $db->model();
                         $pivots = $this->pivots($model)->get();
                         $ids = [];
                         if ($pivots->count() > 0) {
                             foreach ($pivots as $pivot) {
                                 $id = isAke($pivot, substr($field, 0, -1) . '_id', false);
                                 if (false !== $id) {
                                     array_push($ids, $id);
                                 }
                             }
                             if (!empty($ids)) {
                                 return $db->where(['id', 'IN', implode(',', $ids)])->get(null, $object);
                             } else {
                                 return [];
                             }
                         }
                     } else {
                         $idField = $this->_db->table . '_id';
                         return $db->where([$idField, '=', $this->_data['id']])->get(null, $object);
                     }
                 } else {
                     return $default;
                 }
             }
         }
     } elseif (substr($func, 0, strlen('has')) == 'has' && strlen($func) > strlen('has')) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('has'))));
         $field = Inflector::lower($uncamelizeMethod);
         $res = isAke($this->_data, $field, false);
         if (false !== $res) {
             return true;
         } else {
             $resFk = isAke($this->_data, $field . '_id', false);
             if (false !== $resFk) {
                 return true;
             } else {
                 if ($field[strlen($field) - 1] == 's' && isset($this->_data['id']) && $field[0] != '_') {
                     $db = Db::instance($this->_db->db, substr($field, 0, -1));
                     $hasPivot = $this->hasPivot($db);
                     if (true === $hasPivot) {
                         $model = $db->model();
                         $pivots = $this->pivots($model)->get();
                         $ids = [];
                         if ($pivots->count() > 0) {
                             foreach ($pivots as $pivot) {
                                 $id = isAke($pivot, substr($field, 0, -1) . '_id', false);
                                 if (false !== $id) {
                                     return true;
                                 }
                             }
                             return false;
                         }
                     } else {
                         $idField = $this->_db->table . '_id';
                         $count = $db->where([$idField, '=', $this->_data['id']])->count();
                         return $count > 0 ? true : false;
                     }
                 }
             }
         }
         return false;
     } elseif (substr($func, 0, strlen('belongsTo')) == 'belongsTo' && strlen($func) > strlen('belongsTo')) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('set'))));
         $field = Inflector::lower($uncamelizeMethod);
         $fk = current($args);
         if (is_object($fk)) {
             $val = isAke($this->_data, $field . '_id', false);
             $fkId = isset($fk->id) ? $fk->id : false;
//.........这里部分代码省略.........
开发者ID:schpill,项目名称:standalone,代码行数:101,代码来源:Model.php

示例13: __destruct

 public function __destruct()
 {
     $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db)) . DS . ucfirst(Inflector::camelize($this->model->table)) . '.php';
     if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db)))) {
         File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($this->model->db)));
     }
     if (!File::exists($file) || $this->replace) {
         File::delete($file);
         $tplModel = File::read(__DIR__ . DS . 'Model.tpl');
         $tplField = File::read(__DIR__ . DS . 'Field.tpl');
         $uniques = isAke($this->indices, 'unique', []);
         $foreigns = isAke($this->indices, 'foreign', []);
         $softDelete = true === $this->softDelete ? 'true' : 'false';
         $uString = '[';
         if (count($uniques)) {
             foreach ($uniques as $unique) {
                 $uString .= "'" . $unique . "'" . ',';
             }
             $uString = substr($uString, 0, -1);
         }
         $uString .= ']';
         $fString = '[';
         if (count($foreigns)) {
             foreach ($foreigns as $foreign) {
                 $fString .= "'" . $foreign . "'" . ',';
             }
             $fString = substr($fString, 0, -1);
         }
         $fString .= ']';
         $before_create = $this->getHook('before_create');
         $after_create = $this->getHook('after_create');
         $before_update = $this->getHook('before_update');
         $after_update = $this->getHook('after_update');
         $before_read = $this->getHook('before_read');
         $after_read = $this->getHook('after_read');
         $before_delete = $this->getHook('before_delete');
         $after_delete = $this->getHook('after_delete');
         $before_list = $this->getHook('before_list');
         $after_list = $this->getHook('after_list');
         $tplModel = str_replace(['##singular##', '##plural##', '##default_order##', '##soft_delete##', '##foreigns##', '##uniques##', '##before_create##', '##after_create##', '##before_update##', '##after_update##', '##before_read##', '##after_read##', '##before_delete##', '##after_delete##', '##before_list##', '##after_list##'], [$this->singular, $this->plural, $this->order, $softDelete, $fString, $uString, $before_create, $after_create, $before_update, $after_update, $before_read, $after_read, $before_delete, $after_delete, $before_list, $after_list], $tplModel);
         $fieldsSection = '';
         foreach ($this->fields as $field => $infos) {
             if ($field != 'id') {
                 $label = $this->getSetting($field, 'label', ucfirst($field));
                 $form_type = $this->getSetting($field, 'form_type', 'text');
                 $helper = $this->getSetting($field, 'helper', 'false');
                 $required = $this->getSetting($field, 'required', 'true');
                 $form_plus = $this->getSetting($field, 'form_plus', 'false');
                 $length = $this->getSetting($field, 'length', 'false');
                 $is_listable = $this->getSetting($field, 'is_listable', 'true');
                 $is_exportable = $this->getSetting($field, 'is_exportable', 'true');
                 $is_searchable = $this->getSetting($field, 'is_searchable', 'true');
                 $is_sortable = $this->getSetting($field, 'is_sortable', 'true');
                 $is_readable = $this->getSetting($field, 'is_readable', 'true');
                 $is_creatable = $this->getSetting($field, 'is_creatable', 'true');
                 $is_updatable = $this->getSetting($field, 'is_updatable', 'true');
                 $is_deletable = $this->getSetting($field, 'is_deletable', 'true');
                 $content_view = $this->getSetting($field, 'content_view', 'false');
                 $content_list = $this->getSetting($field, 'content_list', 'false');
                 $content_search = $this->getSetting($field, 'content_search', 'false');
                 $content_create = $this->getSetting($field, 'content_create', 'false');
                 $fieldsSection .= str_replace(['##field##', '##form_type##', '##helper##', '##required##', '##form_plus##', '##length##', '##is_listable##', '##is_exportable##', '##is_searchable##', '##is_sortable##', '##is_readable##', '##is_creatable##', '##is_updatable##', '##is_deletable##', '##content_view##', '##content_list##', '##content_search##', '##content_create##', '##label##'], [$field, $form_type, $helper, $required, $form_plus, $length, $is_listable, $is_exportable, $is_searchable, $is_sortable, $is_readable, $is_creatable, $is_updatable, $is_deletable, $content_view, $content_list, $content_search, $content_create, $label], $tplField);
             }
         }
         $tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
         File::put($file, $tplModel);
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:68,代码来源:Schema.php

示例14: __call

 public function __call($fn, $args)
 {
     $method = substr($fn, 0, strlen('findLastBy'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('findLastBy'))));
     if (strlen($fn) > strlen('findLastBy')) {
         if ('findLastBy' == $method) {
             $obj = count($args) == 2 ? $args[1] : true;
             if (!is_bool($obj)) {
                 $obj = true;
             }
             return $this->where([$object, '=', Arrays::first($args)])->last($obj);
         }
     }
     $method = substr($fn, 0, strlen('findFirstBy'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('findFirstBy'))));
     if (strlen($fn) > strlen('findFirstBy')) {
         if ('findFirstBy' == $method) {
             $obj = count($args) == 2 ? $args[1] : true;
             if (!is_bool($obj)) {
                 $obj = true;
             }
             return $this->findFirstBy($object, Arrays::first($args), $obj);
         }
     }
     $method = substr($fn, 0, strlen('findOneBy'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('findOneBy'))));
     if (strlen($fn) > strlen('findOneBy')) {
         if ('findOneBy' == $method) {
             $obj = count($args) == 2 ? $args[1] : false;
             if (!is_bool($obj)) {
                 $obj = false;
             }
             return $this->findOneBy($object, Arrays::first($args), $obj);
         }
     }
     $method = substr($fn, 0, strlen('orderBy'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('orderBy'))));
     if (strlen($fn) > strlen('orderBy')) {
         if ('orderBy' == $method) {
             $fields = $this->fieldsRow();
             if (!Arrays::in($object, $fields) && 'id' != $object) {
                 $object = Arrays::in($object . '_id', $fields) ? $object . '_id' : $object;
             }
             $direction = !empty($args) ? Arrays::first($args) : 'ASC';
             return $this->order($object, $direction);
         } elseif ('groupBy' == $method) {
             $fields = $this->fieldsRow();
             if (!Arrays::in($object, $fields)) {
                 $object = Arrays::in($object . '_id', $fields) ? $object . '_id' : $object;
             }
             return $this->groupBy($object);
         }
     }
     $method = substr($fn, 0, strlen('where'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('where'))));
     if (strlen($fn) > strlen('where')) {
         if ('where' == $method) {
             return $this->where([$object, '=', Arrays::first($args)]);
         }
     }
     $method = substr($fn, 0, strlen('sortBy'));
     $object = Inflector::uncamelize(lcfirst(substr($fn, strlen('sortBy'))));
     if (strlen($fn) > strlen('sortBy')) {
         if ('sortBy' == $method) {
             $fields = $this->fieldsRow();
             if (!Arrays::in($object, $fields) && 'id' != $object) {
                 $object = Arrays::in($object . '_id', $fields) ? $object . '_id' : $object;
             }
             $direction = !empty($args) ? Arrays::first($args) : 'ASC';
             return $this->order($object, $direction);
         } elseif ('findBy' == $method) {
             $obj = count($args) == 2 ? $args[1] : false;
             if (!is_bool($obj)) {
                 $obj = false;
             }
             return $this->findBy($object, Arrays::first($args), false, $obj);
         }
     }
     $model = $this->model();
     $scope = lcfirst(Inflector::camelize('scope_' . Inflector::uncamelize($fn)));
     if (method_exists($model, $scope)) {
         return call_user_func_array([$model, $scope], $args);
     }
     throw new Exception("Method '{$fn}' is unknown.");
 }
开发者ID:schpill,项目名称:standalone,代码行数:85,代码来源:Db.php

示例15: related

 private function related($obj)
 {
     $settings = isAke(self::$config, "{$this->database}.{$this->table}");
     $relations = isAke($settings, 'relations');
     $params = $this->args;
     if (count($relations)) {
         foreach ($relations as $relation) {
             $field = $relation . '_id';
             if (is_string($field)) {
                 $value = $obj->{$field};
                 if (!is_callable($value)) {
                     $fk = $tableFk = $relation;
                     $fks = $fk . 's';
                     $cb = function ($object = true) use($value, $tableFk, $params) {
                         list($database, $table, $host, $username, $password) = $params;
                         $db = Database::instance($database, $tableFk, $host, $username, $password);
                         if ($db) {
                             return $db->find($value, $object);
                         }
                         return null;
                     };
                     $obj->event($fk, $cb);
                     $cb = function ($object = true) use($value, $tableFk, $params) {
                         list($database, $table, $host, $username, $password) = $params;
                         $db = Database::instance($database, $tableFk, $host, $username, $password);
                         if ($db) {
                             return $db->where($db->pk() . " = '" . addslashes($value) . "'")->exec($object);
                         }
                         return null;
                     };
                     $obj->event($fks, $cb);
                     $setter = lcfirst(Inflector::camelize("link_{$fk}"));
                     $cb = function (Container $fkObject) use($obj, $field, $fk) {
                         $obj->{$field} = $fkObject->id();
                         $newCb = function () use($fkObject) {
                             return $fkObject;
                         };
                         $obj->event($fk, $newCb);
                         return $obj;
                     };
                     $obj->event($setter, $cb);
                 }
             }
         }
     }
     return $obj;
 }
开发者ID:noikiy,项目名称:inovi,代码行数:47,代码来源:Database.php


注:本文中的Thin\Inflector::camelize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。