Inheritance: implements Lisphp_Applicable
Esempio n. 1
0
 function apply(Lisphp_Scope $scope, Lisphp_List $arguments)
 {
     $tmp = new Lisphp_Scope();
     $use = new Lisphp_Runtime_Use();
     $ns = (string) $arguments->car();
     $simpleNames = iterator_to_array($arguments[1]);
     foreach ($simpleNames as $name) {
         $names[] = Lisphp_Symbol::get("{$ns}/{$name}");
     }
     $retval = $use->apply($tmp, new Lisphp_List($names));
     foreach ($simpleNames as $i => $name) {
         $scope->let($name, $retval[$i]);
     }
     return $retval;
 }
Esempio n. 2
0
 public function testUse()
 {
     $use = new Lisphp_Runtime_Use();
     $env = Lisphp_Environment::sandbox();
     $scope = new Lisphp_Scope($env);
     $values = $use->apply($scope, self::lst('array_merge
                                              array-slice
                                              [implode array->string]
                                              <ArrayObject>
                                              <Lisphp_Symbol>
                                              <Foo\\Bar>
                                              [<Lisphp-Scope> scope]
                                              +PHP_VERSION+
                                              +PHP_OS+'));
     $this->assertType('Lisphp_Runtime_PHPFunction', $values[0]);
     $this->assertEquals('array_merge', $values[0]->callback);
     $this->assertSame($values[0], $scope['array_merge']);
     $this->assertNull($env['array_merge']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $values[1]);
     $this->assertEquals('array_slice', $values[1]->callback);
     $this->assertSame($values[1], $scope['array-slice']);
     $this->assertNull($env['array-slice']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $values[2]);
     $this->assertEquals('implode', $values[2]->callback);
     $this->assertSame($values[2], $scope['array->string']);
     $this->assertNull($env['implode']);
     $this->assertType('Lisphp_Runtime_PHPClass', $values[3]);
     $this->assertEquals('ArrayObject', $values[3]->class->getName());
     $this->assertSame($values[3], $scope['<ArrayObject>']);
     $this->assertNull($env['<ArrayObject>']);
     $this->assertType('Lisphp_Runtime_PHPClass', $values[4]);
     $this->assertEquals('Lisphp_Symbol', $values[4]->class->getName());
     $this->assertSame($values[4], $scope['<Lisphp_Symbol>']);
     $this->assertNull($env['<Lisphp_Symbol>']);
     $this->assertType('Lisphp_Runtime_PHPClass', $values[5]);
     $this->assertEquals('Foo\\Bar', $values[5]->class->getName());
     $this->assertSame($values[5], $scope['<Foo\\Bar>']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['<Foo\\Bar>/doSomething']);
     $this->assertEquals(array('Foo\\Bar', 'doSomething'), $scope['<Foo\\Bar>/doSomething']->callback);
     $this->assertNull($env['<Foo\\Bar>']);
     $this->assertType('Lisphp_Runtime_PHPClass', $values[6]);
     $this->assertEquals('Lisphp_Scope', $values[6]->class->getName());
     $this->assertSame($values[6], $scope['scope']);
     $this->assertNull($env['scope']);
     $this->assertEquals(PHP_VERSION, $values[7]);
     $this->assertEquals(PHP_VERSION, $scope['+PHP_VERSION+']);
     $this->assertNull($env['+PHP_VERSION+']);
     $this->assertEquals(PHP_OS, $values[8]);
     $this->assertEquals(PHP_OS, $scope['+PHP_OS+']);
     $this->assertNull($env['+PHP_OS+']);
     try {
         $use->apply($scope, self::lst('undefined-function-name'));
         $this->fail();
     } catch (InvalidArgumentException $e) {
         # pass
     }
     try {
         $use->apply($scope, self::lst('<UndefinedClassName>'));
         $this->fail();
     } catch (InvalidArgumentException $e) {
         # pass
     }
 }