Inheritance: extends Lisphp_Runtime_Function
Example #1
0
 function dispatch(Lisphp_Form $name)
 {
     if ($name instanceof Lisphp_Symbol) {
         $phpname = $name = $name->symbol;
     } else {
         $phpname = $name[0]->symbol;
         $name = $name[1]->symbol;
     }
     $phpname = str_replace('-', '_', $phpname);
     try {
         if (preg_match('|^(?:([^/]+/)+)?<(.+?)>$|', $phpname, $matches)) {
             $phpname = str_replace('/', '_', $matches[1] . $matches[2]);
             $class = new Lisphp_Runtime_PHPClass($phpname);
             foreach ($class->getStaticMethods() as $methodName => $method) {
                 $objs["{$name}/{$methodName}"] = $method;
             }
             $objs[$name] = $class;
             return $objs;
         }
         if (preg_match('|^(?:([^/]+/)+)?\\+(.+?)\\+$|', $phpname, $matches)) {
             $phpname = str_replace('/', '_', $matches[1] . $matches[2]);
             $objs[$name] = constant($phpname);
             return $objs;
         }
         return array($name => new Lisphp_Runtime_PHPFunction($phpname));
     } catch (UnexpectedValueException $e) {
         throw new InvalidArgumentException($e);
     }
 }
Example #2
0
 public function testPHPClass()
 {
     $class = new Lisphp_Runtime_PHPClass('ArrayObject');
     $obj = $this->applyFunction($class, array(1, 2, 3));
     $this->assertType('ArrayObject', $obj);
     $this->assertEquals(array(1, 2, 3), $obj->getArrayCopy());
     try {
         new Lisphp_Runtime_PHPClass('UndefinedClassName');
         $this->fail();
     } catch (UnexpectedValueException $e) {
         # pass
     }
     $class = new Lisphp_Runtime_PHPClass('Lisphp_SampleClass');
     $methods = $class->getStaticMethods();
     $this->assertEquals(2, count($methods));
     $this->assertType('Lisphp_Runtime_PHPFunction', $methods['a']);
     $this->assertEquals(array('Lisphp_SampleClass', 'a'), $methods['a']->callback);
     $this->assertType('Lisphp_Runtime_PHPFunction', $methods['b']);
     $this->assertEquals(array('Lisphp_SampleClass', 'b'), $methods['b']->callback);
     $this->assertTrue($class->isClassOf(new Lisphp_SampleClass()));
     $this->assertFalse($class->isClassOf(new stdClass()));
     $this->assertFalse($class->isClassOf(213));
 }