GithubHelp home page GithubHelp logo

carnival's Introduction

Carnival

Build Status Scrutinizer Code Quality Code Coverage HHVM Support

Carnival is a simple library to generate static facades from instance objects. In other words, it takes an object, hides it behind a generated static class, effectively transforming your object into a singleton as long as you access it from the static facade.

Installation

Composer is the only supported way of installing and using Carnival. From your project's root directory, run:

composer require aztech/carnival

You must then include the Composer autoloader in the entry file of your application:

<?php

require_once __DIR__ . 'vendor/autoload.php';

Dafuq is wrong with you ?

Probably a lot of things. But that fails to answer the question, why this library. Because !

Ok, originally, I wrote it as a troll. But if anyone finds it useful, go ahead, have fun !

And you're using eval ?

Isn't that the root of all evil ? Probably, but it's used in a constrained way, and honestly, if you plan on passing tainted data to Masquerade, allow me to ask dafuq is wrong with you ?

So now that its uselessness is settled, how do I use it anyways ?

Simple, bind whatever object you want to a new, non-existing class name (you can even namespace your facade !) like that:

// This call is only required once, you can place it in your application bootstrap or wherever.
Aztech\Carnival\Masquerade::register(); 

// Bind an object to a class name
Aztech\Carnival\Masquerade::bind('\Facades\SomeArray', new \SplObjectStorage());

// Use your facade
Facades\SomeArray::attach(new \stdClass());

Yup, simple as that.

carnival's People

Contributors

aztech-dev avatar

Watchers

James Cloos avatar Thibaud Fabre 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.