本文整理汇总了PHP中Thin\Arrays::in方法的典型用法代码示例。如果您正苦于以下问题:PHP Arrays::in方法的具体用法?PHP Arrays::in怎么用?PHP Arrays::in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thin\Arrays
的用法示例。
在下文中一共展示了Arrays::in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: eagerly
private static function eagerly($mongo, &$parents, $include)
{
$first = reset($parents);
$mongo->attributes = $first->attributes;
$relationship = $mongo->{$include}();
$mongo->attributes = $_ids = array();
foreach ($parents as &$parent) {
$_ids[] = $parent->_id;
$parent->ignore[$include] = Arrays::in($mongo->relating, array('has_many', 'has_and_belongs_to_many')) ? array() : null;
}
if (Arrays::in($relating = $mongo->relating, array('has_one', 'has_many', 'belongs_to'))) {
static::$relating($relationship, $parents, $mongo->relating_key, $include, $_ids);
} else {
static::manyToMany($relationship, $parents, $mongo->relating_key, $mongo->relating_table, $include, $_ids);
}
}
示例2: prepare
public function prepare($text)
{
$slugs = explode(' ', Inflector::slug($text, ' '));
if (count($slugs)) {
$collection = array();
foreach ($slugs as $slug) {
if (strlen($slug) > 1) {
if (!Arrays::in($slug, $collection)) {
array_push($collection, $slug);
}
}
}
asort($collection);
}
return $collection;
}
示例3: init
public function init()
{
$this->view->config = context('config')->load('crudjson');
$guestActions = array('login', 'logout', 'lost');
$guestActions += arrayGet($this->view->config, 'guest.actions', array());
$this->view->isAuth = false;
$this->view->items = isAke($this->view->config, 'tables');
$user = auth()->user();
if (!$user) {
if (!Arrays::in($this->action(), $guestActions)) {
$this->forward('login');
}
} else {
$this->view->isAuth = true;
$this->view->user = $user;
$this->isAdmin = auth()->is('admin');
if ($this->action() == 'login' || $this->action() == 'lost') {
$this->forward('home', 'static');
}
}
}
示例4: eagerly
/**
* Eagerly load a relationship.
*
* @param object $eloquent
* @param array $parents
* @param string $include
* @return void
*/
private static function eagerly($eloquent, &$parents, $include)
{
// We temporarily spoof the query attributes to allow the query to be fetched without
// any problems, since the belongs_to method actually gets the related attribute.
$first = reset($parents);
$eloquent->attributes = $first->attributes;
$relationship = $eloquent->{$include}();
$eloquent->attributes = array();
// Reset the WHERE clause and bindings on the query. We'll add our own WHERE clause soon.
// This will allow us to load a range of related models instead of only one.
$relationship->query->reset_where();
// Initialize the relationship attribute on the parents. As expected, "many" relationships
// are initialized to an array and "one" relationships are initialized to null.
foreach ($parents as &$parent) {
$parent->ignore[$include] = Arrays::in($eloquent->relating, array('has_many', 'has_and_belongs_to_many')) ? array() : null;
}
if (Arrays::in($relating = $eloquent->relating, array('has_one', 'has_many', 'belongs_to'))) {
return static::$relating($relationship, $parents, $eloquent->relating_key, $include);
} else {
static::has_and_belongs_to_many($relationship, $parents, $eloquent->relating_key, $eloquent->relating_table, $include);
}
}
示例5: dispatch
public static function dispatch()
{
static::$method = Request::method();
$uri = substr(str_replace('/ws/', '/', $_SERVER['REQUEST_URI']), 1);
$tab = explode('/', $uri);
if (count($tab) < 3) {
Api::forbidden();
}
$namespace = current($tab);
$controller = $tab[1];
$action = $tab[2];
$tab = array_slice($tab, 3);
$count = count($tab);
if (0 < $count && $count % 2 == 0) {
for ($i = 0; $i < $count; $i += 2) {
$_REQUEST[$tab[$i]] = $tab[$i + 1];
}
}
$file = APPLICATION_PATH . DS . 'webservices' . DS . $namespace . DS . $controller . '.php';
if (!File::exists($file)) {
Api::NotFound();
}
require_once $file;
$class = 'Thin\\' . ucfirst($controller) . 'Ws';
$i = new $class();
$methods = get_class_methods($i);
$call = strtolower(static::$method) . ucfirst($action);
if (!Arrays::in($call, $methods)) {
Api::NotFound();
}
if (Arrays::in('init', $methods)) {
$i->init($call);
}
$i->{$call}();
if (Arrays::in('after', $methods)) {
$i->after();
}
}
示例6: __call
public function __call($method, $args)
{
if (count($this->_items)) {
$first = $this->first();
$db = $first->db();
$methods = get_class_methods($db);
if (Arrays::in($method, $methods)) {
$instance = $db->where(['id', 'IN', implode(',', $this->indexes())]);
return call_user_func_array([$instance, $method], $args);
}
}
}
示例7: fetch
public function fetch($results = null)
{
$this->count = count($results);
$results = empty($results) ? $this->results : $results;
if (count($results)) {
if (null !== $this->groupBy) {
$groupBys = array();
$ever = array();
foreach ($results as $key => $object) {
$id = $object->getId();
$getter = getter($this->groupBy);
$obj = $object->{$getter}();
if ($obj instanceof Container) {
$id = $obj->getId();
}
if (!Arrays::in($id, $ever)) {
$groupBys[$key] = $this->find($id);
$ever[] = $id;
}
}
$this->results = $groupBys;
$this->order($this->groupBy);
$results = $this->results;
}
if (0 < $this->limit) {
$max = count($results);
$number = $this->limit - $this->offset;
if ($number > $max) {
$this->offset = $max - $this->limit;
if (0 > $this->offset) {
$this->offset = 0;
}
$this->limit = $max;
}
$results = array_slice($results, $this->offset, $this->limit);
}
}
$this->results = $results;
return $results;
}
示例8: __get
/**
* @param $key
* @return mixed
*/
public function __get($key)
{
if (Arrays::exists($key, $this->attributes)) {
return $this->attributes[$key];
} elseif (Arrays::exists($key, $this->ignore)) {
return $this->ignore[$key];
} elseif (method_exists($this, $key)) {
$query = $this->{$key}();
return $this->ignore[$key] = Arrays::in($this->relating, array('one', 'oneToOne')) ? $query->first() : $query->get();
}
}
示例9: compare
private function compare($comp, $op, $value)
{
$keyCache = sha1('compare_' . serialize(func_get_args()));
$cached = $this->cached($keyCache);
if (empty($cached)) {
$res = false;
if (isset($comp)) {
$comp = Inflector::lower($comp);
$value = Inflector::lower($value);
switch ($op) {
case '=':
$res = sha1($comp) == sha1($value);
break;
case '>=':
$res = $comp >= $value;
break;
case '>':
$res = $comp > $value;
break;
case '<':
$res = $comp < $value;
break;
case '<=':
$res = $comp <= $value;
break;
case '<>':
case '!=':
$res = sha1($comp) != sha1($value);
break;
case 'LIKE':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (strstr($comp, $value)) {
$res = true;
}
break;
case 'NOTLIKE':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (!strstr($comp, $value)) {
$res = true;
}
break;
case 'LIKE START':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
$res = substr($comp, 0, strlen($value)) === $value;
break;
case 'LIKE END':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (!strlen($comp)) {
$res = true;
}
$res = substr($comp, -strlen($value)) === $value;
break;
case 'IN':
$value = repl('(', '', $value);
$value = repl(')', '', $value);
$tabValues = explode(',', $value);
$res = Arrays::in($comp, $tabValues);
break;
case 'NOTIN':
$value = repl('(', '', $value);
$value = repl(')', '', $value);
$tabValues = explode(',', $value);
$res = !Arrays::in($comp, $tabValues);
break;
}
}
$this->cached($keyCache, $res);
return $res;
}
return $cached;
}
示例10: rowsForm
public static function rowsForm($idField, $table, $fields, $order = null, $valueField = null, $required = true, $default = null, $data = null, $sort = 'ASC', $database = null)
{
/* polymorphism */
$fields = !Arrays::is($fields) ? strstr($fields, ',') ? explode(',', repl(' ', '', $fields)) : [$fields] : $fields;
if (fnmatch('*:*', $table)) {
list($database, $table) = explode(':', $table, 2);
} else {
$database = is_null($database) ? SITE_NAME : $database;
}
$default = null !== request()->{$idField} ? request()->{$idField} : $default;
if ($default instanceof \Closure) {
dd('ici');
$default = $default();
}
$defined = !is_null($default) && null !== request()->{$idField};
$db = Db::instance($database, $table);
$require = $required ? 'required ' : '';
$multiple = $idField == request()->is_multiple ? 'multiple ' : '';
$class = strlen($multiple) ? 'multi-select' : 'form-control';
$inputName = strlen($multiple) ? $idField . '[]' : $idField;
$html = '<span id="span_' . $idField . '"><select ' . $multiple . $require . 'class="' . $class . '" name="' . $inputName . '" id="' . $idField . '">' . NL;
if (false === $defined && !strlen($multiple)) {
$html .= '<option value="">Choisir</option>' . NL;
}
$order = is_null($order) ? 'id' : $order;
$data = is_null($data) ? $db->where(['id', '>', 0])->order($order, $sort)->exec() : $data();
if (count($data)) {
foreach ($data as $target) {
$value = [];
$id = $target['id'];
foreach ($fields as $field) {
if (!$field instanceof Closure) {
$value[] = isAke($target, $field, $field);
} else {
$value[] = $field($target);
}
}
$value = implode(' ', $value);
if (strstr($_SERVER['REQUEST_URI'], '/create/')) {
$valueField = empty($valueField) ? $default : $valueField;
}
if (!Arrays::is($valueField)) {
$selected = $valueField == $id ? 'selected ' : '';
} else {
$selected = Arrays::in($id, $valueField) ? 'selected ' : '';
}
if (false === $defined) {
$html .= '<option ' . $selected . 'value="' . $id . '">' . \Thin\Html\Helper::display($value) . '</option>' . NL;
} else {
if (!strlen($selected)) {
$html .= '<option disabled value="' . $id . '">' . \Thin\Html\Helper::display($value) . '</option>' . NL;
} else {
$html .= '<option selected value="' . $id . '">' . \Thin\Html\Helper::display($value) . '</option>' . NL;
}
}
}
}
$html .= '</select></span>';
if (strlen($multiple)) {
$css = '<style> .ms-container{
background: transparent url(\'/crud/assets/img/switch.png\') no-repeat 50% 50%;
width: 100%;
}
.ms-container:after{
content: ".";
display: block;
height: 0;
line-height: 0;
font-size: 0;
clear: both;
min-height: 0;
visibility: hidden;
}
.ms-container .ms-selectable, .ms-container .ms-selection{
background: #fff;
color: #555555;
float: left;
width: 45%;
font-size: 10px;
}
.ms-container .ms-selection{
float: right;
}
.ms-container .ms-list{
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-webkit-transition: border linear 0.2s, box-shadow linear 0.2s;
-moz-transition: border linear 0.2s, box-shadow linear 0.2s;
-ms-transition: border linear 0.2s, box-shadow linear 0.2s;
-o-transition: border linear 0.2s, box-shadow linear 0.2s;
transition: border linear 0.2s, box-shadow linear 0.2s;
border: 1px solid #ccc;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
position: relative;
//.........这里部分代码省略.........
示例11: row
public function row($tab = array())
{
$fields = array_keys($this->map['fields']);
$pk = $this->pk();
$id = isAke($tab, $pk, false);
if (count($tab)) {
foreach ($tab as $key => $value) {
if (!Arrays::in($key, $fields)) {
unset($tab[$key]);
}
}
foreach ($fields as $field) {
$val = isAke($tab, $field, false);
if (false === $val && false === $id) {
$tab[$field] = null;
}
}
} else {
foreach ($fields as $field) {
if (false === $id) {
$tab[$field] = null;
}
}
}
$o = new Container();
$o->populate($tab);
return $this->closures($o);
}
示例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);
$default = count($args) == 1 ? Arrays::first($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)->exec();
$ids = [];
if (!empty($pivots)) {
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)])->exec($object);
} else {
return [];
}
}
} else {
$idField = $this->_db->table . '_id';
return $db->where([$idField, '=', $this->_data['id']])->exec($object);
}
} else {
return $default;
}
}
}
} elseif (substr($func, 0, strlen('has')) == '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)->exec();
$ids = [];
if (!empty($pivots)) {
foreach ($pivots as $pivot) {
$id = isAke($pivot, substr($field, 0, -1) . '_id', false);
if (false !== $id) {
array_push($ids, $id);
}
}
return !empty($ids) ? true : 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('set')) == 'set') {
$uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('set'))));
$field = Inflector::lower($uncamelizeMethod);
if (!empty($args)) {
$val = Arrays::first($args);
} else {
$val = null;
}
if (is_object($val)) {
$val = (int) $val->id;
}
if (fnmatch('*_id', $field)) {
//.........这里部分代码省略.........
示例13:
function in_arrayi($needle, $haystack)
{
return Arrays::in(Inflector::lower($needle), array_map('strtolower', $haystack));
}
示例14: __call
/**
* Magic Method for handling dynamic method calls.
*/
public function __call($method, $parameters)
{
// To allow the "with", "get", "first", and "paginate" methods to be called both
// staticly and on an instance, we need to have private, underscored versions
// of the methods and handle them dynamically.
if (Arrays::in($method, array('with', 'get', 'first', 'paginate'))) {
return call_user_func_array(array($this, '_' . $method), $parameters);
}
// All of the aggregate and persistance functions can be passed directly to the query
// instance. For these functions, we can simply return the response of the query.
if (Arrays::in($method, array('insert', 'update', 'increment', 'decrement', 'abs', 'count', 'sum', 'min', 'max', 'avg'))) {
return call_user_func_array(array($this->query, $method), $parameters);
}
// Pass the method to the query instance. This allows the chaining of methods
// from the query builder, providing the same convenient query API as the
// query builder itself.
call_user_func_array(array($this->query, $method), $parameters);
return $this;
}
示例15: compare
private function compare($comp, $op, $value)
{
if (isset($comp)) {
$comp = Inflector::lower($comp);
$value = Inflector::lower($value);
switch ($op) {
case '=':
return sha1($comp) == sha1($value);
break;
case '>=':
return $comp >= $value;
break;
case '>':
return $comp > $value;
break;
case '<':
return $comp < $value;
break;
case '<=':
return $comp <= $value;
break;
case '<>':
case '!=':
return sha1($comp) != sha1($value);
break;
case 'LIKE':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (strstr($comp, $value)) {
return true;
}
break;
case 'NOTLIKE':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (!strstr($comp, $value)) {
return true;
}
break;
case 'LIKESTART':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
return substr($comp, 0, strlen($value)) === $value;
break;
case 'LIKEEND':
$value = repl("'", '', $value);
$value = repl('%', '', $value);
if (!strlen($comp)) {
return true;
}
return substr($comp, -strlen($value)) === $value;
break;
case 'IN':
$value = repl('(', '', $value);
$value = repl(')', '', $value);
$tabValues = explode(',', $value);
return Arrays::in($comp, $tabValues);
break;
case 'NOTIN':
$value = repl('(', '', $value);
$value = repl(')', '', $value);
$tabValues = explode(',', $value);
return !Arrays::in($comp, $tabValues);
break;
}
}
return false;
}