Permalink
Browse files

Support built-in PHP classes static-constant-access

  • Loading branch information...
dreamsxin committed May 7, 2015
1 parent 37630ee commit e2f0887fe1766f4a84fbe7f65c7fdd7c5d0175c7
@@ -116,6 +116,33 @@ public function getType()
*/
public function compile(CompilationContext $compilationContext)
{
if ($this->value['type'] == 'static-constant-access') {
$name = $this->value['left']['value'].'::'.$this->value['right']['value'];
if (defined($name)) {
$value = constant($name);
if (is_int($value)) {
$this->value['type'] = 'int';
$this->value['value'] = $value;
} elseif (is_float($value)) {
$this->value['type'] = 'double';
$this->value['value'] = $value;
} elseif (is_bool($value)) {
$this->value['type'] = 'bool';
if (!$value) {
$this->value['value'] = 'false';
} else {
$this->value['value'] = 'true';
}
} elseif (is_string($value)) {
$this->value['type'] = 'string';
$this->value['value'] = $value;
} elseif (is_null($value)) {
$this->value['type'] = 'null';
}
}
}
switch ($this->value['type']) {
case 'constant':
$constant = new Constants();
@@ -16,11 +16,13 @@ class Constants extends ConstantsParent
const className = __CLASS__;
/**
* Test property addSlashes for constants
*/
const ANNOTATION_REGEX = '/@(\w+)(?:\s*(?:\(\s*)?(.*?)(?:\s*\))?)??\s*(?:\n|\*\/)/';
const PARAMETER_REGEX = '/(\w+)\s*=\s*(\[[^\]]*\]|"[^"]*"|[^,)]*)\s*(?:,|$)/';
const STD_PROP_LIST = \ArrayObject::STD_PROP_LIST;
/**
* Test property addSlashes for constants
*/
const ANNOTATION_REGEX = '/@(\w+)(?:\s*(?:\(\s*)?(.*?)(?:\s*\))?)??\s*(?:\n|\*\/)/';
const PARAMETER_REGEX = '/(\w+)\s*=\s*(\[[^\]]*\]|"[^"]*"|[^,)]*)\s*(?:,|$)/';
protected propertyC1 = self::C1 {get};
protected propertyC2 = self::C2 {get};
@@ -30,7 +32,7 @@ class Constants extends ConstantsParent
protected propertyC6 = self::C6 {get};
protected propertyC7 = self::ANNOTATION_REGEX {get};
protected propertyC8 = self::PARAMETER_REGEX {get};
protected propertyC8 = self::PARAMETER_REGEX {get};
public function testReadConstant()
{
@@ -3,8 +3,8 @@ namespace Test\Oo;
class ConstantsInterface implements \Test\TestInterface
{
const CLASSNAME = __CLASS__;
const NAMESPACENAME = __NAMESPACE__;
const CLASSNAME = __CLASS__;
const NAMESPACENAME = __NAMESPACE__;
public function testReadInterfaceConstant1()
{
@@ -12,17 +12,17 @@ class PropertyAccess
protected b;
public function __construct()
{
var test, test1;
let test = new \stdClass;
let test->test = ["1", 2, 3, 5, 6.00];
let test->test2 = test->test[0];
let test->test3 = test->test[1];
let test->test3 = [test->test[1], 1, 2, 3];
{
var test, test1;
let test = new \stdClass;
let test->test = ["1", 2, 3, 5, 6.00];
let test->test2 = test->test[0];
let test->test3 = test->test[1];
let test->test3 = [test->test[1], 1, 2, 3];
let this->a = test;
let this->b = this->a->test2;
let this->a = test;
let this->b = this->a->test2;
let test1 = this->a;
}
let test1 = this->a;
}
}
@@ -35,6 +35,7 @@ public function testConstantsDeclaration()
$this->assertTrue(Constants::C5 === 10.25);
$this->assertTrue(Constants::C6 === 'test');
$this->assertTrue(Constants::className === 'Test\Constants');
$this->assertTrue(Constants::STD_PROP_LIST === \ArrayObject::STD_PROP_LIST);
}
public function testConstantGetters()

0 comments on commit e2f0887

Please sign in to comment.