Phar
is an analog jar
from the world of Java, but only with reference to PHP. Phar
packs project files into a special archive and allows you to easily transfer and install the application without manipulating the project itself as an executable program. { "files": ["src/Put.php"], "main": "bin/main", "output": "example.phar", "stub": true }
files
- files to be included in pharmain
- the file that will be executed when calling the phar fileoutput
- the name of the final phar
filestub
- for console applications set to true
box.json
parameters with comments.box.json
at the root of the project { "chmod": "0755", "directories": ["src","app"], "files": ["README.md"], "main": "bin/nasgrate", "output": "nasgrate.phar", "stub": true }
directories
- this parameter contains a list of directories that will be fully included in the project (in this case, the src
and app
directories).files
- if you need to include any specific files, list them here. { "chmod": "0755", "directories": ["src"], "files": ["app/console.php", "app/index.php", "README.md"], "main": "bin/nasgrate", "output": "nasgrate.phar", "stub": true }
vendors
folder, we would like to include the files of these libraries in the project, but exclude, for example, all tests. Then the file would look like this. { "chmod": "0755", "directories": ["src"], "files": ["app/console.php", "app/index.php", "README.md"], "finder": [ { "name": "*.php", "exclude": [ "tests", "test" ], "in": "vendor" } ], "main": "bin/nasgrate", "output": "nasgrate.phar", "stub": true }
finder
section in this case says: “include all files with the *.php
extension from the vendor
directory except for the tests
and test
folders“.chmod
- allows you to set permissions on the phar
file. In this case, we put 0755
to make the file executable. $ curl -LSs https://box-project.imtqy.com/box2/installer.php | php
box.phar
will appear in the current directory.php box.phar
, or assign permissions to execute chmod 755 box.phar
, rename it to box mv box.phar box
and transfer to /usr/local/bin
. Then it can be run from anywhere just like box
. $ composer global require kherge/box --prefer-source
{ "require-dev": { "kherge/box": "~2.5" } }
$ box -v
php.ini
file the parameter phar.readonly
set to 0
, Off
or false
. $ php -i | grep php.ini >> Configuration File (php.ini) Path => /usr/local/php5/lib >> Loaded Configuration File => /usr/local/php5/lib/php.ini
phar.readonly
and set it to Off
. [Phar] ; http://php.net/phar.readonly phar.readonly = Off
box.json
) and run the compilation $ box build -v
-v
flag allows us to see what happens during the compilation process. Removing previously built Phar... * Building... ? Output path: /Users/dlevsha/Sites/nasgrate/nasgrate.phar ? Adding directories... + /Users/dlevsha/Sites/nasgrate/src/config.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Base/Dump.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Base/Generator.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Base/Helper.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Base/Migration.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Mysql/Dump.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Mysql/Generator.php + /Users/dlevsha/Sites/nasgrate/src/Driver/Mysql/Helper.php + /Users/dlevsha/Sites/nasgrate/src/Process/Base.php + /Users/dlevsha/Sites/nasgrate/src/Process/Console.php + /Users/dlevsha/Sites/nasgrate/src/Process/Server.php + /Users/dlevsha/Sites/nasgrate/src/template.sql + /Users/dlevsha/Sites/nasgrate/src/Util/Console.php + /Users/dlevsha/Sites/nasgrate/src/Util/Db.php + /Users/dlevsha/Sites/nasgrate/app/console.php + /Users/dlevsha/Sites/nasgrate/app/index.php ? Adding files... + /Users/dlevsha/Sites/nasgrate/README.md ? Adding main file: /Users/dlevsha/Sites/nasgrate/bin/nasgrate ? Generating new stub... ? Setting file permissions... * Done.
nasgrate.phar
will appear in the project directory. $ ./nasgrate.phar
Nasgrate is a console utility that let you organise database schema migration process at a consistent and easy way. It supports mysql, mssql, postgresql, oracle and other databases Usage: php nasgrate [command] [options] Command: status - displays migration status generate - creates new migration (migration file) up:show - displays (but not executes) SQL-query, executed by migration update ...
phar
is that it searches for all the resources inside its archive. In most cases, this is not a problem, since it is for this that we phar
and made it independent of the environment. But there are a number of cases when the resources inside the phar
archive need to work with external files..environment
file, write migration files and state files to an external directory.../.environment
, an error is generated because there is no such file inside phar
.phar
file. Phar::mount('phar://.environment', '/etc/nasgrate/.environment');
phar
file. Like that: define(DIR_RUN, dirname(Phar::running(false)));
phar
space phar
or simply specify the absolute path to the configuration file. Suppose the configuration file is in the same folder as phar
itself define(DIR_RUN, dirname(Phar::running(false))); Phar::mount('phar://.environment', DIR_RUN.'/.environment');
Phar::mount
are in readonly mode and how to change it is not very clear. When addressing the absolute path of such problems does not arise.Source: https://habr.com/ru/post/274745/
All Articles