Coder Social home page Coder Social logo

autoload's People

Contributors

corburn avatar edorian avatar erkan-yilmaz avatar glensc avatar gooh avatar grahamcampbell avatar hco avatar hpbuniat avatar jrfnl avatar ktomk avatar martin-helmich avatar martin-rueegg avatar owenvoke avatar remicollet avatar sebastianbergmann avatar suve avatar theseer avatar unfunco avatar zonuexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autoload's Issues

Array to string conversion on parsing composer.json

Hi,

Consider the following psr-4 autoload definition in a composer.json:

    "autoload": {
        "psr-4": {
            "": ["../src/", "modules/"],
            "MyApp\\": "src/"
        }
    },

The first definition contains an array of the paths to search in. For Composer this is a valid configuration. phpab throws an array to string conversion warning when parsing such a file:

PHP Warning:  Array to string conversion in phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/ComposerIterator.php on line 50
PHP Stack trace:
PHP   1. {main}() /home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar:0
PHP   2. TheSeer\Autoload\CLI->run() /home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar:155
PHP   3. TheSeer\Autoload\Application->run() phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/CLI.php:101
PHP   4. TheSeer\Autoload\Application->runCollector() phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/Application.php:53
PHP   5. TheSeer\Autoload\Config->getDirectories() phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/Application.php:86
PHP   6. TheSeer\Autoload\ComposerIterator->__construct($composerFile = class SplFileInfo { private $pathName = 'root/git/projects/vendor/web/composer.json'; private $fileName = 'composer.json' }) phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/Config.php:394
PHP   7. TheSeer\Autoload\ComposerIterator->processAutoload($baseDir = '/home/VERTRIEB/unencrypted/felix.jacobi/,y-project/root/git/projects/vendor/web', $map = ['psr-4' => ['' => [...], 'MyApp\' => 'src/']]) phar:///home/VERTRIEB/felix.jacobi/.phive/phars/phpab-1.26.0.phar/phpab/ComposerIterator.php:33

sttolower with special characters in class names breaks autoload on some systems

If your class name contains special characters the autoloading breaks on some systems, like MacOS.

The problem is that strtolower("ö") on MacOS returns "?". This breaks the autoloading definitions if you are not using only one system.

I would prefer to be able to disable the lowercasing for class names for those who do not need case-insensitive class names but have special characters in their class names.

static.php.tpl does not work

sb@thinkpad bankaccount % phpab -o src/autoload.php -t static.php.tpl src
Autoload file 'src/autoload.php' generated.

sb@thinkpad bankaccount % cat src/autoload.php                           
<?php // this is an autogenerated file - do not edit (created Tue, 30 Nov 2010 07:18:47 +0100)
___FILELIST___

UnitTests fail on Windows due to directory separators

Some of the UnitTests fail on Windows (tested on Win7 x64) due to mixed directory separators in the assertions. __DIR__ will evaluate to a Windows path with backslashes, while the remaining paths are hardcoded with forward slashes. One solution could be to realpath all paths before they are asserted. Another solution could be to replace the slashes of __DIR__.

Example

PHPUnit 3.5.13 by Sebastian Bergmann.

F..FF.....SSSSSS..........................

Time: 0 seconds, Memory: 4.50Mb

There were 3 failures:

1) TheSeer\Tools\Tests\AutoloadBuilderTest::testDefaultRendering
Failed asserting that <text> contains "         $classes = array(
            'demo1' => 'F:\Work\code\Autoload\tests/_data/classfinder/class.php',
".

F:\Work\code\Autoload\tests\autoloadbuilder.test.php:69

2) TheSeer\Tools\Tests\AutoloadBuilderTest::testSettingNonDefaultTemplate
Failed asserting that <text> contains "'demo1' => 'F:\Work\code\Autoload\tests/_data/classfinder/class.php',
".

F:\Work\code\Autoload\tests\autoloadbuilder.test.php:104

3) TheSeer\Tools\Tests\AutoloadBuilderTest::testSettingTemplateCode
Failed asserting that <text> contains "'demo1' => 'F:\Work\code\Autoload\tests/_data/classfinder/class.php',
".

F:\Work\code\Autoload\tests\autoloadbuilder.test.php:115

FAILURES!
Tests: 37, Assertions: 72, Failures: 3, Skipped: 6.

