2017 © Pedro Peláez
 

library php-statical

Allows for easy aliases creation that proxies static calls to a single instance of a class.

image

emados/php-statical

Allows for easy aliases creation that proxies static calls to a single instance of a class.

  • Monday, July 25, 2016
  • by EmadOmar
  • Repository
  • 1 Watchers
  • 0 Stars
  • 498 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 2 % Grown

The README.md

php-statical

Allows for easy aliases creation that proxies static calls to a single instance of a class., (*1)

Installation

composer require emados/php-statical

Usage

Create an alias class that will serve as a statical proxy for a specific class. For example, for a class named App\Core\Language you can either create an alias class for it in the same namespace but with a different name App\Core\Lang or use the same name in a different namespace \Language or both Lang., (*2)

final class Lang {
    use Statical;

    protected function targetClassInstance() {
        return new \App\Core\Language();
    }
}

Now, you can use the proxy class will create a single instance for the target class, and allow to access all its public api statically., (*3)

Notice

If you're using an IDE with the auto-complete feature, you probably now that it won't work with proxy classes (aliases), you can workaround this by using phpdoc annotations, although this will require you to update the docs of the proxy class each time you update the target class api., (*4)

/**
 * @method static string current() Returns current language code.
 * @method static void force(string $lang) Forces using a specific language code.
 * ...
 */
final class Lang {
    use Statical;

    protected function targetClassInstance() {
        return new \App\Core\Language();
    }
}

The Versions

25/07 2016

dev-master

9999999-dev

Allows for easy aliases creation that proxies static calls to a single instance of a class.

  Sources   Download

MIT

by Emad Omar

25/07 2016

v0.1

0.1.0.0

Allows for easy aliases creation that proxies static calls to a single instance of a class.

  Sources   Download

MIT

by Emad Omar