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


PHP Arrays::first方法代码示例

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


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

示例1: __call

 public function __call($event, $args)
 {
     if (substr($event, 0, 3) == 'get' && strlen($event) > 3) {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return $this->get($key);
     } elseif (substr($event, 0, 3) == 'set' && strlen($event) > 3) {
         $value = Arrays::first($args);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return $this->set($key, $value);
     }
     if (true === $this->__has($event)) {
         array_push($args, $this);
         return $this->__fire($event, $args);
     } else {
         if (method_exists($this, $event)) {
             throw new Exception("The method {$event} is a native class' method. Please choose an other name.");
         }
         $value = Arrays::first($args);
         if ($value instanceof Closure) {
             $eventable = $this->__event($event, $value);
         } else {
             $set = function () use($value) {
                 return $value;
             };
             $eventable = $this->__event($event, $set);
         }
         return $this;
     }
 }
开发者ID:noikiy,项目名称:inovi,代码行数:31,代码来源:Context.php

示例2: __call

 public function __call($event, $args)
 {
     if (substr($event, 0, 3) == 'get') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return self::get($key);
     } elseif (substr($event, 0, 3) == 'set') {
         $value = Arrays::first($args);
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($event, 3)));
         $key = Inflector::lower($uncamelizeMethod);
         return self::set($key, $value);
     }
     if (true === self::__has($event)) {
         return self::__fire($event, $args);
     } else {
         $value = Arrays::first($args);
         if ($value instanceof Closure) {
             $eventable = self::__event($event, $value);
         } else {
             $set = function () use($value) {
                 return $value;
             };
             $eventable = self::__event($event, $set);
         }
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:26,代码来源:Di.php

示例3: __construct

 /**
  * Construct new RangeQuery component
  *
  * @return \ElasticSearch\DSL\RangeQuery
  * @param array $options
  */
 public function __construct(array $options = [])
 {
     $this->fieldname = key($options);
     $values = Arrays::first($options);
     if (Arrays::is($values)) {
         foreach ($values as $key => $val) {
             $this->{$key} = $val;
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:16,代码来源:RangeQuery.php

示例4: getOrm

 private function getOrm($seg)
 {
     if (!count($seg)) {
         throw new \Exception('Query is invalid.');
     }
     $seg = Arrays::first($seg);
     $table = isAke($seg, 'table', false);
     if (!$table) {
         throw new \Exception('Query is invalid.');
     }
     if (fnmatch('*.*', $table)) {
         list($database, $table) = explode('.', $table);
     } else {
         $database = SITE_NAME;
     }
     return jdb($database, $table);
 }
开发者ID:schpill,项目名称:standalone,代码行数:17,代码来源:Query.php

示例5: __callStatic

 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 Db::instance($database, $table);
     } elseif (count($args) == 1) {
         $id = Arrays::first($args);
         if (is_numeric($id)) {
             return Db::instance($database, $table)->find($id);
         }
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:18,代码来源:Entity.php

示例6: transformDSLSortToString

 /**
  * Transform search parameters to string
  *
  * @return string
  * @param mixed $dslSort
  */
 protected function transformDSLSortToString($dslSort)
 {
     $string = "";
     if (Arrays::is($dslSort)) {
         foreach ($dslSort as $sort) {
             if (Arrays::is($sort)) {
                 $field = key($sort);
                 $info = Arrays::first($sort);
             } else {
                 $field = $sort;
             }
             $string .= "&sort=" . $field;
             if (isset($info)) {
                 if (is_string($info) && $info == "desc") {
                     $string .= ":reverse";
                 } elseif (Arrays::is($info) && Arrays::exists("reverse", $info) && $info['reverse']) {
                     $string .= ":reverse";
                 }
             }
         }
     }
     return $string;
 }
开发者ID:schpill,项目名称:standalone,代码行数:29,代码来源:Stringify.php

示例7: first

 /**
  * First item
  *
  * @return Model
  */
 public function first($callback = null, $default = null)
 {
     if (is_null($callback)) {
         return count($this->_items) > 0 ? Arrays::first($this->_items) : $default;
     } else {
         foreach ($this->_items as $key => $value) {
             if (call_user_func($callback, $key, $value)) {
                 return $value;
             }
         }
         return value($default);
     }
 }
开发者ID:schpill,项目名称:standalone,代码行数:18,代码来源:Collection.php

示例8: __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);
         $default = count($args) == 1 ? Arrays::first($args) : null;
         return isAke($this->_data, $field, $default);
     } elseif (substr($func, 0, strlen('set')) == 'set') {
         $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('set'))));
         $field = Inflector::lower($uncamelizeMethod);
         if (!empty($args)) {
             $val = Arrays::first($args);
         } else {
             $val = null;
         }
         $this->_data[$field] = $val;
         return $this;
     } else {
         $cb = isake($this->_events, $func, false);
         if (false !== $cb) {
             if ($cb instanceof Closure) {
                 return call_user_func_array($cb, $args);
             }
         }
         dd("{$func} is not a model function of this object.");
     }
 }
