Skip to content

Commit

Permalink
Revert "Phar drop"
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Votruba committed May 31, 2015
1 parent 4dbef42 commit 886d930
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 34 deletions.
33 changes: 15 additions & 18 deletions README.md
Expand Up @@ -12,48 +12,45 @@ Just look at [Doctrine ORM API](http://www.doctrine-project.org/api/orm/2.4/).

## Requirements

- PHP 5.5
- PHP 5.4


## Install

The best way to install ApiGen is via composer:
### 1. As a PHAR

```sh
composer require apigen/apigen --dev
```

Installation via `create-project` is also possible.
1. Download [ApiGen](http://apigen.org/apigen.phar)


## Usage

Run ApiGen with source and destination options:
2. Run ApiGen with source and destination options:

```sh
php bin/apigen generate -s src -d ../my-project-api
php apigen.phar generate -s src -d ../my-project-api
```

To omit cli options just create `apigen.yaml` (or `apigen.neon`) file in your project.
`*.dist` versions are also supported.
To omit cli options just create `apigen.yaml` or `apigen.neon` file in your project.

```yaml
source:
- src
- vendor/some/package
- src

destination: ../my-project-api
```

For global installation, see [documentation](https://github.com/ApiGen/ApiGen/wiki#installation).


### 2. Using Composer

```sh
composer require apigen/apigen --dev
```

Then run with options as above:

```sh
php vendor/bin/apigen generate -s src -d ../my/project-api
```

That's it!


## Options

Expand Down
15 changes: 0 additions & 15 deletions UPGRADE-4.2.md

This file was deleted.

42 changes: 42 additions & 0 deletions box.json
@@ -0,0 +1,42 @@
{
"bootstrap": "src/Herrera/Box/Compactor/PhpNette.php",
"output": "apigen.phar",
"chmod": "0755",
"compactors": [
"ApiGen\\Herrera\\Box\\Compactor\\PhpNette"
],
"compression": "GZ",
"extract": false,
"main": "bin/apigen",
"files": [
"bin/bootstrap.php",
"vendor/autoload.php",
"LICENSE"
],
"finder": [
{
"in": "src"
},
{
"name": ["*.php", "*.json", "*.latte", "*.neon", "*.css", "*.js", "*.png"],
"exclude": ["test", "Test", "Tests", "tests" ],
"in": [
"vendor/andrewsville",
"vendor/apigen",
"vendor/composer",
"vendor/hamcrest",
"vendor/herrera-io",
"vendor/justinrainbow",
"vendor/kdyby",
"vendor/kukulich",
"vendor/latte",
"vendor/michelf",
"vendor/nette",
"vendor/seld",
"vendor/symfony",
"vendor/tracy"
]
}
],
"stub": true
}
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -15,6 +15,7 @@
"andrewsville/php-token-reflection": "^1.4",
"apigen/theme-bootstrap": "1.1.*",
"apigen/theme-default": "1.0.*",
"herrera-io/phar-update": "~2.0",
"kukulich/fshl": "~2.1",
"latte/latte": "^2.3",
"michelf/php-markdown": "~1.4",
Expand All @@ -29,7 +30,8 @@
"tracy/tracy": "^2.3"
},
"require-dev": {
"mockery/mockery": "~0.9"
"mockery/mockery": "~0.9",
"herrera-io/box": "~1.6"
},
"autoload": {
"psr-4": {
Expand Down
88 changes: 88 additions & 0 deletions src/Herrera/Box/Compactor/PhpNette.php
@@ -0,0 +1,88 @@
<?php

/**
* This file is part of the ApiGen (http://apigen.org)
*
* For the full copyright and license information, please view
* the file LICENSE that was distributed with this source code.
*/

namespace ApiGen\Herrera\Box\Compactor;

use Herrera\Box\Compactor\CompactorInterface;


/**
* Keeps Nette system annotations "method" and "return", minimizes PHP source and preserves line numbers.
*/
class PhpNette implements CompactorInterface
{

/**
* {@inheritdoc}
*/
public function compact($contents)
{
$output = '';
foreach (token_get_all($contents) as $token) {
if (is_string($token)) {
$output .= $token;

} elseif ($token[0] === T_COMMENT) {
$output .= $this->preserveLineNumbers($token);

} elseif ($this->isCommentWithoutAnnotations($token, ['@return', '@method'])) {
$output .= $this->preserveLineNumbers($token);

} elseif ($token[0] === T_WHITESPACE) {
if (strpos($token[1], "\n") === FALSE) {
$output .= ' ';

} else {
$output .= $this->preserveLineNumbers($token);
}

} else {
$output .= $token[1];
}
}

return $output;
}


/**
* {@inheritdoc}
*/
public function supports($file)
{
return (pathinfo($file, PATHINFO_EXTENSION) === 'php');
}


/**
* @return string
*/
private function preserveLineNumbers(array $token)
{
return str_repeat("\n", substr_count($token[1], "\n"));
}


/**
* @return bool
*/
private function isCommentWithoutAnnotations(array $token, array $annotationList)
{
if ($token[0] !== T_DOC_COMMENT) {
return FALSE;
}
foreach ($annotationList as $annotation) {
if (strpos($token[1], $annotation) !== FALSE) {
return FALSE;
}
}
return TRUE;
}

}
78 changes: 78 additions & 0 deletions tests/Herrera/Box/Compactor/PhpNetteTest.php
@@ -0,0 +1,78 @@
<?php

namespace ApiGen\Tests\Herrera\Box\Compactor;

use ApiGen\Herrera\Box\Compactor\PhpNette;
use PHPUnit_Framework_TestCase;


class PhpNetteTest extends PHPUnit_Framework_TestCase
{

/**
* @var PhpNette
*/
private $phpNetteCompactor;


protected function setUp()
{
$this->phpNetteCompactor = new PhpNette;
}


public function testCompactCommon()
{
$input = <<<INPUT
<?php
/**
* Some comment
*/
function getSome()
INPUT;
$expected = <<<COMPACT
<?php
function getSome()
COMPACT;
$this->assertSame($expected, $this->phpNetteCompactor->compact($input));
}


public function testCompactMethodAndReturnAnnotations()
{
$input = <<<INPUT
<?php
/**
* @author ApiGen
* @method getThis()
* @return That
*/
function getSomeMore()
INPUT;
$expected = <<<COMPACT
<?php
/**
* @author ApiGen
* @method getThis()
* @return That
*/
function getSomeMore()
COMPACT;
$this->assertSame($expected, $this->phpNetteCompactor->compact($input));
}


public function testSupports()
{
$this->assertTrue($this->phpNetteCompactor->supports('file.php'));
$this->assertFalse($this->phpNetteCompactor->supports('file.json'));
}

}

0 comments on commit 886d930

Please sign in to comment.