Skip to content

Commit

Permalink
4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Nov 5, 2022
1 parent f132809 commit 5369e18
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 51 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Also, if you want to reopen a report, then you are open to do that.
I will try to answer all and every one of the question (in my limited time).

## Some example
| [ExampleTicketPHP](https://github.com/jorgecc/ExampleTicketPHP) | [Example cupcakes](https://github.com/EFTEC/example.cupcakes) | [Example Search](https://github.com/EFTEC/example-search) | [Example Editable Grid](https://github.com/EFTEC/example-php-editablegrid) |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| [ExampleTicketPHP](https://github.com/jorgecc/ExampleTicketPHP) | [Example cupcakes](https://github.com/EFTEC/example.cupcakes) | [Example Search](https://github.com/EFTEC/example-search) | [Example Editable Grid](https://github.com/EFTEC/example-php-editablegrid) |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| <img src="https://camo.githubusercontent.com/3c938f71f46a90eb85bb104f0f396fcba62b8f4a/68747470733a2f2f74686570726163746963616c6465762e73332e616d617a6f6e6177732e636f6d2f692f3436696b7061376661717677726533797537706a2e6a7067" alt="example php bladeone" width="200"/> | <img src="https://github.com/EFTEC/example.cupcakes/raw/master/docs/result.jpg" alt="example php bladeone cupcakes" width="200"/> | <img src="https://github.com/EFTEC/example-search/raw/master/img/search_bootstrap.jpg" alt="example php bladeone search" width="200"/> | <img src="https://github.com/EFTEC/example-php-editablegrid/raw/master/docs/final.jpg" alt="example php bladeone search" width="200"/> |

[https://www.southprojects.com](https://www.southprojects.com)
Expand Down Expand Up @@ -82,7 +82,7 @@ This version does not support PHP 5.x anymore. However, you can use the old vers

You can find some tutorials and example on the folder [Examples](examples).

You could also check the wiki [Wiki](https://github.com/EFTEC/BladeOne/wiki)
You could also check the [Wiki](https://github.com/EFTEC/BladeOne/wiki)

## About this version
By standard, The original Blade library is part of Laravel (Illuminate components) and to use this template library, you require install Laravel and Illuminate-view components.
Expand Down Expand Up @@ -449,18 +449,22 @@ How to run it?
* Go to your home path and call the PHP script as follows:

```shell
php vendor/lib/eftec/bladeone/lib/BladeOne.php
php vendor/bin/bladeonecli # windows/linux/macos
# or you could execute the script as:
./vendor/bin/bladeonecli.bat # windows
./vendor/bin/bladeonecli # linux/macos
```

Or change you folder according to your installation.

And you can set the syntax as follows:

* **-templatepath** <templatepath> (optional) the template-path.
* **-templatepath** <templatepath> (optional) the template-path (view paths).
* Example: '/folder/views' or 'views' (relative)
* **-compilepath** <compilepath> (optional) the compile-path.
* Example: '/folder/compiles or 'compiles' (relative)
* **-clearcompile** It deletes the content of the compile-path
* **-createfolder** It creates the "compile" and "template" folders
* **-check** It checks the library

Clear the compile-folder
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
"eftec\\tests\\": "tests/"
}
},
"bin": [
"lib/bladeonecli"
],
"require-dev": {
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^8.5.23"
}
}
103 changes: 58 additions & 45 deletions lib/BladeOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
* @copyright Copyright (c) 2016-2022 Jorge Patricio Castro Castillo MIT License.
* Don't delete this comment, its part of the license.
* Part of this code is based in the work of Laravel PHP Components.
* @version 4.6
* @version 4.7
* @link https://github.com/EFTEC/BladeOne
*/
class BladeOne
{
//<editor-fold desc="fields">
public const VERSION = '4.6';
public const VERSION = '4.7';
/** @var int BladeOne reads if the compiled file has changed. If it has changed,then the file is replaced. */
public const MODE_AUTO = 0;
/** @var int Then compiled file is always replaced. It's slow and it's useful for development. */
Expand Down Expand Up @@ -272,16 +272,7 @@ public function __construct($templatePath = null, $compiledPath = null, $mode =
return false;
};

if (!\is_dir($this->compiledPath)) {
$ok = @\mkdir($this->compiledPath, 0777, true);
if ($ok === false) {
$this->showError(
'Constructing',
"Unable to create the compile folder [$this->compiledPath]. Check the permissions of it's parent folder.",
true
);
}
}

// If the traits has "Constructors", then we call them.
// Requisites.
// 1- the method must be public or protected
Expand Down Expand Up @@ -1249,18 +1240,6 @@ public function compile($templateName = null, $forced = false)
// compile the original file
$contents = $this->compileString($this->getFile($template));
$this->compileCallBacks($contents, $templateName);
$dir = \dirname($compiled);
if (!\is_dir($dir)) {
$ok = @\mkdir($dir, 0777, true);
if ($ok === false) {
$this->showError(
'Compiling',
"Unable to create the compile folder [$dir]. Check the permissions of it's parent folder.",
true
);
return false;
}
}
if ($this->optimize) {
// removes space and tabs and replaces by a single space
$contents = \preg_replace('/^ {2,}/m', ' ', $contents);
Expand Down Expand Up @@ -4164,6 +4143,8 @@ public static function colorLog($str, $type = 'i'): string
return "\033[33m$str\033[0m";
case 'i': //info
return "\033[36m$str\033[0m";
case 'b':
return "\e[01m$str\e[22m";
default:
return $str;
}
Expand All @@ -4179,6 +4160,14 @@ public function checkHealthPath(): bool
$status=false;
echo "Compile-path [$this->compiledPath] is not a folder " . self::colorLog("ERROR", 'e') . "\n";
}
foreach($this->templatePath as $t) {
if (is_dir($t)) {
echo "Template-path (view) [$t] is a folder " . self::colorLog("OK") . "\n";
} else {
$status = false;
echo "Template-path (view) [$t] is not a folder " . self::colorLog("ERROR", 'e') . "\n";
}
}
$error = self::colorLog('OK');
try {
/** @noinspection RandomApiMigrationInspection */
Expand All @@ -4199,6 +4188,34 @@ public function checkHealthPath(): bool
echo "View(s) found :" . count($files) . "\n";
return $status;
}
public function createFolders(): void
{
echo self::colorLog("Creating Folder\n");
echo "Creating compile folder[".self::colorLog($this->compiledPath,'b')."] ";
if (!\is_dir($this->compiledPath)) {
$ok = @\mkdir($this->compiledPath, 0770, true);
if ($ok === false) {
echo self::colorLog("Error: Unable to create folder, check the permissions\n", 'e');
} else {
echo self::colorLog("OK\n");
}
} else {
echo self::colorLog("Note: folder already exist.\n", 'w');
}
foreach($this->templatePath as $t) {
echo "Creating template folder [".self::colorLog($t,'b')."] ";
if (!\is_dir($t)) {
$ok = @\mkdir($t, 0770, true);
if ($ok === false) {
echo self::colorLog("Error: Unable to create folder, check the permissions\n", 'e');
} else {
echo self::colorLog("OK\n");
}
} else {
echo self::colorLog("Note: folder already exist.\n", 'w');
}
}
}

public function clearcompile(): int
{
Expand All @@ -4224,6 +4241,7 @@ public function clearcompile(): int
public function cliEngine(): void
{
$clearcompile = self::getParameterCli('clearcompile');
$createfolder = self::getParameterCli('createfolder');
$check = self::getParameterCli('check');
echo ' ____ _ _ ____ ' . "\n";
echo ' | _ \| | | | / __ \ ' . "\n";
Expand All @@ -4241,12 +4259,24 @@ public function cliEngine(): void
$done = true;
$this->clearcompile();
}
if($createfolder) {
$done=true;
$this->createFolders();
}
if (!$done) {
echo " Syntax:\n";
echo " -templatepath <templatepath> (optional) the template-path.\n Example: '/folder/views' or 'views' (relative)\n";
echo " -compilepath <compilepath> (optional) the compile-path.\n Example: '/folder/compiles or 'compiles' (relative)\n";
echo " -clearcompile It deletes the content of the compile path\n";
echo " -check It checks the library\n";
echo " ".self::colorLog("-templatepath","b")." <templatepath> (optional) the template-path (view path).\n";
echo " Default value: 'views'\n";
echo " Example: 'php /vendor/bin/bladeonecli /folder/views' (absolute)\n";
echo " Example: 'php /vendor/bin/bladeonecli folder/view1' (relative)\n";
echo " ".self::colorLog("-compilepath","b")." <compilepath> (optional) the compile-path.\n";
echo " Default value: 'compiles'\n";
echo " Example: 'php /vendor/bin/bladeonecli /folder/compiles' (absolute)\n";
echo " Example: 'php /vendor/bin/bladeonecli compiles' (relative)\n";
echo " ".self::colorLog("-createfolder","b")." it creates the folders if they don't exist.\n";
echo " Example: php ./vendor/bin/bladeonecli -createfolder\n";
echo " ".self::colorLog("-clearcompile","b")." It deletes the content of the compile path\n";
echo " ".self::colorLog("-check","b")." It checks the folders and permissions\n";
}
}

Expand All @@ -4264,20 +4294,3 @@ public static function isAbsolutePath($path): bool

//</editor-fold>
}