开发者ID:schpill,项目名称:thin,代码行数:27,代码来源:Fly.php

示例9: get

 public function get($var)
 {
     if (isset($this->{$var})) {
         if (isset($this->thin_type)) {
             Data::getModel($this->thin_type);
             $type = $this->thin_type;
             $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : [];
             if (Arrays::exists('relationships', $settings)) {
                 if (Arrays::exists($var, $settings['relationships'])) {
                     return Data::getById($var, $this->{$var});
                 }
             }
         }
         return $this->{$var};
     } else {
         if (isset($this->thin_type)) {
             Data::getModel($this->thin_type);
             $type = $this->thin_type;
             $settings = Arrays::exists($type, Data::$_settings) ? Data::$_settings[$type] : [];
             if (Arrays::exists($var, $settings['relationships']) && 's' == $var[strlen($var) - 1]) {
                 if (Arrays::exists($var, $settings['relationships'])) {
                     $res = Data::query(substr($var, 0, -1), "{$type} = " . $this->id);
                     $collection = [];
                     if (count($res)) {
                         foreach ($res as $row) {
                             $obj = Data::getObject($row);
                             $collection[] = $obj;
                         }
                     }
                     return 1 == count($collection) ? Arrays::first($collection) : $collection;
                 }
             }
         }
     }
     return null;
 }
开发者ID:schpill,项目名称:thin,代码行数:36,代码来源:Object.php

