get() public static method

This function allows you to concisely access an index which may or may not exist without raising a warning.
public static get ( array &$var, mixed $default = null ) : mixed
$var array Array value to access
$default mixed Default value to return if the key is not
return mixed
Beispiel #1
0
 /**
  * @param \WP_User $user
  * @return UserEntity|null
  */
 protected function _convertToEntity(\WP_User $user)
 {
     $id = (int) $user->ID;
     if ($entity = $this->_getEntity($id)) {
         return $entity;
     }
     $caps = $user->get_role_caps();
     $isAdmin = (bool) Vars::get($caps['administrator'], false);
     $data = new Data(['id' => $id, 'login' => $user->get('user_login'), 'name' => $user->get('display_name'), 'email' => $user->get('user_email'), 'is_admin' => $isAdmin]);
     $this->_users[$id] = new UserEntity($data);
     return $this->_users[$id];
 }
Beispiel #2
0
 public function testFunctionOverhead()
 {
     runBench(array('Clean' => function () {
         return pathinfo(__FILE__, PATHINFO_BASENAME);
     }, 'Wrapper' => function () {
         return FS::base(__FILE__);
     }), array('name' => 'Pathinfo overhead', 'count' => 10000));
     runBench(array('Vars::get' => function () {
         return Vars::get($GLOBALS['somevar']);
     }, 'isset' => function () {
         return isset($GLOBALS['somevar']);
     }), array('name' => 'Isset overhead', 'count' => 10000));
     $randArr = array_fill(0, 100, null);
     for ($i = 0; $i < 100; $i += 1) {
         $randArr[$i] = mt_rand(0, 9);
     }
     runBench(array('array_keys(+flip)' => function () use($randArr) {
         return Arr::unique($randArr, false);
     }, 'array_unique' => function () use($randArr) {
         return Arr::unique($randArr, true);
     }), array('name' => 'Isset overhead', 'count' => 1000));
 }
Beispiel #3
0
 public function testLastKey()
 {
     $test = array('a' => array('a' => 'b', 'c' => 'd'));
     is('c', Arr::lastKey(Vars::get($test['a'])));
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function dbPrefix()
 {
     return Vars::get($GLOBALS['table_prefix'], '');
 }
Beispiel #5
0
 /**
  * Is current request - ajax
  * @return bool
  */
 public function isAjax()
 {
     $method = Vars::get($_SERVER['HTTP_X_REQUESTED_WITH'], '');
     $method = Filter::cmd($method);
     $orig = Filter::cmd('XMLHttpRequest');
     return $orig === $method;
 }
Beispiel #6
0
 /**
  * @param $id
  * @return User|null
  */
 protected function _getEntity($id)
 {
     return Vars::get($this->_users[$id]);
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function getVersion()
 {
     return Vars::get($GLOBALS['wp_version'], '1.0.0');
 }
Beispiel #8
0
     }
     if (isset($_REQUEST['test-header-title'])) {
         $cms['header']->setTitle($_REQUEST['test-header-title']);
     }
     if (isset($_REQUEST['test-header-noindex'])) {
         $cms['header']->noindex();
     }
     if (isset($_REQUEST['test-header-description'])) {
         $cms['header']->setDesc($_REQUEST['test-header-description']);
     }
     if (isset($_REQUEST['test-header-keywords'])) {
         $cms['header']->setKeywords($_REQUEST['test-header-keywords']);
     }
     if (isset($_REQUEST['test-header-addmeta'])) {
         $_REQUEST['test-header-addmeta']['meta'] = str_replace(array('\\"', "\\'"), array('"', "'"), $_REQUEST['test-header-addmeta']['meta']);
         $cms['header']->addMeta($_REQUEST['test-header-addmeta']['meta'], Vars::get($_REQUEST['test-header-addmeta']['value']));
     }
 });
 /* Response *******************************************************************************************************/
 add_action('wp', function () use($cms) {
     if (isset($_REQUEST['test-response-set404'])) {
         $cms['response']->set404();
     }
     if (isset($_REQUEST['test-response-set500'])) {
         $cms['response']->set500($_REQUEST['test-response-set500']);
     }
     if (isset($_REQUEST['test-response-redirect'])) {
         $cms['response']->redirect($_REQUEST['test-response-redirect']);
     }
     if (isset($_REQUEST['test-response-json'])) {
         $cms['response']->json((array) $_REQUEST['test-response-json'], true);
Beispiel #9
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function __construct(Cms $cms)
 {
     parent::__construct($cms);
     $this->_wp_query = Vars::get($GLOBALS['wp_query']);
 }
Beispiel #10
0
 public function onAfterDispatch()
 {
     if (!$this->_request('jbzoo-phpunit')) {
         return false;
     }
     /* Header *****************************************************************************************************/
     if ($test = $this->_request('test-header-title')) {
         $this->_cms['header']->setTitle($test);
     }
     if ($test = $this->_request('test-header-keywords')) {
         $this->_cms['header']->setKeywords($test);
     }
     if ($test = $this->_request('test-header-description')) {
         $this->_cms['header']->setDesc($test);
     }
     if ($test = $this->_request('test-header-noindex')) {
         $this->_cms['header']->noindex();
     }
     if ($test = $this->_request('test-header-jsfile')) {
         $this->_cms['header']->jsFile($test . '.js');
     }
     if ($test = $this->_request('test-header-cssfile')) {
         $this->_cms['header']->cssFile($test . '.css');
     }
     if ($test = $this->_request('test-header-jscode')) {
         $this->_cms['header']->jsCode($test);
     }
     if ($test = $this->_request('test-header-csscode')) {
         $this->_cms['header']->cssCode($test);
     }
     if ($test = $this->_request('test-header-addmeta')) {
         $this->_cms['header']->addMeta($_REQUEST['test-header-addmeta']['meta'], Vars::get($_REQUEST['test-header-addmeta']['value']));
     }
     /* Response ***************************************************************************************************/
     if ($test = $this->_request('test-response-set404')) {
         $this->_cms['response']->set404();
     }
     if ($test = $this->_request('test-response-set500')) {
         $this->_cms['response']->set500($test);
     }
     if ($test = $this->_request('test-response-redirect')) {
         $this->_cms['response']->redirect($test);
     }
     if ($test = $this->_request('test-response-json')) {
         $this->_cms['response']->json((array) $test, true);
     }
     if ($test = $this->_request('test-response-nocache')) {
         $this->_cms['response']->noCache();
     }
     if ($test = $this->_request('test-response-raw')) {
         $this->_cms['response']->raw();
     }
     if ($test = $this->_request('test-response-component')) {
         $this->_cms['response']->component();
     }
     /* Libs *******************************************************************************************************/
     if ($test = $this->_request('test-libs-jquery')) {
         $this->_cms['libs']->jQuery();
     }
     if ($test = $this->_request('test-libs-jqueryui')) {
         $this->_cms['libs']->jQueryUI();
     }
     if ($test = $this->_request('test-libs-autocomplete')) {
         $this->_cms['libs']->jQueryAutocomplete();
     }
     if ($test = $this->_request('test-libs-datepicker')) {
         $this->_cms['libs']->jQueryDatePicker();
     }
     if ($test = $this->_request('test-libs-colorpicker')) {
         $this->_cms['libs']->colorPicker();
     }
 }
Beispiel #11
0
 public function testClean()
 {
     $dirSep = DIRECTORY_SEPARATOR;
     $empty = Vars::get($_SERVER['DOCUMENT_ROOT'], '');
     isSame($empty, FS::clean(''));
     isSame($empty, FS::clean(false));
     isSame($empty, FS::clean(null));
     isSame('path', FS::clean('path'));
     isSame("{$dirSep}path", FS::clean('/path'));
     isSame("{$dirSep}path", FS::clean(' /path '));
     isSame("{$dirSep}path{$dirSep}", FS::clean('/path/'));
     isSame("{$dirSep}path{$dirSep}", FS::clean('///path///'));
     isSame("{$dirSep}path{$dirSep}path", FS::clean('///path///path'));
     isSame("{$dirSep}path{$dirSep}path{$dirSep}path", FS::clean('///path///path/path'));
     isSame("{$dirSep}path{$dirSep}path{$dirSep}path{$dirSep}", FS::clean('\\path\\path\\path\\\\\\\\'));
     isSame('\\path\\path\\path\\', FS::clean('\\path\\path\\path\\\\\\\\', '\\'));
     isSame('\\path\\path\\path\\', FS::clean('\\path\\path\\path\\\\\\\\', '\\'));
     isSame('\\\\path\\path\\path\\', FS::clean('\\\\path\\path\\path\\\\\\\\', '\\'));
     isSame('../../path/', FS::clean('..///..///path/', '/'));
     isSame('./../path/', FS::clean('.///..///path/', '/'));
     isSame('/../../path/', FS::clean('/..///..///path/', '/'));
 }