if (
!defined('PHPUNIT_COMPOSER_INSTALL') && !defined('__PHPUNIT_PHAR__')
&& isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) === 'BladeOne.php'
&& BladeOne::isCli()
) {
$compilepath = BladeOne::getParameterCli('compilepath', null);
$templatepath = BladeOne::getParameterCli('templatepath', null);
if (!BladeOne::isAbsolutePath($compilepath)) {
$compilepath = getcwd() . '/' . $compilepath;
}
if (!BladeOne::isAbsolutePath($templatepath)) {
$templatepath = getcwd() . '/' . $templatepath;
}
$inst = new BladeOne($templatepath, $compilepath);
$inst->cliEngine();
}
29 changes: 29 additions & 0 deletions lib/bladeonecli
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace eftec;

// this code only runs on CLI but only if bladeonecli.php is called directly and via command line.
use eftec\bladeone\BladeOne;

if (!defined('PHPUNIT_COMPOSER_INSTALL') && !defined('__PHPUNIT_PHAR__')
&& isset($_SERVER['PHP_SELF']) &&
!http_response_code() &&
(basename($_SERVER['PHP_SELF']) === 'bladeonecli.php' || basename($_SERVER['PHP_SELF']) === 'bladeonecli')
) {
// we also excluded it if it is called by phpunit.
include_once __DIR__ . '/BladeOne.php';

$compilepath = BladeOne::getParameterCli('compilepath', null);
$templatepath = BladeOne::getParameterCli('templatepath', null);
if (!BladeOne::isAbsolutePath($compilepath)) {
$compilepath = getcwd() . '/' . $compilepath;
}
if (!BladeOne::isAbsolutePath($templatepath)) {
$templatepath = getcwd() . '/' . $templatepath;
}
$inst = new BladeOne($templatepath, $compilepath);
$inst->cliEngine();
} else {
@http_response_code(404);
}

0 comments on commit 5369e18

Please sign in to comment.