Giter Site home page Giter Site logo

recompilr's Introduction

recompilr

PHP 5.5+ factory runtime class compiler

Build Status Scrutinizer Code Quality Latest Stable Version License Coverage Status

Description

recompilr uses a class definition and recompiles it at runtime using eval and a unique hash identifier. Classes may be recompiled after changes are made to the class definition without requiring the application to restart. This effectively allows an application to redeclare classes at runtime.

Installation

Install via cli using composer:

php composer.phar require jgswift/recompilr:0.1.*

Install via composer.json using composer:

{
    "require": {
        "jgswift/recompilr": "0.1.*"
    }
}

Dependency

Usage

Basic compiling and instantiation

// # path/to/FooClass.php
class FooClass {
    /* */
}

// compiles FooClass from given class definition file
recompilr\execute('FooClass','path/to/FooClass.php');

// factory creates an instance of FooClass
$foo = recompilr\make('FooClass');

var_dump($foo); // (object) FooClass_*hash

Compile from autoloaded class

// class must be available to autoloader
namespace MyNamespace;
class FooClass {
    /* */
}

// compiles FooClass without an explicit class file, relying on the autoloader to find the class definition
recompilr\execute('MyNamespace\FooClass');

// factory creates an instance of FooClass
$foo = recompilr\make('MyNamespace\FooClass');

var_dump($foo); // (object) FooClass_*hash

Recompiling everything

When class definitions are expected to have changed, all classes may be recompiled using recompilr\all.

// change path/to/FooClass.php while application is running

recompilr\all();

Note: will not compile files where bracketed namespaces are used

Note: all compiled classes are final and may not be inherited from

Binary handling

Saving to file

recompilr\execute('MyNamespace\FooClass');

recompilr\binary('path/to/binary.rcx');

Loading from file

recompilr\load('path/to/binary.rcx');

$foo = recompilr\make('MyNamespace\FooClass');

var_dump($foo); // (object) FooClass_*hash

recompilr's People

Contributors

jgswift avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.