Commit 0ee1e19e authored by Felix Flor's avatar Felix Flor

Merge branch '9-new-check-php-file-for-cli-only' into 'master'

Resolve "New check.php file for CLI only"

Closes #9

See merge request code-mesa/aphpbreakdown!7
parents 74a5a5f1 346a0b8a
......@@ -19,12 +19,12 @@ function checkGivenArguments($argv) {
throw new \Exception ("APHPBreakdown: Invalid parameter type! Must: array, Is: " . gettype($argv));
$acceptedOutputArguments = array("--console-basic","--console-full", "--console-makefile", "--testfile");
$acceptedTemplateArguments = array("--basic", "--advanced");
$acceptedTemplateArguments = array("--basic", "--advanced", "--ci");
$path = realpath($argv[1]);
if(!isset($path) || !isset($argv[2]))
exitWithErrorMessage("APHPBreakdown: Not enough arguments given!\n\t\t aphpbreakdown <PATH> <OPTIONS> [--testfile <TEMPLATE>] [--testfile <EXPORT_FILENAME>]\n\t\t <PATH> /path/to/dir\n\t\t <OPTIONS> --console-basic | --console-full | --console-makefile | --testfile\n\t\t [--testfile <TEMPLATE>] --basic | --advanced\n\t\t [<EXPORT_FILENAME>] optional, no path, don't forget file extension\n");
exitWithErrorMessage("APHPBreakdown: Not enough arguments given!\n\t\t aphpbreakdown <PATH> <OPTIONS> [--testfile <TEMPLATE>] [--testfile <EXPORT_FILENAME>]\n\t\t <PATH> /path/to/dir\n\t\t <OPTIONS> --console-basic | --console-full | --console-makefile | --testfile\n\t\t [--testfile <TEMPLATE>] --basic | --advanced | --ci\n\t\t [<EXPORT_FILENAME>] optional, no path, don't forget file extension\n");
if(!is_dir($path))
exitWithErrorMessage("APHPBreakdown: There is no directory found on path \"$path\"\n");
......@@ -54,10 +54,10 @@ function checkGivenArguments($argv) {
exitWithErrorMessage("APHPBreakdown: The Argument you have given is not valid. Avaible Options: <OUTPUT> [ --console-basic | --console-full | --console-makefile | --testfile ].\n");
if($argv[2] == "--testfile" && !isset($argv[3]))
exitWithErrorMessage("APHPBreakdown: Missing Argument for --testfile. Avaible Options: [<TEMPLATE>] [ --basic | --advanced ].\n");
exitWithErrorMessage("APHPBreakdown: Missing Argument for --testfile. Avaible Options: [<TEMPLATE>] [ --basic | --advanced | --ci].\n");
if($argv[2] == "--testfile" && !in_array($argv[3], $acceptedTemplateArguments))
exitWithErrorMessage("APHPBreakdown: The Argument you have given is not valid. Avaible Options: [<TEMPLATE>] [ --basic | --advanced ].\n");
exitWithErrorMessage("APHPBreakdown: The Argument you have given is not valid. Avaible Options: [<TEMPLATE>] [ --basic | --advanced | --ci].\n");
if(preg_match('/[^A-Za-z0-9 _ .-]/', $argv[4]) && isset($argv[4]))
exitWithErrorMessage("APHPBreakdown: You use inadmissible charachters for filename! Not Path! \n");
......
......@@ -127,6 +127,14 @@ function createTestfileFromTemplate($filesToCheck, $template, $exportFileName){
$exportFileTemplate = file_get_contents('inc/output/fileTemplates/advancedDeveloperTestfile.template');
}
if($template == "--ci"){
if(!isset($exportFileName))
$exportFileName = "ciItegrationCheck.php";
$exportFileTemplate = file_get_contents('inc/output/fileTemplates/ciIntegrationTestfile.template');
}
$exportFileTemplate = str_replace('<NEEDEDMODULES>', $neededModules, $exportFileTemplate);
$exportFileTemplate = str_replace('<NEEDEDFUNCTIONS>', $neededFunctions, $exportFileTemplate);
$exportFileTemplate = str_replace('<NEEDEDCONSTANTS>', $neededConstants, $exportFileTemplate);
......
<?php
$neededModules = array( '<NEEDEDMODULES>' );
$neddedModulesInstallStatus = array();
$neededFunctions = array( '<NEEDEDFUNCTIONS>' );
$neededFunctionsInstallStatus = array();
$neededConstants = array( '<NEEDEDCONSTANTS>' );
$neededConstantsInstallStatus = array();
$neededClasses = array( '<NEEDEDCLASSES>' );
$neededClassesInstallStatus = array();
$error = false;
# needed modules
foreach($neededModules as $neededModule){
if(!extension_loaded($neededModule) && $neededModule != "base"){
$neddedModulesInstallStatus[$neededModule] = false;
} else {
$neddedModulesInstallStatus[$neededModule] = true;
}
}
if (in_array(false, $neddedModulesInstallStatus)) {
$error = true;
echo "\e[31mMissing Modules: ";
foreach($neddedModulesInstallStatus as $module => $moduleStatus){
if(!$moduleStatus)
echo $module." ";
}
echo "\n\n\e[39m";
}
# needed functions
foreach($neededFunctions as $neededFunction){
if(!function_exists($neededFunction)){
$neededFunctionsInstallStatus[$neededFunction] = false;
} else {
$neededFunctionsInstallStatus[$neededFunction] = true;
}
}
if (in_array(false, $neededFunctionsInstallStatus)) {
$error = true;
echo "\e[31mMissing Functions: ";
foreach($neededFunctionsInstallStatus as $function => $functionStatus){
if(!$functionStatus)
echo $function." ";
}
echo "\n\n\e[39m";
}
# needed constants
foreach($neededConstants as $neededConstant){
if(!defined($neededConstant)){
$neededConstantsInstallStatus[$neededConstant] = false;
} else {
$neededConstantsInstallStatus[$neededConstant] = true;
}
}
if (in_array(false, $neededConstantsInstallStatus)) {
$error = true;
echo "\e[31mMissing Constants: ";
foreach($neededConstantsInstallStatus as $constants => $constantsStatus){
if(!$constantsStatus)
echo $constants." ";
}
echo "\n\n\e[39m";
}
# needed classes
foreach($neededClasses as $neededClass){
if(!class_exists($neededClass)){
$neededClassesInstallStatus[$neededClass] = false;
} else {
$neededClassesInstallStatus[$neededClass] = true;
}
}
if (in_array(false, $neededClassesInstallStatus)) {
$error = true;
echo "\e[31mMissing Classes: ";
foreach($neededClassesInstallStatus as $class => $classStatus){
if(!$classStatus)
echo $class." ";
}
echo "\n\n\e[39m";
}
if($error)
exit(1);
echo "\e[32mEverything OK!\n\e[39m";
exit(0);
......@@ -42,10 +42,10 @@ here are some different examples for different results:
## Hot To install
# download the aphpbreakdown.phar
wget http://phar.code-mesa.com/aphpbreakdown-2.0.0.phar
wget http://phar.code-mesa.com/aphpbreakdown-2.1.0.phar
# alternativ download way
fetch http://phar.code-mesa.com/aphpbreakdown-2.0.0.phar
fetch http://phar.code-mesa.com/aphpbreakdown-2.1.0.phar
# make it executable
chmod +x aphpbreakdown.phar
......@@ -107,7 +107,7 @@ available options
--console-makefile
this is special output to check your project required php modules for the makefile e.g.
used by FreeBSD Portstree
used by FreeBSD Portstree
--testfile [--testfile <TEMPLATE>]
......@@ -137,6 +137,14 @@ available options
moment if you (1) know what you do (2) the basic template says that everything
is ok but everything is not working.
--ci
generates a simple php file which can used in your CI (Continuos Integration)
of GitLab and so on. You can deploy it on the target system and run it. If
everything is fine, it returns an Exit-Code 0. If everything goes wrong, it
tells you what and returns an Exit-Code of 1. The Basic-Name of the Output
file is "ciItegrationCheck.php".
**EXPORT_FILENAME**
this is an **optional** argument for --testfile. if you choose basic or advanced, you will get a default filename for the created file. if you want to give a name by yourself for it you can define it here. make sure you will only give a filename **without** a path in and with the file extension you want to use (e.g. .php).
......@@ -151,10 +159,10 @@ examples
aphpbreakdown path/to/directory_i_want_to_test/ --testfile --advanced
# generated file: advancedModuleCheck.php
aphpbreakdown path/to/directory_i_want_to_test/ --testfile ( --basic | --advanced ) myfile
aphpbreakdown path/to/directory_i_want_to_test/ --testfile ( --basic | --advanced | --ci) myfile
# generated file: myfile
aphpbreakdown path/to/directory_i_want_to_test/ --testfile ( --basic | --advanced ) myfile.php
aphpbreakdown path/to/directory_i_want_to_test/ --testfile ( --basic | --advanced | --ci) myfile.php
# generated file: myfile.php
## F.A.Q.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment