本文整理汇总了PHP中Map::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Map::set方法的具体用法?PHP Map::set怎么用?PHP Map::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAssignsNewValue
/** @test */
public function setAssignsNewValue()
{
$map = new Map(array('foo' => 'bar'));
$map->set('foo', 'baz');
$this->assertEquals('baz', $map->get('foo'));
$map->set('ping', 'pong');
$this->assertEquals('pong', $map->get('ping'));
}
示例2: test_key_normalization
/**
* In PHP, float and boolean keys are truncated to integers, thus if you
* want to store $a[1] and $a[1.0], you can't, without hashing the key
* yourself. Map does not behave this way: these are distinct keys.
*
* @see http://php.net/manual/en/language.types.array.php
*/
public function test_key_normalization()
{
$map = new Map();
$map->set(true, 'foo');
$map->set(1, 'bar');
$map->set(1.0, 'baz');
$this->assertCount(3, $map);
}
示例3: load
/**
* Loads the list from a sql query.
*
* @param Recipe_Database_Statement_Abstract $result Result set
* @param integer $start Rank/Counter start
*
* @return Bengine_Game_Alliance_List
*/
public function load($result, $start = 0)
{
foreach ($result->fetchAll() as $row) {
$row["counter"] = $start;
$start++;
$row["rank"] = $start;
$row = $this->formatRow($row);
$key = !is_null($this->key) ? (int) $row[$this->key] : $start;
$this->list->set($key, $row);
}
$result->closeCursor();
return $this;
}
示例4: set
/**
* Set the value at a given key, provided that the value passes the
* defined guard. Optionally, normalize the value before setting.
*
* {@inheritDoc}
* @throws \UnexpectedValueException
*/
public function set($key, $value)
{
$result = $this->allowed($value);
if ($this->passes($result)) {
parent::set($key, $this->normalize($value));
} else {
throw new \UnexpectedValueException(sprintf('Value of type "%s" forbidden in this instance of %s', gettype($value), get_class($this)));
}
}
示例5: toCollection
private static function toCollection($data)
{
if (is_object($data)) {
$map = new Map();
foreach ($data as $k => $v) {
if (is_object($v) || is_array($v)) {
$map->set($k, self::toCollection($v));
} else {
$map->set($k, $v);
}
}
return $map;
} else {
if (is_array($data)) {
$list = new ArrayList();
foreach ($data as $v) {
$list->add(is_object($v) || is_array($v) ? self::toCollection($v) : $v);
}
return $list;
}
}
}
示例6: test_set
/**
* @dataProvider provider__construct
*/
public function test_set($base, $diff)
{
$map = new Map($base);
foreach ($base as $key => $value) {
$this->assertEquals($map->get($key), $value);
}
foreach ($diff as $key => $value) {
$map->set($key, $value);
$base[$key] = $value;
}
foreach ($base as $key => $value) {
$this->assertEquals($map->get($key), $value);
}
}
示例7: set
/**
* Put something in the map
*
* @param int|string $key The key. Strings that are ints are cast to ints.
* @param mixed $value The value to cache
*
* @return LRUMap
*/
public function set($key, $value)
{
if (parent::get($key)->isDefined()) {
parent::set($key, $value);
$this->recordAccess($key);
} else {
parent::set($key, $value);
if ($this->length() > $this->maximumSize) {
// remove least recently used element (front of array)
reset($this->elements);
unset($this->elements[key($this->elements)]);
}
}
return $this;
}
示例8: loadAllianceRelations
/**
* Loads the alliance relations.
*
* @return Bengine_Game_User_Relation
*/
protected function loadAllianceRelations()
{
if ($this->alliancesLoaded) {
return $this;
}
$select = array("ar.rel1", "ar.rel2", "ar.mode", "rt.acs", "rt.name", "rt.css");
$joins = "LEFT JOIN " . PREFIX . "ally_relationship_type rt ON (rt.type_id = ar.mode)";
$where = Core::getDB()->quoteInto("(ar.rel1 = ? OR ar.rel2 = ?)", $this->aid);
$result = Core::getQuery()->select("ally_relationships ar", $select, $joins, $where);
foreach ($result->fetchAll() as $row) {
$rel = $row["rel1"] == $this->aid ? $row["rel2"] : $row["rel1"];
$data = new stdClass();
$data->mode = $row["mode"];
$data->css = $row["css"];
$data->name = $row["name"];
$data->acs = $row["acs"];
$this->alliances->set($rel, $data);
}
$result->closeCursor();
$this->alliancesLoaded = true;
Hook::event("AllianceRelationsLoaded", array(&$this->alliances));
return $this;
}
示例9: map
/**
* @param callable $fn
*
* @return Map
*/
public function map($fn)
{
$map = new Map();
foreach ($this->data as $data) {
$map->set($data['offset'], $fn($data['value'], $data['offset']));
}
return $map;
}
示例10: testKeysLocked
public function testKeysLocked()
{
$map = new Map(['foo6' => 'bar6'], true);
$success = false;
try {
$map->set('foo7', 'bar7');
} catch (\RuntimeException $e) {
$success = true;
}
$this->assertTrue($success);
$this->assertTrue($map->remove('foo6')->has('foo6'));
$this->assertEquals('bar6', $map->set('foo6', 'bar6')->get('foo6'));
$this->assertEquals(['foo6' => null], $map->clear()->toArray());
}
示例11: add
public static function add($a, $b, $options = null)
{
$out = new Map($a->lines, $a->columns, $options);
$map_a = $a->map();
$map_b = $b->map();
$l_start = 0;
$c_start = 0;
$transparent = false;
if (!$options) {
$options = $b->options;
}
if ($options) {
foreach ($options as $key => $value) {
${$key} = $value;
}
}
for ($l = $l_start; $l < $a->lines; $l++) {
if (!isset($map_b[$l])) {
for ($c = $c_start; $c < $a->columns; $c++) {
$out->set($l, $c, $map_a[$l][$c]);
}
} else {
for ($c = $c_start; $c < $a->columns; $c++) {
if (isset($map_b[$l][$c])) {
$bc = $map_b[$l][$c];
if ($bc != $transparent) {
$out->set($l, $c, $bc);
} else {
$out->set($l, $c, $map_a[$l][$c]);
}
} else {
$out->set($l, $c, $map_a[$l][$c]);
}
}
}
}
return $out;
}
示例12: set
/**
* Puts the given key-value pair into the map.
* @param mixed $key
* @param mixed $value
* @throws \InvalidArgumentException if $value is not numeric
*/
public function set($key, $value)
{
$this->assertIsNumeric($value);
parent::set($key, $value);
}