Skip to content
/ Aliaser Public

Simple PHP library for parsing and handling class aliases defined by USE statements.

Notifications You must be signed in to change notification settings

uestla/Aliaser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aliaser

Simple PHP library for parsing and handling class and function aliases defined by USE statements.

Usage

Book.php

Here we have an entity class Book with some annotations:

namespace Model\Entities;

use \DateTime;

/**
 * @property User $author
 * @property DateTime $written
 */
class Book
{}

function foo()
{}

foo.php

And now let's say we would like to take those annotations and get the full class name of those @property types defined. And that's where we'll use Aliaser:

$reflection = new ReflectionClass('Model\Entities\Book');

Aliaser\Container::getClass('User', $reflection); // 'Model\Entities\User'
Aliaser\Container::getClass('DateTime', $reflection); // 'DateTime'

We can discover full function/callback name according to given namespace context as well.

Aliaser\Container::getCallback('DateTime::format', $reflection); // 'DateTime::format'
Aliaser\Container::getCallback('User::getName', $reflection); // 'Model\Entities\User::getName'

Aliaser\Container::getCallback('foo', $reflection); // 'Model\Entities\foo'

It handles multiple namespace definitions in a single file as well.

However, parsing can be quite expensive - we can use a Nette Framework Cache:

$storage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp');
Aliaser\Container::setCacheStorage($storage);

// ...

Enjoy.

About

Simple PHP library for parsing and handling class aliases defined by USE statements.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages