-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored entire Reflector to be more flexible #3
Changes from all commits
73a6965
8c3b5d6
a803023
0ef3495
1491cc3
52572f4
89aacdc
6f9c34d
4f43056
d5be5bb
60b3198
013d360
d4e2480
c4913f8
2dc20ce
bc0d081
9e651dc
4121d55
06b4574
1e0dcd6
89282e9
e2e268c
14d6322
7c1d8a4
f2f775f
61834e7
cccbb2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace BetterReflection\Identifier; | ||
|
||
use PhpParser\Node; | ||
|
||
class Identifier | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var IdentifierType | ||
*/ | ||
private $type; | ||
|
||
public function __construct($name, IdentifierType $type) | ||
{ | ||
$this->type = $type; | ||
|
||
$name = ltrim($name, '\\'); | ||
// @todo validate the name somehow (see issue #20) | ||
$this->name = (string)$name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return IdentifierType | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @todo implement this | ||
* @return bool | ||
*/ | ||
public function isLoaded() | ||
{ | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace BetterReflection\Identifier; | ||
|
||
use PhpParser\Node; | ||
use BetterReflection\Reflection\ReflectionClass; | ||
use BetterReflection\Reflection\Reflection; | ||
|
||
class IdentifierType | ||
{ | ||
const IDENTIFIER_CLASS = ReflectionClass::class; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $validTypes = [ | ||
self::IDENTIFIER_CLASS, | ||
]; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
public function __construct($type = self::IDENTIFIER_CLASS) | ||
{ | ||
if (!in_array($type, $this->validTypes, true)) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'%s is not a valid identifier type', | ||
$type | ||
)); | ||
} | ||
$this->name = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDisplayName() | ||
{ | ||
return ucfirst(basename($this->name)); | ||
} | ||
|
||
public function isMatchingReflector(Reflection $reflector) | ||
{ | ||
return $this->name === get_class($reflector); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace BetterReflection\NodeCompiler; | ||
|
||
use PhpParser\Node; | ||
|
||
class CompileNodeToValue | ||
{ | ||
/** | ||
* Compile an expression from a node into a value | ||
* | ||
* @param Node $node | ||
* @return mixed | ||
*/ | ||
public function __invoke(Node $node) | ||
{ | ||
switch (get_class($node)) { | ||
case Node\Scalar\String_::class: | ||
case Node\Scalar\DNumber::class: | ||
case Node\Scalar\LNumber::class: | ||
return $node->value; | ||
case Node\Expr\Array_::class: | ||
return []; // @todo compile expression | ||
case Node\Expr\ConstFetch::class: | ||
if ($node->name->parts[0] == 'null') { | ||
return null; | ||
} else if ($node->name->parts[0] == 'false') { | ||
return false; | ||
} else if ($node->name->parts[0] == 'true') { | ||
return true; | ||
} else { | ||
// @todo this should evaluate the VALUE, not the name | ||
return $node->name->parts[0]; | ||
} | ||
break; | ||
case Node\Expr\ClassConstFetch::class: | ||
// @todo this should evaluate the VALUE, not the name | ||
$className = implode('\\', $node->class->parts); | ||
$constName = $node->name; | ||
return $className . '::' . $constName; | ||
default: | ||
throw new \LogicException('Unable to compile expression: ' . $type); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace BetterReflection\Reflection\Exception; | ||
|
||
class InvalidDefaultValueType extends \RuntimeException | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace BetterReflection\Reflection; | ||
|
||
/** | ||
* This interface is used internally by the Generic reflector in order to | ||
* ensure we are working with BetterReflection reflections | ||
* | ||
* @internal | ||
*/ | ||
interface Reflection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docblocks (overall) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is for internal use, use |
||
{ | ||
/** | ||
* Get the name of the reflection (e.g. if this is a ReflectionClass this | ||
* will be the class name). | ||
* | ||
* @return string | ||
*/ | ||
public function getName(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getClassesFromFile
without parameter? Seems a bit weird. The API is probably also redundant, now that you have the locator:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue #4 to implement this later