Coder Social home page Coder Social logo

processus-kindergarten's Introduction

Simple Bootstrapping and Sandboxing of untrusted legacy code

Features:

  • decorate set_error_handler & errorreporting: in sync ! switch'em whenever you want during runtime.
  • decorate set_exception_handler
  • decorate register_shutdown_function: unfortunately all functions get executed. Solution: Callback Proxy and Manager
  • callback functions for all kind of events (onError, onException, onShutdownFailed, ...). No need to override class methods when trying to tweak current business logic.
  • sandbox untrusted legacy code: all error-/exception-/shutdown-settings you changed to make dirty code run will be reverted after executing.

Sandbox Example: let's play with dirty legacy toy ...

// use dirty legacy code: but sandboxed.
var_dump('using dirty code, sandboxed ... ');
$playground = Bootstrap::getInstance()
  ->getPlayground();
$sandbox = $playground->createSimpleSandbox();

$sandbox
  ->setErrorReportingCaptureLevel(
    $sandbox->getErrorReportingCaptureLevelAllStrictNoNotice() // (E_ALL|E_STRICT) ^ E_NOTICE
  )
  ->setDelegateExceptionEnabled(false) // catch exceptions, do not rethrow
  ->setToy(
    function () {
      $data = array();
      $value = $data[0]; // E_NOTICE, but not captured at errorReporting
      var_dump('the value is ...');
      var_dump($value);
      var_dump('this was dirty');

      return true;
    }
   )
  ->setOnError(
     function (Playground $playground, $error) {
       var_dump('ERROR');
     }
    )
  ->setParams(array())
  ->play();
  
 var_dump('--------- SANDBOX HAS EXCEPTION -----------');
 var_dump($sandbox->hasException());
 if ($sandbox->hasException()) {
    var_dump($sandbox->getException()->getMessage());
 }
 var_dump('--------- SANDBOX RESULT -----------');
 var_dump($sandbox->getResult());

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.