Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

packfire-archived/fuelblade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Packfire FuelBlade

##What is FuelBlade?

Packfire FuelBlade is a library that helps you the power of dependency injection into your PHP application. Through the Inversion of Control (IoC) technique, you can decouple class dependencies and build better test-friendly code.

##What is IoC?

Traditionally, a class is easily coupled like this:

    class ConsoleOutput
    {
        public function write($message)
        {
            echo $message;
        }        
    }

    class TaskManager
    {
        protected $output;

        public function __construct()
        {
            $this->output = new ConsoleOutput();
        }
    }

    class Application
    {
        public function run()
        {
            $manager = new TaskManager();
            $manager->run();                  
        }
    }

However, TaskManager is now coupled to ConsoleOutput. Any output made by TaskManager can only go to console output and there is no flexibility in choosing which output to use. Hence, we can perform some abstraction magic and write some code like this:

    interface OutputInterface
    {
        public function write($message);
    }

    class ConsoleOutput implements OutputInterface
    {
        public function write($message)
        {
            echo $message;
        }        
    }

    class FileOutput implements OutputInterface
    {
        public function write($message)
        {
            // write to file
        }        
    }

    class TaskManager
    {
        protected $output;

        public function __construct(OutputInterface $output)
        {
            $this->output = $output;
        }

    }

    class Application
    {
        public function run()
        {
            $ioc = new \Packfire\FuelBlade\Container();
            $ioc['manager'] = $this->share(
                function ($ioc) {
                    return new TaskManager($ioc['output']);
                }
            );
            $ioc['output'] = $this->share(new FileOutput());
            $ioc['manager']->run();                    
        }
    }

Nettuts+ has a great article on explaining the various methods of dependency injections, and ultimately explaining IoC as the ultimate solution.

##Sounds Great! How do I install FuelBlade?

You can install FuelBlade from Packagist via Composer.

{
    "require": {
        "packfire/fuelblade": "1.1.*"
    }
}

All of the releases of Packfire FuelBlade are described on the package's Packagist page. Through Composer's autoloader (or your own), you will be able to use FuelBlade directly into your application.

About

FuelBlade Dependency Injection / IoC Library for PHP

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages