Coder Social home page Coder Social logo

dmitrymomot / flex-facade Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 152 KB

PHP Classbuilder that allows you to call instance methods using the elegance of static syntax. Has an expandable IoC container as long as the Facade class that allows for the static syntax. Documentation is in the readme.

flex-facade's Introduction

Flex Facade Container

To install, all you need to do is run the following command

sudo composer create-project flex/facade projectname -s dev

Then. run sudo composer install and the Flex Facade Container will be installed!

All of your classes/facade classes must be autoloaded.
Inside classes/ and facades/ your classes will automatically be autoloaded.

Usage

Initiate the Container

$app = new Flex\Container;

initiates the container class. Because Flex\Container implements ArrayAccess, we can now access any classes we put in here by doing $app['classname']

Creating the Class

Let's create a class that we want to later put in our container.

class Hello
{
	public function say(){
		echo 'Hello, World!';
	}
}

Register a Class in the Container

Let's say you want to register class "Hello", so you can just do $app['hello'] to get an instance. (I am assuming Hello is inside a namespace 'Classes'. This way we can use 'Hello' as an alias)

$app->register('hello', function()
{
	return new Classes\Hello;
});

This registers the Classes\Hello class inside the $app['hello'] container accessor. Now, if we run the following:

$app['hello']->say();

you should see our Hello, World! message.

Creating the Facade

Now, we want to create a facade class, so we can access $app['hello'] by using an Alias.

namespace Facade;

class Hello extends \Flex\Facade
{
	public static function service(){
		return 'hello';
	}
}

This class, when called, will return $app['hello'], as defined in the service method we just created.

Creating the Alias

We are almost done! Now, we just want to create an alias for the 'Facade\Hello' class for simple/elegant access.

$app->alias('Hello', 'Facade\Hello');

Now, we can just call our Hello class using

Hello::say();

and you should see

Hello, World!

Congratulations, now you can access your classes with elegant syntax! Feel free to expand on this. Stay tuned for the Flex PHP Framework.

flex-facade's People

Contributors

elliotlanderson avatar

Watchers

James Cloos avatar Dmytro Momot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.