if (empty($v)) { return null; } return isset($v[$p]) ? $v[$p] : null; } /** * Sets an object property. * * @param Itafroma\Zork\Struc\StrucInterface $o The object to modify. * @param mixed $p The property to modify. * @param mixed $x The value to set. */ function oput(StrucInterface $o, $p, $x, $add = true) { if (!($o instanceof Object || $o instanceof Room)) { throw new InvalidArgumentException('$o must be of type Itafroma\\Zork\\Struc\\Object or Itafroma\\Zork\\Struc\\Room'); } $v = $o instanceof Object ? $o->oprops : $o->rprops; if (empty($v) && $add || isset($v[$p])) { if ($o instanceof Object) { $o->oprops[$p] = $x; } else { $o->rprops[$p] = $x; } } return $o; } setg('ROOMS', []); setg('OBJECTS', []); setg('ACTORS', []);
/** * Tests Itafroma\Zork\setg(). * * @covers ::Itafroma\Zork\setg * @dataProvider propertyProvider */ public function testSetg($name, $value) { $atoms = $this->container->get('atoms'); $this->assertEquals($value, setg($name, $value)); $this->assertEquals($value, $atoms->get($name)); }