2017 © Pedro Peláez
 

library veval

Virtual eval

image

adlawson/veval

Virtual eval

  • Friday, October 31, 2014
  • by adlawson
  • Repository
  • 1 Watchers
  • 6 Stars
  • 140 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Veval (Virtual eval)

Virtual Eval, (*1)

![Master branch build status][ico-build] Published version PHP ~5.4 ![MIT Licensed][ico-license], (*2)

Veval is an implementation of eval that uses a virtual file system to store code for evaluation and then require it back out. It should work on PHP installations that don't support or have disabled native eval., (*3)

It can be installed in whichever way you prefer, but I recommend Composer., (*4)

{
    "require": {
        "adlawson/veval": "*"
    }
}

Documentation

The Veval API is exposed as a collection of Veval\ namespaced functions, though you may prefer to use Veval:: to take advantage of autoloading and namespace aliasing (PHP < 5.6)., (*5)

<?php

// Evaluate some code
Veval\execute(<<<'EOF'
class Foo {
    public $name;
    public function __construct($name) {$this->name = $name;}
}
EOF
);

// Use your newly evaulated code
$foo = new Foo('bar');
$foo->name; // bar

Debugging

Storing all of the "files" in memory is all fine if your evaluated code is workng as you expect, but sometimes it's useful to read the generated code to debug any problems. There are a few different debugging functions available to suit your needs., (*6)

<?php

// Debug all evaluated strings
Veval\debug(function ($name, $content) {
    // Debug some things here
});

// Iterate over all evaulated strings
foreach (Veval\iterator() as $name => $content) {
    // Debug some things here
}

// Dump all to path
Veval\dump(sys_get_temp_dir(), 'veval-%s.php');

Warning

Eval Warning Using Veval, just like eval, is considered dangerous to use if you're evaluating user input. Always be careful not to do this as it can open up quite a large hole in the security of your system., (*7)

Contributing

Contributions are accepted via Pull Request, but passing unit tests must be included before it will be considered for merge., (*8)

$ curl -O https://raw.githubusercontent.com/adlawson/vagrantfiles/master/php/Vagrantfile
$ vagrant up
$ vagrant ssh
...

$ cd /srv
$ composer install
$ vendor/bin/phpunit

License

The content of this library is released under the MIT License by Andrew Lawson.br/ You can find a copy of this license in LICENSE or at http://opensource.org/licenses/mit., (*9)

The Versions

31/10 2014

dev-master

9999999-dev

Virtual eval

  Sources   Download

MIT

The Requires

 

The Development Requires

code wrapper generate stream virtual generation meta metaprogramming eval

07/09 2014

1.0.0

1.0.0.0

Virtual eval

  Sources   Download

MIT

The Requires

 

The Development Requires

code wrapper generate stream virtual generation meta metaprogramming eval