public function testGetResource() { $resources = new \Bonder\Collections\Map(); $resources->set("1", "one"); $resources->set("2", "two"); $context = new \Bonder\Contexts\MapContext($resources); $this->assertEquals("one", $context->get("1")); $this->assertEquals("two", $context->get("2")); $this->assertEquals("one", $context->get("1")); }
/** * (non-PHPdoc) * @see Bonder\Util.Matcher::getMatchVariables() */ public function getMatchVariables($expression, $literal) { $variables = array(); $result = @preg_match_all("#^{$expression}/?\$#Ui", $literal, $variables); if ($result === false) { throw new \Bonder\Exceptions\Exception("Unmatched regex {$expression} : {$literal}"); } $map = new \Bonder\Collections\Map(); foreach ($variables as $k => $v) { if (count($v) != 1) { throw new \Bonder\Exceptions\Exception("Unexpected array size in preg matching array"); } $map->set($k, reset($v)); } return $map; }
public function getHttpProtocol() { // Copied from https://github.com/facebook/facebook-php-sdk /*apache + variants specific way of checking for https*/ if (in_array($this->server->get('HTTPS'), array(1, 'on', '1'), true)) { return 'https'; } /*nginx way of checking for https*/ if ($this->server->get('SERVER_PORT') === '443') { return 'https'; } return 'http'; }
/** * Returns a new Map, linked to the array given. * * @param array $array the array to link to. * @return \Bonder\Collections\Map the map. */ public static function fromReference(array &$array) { $map = new \Bonder\Collections\Map(); $map->linkTo($array); return $map; }
public function testContains() { $map = new \Bonder\Collections\Map(); $map->set("mykey", 79); $map->set("mykey2", 80); $otherMap = new \Bonder\Collections\Map(); $this->assertTrue($map->contains($otherMap)); $otherMap->set("mykey", 79); $this->assertTrue($map->contains($otherMap)); $otherMap->set("mykey3", 81); $this->assertFalse($map->contains($otherMap)); $this->assertFalse($otherMap->contains($map)); $map->remove("mykey2"); $this->assertTrue($otherMap->contains($map)); $map->set("mykey", "old_79"); $this->assertFalse($otherMap->contains($map)); }