Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

wrong autoload location if installed with composer #21

Closed
yurii-github opened this issue Feb 7, 2013 · 21 comments
Closed

wrong autoload location if installed with composer #21

yurii-github opened this issue Feb 7, 2013 · 21 comments

Comments

@yurii-github
Copy link

when installed with composer you get error
" Error: I cannot find the autoloader of the application. "

This is because of subdirectory of zendframework. It can be resovled by adding 1 dirname to zf.php (line 17) :

$basePath = dirname(dirname(dirname($basePath)));

regards

@ezimuel
Copy link
Contributor

ezimuel commented Feb 7, 2013

I'm checking this issue and testing the possibility to use the bin options of composer to manage the zf.php. See the PR #20. I will update this issue asap.

@mtcocktail
Copy link

I've the same error, but it seems that it check the good directory. I've install with composer.

~/application/vendor/zendframework/zftool$ ./zf.php modules list
Error: I cannot find the autoloader of the application.

@Lohoris
Copy link

Lohoris commented Feb 27, 2013

I have encountered the same error, and that fix didn't work for me.

@gabel
Copy link

gabel commented Mar 3, 2013

I had the same issue installing the sceleton via git clone and then add zftool via composer.

If i move the zftool directly into vendor the tooling works fine.

  • not working (default directory via composer installation)
    vendor/zendframework/zftool
  • working
    vendor/zftool
{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.*",
        "zendframework/zftool": "dev-master"
    }
}

@jhogendorn
Copy link

Heya, am I correct in following that this is still not resolved?

It's certainly still the case with my own zftool install.

@glen-84
Copy link

glen-84 commented Mar 24, 2013

Same issue for me, and I can't seem to create the phar either:

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(***\zf2-tutorial\vendor\zftool/vendor,***\zf2-tutorial\vendor\zftool/vendor): The system cannot find the file specified. (code: 2)' in ***\zf2-tutorial\vendor\zftool\bin\create-phar on line 65

UnexpectedValueException: RecursiveDirectoryIterator::__construct(***\zf2-tutorial\vendor\zftool/vendor,***\zf2-tutorial\vendor\zftool/vendor): The system cannot find the file specified. (code: 2) in ***\zf2-tutorial\vendor\zftool\bin\create-phar on line 65

Call Stack:
    0.0004     135816   1. {main}() ***\zf2-tutorial\vendor\zftool\bin\create-phar:0
    0.0134     148224   2. addDir() ***\zf2-tutorial\vendor\zftool\bin\create-phar:26
    0.0134     148896   3. RecursiveDirectoryIterator->__construct() ***\zf2-tutorial\vendor\zftool\bin\create-phar:65

PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(***\zf2-tutorial\vendor\zftool/vendor,***\zf2-tutorial\vendor\zftool/vendor): The system cannot find the file specified. (code: 2)' in ***\zf2-tutorial\vendor\zftool\bin\create-phar:65
Stack trace:
#0 ***\zf2-tutorial\vendor\zftool\bin\create-phar(65): RecursiveDirectoryIterator->__construct('D:\Programming\...')
#1 ***\zf2-tutorial\vendor\zftool\bin\create-phar(26): addDir(Object(Phar), 'D:\Programming\...', 'D:\Programming\...')
#2 {main}
  thrown in ***\zf2-tutorial\vendor\zftool\bin\create-phar on line 65

@noose
Copy link
Contributor

noose commented Apr 13, 2013

Please Ignore commit a27e238 ;-)

@webzellent
Copy link

Thank you :-)

@MarcusReimann
Copy link

The solution from noose is correct.

@ezimuel
Copy link
Contributor

ezimuel commented Apr 23, 2013

I merged the PR #31 that seems to fix the issue.

@ezimuel ezimuel closed this as completed Apr 23, 2013
@pawlik
Copy link

pawlik commented May 6, 2013

Is there a way to check how deep zf.php is installed? After installing with composer it 'thinks' base dir is APPDIR/vendor and can't find any modules...

This fix is not right - it allows zftool to ignore the fact that baseDir is set for APPDIR/vendor and then it silently fails because no modules are visible.

@yurii-github
Copy link
Author

my bad i didn't provide a solution, last time i've just added 1 more dirname() and forget about it.

right now i don't use zend right now, so my vision for fix is virtual

