Giter Club home page Giter Club logo

editable's Introduction

Editable

This class can add functions and variables dynamically to objects.
It can add new public and private variables to an object that extends the editable class. The variables may be set to a given initial value.
It can also add or replace public and private functions with a new function code.
The class can also intercept calls to functions by calling the code of a given function before calling the actual function being intercepted.

Feaures

  • add public and private variables
  • add public and private functions
  • override public and private functions
  • handle functions call registering interceptors with a callback
  • handle dinamically generated public/private variables changes

Usage

Installation

Require PHP >= 5.4
First of all download Editable.php and pathwork.phar in the same directory .
Now choose the classes that should be editable by this script adding the word extends Editable:

    class MyClass extends Editable

Then include in your main script Editable.php and use your class with new features!

    require "Editable.php";
    $f = new MyClass(); // instantiate your class extending Editable
    $f-> ...

Managment of variables

Adding a variable
    //private
    $f->addPrivateVariable("var1","Hello World",$handler,$handlerArgs);
    //or public
    $f->addPublicVariable("var2","Hello World 2",$handler,$handlerArgs);
  • The first argument represent the variable name, the second its value.
  • You can't assign the same variable both private and public.
  • If the variable already exist an exception will be thrown.
  • $handler is a callable function that will be called on variable changes.(optional)
  • $handlerArgs is an array of arguments of the above function.(optional)
  • Variable handling will work only on dinamically generated public/private variables.

Managment of functions

Adding a function
    //private
    $f->addPrivateFunction("sayHello",$callback);
    //or public
    $f->addPublicFunction("sayHello2",$callback);
  • The first argument represent the function name, the second its definition.
  • $callback must be callable or a closure.
  • You can't assign the same function both private and public.
  • If the function already exist an exception will be thrown.
Rewritting a function
    $f->replaceFunction($callbackOld,$callbackNew);
  • The first argument rappresent the callback of function to rewrite , the second the callback(or closure) for its new definition.
  • If the function doesn't exist an exception will be thrown.
Intercepting a function
    $f->interceptFunction($callbackFunction,$callbackInterceptor);
  • The first argument rappresent the callback of function to handle , the second the callback(or closure) for the interceptor definition.
  • $callbackInterceptor is called before the target function.

editable's People

Contributors

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