Skip to content

Add AutoloadSourceLocator enabling ReflectionClass and ReflectionFunction instantiation#41

Merged
Ocramius merged 10 commits intomasterfrom
add-autoload-source-locator
Jul 9, 2015
Merged

Add AutoloadSourceLocator enabling ReflectionClass and ReflectionFunction instantiation#41
Ocramius merged 10 commits intomasterfrom
add-autoload-source-locator

Conversation

@asgrim
Copy link
Copy Markdown
Member

@asgrim asgrim commented Jul 6, 2015

Implemented the AutoloadSourceLocator which means we can now use "static" creation of ReflectionClass objects, e.g.:

$reflection = ReflectionClass::createFromName('BetterReflectionTest\Fixture\ExampleClass');

There are caveats (we expect the autoloader to load classes from a file, i.e. using require/include), but it does actually work.

It also means this can actually implement the LoadSafeSourceLocator (to be implemented)

Merging this would fix #36 and would be a better solution that I initially proposed actually 😀

Todo

@asgrim asgrim self-assigned this Jul 6, 2015
@asgrim asgrim added this to the 1.0.0 milestone Jul 6, 2015
@asgrim asgrim force-pushed the add-autoload-source-locator branch from c9a9981 to 6b86df7 Compare July 7, 2015 21:25
@asgrim asgrim force-pushed the add-autoload-source-locator branch from 6b86df7 to 84ba5d6 Compare July 8, 2015 07:38
@asgrim asgrim changed the title [WIP] Add AutoloadSourceLocator Add AutoloadSourceLocator enabling ReflectionClass and ReflectionFunction instantiation Jul 8, 2015
@asgrim asgrim assigned Ocramius and unassigned asgrim Jul 8, 2015
@asgrim asgrim mentioned this pull request Jul 8, 2015
1 task
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is null allowed ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that is how ::createFromNode works.

doing this:

$classInfo = new ReflectionClass('Foo');

creates autoload source locator > creates class reflector > calls reflect > locates class > loads source code > loads AST > calls ReflectionClass::createFromNode() > which instantiates a new ReflectionClass but with no parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asgrim you are changing public API to please package API? Seems wrong :-\

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see another way around it, ideally I need two constructors.. a private one for internal (::createFromNode) use and one for public API :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache the call to $identifier->getType()->getName(). You should also probably make a method that matches the constant, rather than getting the constant and then comparing outside the VO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like $type->isClass()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement "autoloading" source locator

2 participants