so, I see we may replace this part of code (from line 14 zf.php)

$basePath = __DIR__;
if (file_exists("$basePath/vendor/autoload.php")) {
    require_once "$basePath/vendor/autoload.php";
} else {
    $basePath = dirname(dirname($basePath));
    chdir($basePath);
    if (file_exists("init_autoloader.php")) {
        require_once "init_autoloader.php";
    } elseif (file_exists("vendor/autoload.php")) {
        require_once "vendor/autoload.php";
    } elseif (file_exists("autoload.php")) {
        require_once "autoload.php";
    } else {
        echo 'Error: I cannot find the autoloader of the application.' . PHP_EOL;
        echo "Check if $basePath contains a valid ZF2 application." . PHP_EOL;
        exit(2);
    }
}

with this

$basePath = __DIR__;
try {               
    $base_dirs = array(__DIR__, dirname(dirname($__DIR__)), dirname(dirname(dirname($__DIR__))));   //possible dirs     
    $files = array("vendor/autoload.php", "init_autoloader.php", "autoload.php", ); //possible autoload files       
    $exists = false;
    foreach($base_dirs as $bd) {
        foreach($files as $f) {
            if (file_exists($bd . "/$f)) {
                chdir($bd); //fallback
                $basePath = $bd;                    
                require_once $bd . "/$f";
                $exists = true;
                break 2;
            }
        }
    }

    if(!$exists) {
        throw new Exception('Error: I cannot find the autoloader of the application.' . PHP_EOL . "Check if $basePath contains a valid ZF2 application." . PHP_EOL ,2);
    }

} catch (Exception $e) {
    echo $e->getMessage();
    exit($e->getCode());
}

as for me, it is easier to get vision of the logic

regards

@cdekok
Copy link

cdekok commented May 8, 2013

Yes can this be reopened still not work

@tapankumar
Copy link

Hi..

I am still facing the same issue after downloading latest zftool.

Is this already fixed?

@ericmorand
Copy link

I had to create a symlink of vendor/bin/zf.php into my application folder, and then call "php zf.php" from there, to have it work properly.

A fix would be welcome.

@robbestad
Copy link

Yes, doesn't work for me either through composer. Changed
$basePath=getcwd(); to $basePath=getcwd()."/../../../"; to get it working. Of course, that assumes zftools is in vendor/zendframework/zftool

@tasmaniski
Copy link

Still not working ...
(^ even with the above solution)

@altdprogrammer
Copy link

Yurii's code worked for me after I removed the $ from the __DIR__. Modified code is as follows

$basePath = __DIR__;
try {               
    $base_dirs = array(__DIR__, dirname(dirname(__DIR__)), dirname(dirname(dirname(__DIR__))));   //possible dirs     
    $files = array("vendor/autoload.php", "init_autoloader.php", "autoload.php", ); //possible autoload files       
    $exists = false;
    foreach($base_dirs as $bd) {
        foreach($files as $f) {
            if (file_exists($bd . "/$f")) {
                chdir($bd); //fallback
                $basePath = $bd;                    
                require_once $bd . "/$f";
                $exists = true;
                break 2;
            }
        }
    }

    if(!$exists) {
        throw new Exception('Error: I cannot find the autoloader of the application.' . PHP_EOL . "Check if $basePath contains a valid ZF2 application." . PHP_EOL ,2);
    }

} catch (Exception $e) {
    echo $e->getMessage();
    exit($e->getCode());
}

@speermahi
Copy link

I update zf.php as follows

$basePath = getcwd(); -> points to vendor/bin folder 
ini_set('user_agent', 'ZFTool - Zend Framework 2 command line tool');

// load autoloader -> swap $basePath with "../../"
if (file_exists("../../vendor/autoload.php")) {    
    require_once "../../vendor/autoload.php";
} elseif (file_exists("../../init_autoload.php")) {    // swap $basePath with "../../"
    require_once "../../init_autoload.php";

@freeentr
Copy link

The zf.php should be installed into the vendor/ZFTool directory (relative to your project root) - however, the command needs to be run from your project root in order for it to work correctly.

http://framework.zend.com/manual/2.3/en/modules/zendtool.introduction.html

@lubyshev
Copy link

Just run ZF from root dir:

$ php ./vendor/zendframework/zftool/zf.php modules list

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests