Permalink
Browse files

Importing constants with use.

  • Loading branch information...
1 parent df6eb30 commit 398b66be342c43983181ec3edac52e76d478bcc5 @dahlia dahlia committed Nov 29, 2009
Showing with 14 additions and 1 deletion.
  1. +6 −1 Lisphp/Runtime/Use.php
  2. +8 −0 Lisphp/Test/RuntimeTest.php
View
@@ -27,7 +27,7 @@ function dispatch(Lisphp_Form $name) {
}
$phpname = str_replace('-', '_', $phpname);
try {
- if (preg_match('|^(?:([^/]+/)+)?<([^>]+)>$|', $phpname, $matches)) {
+ if (preg_match('|^(?:([^/]+/)+)?<(.+?)>$|', $phpname, $matches)) {
$phpname = str_replace('/', '_', $matches[1] . $matches[2]);
$class = new Lisphp_Runtime_PHPClass($phpname);
foreach ($class->getStaticMethods() as $methodName => $method) {
@@ -36,6 +36,11 @@ function dispatch(Lisphp_Form $name) {
$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);
@@ -704,6 +704,8 @@ function testUse() {
<Lisphp_Symbol>
Lisphp/<Program>
[<Lisphp-Scope> scope]
+ +PHP_VERSION+
+ PHP/+OS+
}', $_));
$this->assertType('Lisphp_Runtime_PHPFunction', $values[0]);
$this->assertEquals('array_merge', $values[0]->callback);
@@ -737,6 +739,12 @@ function testUse() {
$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,

0 comments on commit 398b66b

Please sign in to comment.