示例10: listing

 public function listing($customFields = false)
 {
     $fields = $this->fields();
     $fieldInfos = isAke($this->config, 'fields');
     $before_list = isAke($this->config, 'before_list', false);
     if (false !== $before_list) {
         $before_list([]);
     }
     $fieldsSettings = Db::instance('core', 'datafieldssettings')->where("table = " . $this->model->table)->where("database = " . $this->model->db)->where('user_id = ' . auth()->user()->getId())->exec();
     $userSettings = [];
     if (count($fieldsSettings)) {
         foreach ($fieldsSettings as $fieldSettings) {
             foreach ($fieldSettings as $k => $v) {
                 if (strstr($k, 'is_')) {
                     $userSettings[$fieldSettings['field']][$k] = 1 == $v ? true : false;
                 }
             }
         }
     }
     $tableSettings = Db::instance('core', 'datatablesettings')->where("table = " . $this->model->table)->where('database = ' . $this->model->db)->where('user_id = ' . auth()->user()->getId())->first();
     if (request()->getKill() == 1) {
         session('dataTableCrudRedis::' . $this->model->table)->setPage(null)->setOrder(null)->setOrderDirection(null)->setWhere(null);
     }
     $limit = isAke($tableSettings, 'rows', isAke($this->config, 'items_by_page', Config::get('crud.items.number', 25)));
     $defaultOrder = isAke($tableSettings, 'sort', isAke($this->config, 'default_order', $this->model->pk()));
     $defaultDir = isAke($this->config, 'default_order_direction', 'ASC');
     $many = isAke($this->config, 'many');
     $plus = isAke($this->config, 'options_form', '');
     $readable = isAke($this->config, 'readable', true);
     $updatable = isAke($this->config, 'updatable', true);
     $duplicatable = isAke($this->config, 'duplicatable', true);
     $deletable = isAke($this->config, 'deletable', true);
     $optionsConfig = ['readable' => $readable, 'updatable' => $updatable, 'duplicatable' => $duplicatable, 'deletable' => $deletable];
     $where = isAke($_REQUEST, 'crud_where', null);
     $page = isAke($_REQUEST, 'crud_page', 1);
     $order = isAke($_REQUEST, 'crud_order', $defaultOrder);
     $orderDirection = isAke($_REQUEST, 'crud_order_direction', $defaultDir);
     $export = isAke($_REQUEST, 'crud_type_export', false);
     $updated_at = isAke($this->config, 'updated_at', false);
     $created_at = isAke($this->config, 'created_at', false);
     $export = !strlen($export) ? false : $export;
     $offset = $page * $limit - $limit;
     if (!count($_POST)) {
         $sessionWhere = session('dataTableCrudRedis::' . $this->model->table)->getWhere();
         $sessionPage = session('dataTableCrudRedis::' . $this->model->table)->getPage();
         $sessionOrder = session('dataTableCrudRedis::' . $this->model->table)->getOrder();
         $sessionOrderDirection = session('dataTableCrudRedis::' . $this->model->table)->getOrderDirection();
         $where = !strlen($sessionWhere) ? $where : $sessionWhere;
         $page = !strlen($sessionPage) ? $where : $sessionPage;
         $order = !strlen($sessionOrder) ? $order : $sessionOrder;
         $orderDirection = !strlen($sessionOrderDirection) ? $orderDirection : $sessionOrderDirection;
     }
     $page = !is_numeric($page) ? 1 : $page;
     session('dataTableCrudRedis::' . $this->model->table)->setPage($page)->setOrder($order)->setOrderDirection($orderDirection)->setWhere($where);
     $whereData = '';
     if (!empty($where)) {
         $whereData = $this->parseQuery($where);
     }
     $db = call_user_func_array(['\\Dbredis\\Db', 'instance'], [$this->model->db, $this->model->table]);
     if (strstr($whereData, ' && ') || strstr($whereData, ' || ')) {
         $db = $this->model->query($whereData);
     } else {
         if (strlen($whereData)) {
             $db = $this->model->where($whereData);
         } else {
             $db = $this->model->full();
         }
     }
     $results = $db->order($order, $orderDirection)->exec();
     if (count($results) < 1) {
         if (strlen($where)) {
             return '<div class="alert alert-danger col-md-4 col-md-pull-4 col-md-push-4">La requête ne remonte aucun résultat.</div>';
         } else {
             return '<div class="alert alert-info col-md-4 col-md-pull-4 col-md-push-4">Aucune donnée à afficher..</div>';
         }
     }
     if (false !== $export) {
         return $this->export($export, $results);
     }
     $total = count($results);
     $last = ceil($total / $limit);
     $paginator = new Paginator($results, $page, $total, $limit, $last);
     $data = $paginator->getItemsByPage();
     $pagination = $paginator->links();
     $start = $limit * $page - ($limit - 1);
     $end = $limit * $page;
     $end = $end > $total ? $total : $end;
     if (strlen($pagination)) {
         $pagination = '<div class="row">
             <div class="col-md-3">
             Enregistrements ' . $start . ' à ' . $end . ' sur ' . $total . '
             </div>
             <div class="col-md-9">
             ' . $pagination . '
             </div>
             </div>';
     } else {
         $pagination = '<div class="row"><div class="col-md-12">' . $total . ' enregistrements<br /><br /></div></div>';
     }
     $html = $pagination . '<div class="row"><div class="col-md-12"><form action="' . urlAction('list') . '/table/' . $this->model->table . '/database/' . $this->model->db . '" id="listForm" method="post">
//.........这里部分代码省略.........
开发者ID:schpill,项目名称:standalone,代码行数:101,代码来源:Crud.php

示例11: getTime

 private function getTime()
 {
     $time = microtime();
     $time = explode(' ', $time, 2);
     return Arrays::last($time) + Arrays::first($time);
 }
开发者ID:schpill,项目名称:standalone,代码行数:6,代码来源:Db.php

示例12: siren2

 private function siren2($siren)
 {
     $infos = [];
     if (is_numeric($siren) && strlen($siren)) {
         $cache = redis()->get('siren::' . $siren);
         if (!strlen($cache)) {
             $data = dwn("http://www.verif.com/imprimer/{$siren}/1/1/");
             redis()->set('siren::' . $siren, $data);
         } else {
             $data = $cache;
         }
         $formeJuridique = $registre = $capital = $dirigeant = $immatriculation = $departement = $codePostal = $ville = $adresse = $ape = $creation = $activite = $tel = $fax = $effectif = $siret = null;
         $cmdTel = "curl 'http://www.pagespro.com/recherche.php' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' -H 'Connection: keep-alive' -H 'Cookie: EIRAM=1; xtvrn=\$486926\$; xtan=-; xtant=1' -H 'Host: www.pagespro.com' -H 'Referer: http://www.pagespro.com/recherche.php' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0' -H 'Content-Type: application/x-www-form-urlencoded' --data 'p_ACTION=&p_ORDRE=AfficheRes&a_PAGE=1&a_TAG=&a_OccRecherche=&typeRecherche=express&satellite=siret&a_activ=&a_rai_soc=&a_naf=&a_siren={$siren}&a_tel=&a_geo=&typeTri=&ordreTri=&a_session='";
         $cacheTel = redis()->get('siren::tel::' . $siren);
         if (!strlen($cacheTel)) {
             exec($cmdTel, $dataTel);
             $dataTel = implode("", $dataTel);
             redis()->set('siren::tel::' . $siren, $dataTel);
         } else {
             $dataTel = $cacheTel;
         }
         if (strstr($dataTel, '<span itemprop="tel">')) {
             $tel = strReplaceFirst('0', '+33', str_replace(["\t", '&nbsp;', ' '], '', Utils::cut('<span itemprop="tel">', '</span>', $dataTel)));
         }
         $dataFax = str_replace(["\t"], '', $dataTel);
         if (strstr($dataFax, "<span>fax")) {
             $segFax = Utils::cut('<span>fax', '</d', $dataFax);
             $fax = strReplaceFirst('0', '+33', str_replace(["\t", '&nbsp;', ' '], '', Utils::cut('<span itemprop="tel">', '</span>', $segFax)));
         }
         if (strstr($dataTel, '<b>Effectif')) {
             $segEffectif = Utils::cut('<b>Effectif', '/div>', $dataTel);
             $effectif = str_replace(["\t", '&nbsp;'], '', Utils::cut('</b>', '<', $segEffectif));
         }
         if (strstr($dataTel, '<b>Siret')) {
             $segSiret = Utils::cut('<b>Siret', '/div>', $dataTel);
             $siret = str_replace(["\t", '&nbsp;'], '', Utils::cut('</b>', '<', $segSiret));
         }
         $seg = Utils::cut('<h4>Informations g&eacute;n&eacute;rales</h4>', '</table>', $data);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Raison sociale</td>', '</tr>', $seg);
         $raisonSociale = Utils::cut('<td>', '</td>', $sousSeg);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">APE</td>', '</tr>', $seg);
         $ape = Utils::cut('<td>', '</td>', $sousSeg);
         list($ape, $activite) = explode(' / ', Utils::cut('>', '</', $ape), 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Forme juridique', '</tr>', $seg);
         list($formeJuridique, $creation) = explode(', cr&eacute;&eacute;e le ', Utils::cut('<td>', '</td>', $sousSeg), 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Adresse', '</tr>', $seg);
         $adr = Utils::cut('<td>', '</td>', $sousSeg);
         $adr = explode("\n", $adr);
         array_pop($adr);
         $adresse = Arrays::first($adr);
         $cpville = Arrays::last($adr);
         $adresse = $this->clean(str_replace(["\t", "<br />"], '', $adresse));
         list($codePostal, $ville) = explode('&nbsp;', $cpville, 2);
         $codePostal = $this->clean(str_replace(["\t", " "], '', $codePostal));
         $departement = substr($codePostal, 0, 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Capital Social', '</tr>', $seg);
         $capital = Utils::cut('<td>', '&', $sousSeg);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Registre du commerce', '</tr>', $seg);
         $registre = Utils::cut('<td>', '<', $sousSeg);
         $registre = str_replace(' ', '', $registre);
         if (null === $siret && strstr($seg, 'tdhead">SIRET</td>')) {
             $sousSeg = Utils::cut('<td class="fiche_tdhead">SIRET</td>', '</tr>', $seg);
             $siret = str_replace(' ', '', Utils::cut('<td>', '</td>', $sousSeg));
         }
         if (strstr($data, '<H4>Dirigeants</H4>')) {
             $segDirigeant = Utils::cut('<H4>Dirigeants</H4>', '</div>', $data);
             $d = Utils::cut('<table', '</table>', $segDirigeant);
             $d = Utils::cut('<tr', '</tr>', $d);
             $rows = explode("\n", $d);
             array_shift($rows);
             array_pop($rows);
             $fonction = Utils::cut('>', '<', Arrays::first($rows));
             $segPersonne = Arrays::last($rows);
             if (fnmatch('*(*', $segPersonne)) {
                 $personne = Utils::cut('>', '(', $segPersonne);
                 $personne = str_replace(['&nbsp;'], '', $personne);
             } else {
                 $personne = Utils::cut('>', '</', $segPersonne);
             }
             $dirigeant = "{$personne} - {$fonction}";
         }
         $infos = ['siren' => $this->clean($siren), 'siret' => $this->clean($siret), 'raison_sociale' => $this->clean($raisonSociale), 'ape' => $this->clean($ape), 'activite' => $this->clean($activite), 'forme_juridique' => $this->clean($formeJuridique), 'telephone' => $this->clean($tel), 'fax' => $this->clean($fax), 'adresse' => $this->clean($adresse), 'code_postal' => $this->clean($codePostal), 'ville' => $this->clean($ville), 'departement' => $this->clean($departement), 'effectif' => $this->clean($effectif), 'date_immatriculation' => $this->clean($creation), 'registre' => $this->clean($registre), 'capital' => $this->clean($capital), 'dirigeant' => $this->clean($dirigeant)];
     }
     return $infos;
 }
开发者ID:schpill,项目名称:standalone,代码行数:85,代码来源:crawl.php

示例13: detach

 public function detach($model)
 {
     if (!isset($this->_data['id'])) {
         throw new Exception("detach method requires a valid model.");
     }
     $m = !is_array($model) ? $model : Arrays::first($model);
     if ($m instanceof Db) {
         $m = $m->model();
     }
     $all = false;
     if (empty($m->id)) {
         $all = true;
     }
     $mTable = $m->db()->table;
     $names = [$this->_db->table, $mTable];
     asort($names);
     $pivot = Inflector::lower('pivot' . implode('', $names));
     $db = Db::instance($this->_db->db, $pivot);
     if (is_array($model)) {
         foreach ($model as $mod) {
             $id = (int) $mod->id;
             $row = $mod->db()->find($id);
             if ($row) {
                 $fieldAttach = $mTable . '_id';
                 $fieldModel = $this->_db->table . '_id';
                 $attach = $db->where([$fieldAttach, '=', (int) $id])->where([$fieldModel, '=', (int) $this->_data['id']])->first(true);
                 if ($attach) {
                     $attach->delete();
                 }
             }
         }
     } else {
         if (false === $all) {
             $id = (int) $model->id;
             $row = $model->db()->find($id);
             if ($row) {
                 $fieldAttach = $mTable . '_id';
                 $fieldModel = $this->_db->table . '_id';
                 $attach = $db->where([$fieldAttach, '=', (int) $id])->where([$fieldModel, '=', (int) $this->_data['id']])->first(true);
                 if ($attach) {
                     $attach->delete();
                 }
             }
         } else {
             $fieldModel = $this->_db->table . '_id';
             $attachs = $db->where([$fieldModel, '=', (int) $this->_data['id']])->exec(true);
             if (!empty($attachs)) {
                 foreach ($attachs as $attach) {
                     $attach->delete();
                 }
             }
         }
     }
     return $this;
 }
开发者ID:schpill,项目名称:standalone,代码行数:55,代码来源:Model.php

示例14: checkTable

 private function checkTable($table)
 {
     $res = $this->db->prepare("SHOW TABLES");
     $res->execute();
     if (Arrays::is($res)) {
         $count = count($res);
     } else {
         $count = $res->rowCount();
     }
     if ($count < 1) {
         return false;
     }
     foreach ($res as $row) {
         $tabletmp = Arrays::first($row);
         if ($table == $tabletmp) {
             return true;
         }
     }
     return false;
 }
开发者ID:noikiy,项目名称:inovi,代码行数:20,代码来源:Dbeav.php

示例15: first

 public function first($object = false)
 {
     $res = $this->results;
     $this->reset();
     if (true === $object) {
         return count($res) ? $this->makeObject(Arrays::first($res)) : null;
     } else {
         return count($res) ? Arrays::first($res) : array();
     }
 }
开发者ID:noikiy,项目名称:inovi,代码行数:10,代码来源:Eav.php


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