Exemplo n.º 1
0
/**
 * Creates a flag/bit field.
 *
 * In the original source, there's a hard limit of 35 flags that can be added to
 * the flag field, presumably done for memory conservation.
 *
 * @param string ... $fs A list of flags to add.
 * @return int The number of flags added.
 * @throws Itafroma\Zork\Exception\FlagwordException
 */
function flagword(...$fs)
{
    $container = ServiceContainer::getContainer();
    $oblists = $container->get('oblists');
    $tot = 1;
    $cnt = 1;
    // Given <FLAGWORD>'s usage in the rest of the original source, this could
    // be simplified to a simple foreach loop. The use of array_walk_recursive()
    // here is to emulate the use of MDL's <MAPF> SUBR in the original source.
    array_walk_recursive($fs, function ($f) use($oblists, &$tot, &$cnt) {
        // It's unknown what the GROUP-GLUE symbol is in the oblist. It appears
        // to be always empty.
        if (is_scalar($f) && !lookup('GROUP-GLUE', $oblists->get('INITIAL'))) {
            msetg($f, $tot);
        }
        $tot *= 2;
        // This appears to be a bug in the original source: the intention seems
        // to be to allow bit fields with up to 36 flags, but because the size
        // is incremented and checked after the last value is set, it only
        // allows 35 flags.
        $cnt++;
        if ($cnt > 36) {
            throw new FlagwordException();
        }
    });
    // Also a bug in the original source: since count is incremented after the
    // last value is added, the reported number of flags added is off by one.
    return $cnt;
}
Exemplo n.º 2
0
 public function setUp()
 {
     $this->container = ServiceContainer::getContainer(true);
 }
Exemplo n.º 3
0
/**
 * Assign a value to a variable within the global state.
 *
 * @param string $atom The name of the variable to assign the value.
 * @param mixed $any The value to assign.
 * @return mixed The new value of the variable.
 */
function setg($atom, $any)
{
    $atoms = ServiceContainer::getContainer()->get('atoms');
    return $atoms->set($atom, $any);
}
Exemplo n.º 4
0
 /**
  * Tests Itafroma\Zork\ServiceContainer::create().
  *
  * @covers Itafroma\Zork\ServiceContainer::create
  */
 public function testCreate()
 {
     $this->assertInstanceOf(ContainerBuilder::class, ServiceContainer::create());
 }