Skip to content

Commit

Permalink
Massive updates due to feedback. Travis stuff should work now as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremeamia committed Feb 5, 2014
1 parent 9cadee5 commit 0bbf5e0
Show file tree
Hide file tree
Showing 32 changed files with 324 additions and 267 deletions.
20 changes: 20 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
filter:
paths:
- src/

before_commands:
- 'composer install --no-interaction --prefer-source --dev'
- 'cp phpunit.xml.dist phpunit.xml'

tools:
sensiolabs_security_checker: true
php_code_coverage:
test_command: vendor/bin/phpunit
config_path: phpunit.xml
php_hhvm:
config:
unknown_class: true
unknown_base_class: true
unknown_function: true
unknown_object_method: true
unknown_trait: true
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- hhvm

before_script:
- sh -c 'if [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- cp phpunit.xml.dist phpunit.xml
- composer install --dev
script: vendor/bin/phpunit --coverage-text
- composer self-update
- composer install --no-interaction --prefer-source --dev
- cp phpunit.xml.dist phpunit.xml

script:
- vendor/bin/phpunit

matrix:
allow_failures:
- php: hhvm
fast_finish: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ I'm not joking, *you really can serialize a PHP closure*!

require 'vendor/autoload.php';

use Jeremeamia\SuperClosure\SerializableClosure;
use SuperClosure\SerializableClosure;

$greeting = 'Hello';
$helloWorld = new SerializableClosure(function ($name = 'World') use ($greeting) {
Expand Down
28 changes: 0 additions & 28 deletions autoload.php

This file was deleted.

6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"phpunit/phpunit": "~3.7"
},
"autoload": {
"files": [
"autoload.php",
"src/functions.php"
]
"psr-4": {"SuperClosure\\": "src/SuperClosure/"},
"files": ["src/functions.php"]
}
}
2 changes: 1 addition & 1 deletion demo/factorial.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require __DIR__ . '/../vendor/autoload.php';

use Jeremeamia\SuperClosure\SerializableClosure;
use SuperClosure\SerializableClosure;

$factorial = new SerializableClosure(function ($n) use (&$factorial) {
return ($n <= 1) ? 1 : $n * $factorial($n - 1);
Expand Down
2 changes: 1 addition & 1 deletion demo/hello-world.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$helloWorld('Jeremy');
//> Hello, Jeremy!

$serialized = serialize_closure($helloWorld);
$serialized = SuperClosure\serialize($helloWorld);
$unserialized = unserialize($serialized);

$unserialized();
Expand Down
75 changes: 0 additions & 75 deletions src/ClosureParser/ClosureParserFactory.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/ClosureParser/ClosureParserInterface.php

This file was deleted.

25 changes: 17 additions & 8 deletions src/ClosureBinding.php → src/SuperClosure/ClosureBinding.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php

namespace Jeremeamia\SuperClosure;
namespace SuperClosure;

/**
* A value object representing the binding of a PHP Closure.
*
* Closures, as of 5.4+, are bound to an object and a scope depending on where they are declared, or if they were
* created via `Closure::bind` or `Closure::bindTo`. The binding information is especially important if the closure
* references `$this` or `self` inside the function body.
*
* @package SuperClosure
*/
class ClosureBinding
{
/**
Expand Down Expand Up @@ -36,17 +45,17 @@ public static function fromReflection(\ReflectionFunction $reflection)
throw new \InvalidArgumentException('Please provide the reflection of a closure.');
}

// Only closures in PHP 5.4+ have bindings
if (PHP_VERSION_ID < 50400) {
// Only closures in PHP 5.4+ have bindings
return new self(null, null);
} else {
/** @var \ReflectionFunction $scope */
if ($scope = $reflection->getClosureScopeClass()) {
$scope = $scope->getName();
}
}

return new self($reflection->getClosureThis(), $scope);
/** @var \ReflectionFunction $scope */
if ($scope = $reflection->getClosureScopeClass()) {
$scope = $scope->getName();
}

return new self($reflection->getClosureThis(), $scope);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Jeremeamia\SuperClosure\ClosureParser;
namespace SuperClosure\ClosureParser;

use Jeremeamia\SuperClosure\ClosureBinding;
use SuperClosure\ClosureBinding;

abstract class AbstractClosureContext implements ClosureContextInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php

namespace Jeremeamia\SuperClosure\ClosureParser;
namespace SuperClosure\ClosureParser;

use Jeremeamia\SuperClosure\SuperClosure;
use SuperClosure\SuperClosure;

abstract class AbstractClosureParser implements ClosureParserInterface
{
/**
* @var array
* @var Options
*/
protected $options;

/**
* @param array $options
* @param Options $options
*/
public function __construct(array $options = array())
public function __construct(Options $options = null)
{
$this->options = $options + $this->getDefaultOptions();
$this->options = $this->getDefaultOptions();
if ($options) {
$this->options->merge($options);
}
}

/**
Expand All @@ -28,7 +31,7 @@ public function __construct(array $options = array())
protected function prepareClosure($closure)
{
if ($closure instanceof \Closure) {
$closure = new SuperClosure($closure);
return new SuperClosure($closure);
}

if ($closure instanceof SuperClosure) {
Expand All @@ -39,7 +42,7 @@ protected function prepareClosure($closure)
}

/**
* @return array
* @return Options
*/
abstract protected function getDefaultOptions();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Jeremeamia\SuperClosure\ClosureParser\Ast;
namespace SuperClosure\ClosureParser\Ast;

use Jeremeamia\SuperClosure\ClosureBinding;
use Jeremeamia\SuperClosure\ClosureParser\AbstractClosureContext;
use Jeremeamia\SuperClosure\ClosureParser\ClosureLocation;
use SuperClosure\ClosureBinding;
use SuperClosure\ClosureParser\AbstractClosureContext;
use SuperClosure\ClosureParser\ClosureLocation;
use PHPParser_Node_Expr_Closure as ClosureAst;

class AstClosureContext extends AbstractClosureContext
Expand Down
Loading

0 comments on commit 0bbf5e0

Please sign in to comment.