in() public static method

Check is value exists in the array
public static in ( string $value, array $array, boolean $returnKey = false ) : mixed
$value string
$array array
$returnKey boolean
return mixed
Ejemplo n.º 1
0
Archivo: Radio.php Proyecto: JBZoo/Html
 /**
  * Generates an HTML radio list.
  *
  * @param array $options
  * @param string $name
  * @param array $selected
  * @param array $attrs
  * @param bool|false $tpl
  * @return string
  */
 public function render(array $options, $name, $selected = array(), array $attrs = array(), $tpl = false)
 {
     if (is_array($selected)) {
         $last = Arr::last($selected);
         $selectedVal = Arr::in($last, $selected) ? $last : null;
         list($options, $selected) = $this->_checkSelected($options, $selectedVal);
     }
     if (is_string($selected)) {
         list($options, $selected) = $this->_checkSelected($options, $selected);
     }
     return parent::render($options, $name, $selected, $attrs, $tpl);
 }
Ejemplo n.º 2
0
 /**
  * Converts many english words that equate to true or false to boolean.
  *
  * @param  string $string The string to convert to boolean
  * @return boolean
  */
 public static function bool($string)
 {
     $yesList = array('affirmative', 'all right', 'aye', 'indubitably', 'most assuredly', 'ok', 'of course', 'oui', 'okay', 'sure thing', 'y', 'yes', 'yea', 'yep', 'sure', 'yeah', 'true', 't', 'on', '1', 'vrai', 'да', 'д', '+', '++', '+++', '++++', '+++++', '*');
     $noList = array('no*', 'no way', 'nope', 'nah', 'na', 'never', 'absolutely not', 'by no means', 'negative', 'never ever', 'false', 'f', 'off', '0', 'non', 'faux', 'нет', 'н', 'немає', '-');
     $string = Str::low($string);
     if (Arr::in($string, $yesList) || self::float($string) !== 0.0) {
         return true;
     } elseif (Arr::in($string, $noList)) {
         return false;
     }
     return filter_var($string, FILTER_VALIDATE_BOOLEAN);
 }
Ejemplo n.º 3
0
 /**
  * Initialize hook method.
  *
  * @param array $config
  * @return void
  */
 public function initialize(array $config)
 {
     $this->config('loginRedirect', $this->_loginRedirect());
     $controller = $this->_registry->getController();
     $this->_controller = $controller;
     $permissions = new Permissions($this->user(), $this->request);
     $allowedActions = $permissions->getAllowed();
     $isAllowed = Arr::in($this->request->param('action'), $allowedActions);
     $this->request->offsetSet('isAllowed', $isAllowed);
     if ($this->user('role_id') == Role::ADMIN_ID) {
         $this->allow();
     } else {
         $this->allow($allowedActions);
     }
     $controller->set('loggedUser', $this->_getLoggedUserForView());
     parent::initialize($config);
 }
Ejemplo n.º 4
0
 public function testIn()
 {
     $array = array('key' => 'asd', 'null' => null, 'some-bool' => false, 'some-string' => '1234567890098765432111111', 'some-int' => 1.111112345678901E+24);
     isFalse(Arr::in(0, $array));
     isTrue(Arr::in(false, $array));
     isFalse(Arr::in(0, $array, false));
     isTrue(Arr::in(false, $array, false));
     isSame('some-string', Arr::in('1234567890098765432111111', $array, true));
     isTrue('some-int', Arr::in(1.111112345678901E+24, $array, true));
     isTrue('some-bool', Arr::in(false, $array, true));
 }
Ejemplo n.º 5
0
 /**
  * Check skip files.
  *
  * @param SplFileInfo $file
  * @return bool
  */
 protected function _isSkip(SplFileInfo $file)
 {
     $name = $file->getFilename();
     $ext = $file->getExtension();
     return Arr::in($ext, $this->_skipFileExt) || Arr::in($name, $this->_skipFileNames);
 }
