Package Data | |
---|---|
Maintainer Username: | IftekherSunny |
Maintainer Contact: | iftekhersunny@hotmail.com (Iftekher Sunny) |
Package Create Date: | 2015-07-10 |
Package Last Update: | 2015-09-18 |
Home Page: | https://packagist.org/packages/sun/alien |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-13 03:00:10 |
Package Statistics | |
---|---|
Total Downloads: | 56 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Alien helps you to create alias for your class namespace. Its also injected all the dependencies of your class.
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();
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'
];
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 ).
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();
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();
}
This package is licensed under the MIT License