Incorrect "Redeclaration of class" error

➜  phpcpd git:(master) ✗ ant phpab 
Buildfile: /usr/local/src/phpcpd/build.xml

phpab:
     [exec] phpab 1.7.0 - Copyright (C) 2009 - 2011 by Arne Blankerts
     [exec] 
     [exec] Error while processing request:
     [exec]  - Redeclaration of class 'sebastianbergmann\\phpcpd\\strategy\\abstractstrategy' detected
     [exec]    Original:  /usr/local/src/phpcpd/src/Detector/Strategy/AbstractStrategy.php
     [exec]    Secondary: /usr/local/src/phpcpd/src/Detector/Strategy/Default.php
     [exec] 
     [exec] 
     [exec] Result: 1

BUILD SUCCESSFUL
Total time: 0 seconds

➜  phpcpd git:(master) ✗ grep AbstractStrategy **/*.php
src/Detector/Detector.php:    use SebastianBergmann\PHPCPD\Strategy\AbstractStrategy;
src/Detector/Detector.php:         * @param AbstractStrategy $strategy
src/Detector/Detector.php:        public function __construct(AbstractStrategy $strategy, \ezcConsoleOutput $output = NULL)
src/Detector/Strategy/AbstractStrategy.php:    abstract class AbstractStrategy
src/Detector/Strategy/Default.php:    class Default extends AbstractStrategy
src/Detector/Strategy/SaveMemory.php:    class SaveMemory extends AbstractStrategy

If I change class Default extends AbstractStrategy to just class Default it works.

PEAR install procedure doesn't work

The install guide recommends installing through the PEAR repository, but this is how it works for me:

root@local:# pear channel-discover pear.netpirates.net
Adding Channel "pear.netpirates.net" succeeded
Discovery of channel "pear.netpirates.net" succeeded
root@local:
# pear channel-discover components.ez.no
Channel "components.ez.no" is already initialized
root@local:~# pear install theseer/Autoload
Package "Autoload" does not have REST info xml available
install failed

I guess there's only one tiny bit missing, but still, it's a bit frustrating...

Trait sorted after using class when --static is used

DbUnit 2.0, bundled with PHPUnit >= 5.0.1, has

trait PHPUnit_Extensions_Database_TestCase_Trait
{
    // ...
}

and

abstract class PHPUnit_Extensions_Database_TestCase extends PHPUnit_Framework_TestCase
{
    use PHPUnit_Extensions_Database_TestCase_Trait;
}

for which PHPAB generates

require 'phar://phpunit-5.0.1.phar' . '/phar/dbunit/Extensions/Database/TestCase.php';
require 'phar://phpunit-5.0.1.phar' . '/phar/dbunit/Extensions/Database/TestCaseTrait.php';

which means that the source of the trait is loaded after the source of a class that is using it. This leads to the problem described in sebastianbergmann/phpunit#1887

Issue with Installation/Running phpab

Below are the results of me installing from the example using pear. It

I'm on Mac Lion

sudo pear install theseer/Autoload
downloading Autoload-1.8.0.tgz ...
Starting to download Autoload-1.8.0.tgz (12,685 bytes)
.....done: 12,685 bytes
install ok: channel://pear.netpirates.net/Autoload-1.8.0

I don't see the DirectoryScanner and ConsoleTools like the example below pulled from the installation page.

after i do the install with the results from above, when trying to use phpab I see this:

phpab

Warning: require(TheSeer/DirectoryScanner/autoload.php): failed to open stream: No such file or directory in /usr/bin/phpab on line 45

Fatal error: require(): Failed opening required 'TheSeer/DirectoryScanner/autoload.php' (include_path='.:') in /usr/bin/phpab on line 45

I'm pretty new to this so it might just be ignorance, but i've done a bit of research before writing this and I can't figure it out.

Also I ran: sudo pear install pear.phpqatools.org/phpqatools PHPDocumentor first because i'm trying to go through the
BankAccount (https://github.com/thePHPcc/bankaccount) sample learning phpUNIT.

Thanks for any help.


Example shows a lot more being downloaded.

[theseer@rikka ~]$ sudo pear install theseer/Autoload
downloading Autoload-1.8.0.tgz ...
Starting to download Autoload-1.8.0.tgz (7,596 bytes)
.....done: 7,596 bytes
downloading DirectoryScanner-1.0.1.tgz ...
Starting to download DirectoryScanner-1.0.1.tgz (3,400 bytes)
...done: 3,400 bytes
downloading ConsoleTools-1.6.tgz ...
Starting to download ConsoleTools-1.6.tgz (869,925 bytes)
...done: 869,925 bytes
install ok: channel://pear.netpirates.net/DirectoryScanner-1.0.1
install ok: channel://components.ez.no/ConsoleTools-1.6
install ok: channel://pear.netpirates.net/Autoload-1.1.0

BUG: cannot build static include with more than 50 files

$phpab -s includes
phpab 1.3.3 - Copyright (C) 2009 - 2011 by Arne Blankerts

Error while processing request:

  • Can't resolve more than 50 levels of dependencies

ClassDependencySorter::resolve increases level, but does not decrease at and of method
This fix works for me:

--- TheSeer/Autoload/dependencysorter.php     2011-01-19 14:50:56.000000000 +0000
+++ TheSeer/Autoload/dependencysorter.php     2011-01-21 13:07:55.000000000 +0000
@@ -87,6 +87,7 @@
             }
          }
          $this->sorted[] = $class;
+         $this->level--;
       }
    }

Best Regards Matthias

`__halt_compiler` detection

PSR12 wants all keywords to be lower case which includes __halt_compiler(). phpab checks for an exact match of the uppercase version in the template:

if (strpos($code, '__HALT_COMPILER();') === FALSE)

While not a deal breaker, the warning is annoying.

Can we perhaps make this check for lower case as well?

Can't generate autoloader for nikic/php-parser

phpab 1.25.9 - Copyright (C) 2009 - 2020 by Arne Blankerts and Contributors

Scanning directory lib/PhpParser
Could not process file '/dev/shm/BUILD/PHP-Parser-1c13d05035deff45f1230ca68bd7d74d621762d9/lib/PhpParser/Error.php' due to parse errors: Parse error while trying to process class definition (unexpected token in name).

This only happens with PHP 7.3, ok with PHP 7.4

cannot work at windows

my php version is php5.3. When I use phpab to generate autoload.php on windows 7, something wrong happened. The same code will work under linux.The error is shown under.

Scanning directory myrecsys/

Fatal error: Class 'finfo' not found in phar://D:/develop/bin/phpab.phar/DirectoryScanner-1.3.0/TheSeer/DirectoryScan ner/phpfilter.php on line 56

Call Stack:
0.0015 737472 1. {main}() D:\develop\bin\phpab.phar:0
0.0048 1056744 2. TheSeer\Autoload\CLI->run() D:\develop\bin\phpab.phar:150
0.0220 2200256 3. TheSeer\Autoload\Application->run() phar://D:/develop/bin/phpab.phar/phpab/CLI.php:97
0.0220 2200256 4. TheSeer\Autoload\Application->runCollector() phar://D:/develop/bin/phpab.phar/phpab/Applic ation.php:53
0.0271 2542224 5. TheSeer\Autoload\Collector->processDirectory() phar://D:/develop/bin/phpab.phar/phpab/Appl ication.php:79
0.0292 2554952 6. TheSeer\DirectoryScanner\PHPFilterIterator->accept() phar://D:/develop/bin/phpab.phar/phpa b/Application.php:0

PHP Fatal error: Class 'finfo' not found in phar://D:/develop/bin/phpab.phar/DirectoryScanner-1.3.0/TheSeer/Director yScanner/phpfilter.php on line 56
PHP Stack trace:
PHP 1. {main}() D:\develop\bin\phpab.phar:0
PHP 2. TheSeer\Autoload\CLI->run() D:\develop\bin\phpab.phar:150
PHP 3. TheSeer\Autoload\Application->run() phar://D:/develop/bin/phpab.phar/phpab/CLI.php:97
PHP 4. TheSeer\Autoload\Application->runCollector() phar://D:/develop/bin/phpab.phar/phpab/Application.php:53
PHP 5. TheSeer\Autoload\Collector->processDirectory() phar://D:/develop/bin/phpab.phar/phpab/Application.php:79
PHP 6. TheSeer\DirectoryScanner\PHPFilterIterator->accept() phar://D:/develop/bin/phpab.phar/phpab/Application.php:

Class redeclaration detection too strict

Zend Framework, at least 1.10, uses conditional class definitions, for example in Zend/InfoCard/Exception.php. phpab should ignore redefinitions within the same file.

if (class_exists("Zend_Exception")) {
    abstract class Zend_InfoCard_Exception_Abstract extends Zend_Exception
    {
    }
} else {
    abstract class Zend_InfoCard_Exception_Abstract extends Exception
    {
    }
}

Add option to handle duplicate declarations across multiple files

At the moment, --tolerant only ignores duplicate declarations of classes, interfaces, and traits that occur in the same source file.

Some code bases have duplicate declarations of classes, interfaces, and traits that do not occur in the same source file. Currently, PHPAB errors out on a code base like that. It would be nice to have a separate option that handles a situation like that by using the first source file found when multiple source files exist that declare a unit of code of the same name.

Add support for parent templates

It would be nice if PHPAB supported an additional switch along the lines of --parent <file> that would result in

require '<file>';

to be added at the top of the generated code.

This would add out-of-the-box support for situations where you want to have one autoload script generated for the src directory and another for the tests directory of a project and the latter has to load the former.

Warnings and Notices in ComposerIterator

$ php --version
PHP 7.3.11 (cli) (built: Oct 22 2019 08:11:04) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
$ git clone https://github.com/sebastianbergmann/phpunit.git                                 
Cloning into 'phpunit'...
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 97669 (delta 6), reused 7 (delta 1), pack-reused 97647
Receiving objects: 100% (97669/97669), 45.98 MiB | 10.23 MiB/s, done.
Resolving deltas: 100% (64681/64681), done.
$ cd phpunit
$ ./tools/phpab --static -o vendor/autoload.php composer.json
phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors

PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
PHP Warning:  file_get_contents(): Filename cannot be empty in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 64
Scanning directory /tmp/phpunit/src

Error while processing request:
 - Given basedir '' does not exist or is not a directory
$ ./tools/composer install 
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 28 installs, 0 updates, 0 removals
  - Installing phar-io/version (2.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.3): Loading from cache
  - Installing phpunit/php-timer (2.1.2): Loading from cache
  - Installing sebastian/diff (3.0.2): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/global-state (3.0.0): Loading from cache
  - Installing sebastian/object-enumerator (3.0.3): Loading from cache
  - Installing sebastian/resource-operations (2.0.1): Loading from cache
  - Installing sebastian/type (1.1.3): Loading from cache
  - Installing myclabs/deep-copy (1.9.3): Loading from cache
  - Installing doctrine/instantiator (1.2.0): Loading from cache
  - Installing sebastian/exporter (3.1.2): Loading from cache
  - Installing sebastian/comparator (3.0.2): Loading from cache
  - Installing symfony/polyfill-ctype (v1.12.0): Loading from cache
  - Installing webmozart/assert (1.5.0): Loading from cache
  - Installing phpdocumentor/reflection-common (2.0.0): Loading from cache
  - Installing phpdocumentor/type-resolver (1.0.1): Loading from cache
  - Installing phpdocumentor/reflection-docblock (4.3.2): Loading from cache
  - Installing phpspec/prophecy (1.9.0): Loading from cache
  - Installing theseer/tokenizer (1.1.3): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/environment (4.2.2): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/php-token-stream (3.1.1): Loading from cache
  - Installing phpunit/php-file-iterator (2.0.2): Loading from cache
  - Installing phpunit/php-code-coverage (7.0.8): Loading from cache
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.7.2)
Writing lock file
Generating optimized autoload files
$ ./tools/phpab --static -o vendor/autoload.php composer.json
phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors

PHP Notice:  Array to string conversion in phar:///tmp/phpunit/tools/phpab/phpab/ComposerIterator.php on line 50
Scanning directory /tmp/phpunit/vendor/doctrine/instantiator/src/Doctrine/Instantiator
Scanning directory /tmp/phpunit/vendor/myclabs/deep-copy/src/DeepCopy
Scanning directory /tmp/phpunit/vendor/phar-io/version/src
Scanning directory /tmp/phpunit/vendor/phar-io/manifest/src
Scanning directory /tmp/phpunit/vendor/phpdocumentor/reflection-common/src
Scanning directory /tmp/phpunit/vendor/phpdocumentor/type-resolver/src
Scanning directory /tmp/phpunit/vendor/symfony/polyfill-ctype
Scanning directory /tmp/phpunit/vendor/webmozart/assert/src
Scanning directory /tmp/phpunit/vendor/sebastian/diff/src
Scanning directory /tmp/phpunit/vendor/sebastian/recursion-context/src
Scanning directory /tmp/phpunit/vendor/sebastian/exporter/src
Scanning directory /tmp/phpunit/vendor/sebastian/comparator/src
Scanning directory /tmp/phpunit/vendor/phpspec/prophecy/src/Prophecy
Scanning directory /tmp/phpunit/vendor/phpunit/php-file-iterator/src
Scanning directory /tmp/phpunit/vendor/phpunit/php-token-stream/src
Scanning directory /tmp/phpunit/vendor/phpunit/php-text-template/src
Scanning directory /tmp/phpunit/vendor/sebastian/code-unit-reverse-lookup/src
Scanning directory /tmp/phpunit/vendor/sebastian/environment/src
Scanning directory /tmp/phpunit/vendor/sebastian/version/src
Scanning directory /tmp/phpunit/vendor/theseer/tokenizer/src
Scanning directory /tmp/phpunit/vendor/phpunit/php-code-coverage/src
Scanning directory /tmp/phpunit/vendor/phpunit/php-timer/src
Scanning directory /tmp/phpunit/vendor/sebastian/object-reflector/src
Scanning directory /tmp/phpunit/vendor/sebastian/global-state/src
Scanning directory /tmp/phpunit/vendor/sebastian/object-enumerator/src
Scanning directory /tmp/phpunit/vendor/sebastian/resource-operations/src
Scanning directory /tmp/phpunit/vendor/sebastian/type/src
Scanning directory /tmp/phpunit/src

Autoload file vendor/autoload.php generated.

symfony/event-dispatcher Duplicate definitions of the following unit(s) found

Hello Arne,

we're trying to build our own coding standard as a phar file. This is currently failing due to the following error:

$ tools/phpab --all --phar --alias cs.phar --gzip --exclude \*tests\* --output build/phar/cs-${version}.phar --template phar/templates/bootstrap.php.in --basedir . ./src ./vendor

 phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors
 
 Scanning directory ./src
 Scanning directory ./vendor
 Duplicate (potentially conditional) definitions of the following unit(s) found:
 
     Unit(s): symfony\contracts\eventdispatcher\eventdispatcherinterface
     File: /var/www/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php

To make this easier I could nail the issue down to the composer dependency symfony/event-dispatcher. Here a simplified version of the composer.json which causes the problem.

{
    "require": {
        "php": ">=7.3",
        "symfony/event-dispatcher": "^4.3"
    }
}

Dep missing in Readme

ext/fileinfo not installed/enabled
The README.md should also list ext/fileinfo before Tokenizer (ext/tokenizer)

PHPAB 1.25.7 generates broken PHAR for PHPUnit

$ git clone https://github.com/sebastianbergmann/phpunit.git
$ cd phpunit
$ git checkout 8.4
$ ant phar
.
.
.
    [phpab] phpab 1.25.7 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/phar-scoped
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/phpunit-library-8.4.3-16-g46cbb7501.phar' generated.
    [phpab] 
     [copy] Copying 1 file to /usr/local/src/phpunit/build
    [phpab] phpab 1.25.7 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/phar-scoped
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/phpunit-8.4.3-16-g46cbb7501.phar' generated.
    [phpab] 
   [delete] Deleting directory /usr/local/src/phpunit/build/phar
   [delete] Deleting: /usr/local/src/phpunit/build/binary-phar-autoload.php
$ /usr/local/src/phpunit/build/phpunit-8.4.3-16-g46cbb7501.phar --version
PHP Parse error:  syntax error, unexpected '/' in /usr/local/src/phpunit/build/phpunit-8.4.3-16-g46cbb7501.phar on line 41
.
.
.
define('__PHPUNIT_PHAR__', str_replace(DIRECTORY_SEPARATOR, '/', __FILE__));
define('__PHPUNIT_PHAR_ROOT__', 'phar://phpunit-8.4.3-16-g46cbb7501.phar');

Phar::mapPhar('phpunit-8.4.3-16-g46cbb7501.phar');

require /myclabs-deep-copy/DeepCopy/DeepCopy.php';
require 'phar://phpunit-8.4.3-16-g46cbb7501.phar' . '/myclabs-deep-copy/DeepCopy/Exception/CloneException.php';
require 'phar://phpunit-8.4.3-16-g46cbb7501.phar' . '/myclabs-deep-copy/DeepCopy/Exception/PropertyException.php';
$ git revert --no-commit d2666181bc3c8ea5ad096f3eb7e4f1ad742c199f
.
.
.
     [copy] Copying 1 file to /usr/local/src/phpunit/build/phar-scoped
    [phpab] phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/phar-scoped
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/phpunit-library-8.4.3-16-g46cbb7501.phar' generated.
    [phpab] 
     [copy] Copying 1 file to /usr/local/src/phpunit/build
    [phpab] phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors
    [phpab] 
    [phpab] Scanning directory /usr/local/src/phpunit/build/phar-scoped
    [phpab] 
    [phpab] phar archive '/usr/local/src/phpunit/build/phpunit-8.4.3-16-g46cbb7501.phar' generated.
    [phpab] 
   [delete] Deleting directory /usr/local/src/phpunit/build/phar
   [delete] Deleting: /usr/local/src/phpunit/build/binary-phar-autoload.php
$ /usr/local/src/phpunit/build/phpunit-8.4.3-16-g46cbb7501.phar --version
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.

class redeclaration with conditional classes

+ cd HttpFoundation-2.4.8
+ phpab -n -e '*/Tests/*' -o autoload.php .
phpab 1.14.2 - Copyright (C) 2009 - 2014 by Arne Blankerts

Scanning directory .

Error while processing request:
 - Redeclaration of class, interface or trait 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler' detected
 Original: ./Session/Storage/Handler/NativeSessionHandler.php
 Secondary: ./Session/Storage/Handler/NativeSessionHandler.php

reality is that the class is defined on condition in NativeSessionHandler.php:

if (version_compare(phpversion(), '5.4.0', '>=')) {
    class NativeSessionHandler extends \SessionHandler {}
} else {
    class NativeSessionHandler {}
}

ps: it would be also nice if phpab would understand the error is in the same file (and say accordingly), as i had to stare the error for a minute to find what's the difference in two filenames :)

Not an issue, just a question

Hey. I keep getting 'No classes were found - process aborted.' while running this with jenkins. I couldn't find what the error meant or how to resolve it. Any ideas?

pear.netpirates.net is down

Hi I am trying to install phpab. Nevertheless when I try to run:

pear channel-discover pear.netpirates.net

The result is:

Discovering channel pear.netpirates.net over http:// failed with message: channel-add: Cannot open "http://pear.netpirates.net/channel.xml" (Connection to pear.netpirates.net:80' failed: php_network_getaddresses: getaddrinfo failed: Name or service not known) Trying to discover channel pear.netpirates.net over https:// instead Discovery of channel "pear.netpirates.net" failed (channel-add: Cannot open "https://pear.netpirates.net/channel.xml" (Connection topear.netpirates.net:443' failed: php_network_getaddresses: getaddrinfo failed: Name or service not known))

After some retry: I tried to access the pear.netpirates.net and is down. Are there some alternative site to download phpab?.
Regards
sdvf

Missing dependency on PHP/Timer

On fresh install, the default instructions set in README doesn't leave a working phpab.

Autoload phpab depends on PHP/Timer but doesn't install it with pear.

Simply beautiful!

This is not an issue! Just a note: Beautiful project!

After having spend days trying to get PSR-0 autoloader and old legacy code playing nicely together, your application solved ALL problems in about 2 seconds!

With this project I don't even understand why the PSR-0 is an issue!

PHP 5.2 compatibility mode renders syntax errors

Steps to reproduce:

  1. Create test.php with contents:

    <?php
    class test {
    }
    
  2. Run phpab with the following command (tested with 1.19.2 and 1.20.0):

    php phpab-1.19.2.phar -o autoload.php -c .
    
  3. Inspect generated autoload.php:

    <?php
    // @codingStandardsIgnoreFile
    // @codeCoverageIgnoreStart
    // this is an autogenerated file - do not edit
    function autoload41f7643157dbaecc9a2499d6fd2348d4($class) {
        static $classes = null;
        if ($classes === null) {
            $classes = array(
                'test' => '/test.php'
            );
        }
        $cn = strtolower($class);
        if (isset($classes[$cn])) {
            require dirname(__FILE__) . $classes[$cn];
        },
        true,
        false
    }
    spl_autoload_register('autoload41f7643157dbaecc9a2499d6fd2348d4');
    // @codeCoverageIgnoreEnd
    

The generated file is syntactically incorrect.

$ php -l autoload.php 
PHP Parse error:  syntax error, unexpected ',' in autoload.php on line 15

Parse error: syntax error, unexpected ',' in autoload.php on line 15

Errors parsing autoload.php

CI: move to GH Actions ?

While creating PR #99, I wanted to check that the deprecation notices I mentioned would be shown in CI, only to realize that this repo is still on Travis.

Is that intentional ? Or should the CI of this repo be converted to GH Actions ?

Functions

Is there any plans to support loading files with just functions in them? Or would you be open to a PR that added that as a feature?

Context:

This tools solves 50% of my problem flawlessly but...

I’m writing a PHP functional programming library. Naturally, I have a large number files containing just plain old functions and it’s tedious to keep updating composer files.

I wanted a way to quickly generate an autoloader but everything only seems to work on classes (including this project). I have a few interfaces already (more on the way) and will have a number of traits and classes too so that works fine.

I could write my own tool that simply creates an includes file as a build artefact but not sure if PHP requires interfaces to be defined before they’re used in typehints. So I was looking at this tool and it does a great job with interfaces, and I’m assuming traits and classes. But, looking at the code, it doesn’t consider plain old functions.

The design decision makes sense given most high quality PHP projects use solid OO principles so I totally understand why it’s this way :)

--exclude switch not working

To me it seems, that phpabs -e switch does not longer work. It tried
phpab.phar -o autoload.php -e vendor .
phpab.phar -o autoload.php -e /path/to/vendor* .
phpab.phar -o autoload.php -e /path/to/vendor .
etc.
This does not seem to work since some releases. At least I didn't got it to work with different versions.

It used to work with 1.8.0.

Failed test with php 5.3

1) TheSeer\Autoload\Tests\ClassFinderTest::testParseTraitWorks
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:397
2) TheSeer\Autoload\Tests\ClassFinderTest::testParseUseTraitWorks
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:405
3) TheSeer\Autoload\Tests\ClassFinderTest::testParseUseTraitWorksWhenDependencyIsDisabled
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:421
4) TheSeer\Autoload\Tests\ClassFinderTest::testParseUseMultipleTraitWorks
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:431
5) TheSeer\Autoload\Tests\ClassFinderTest::testParseUseTraitWorksEvenWithUseStatementInMethodForClosure
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:448
6) TheSeer\Autoload\Tests\ClassFinderTest::testParseUseTraitsWithOverwriteSkipsBracketContent
Undefined offset: 10355
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:349
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:244
/builddir/build/BUILDROOT/php-theseer-autoload-1.14.1-1.el6.noarch64/usr/share/pear/TheSeer/Autoload/ClassFinder.php:158
/builddir/build/BUILD/php-theseer-autoload-1.14.1/Autoload-1.14.1/tests/classfinder.test.php:464
FAILURES!

Those tests, on trait, should probably be skiped with PHP < 5.4

Add example for recursively scanning directories

It looks like 1.15.0 changed this behaviour and 1.14.2 is not installable by composer (oldest installable version on composer is 1.17.0). How can we recreate this behaviour using wildcards? It looks like phpab uses PHP's glob() which doesn't support recursion, so I'm at a loss.

$ ./vendor/bin/phpab tests/src/*
phpab %development% - Copyright (C) 2009 - 2015 by Arne Blankerts

Scanning directory tests/src/base
Scanning directory tests/src/integration-tests
Scanning directory tests/src/unit-tests

Error while processing request:
 - No units were found - process aborted.

default basedir

About defaut basedir.
Would it make sense to use directory of output file (if given), so the generated file will be usable) ?

It is quite common to run

 $ phpab  --output  top/foo/autoload.php --basedir  top/foo   top

Because sometime library have file in "top"
Without --basedir, default value is "top" which make the generated autoload.php unusable.

Ex : https://github.com/sebastianbergmann/version

Restoring a PSR-0 tree, this will be installed as

/usr/share/php/SebastianBergmann/Version.php
/usr/share/php/SebastianBergmann/Version/autoload.php

Obviously we cannot save the autoloader in top directory (which contains various libraries)

Zeta Components ConsoleTools uses PHP syntax deprecated in PHP 7.4

$ php-74 --version
PHP 7.4.0-dev (cli) (built: Nov  1 2019 06:12:40) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
    with Xdebug v2.8.0beta3-dev, Copyright (c) 2002-2019, by Derick Rethans
$ git clone https://github.com/sebastianbergmann/raytracer.git
$ cd raytracer
$ php-74 ./tools/phpab -o src/autoload.php src

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in phar:///usr/local/src/raytracer/tools/phpab/vendor/zetacomponents/console-tools/src/input.php on line 535
phpab 1.25.6 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors

Scanning directory src

Autoload file src/autoload.php generated.

Error with recursive Composer dependencies

Description

There is nesting error with some Composer dependencies. This happens when some dependency have a lot of dependencies which sometimes require back original dependency.

In my case, package cakephp/core requires cakephp/utility which requires cakephp/core and so on. This is because I have robmorgan/phinx and it depends on cakephp/core.

dependencies

Log

phpab 1.25.2 - Copyright (C) 2009 - 2019 by Arne Blankerts and Contributors

PHP Fatal error:  Uncaught Error: Maximum function nesting level of '8192' reached, aborting! in phar:///usr/local/bin/phpab/phpab/ComposerIterator.php:76
Stack trace:
#0 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(76): file_exists('/projects/Sunsh...')
#1 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(56): TheSeer\Autoload\ComposerIterator->findComposerJson('/projects/Sunsh...')
#2 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(64): TheSeer\Autoload\ComposerIterator->processRequire('/projects/Sunsh...', 'cakephp/utility')
#3 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(64): TheSeer\Autoload\ComposerIterator->processRequire('/projects/Sunsh...', 'cakephp/utility')
#4 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(64): TheSeer\Autoload\ComposerIterator->processRequire('/projects/Sunsh...', 'cakephp/core')
#5 phar:///usr/local/bin/phpab/phpab/ComposerIterator.php(64): TheSeer\Autoload\ComposerIterator->processRequire('/projects/Sunsh...', 'cakephp/utility')
#6 phar:///usr/local/bin/ph in phar:///usr/local/bin/phpab/phpab/ComposerIterator.php on line 76

Required packages

(part of composer.json)

{
    "require": {
        "php": ">= 5.5.9",
        "slim/slim": "^3.0",
        "league/plates": "^3.0",
        "robmorgan/phinx": "^0.9|^0.10",
        "illuminate/database": "^5.0",
        "filp/whoops": "^2.0",
        "monolog/monolog": "^1.0",
        "phpmailer/phpmailer": "^6.0",
        "filips123/monolog-phpmailer": "^1.0",
        "filips123/eventy": "^0.6",
        "nadar/php-composer-reader": "^1.0", 
        "willdurand/negotiation": "^3.0@alpha"
    }
}

Add template that throws an exception in case a class cannot be loaded

The default behaviour of a callback that is registered with spl_autoload_register() is to not do anything in case it cannot load the requested class. This is because, by default, a queue of autoload callbacks is desired. When none of the registered autoload callbacks can load the class, PHP triggers a fatal error that cannot be caught.

In the case where only one autoload callback is used it might make sense to raise an exception inside the autoload callback when it cannot load the class. That way the application can perform proper error handling.

Do not bail out on first duplicate code unit

It would be nice if PHPAB would not bail out on the first duplicate code unit it finds. Instead, please collect all duplicate units of code and error out with a list of all duplicate code units found.

Add support for Composer's autolaoder and adding autoloading in code

Add support to use Composer's autoloader to PHAR file or somehow make class Composer\Autoload\ClassLoader available.

Also, add support for adding autoloading in code (https://getcomposer.org/apidoc/1.3.0/Composer/Autoload/ClassLoader.html). This is currently not possible because Composer\Autoload\ClassLoaderis not available.

For example:

$loader = new \Composer\Autoload\ClassLoader();

// register classes with namespaces
$loader->add('Symfony\Component', __DIR__.'/component');
$loader->add('Symfony',           __DIR__.'/framework');

// activate the autoloader
$loader->register();

// to enable searching the include path (eg. for PEAR packages)
$loader->setUseIncludePath(true);

If including Composer autoloader is not possible, you could make your own class with that name that support those things.

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.