Skip to content

Commit

Permalink
Merge pull request #61 from WyriHaximus/2.x
Browse files Browse the repository at this point in the history
Support php-parser 1 and 2
  • Loading branch information
koriym committed May 1, 2016
2 parents d0e3887 + 3152882 commit 867c018
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ php:
- 5.6
- hhvm
- 7
matrix:
include:
- php: 5.5
env: dependencies=lowest
- php: 5.6
env: dependencies=lowest
- php: hhvm
env: dependencies=lowest
- php: 7
env: dependencies=lowest
before_script:
- composer self-update
- composer install
- if [ -z "$dependencies" ]; then composer install; fi;
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest; fi;
script:
- phpunit --coverage-clover=coverage.clover
after_script:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
],
"require": {
"php": ">=5.4.0",
"doctrine/annotations": "~1.1",
"nikic/php-parser": "~1.0"
"doctrine/annotations": "^1.2.7",
"nikic/php-parser": "~1.3||~2.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 1 addition & 3 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
namespace Ray\Aop;

use PhpParser\BuilderFactory;
use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\PrettyPrinter\Standard as StandardPrettyPrinter;
use Ray\Aop\Exception\NotWritableException;

Expand All @@ -35,7 +33,7 @@ public function __construct($classDir, CodeGenInterface $codeGen = null)
}
$this->classDir = $classDir;
$this->codeGen = $codeGen ?: new CodeGen(
new Parser(new Lexer()),
(new ParserFactory)->newInstance(),
new BuilderFactory(),
new StandardPrettyPrinter()
);
Expand Down
23 changes: 23 additions & 0 deletions src/ParserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* This file is part of the Ray.Aop package
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*/
namespace Ray\Aop;

use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\ParserFactory as PHPParserFactory;

class ParserFactory
{
public function newInstance()
{
if (class_exists('PhpParser\ParserFactory')) {
return (new PHPParserFactory)->create(PHPParserFactory::PREFER_PHP7);
}

return new Parser(new Lexer());
}
}
4 changes: 1 addition & 3 deletions tests/CodeGenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
namespace Ray\Aop;

use PhpParser\BuilderFactory;
use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\PrettyPrinter\Standard;

class CodeGenTest extends \PHPUnit_Framework_TestCase
{
public function testAddNullDefaultWithAssisted()
{
$codeGen = new CodeGen(new Parser(new Lexer), new BuilderFactory, new Standard);
$codeGen = new CodeGen((new ParserFactory)->newInstance(), new BuilderFactory, new Standard);
$bind = new Bind;
$bind->bindInterceptors('run', []);
$code = $codeGen->generate('a', new \ReflectionClass(FakeAssistedConsumer::class), $bind);
Expand Down
11 changes: 11 additions & 0 deletions tests/ParserFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Ray\Aop;

class ParserFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$this->assertInstanceOf('PhpParser\Parser', (new ParserFactory)->newInstance());
}
}

0 comments on commit 867c018

Please sign in to comment.