Ejemplo n.º 6
0
 /**
  * Find theme path.
  *
  * @param string $name
  * @return null|string
  */
 protected static function _find($name)
 {
     $paths = App::path('Plugin');
     foreach ($paths as $path) {
         $path = FS::clean($path . '/', DS);
         $details = explode(DS, rtrim($path, DS));
         $folder = Str::trim(array_pop($details));
         $themeFolder = $path . $name;
         if (Arr::in($folder, self::$_skipFolder) || !FS::isDir($themeFolder)) {
             $themeFolder .= self::POSTFIX;
         }
         if (FS::isDir($themeFolder)) {
             return $themeFolder;
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * Build action.
  *
  * @param string $type
  * @trows BadRequestException
  * @return \Cake\Network\Response|null
  */
 public function build($type = 'synchronize')
 {
     if (!Arr::in($type, $this->_buildTypes)) {
         throw new BadRequestException(__d('community', 'Unable to find build type "{0}"', $type));
     }
     $AclExtras = new AclExtras();
     $AclExtras->startup($this);
     if ($type == 'synchronize') {
         $AclExtras->acoSync();
     } else {
         $AclExtras->acoUpdate();
     }
     return $this->redirect(['action' => 'permissions']);
 }
Ejemplo n.º 8
0
 /**
  * Remove disallow attributes.
  *
  * @param array $attrs
  * @return array
  * @SuppressWarnings("unused")
  */
 protected function _cleanAttrs(array $attrs = array())
 {
     foreach ($attrs as $key => $val) {
         if (Arr::in($key, $this->_disallowAttr)) {
             unset($attrs[$key]);
         }
     }
     return $attrs;
 }
Ejemplo n.º 9
0
 /**
  * Load process behavior.
  *
  * @param Table $table
  */
 protected function _loadBehavior(Table $table)
 {
     $behaviors = $table->behaviors();
     if (!Arr::in('Process', $behaviors->loaded())) {
         $behaviors->load('Union/Core.Process');
     }
 }
Ejemplo n.º 10
0
 /**
  * Clean and validate HTTP-method type
  *
  * @param string $method
  * @return string
  * @throws Exception
  */
 protected function _getMethod($method)
 {
     $method = trim(Str::up($method));
     $validList = array(self::METHOD_GET, self::METHOD_POST, self::METHOD_HEAD, self::METHOD_PUT, self::METHOD_DELETE, self::METHOD_OPTIONS, self::METHOD_PATCH);
     if (Arr::in($method, $validList)) {
         return $method;
     } else {
         throw new Exception('Unsupported Request Method: ' . $method);
     }
 }
Ejemplo n.º 11
0
 /**
  * Check serialize data for response types.
  *
  * @return bool
  */
 protected function _needSerialize()
 {
     return !Arr::key('_serialize', $this->viewVars) && Arr::in($this->response->type(), $this->_serializeTypes);
 }
Ejemplo n.º 12
0
 /**
  * Build assets.
  *
  * @param array $filters
  * @return array
  */
 public function build(array $filters = [])
 {
     $assets = [];
     foreach (array_keys($this->_queued) as $alias) {
         $this->_resolveDependencies($this->_collection->get($alias), $assets);
     }
     /** @var Asset $asset */
     $result = [Asset::TYPE_JS_FILE => [], Asset::TYPE_JS_CODE => [], Asset::TYPE_JSX_FILE => [], Asset::TYPE_JSX_CODE => [], Asset::TYPE_CSS_FILE => [], Asset::TYPE_CSS_CODE => []];
     foreach ($assets as $asset) {
         $source = $asset->load($filters);
         if (Asset::TYPE_CALLBACK === $source[0]) {
             continue;
         }
         if (Asset::TYPE_COLLECTION === $source[0]) {
             $source = $source[1];
         } else {
             $source = array($source);
         }
         foreach ($source as $sourceItem) {
             $type = $sourceItem[0];
             $src = $sourceItem[1];
             if ($src && !Arr::in($src, $result[$type])) {
                 $result[$type][] = $src;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 13
0
 /**
  * Get user avatar by email
  *
  * @param int    $avatarSize
  * @param string $defaultPic
  * @return string
  */
 public function getAvatar($avatarSize = 64, $defaultPic = 'identicon')
 {
     $md5 = md5(trim($this->_email));
     $avatarSize = (int) $avatarSize;
     $defaultPic = trim($defaultPic);
     $validList = array('404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
     if (strpos($defaultPic, 'http') === 0) {
         $default = urlencode($defaultPic);
     } elseif (Arr::in((string) $defaultPic, $validList)) {
         $default = $defaultPic;
     } else {
         $default = 'identicon';
     }
     if (Url::isHttps()) {
         $avatarUrl = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatarSize . '&d=' . $default;
     } else {
         $avatarUrl = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatarSize . '&d=' . $default;
     }
     return $avatarUrl;
 }
Ejemplo n.º 14
0
 /**
  * Check selected option.
  *
  * @param string $value
  * @param array $selected
  * @return bool
  */
 protected function _isSelected($value, array $selected = array())
 {
     $return = false;
     if (Arr::in($value, $selected)) {
         $return = true;
     }
     return $return;
 }