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

Added the zf.php and the PHAR support #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ nbproject
tmp/
.DS_Store
composer.lock
composer.phar
.*.sw*
.*.un~
vendor/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
--append | -a Append to classmap file if it exists
--overwrite | -w Whether or not to overwrite existing classmap file

### Compile the PHAR file

You can create a .phar file containing the ZFTool project. In order to compile ZFTool in a .phar file you need
to execute the following command:

bin/create-phar.php

This command will create a zftool.phar file in th bin folder.
You can use and ship only this file to execute all the ZFTool functionalities.


## Todo
* Module maintenance (installation, configuration, removal etc.)
* Inspection of application configuration.
Expand Down
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.phar
77 changes: 77 additions & 0 deletions bin/create-phar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env php
<?php
/**
* Create zf.phar
*
* @link http://github.com/zendframework/ZFTool for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

$srcRoot = dirname(__DIR__);
$buildRoot = __DIR__ ;
$filename = 'zftool.phar';

if (file_exists($buildRoot . "/$filename")) {
unlink($buildRoot . "/$filename");
}

$phar = new \Phar($buildRoot . "/$filename", 0, $filename);
$phar->startBuffering();

addFile($phar, "$srcRoot/zf.php", $srcRoot);
addDir($phar, "$srcRoot/vendor", $srcRoot);
addDir($phar, "$srcRoot/config", $srcRoot);
addDir($phar, "$srcRoot/src", $srcRoot);

$stub = <<<EOF
#!/usr/bin/env php
<?php
/*
* This file is part of ZFTool command line tool
*
* @link http://github.com/zendframework/ZFTool for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
Phar::mapPhar('$filename');
require 'phar://$filename/zf.php';
__HALT_COMPILER();

EOF;

$phar->setStub($stub);
$phar->stopBuffering();

/**
* Add a directory in phar removing whitespaces from PHP source code
*
* @param Phar $phar
* @param string $sDir
*/
function addDir($phar, $sDir, $baseDir = null) {
$oDir = new RecursiveIteratorIterator (
new RecursiveDirectoryIterator ($sDir),
RecursiveIteratorIterator::SELF_FIRST
);

foreach ($oDir as $sFile) {
if (preg_match ('/\\.php$/i', $sFile)) {
addFile($phar, $sFile, $baseDir);
}
}
}

/**
* Add a file in phar removing whitespaces from the file
*
* @param Phar $phar
* @param string $sFile
*/
function addFile($phar, $sFile, $baseDir = null) {
if (null !== $baseDir) {
$phar->addFromString(substr($sFile, strlen($baseDir) + 1), php_strip_whitespace($sFile));
} else {
$phar->addFromString($sFile, php_strip_whitespace($sFile));
}
}
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
},
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": ">=2.0.0"
"zendframework/zend-mvc": ">=2.0.0",
"zendframework/zend-modulemanager": ">=2.0.0",
"zendframework/zend-console": ">=2.0.0",
"zendframework/zend-view": ">=2.0.0",
"zendframework/zend-stdlib": ">=2.0.0",
"zendframework/zend-servicemanager": ">=2.0.0",
"zendframework/zend-file": ">=2.0.0",
"zendframework/zend-loader": ">=2.0.0",
"zendframework/zend-version": ">=2.0.0",
"zendframework/zend-text": ">=2.0.0"
}
}
27 changes: 27 additions & 0 deletions zf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
/**
* ZF2 command line tool
*
* @link http://github.com/zendframework/ZFTool for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

require_once 'vendor/autoload.php';

$appConfig = array(
'modules' => array(
'ZFTool',
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'.',
'./vendor',
),
),
);
Zend\Mvc\Application::init($appConfig)->run();