sun/alien

Alien helps you to create alias for your class namespace. Its also injected all the dependencies of your class.

v1.7 2015-09-18 06:30 UTC

This package is auto-updated.

Last update: 2024-12-08 18:22:08 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Alien helps you to create alias for your class namespace. Its also injected all the dependencies of your class.

Installation Process

Just copy Alien folder somewhere into your project directory. Then include Alien autoloader.

 require_once('/path/to/Alien/autoload.php');

Alien is also available via Composer/Packagist.

 composer require sun/alien

You need to call Alien load method to initialize everything.

 Sun\AlienLoader::load();

Configuration

If you install Alien manually just open config.php file located at Alien/config.php.

If you install Alien via composer you need to publish Alien configuration file. Run this command in your terminal to publish alien configuration file.

 Php vendor/sun/alien/publish

Then, open alien.php file located at config/alien.php.

Added your alias and namespace. Like as..

 return [
     'File' => 'Sun\FilesystemAlien',
     'Mail'	=> 'SunMailer\MailerAlien',
     'View'	=> 'SunMailer\ViewAlien'

 ];

Creating Alien

You can create Alien by extending Alien class. Here an example -

namespace Sun;

class FilesystemAlien extends \Sun\Alien
{

    /**
     * To register Alien
     *
     * @return string namespace
     */
    public static function registerAlien()
    {
        return 'Sun\Filesystem';
    }
}

Now you can use any method of your class static way ( without creating object of your class ).

Example:

Let, Filesystem class has a method create(). Calling create method of Filesystem class -

$filesystem = new Sun\Filesystem;
$filesystem->create();

Using Alien Now, you can also call create method by this way -

File::create();

Testing Alien

You can test your alien class, here an example

$mocked = File::shouldReceive('create')
                ->once()
                ->andReturn('mocked');

$this->assertEquals('mocked', $mocked); // true

Don't forget to call close method of the mockery class. Here an example for the PHPUnit testing framework

public function tearDown()
{
    Mockery::close();
}

License

This package is licensed under the MIT License