PHP application packaging

I am trying to create a .phar file from my web application. Following an example php documentation , I tried the following for this purpose.

<?php
$srcRoot = __DIR__ . "/../app";
$buildRoot = __DIR__ . "/../build";
$p = new Phar("$buildRoot/build.phar", 0, 'build.phar');
$p->buildFromIterator(
    new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($srcRoot)
    ),
    $srcRoot
);

However, I got the following error. I have no idea about the error. What is wrong with the code?

PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message
'Iterator RecursiveIteratorIterator returned a path "D:\site\app" that is
 not in the base directory "D:\site\app"'
in D:\site\tools\create-phar.php:7
+4
source share
4 answers

The source of the problem is that it RecursiveDirectoryIteratoralso lists point files - .and ... When repeated using, /path/to/fooit also displays /path/to/foo/.and /path/to/foo/.., which goes to the parent directory - outside the base directory.

, "..", FilesystemIterator::SKIP_DOTS DirectoryIterator:

new RecursiveDirectoryIterator($srcRoot, FilesystemIterator::SKIP_DOTS)
+5

(@cweiske - , , , !)

, unix/. /..:

<?php
$srcRoot = __DIR__ . "/../app";
$buildRoot = __DIR__ . "/../build";
$p = new Phar("$buildRoot/build.phar", 0, 'build.phar');
$p->buildFromIterator(
    new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($srcRoot, FilesystemIterator::SKIP_DOTS)
    ),
    $srcRoot
);
+2

Box PHAR- . , PHAR, box build .

Matthieu Moquet, , Box PHP Cli. Box CLI, CLI, Box :

Phars.

The Box project provides a PHAR script assembly and ensures that all paths are configured correctly, so this may solve your problem.

0
source

Take a look at the php.ini file to check the value of the phar.readonly field. To create a phar archive must be 0.

Link: http://php.net/manual/en/phar.configuration.php#ini.phar.readonly

-1
source

All Articles