has() public method

Checks if an element is in the collection by key.
public has ( string $key ) : boolean
$key string
return boolean
 public function testHasNotStrict()
 {
     $collection = new Collection(['1']);
     $this->assertTrue($collection->has('1', false));
     $this->assertTrue($collection->has(1, false));
     $this->assertFalse($collection->has(2, false));
 }
Example #2
0
 protected function prepareRequestUri()
 {
     $requestUri = '';
     if ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
         // check this first so IIS will catch
         $requestUri = $this->headers->get('X_REWRITE_URL');
     } elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
         // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
         $requestUri = $this->server->get('UNENCODED_URL');
     } elseif ($this->server->has('REQUEST_URI')) {
         $requestUri = $this->server->get('REQUEST_URI');
         // HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
         $schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost();
         if (strpos($requestUri, $schemeAndHttpHost) === 0) {
             $requestUri = substr($requestUri, strlen($schemeAndHttpHost));
         }
     } elseif ($this->server->has('ORIG_PATH_INFO')) {
         // IIS 5.0, PHP as CGI
         $requestUri = $this->server->get('ORIG_PATH_INFO');
         if ($this->server->get('QUERY_STRING')) {
             $requestUri .= '?' . $this->server->get('QUERY_STRING');
         }
     }
     return $requestUri;
 }
Example #3
0
 public function encode($script)
 {
     $this->search($script);
     $this->words->sort();
     $encoded = new Collection();
     // a dictionary of base62 -> base10
     $size = $this->words->size();
     for ($i = 0; $i < $size; $i++) {
         $encoded->put(Packer::encode62($i), $i);
     }
     $index = 0;
     foreach ($this->words as $word) {
         if ($encoded->has($word)) {
             $word->index = $encoded->get($word);
             $word->clear();
         } else {
             while ($this->words->has(Packer::encode62($index))) {
                 $index++;
             }
             $word->index = $index++;
             if ($word->count == 1) {
                 $word->clear();
             }
         }
         $word->replacement = Packer::encode62($word->index);
         if (strlen($word->replacement) == strlen($word)) {
             $word->clear();
         }
     }
     // sort by encoding
     $this->words->sort(array('Base62', 'sorter'));
     // trim unencoded words
     $this->words = $this->words->slice(0, preg_match_all('/\\|/', $this->getKeyWords(), $matches) + 1);
     $script = preg_replace_callback($this->getPattern(), array(&$this, '_word_replacement'), $script);
     /* build the packed script */
     $p = $this->escape($script);
     $a = '[]';
     $c = max($this->words->size(), 1);
     $k = $this->getKeyWords();
     $e = $this->getEncoder();
     $d = $this->getDecoder();
     // the whole thing
     return $this->format(Base62::$UNPACK, $p, $a, $c, $k, $e, $d);
 }
Example #4
0
 /**
  * @param string $name
  * @param string $def
  * @return string
  */
 public function getOldOnce($name, $def = '')
 {
     if ($this->storage) {
         $old_once = $this->storage->get(OldValue::OLD_ONCE_KEY);
         $old_once = new Collection($old_once);
         if ($old_once->has($name)) {
             $v = $old_once->get($name);
             $old_once->delete($name);
             $this->storage->set(OldValue::OLD_ONCE_KEY, $old_once->get());
             return $v;
         }
     }
     return $def;
 }
Example #5
0
 public function test7_Deletion()
 {
     # deletion
     static::$collection->delete('part2.item2', 'name');
     $this->assertTrue(!static::$collection->has('part2.item2.name'));
 }
Example #6
0
 /**
  * Does this collection have a given header?
  *
  * @param  string $key The case-insensitive header name
  *
  * @return bool
  */
 public function has($key)
 {
     return parent::has($this->normalizeKey($key));
 }
Example #7
0
 /**
  * @inheritDoc
  */
 public function has($name)
 {
     return parent::has($this->normalizeName($name));
 }
Example #8
0
 /**
  * Checks if a page is in a set of children
  *
  * @param Page | string $page
  * @return boolean
  */
 public function has($page)
 {
     $uri = is_string($page) ? $page : $page->id();
     return parent::has($uri);
 }
Example #9
0
 /**
  * /
  * @param  [type]  $id [description]
  * @return boolean     [description]
  */
 public function has($id)
 {
     $newId = str_replace('.', '_', $id);
     return parent::has($newId);
 }