Skip to content

Commit

Permalink
Merge pull request #62 from phalcon-nucleon/1.3
Browse files Browse the repository at this point in the history
1.3
  • Loading branch information
Ark4ne authored Mar 8, 2019
2 parents f31b89e + 608dc0b commit 1333dd8
Show file tree
Hide file tree
Showing 119 changed files with 3,089 additions and 1,341 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- PHALCON_VERSION="3.1.x"
- PHALCON_VERSION="3.2.x"
- PHALCON_VERSION="3.3.x"
- PHALCON_VERSION="3.4.x"

matrix:
exclude:
Expand Down
44 changes: 44 additions & 0 deletions CHANGELOG-1.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Release Note

## v1.3.0

### Added
- Own Preloader.
Improved class compilation, removing "use", converting the long syntax "array" to the short syntax.
Thanks to [nikic/php-parser](https://github.com/nikic/PHP-Parser).
- Kernel HTTP : Routes cache
- Volt :
- Csrf Extension, add functions : csrf_field, csrf_token.
- Function route(name, arguments, query)
- Middleware : Auth\Middleware\Authenticate
- Config : app->static_base_uri : configure url->static_base_uri
- Console : Allow force enable / disable color.
- Debug : add syntax highlight with ark4ne/highlight.
- Migration : add pretend option Dump the SQL queries that would be run.
- Migration : implement rename table function.
- Crypt : Configurable cipher algorithm.
- Session : Multiple backend adapter configuration
- Improved debug tools (File highlight, improve exception/error format, improve variable verbose, ...)
- App : Allow to configure base_url & static_url.
- ServerTask : Allow to configure host and ip, insteadof only ip.
- Process : Add watch method.

### Changed
- Config::Cache : Aggregate now all config files into one file, and keep file content.
- Dotconst::PhpDir : Compile now relative path to basePath, from compilePath.
- Str::normalizePath trigger E_USER_DEPRECATED.
- Str::random : Use lib sodium.
- Arr::isAssoc : Improve performance.
- Arr::sortRecursive : Add $sort_flags
- Middlewares : All middlewares define response insteadof throw Exception.
- Config::Session : Allow to describe multiple store for session
- Debug : Clean output before render error
- Auth : Fixed session remember, and remember cookie deletion on logout.
- HttpClient : Fixed methods arguments for post, put, patch.
- HttpClient : Remove default timeout.
- ListTask : Display an error if a command has a nonexistent method.
- Migration : Fixed addition primary key to an existing table
- Error\Writer\Json : Return now : [code: http_status_code, status: http_status_msg [, debug: error]]

### Removed
- classpreloader/classpreloader
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# UPGRADING

## 1.2 > 1.3

### Config
You must modify all paths using "\_\_DIR__", so that it now uses "BASE_PATH".
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nucleon/framework",
"description": "Phalcon extended framework. (Nucleon:Kernel)",
"keywords": ["framework", "phalcon", "nucleon"],
"minimum-stability": "stable",
"minimum-stability": "dev",
"license": "MIT",
"authors": [
{
Expand All @@ -11,9 +11,10 @@
}
],
"require": {
"php": ">=5.6",
"ext-phalcon": ">=3.0",
"classpreloader/classpreloader": "~3.0"
"php": "5.6 - 7.2",
"ext-phalcon": "~3.0",
"nikic/php-parser": "^3.0",
"ark4ne/highlight": "dev-master"
},
"require-dev": {
"phalcon/ide-stubs": "dev-master",
Expand Down
18 changes: 14 additions & 4 deletions src/Neutrino/Assets/ClosureCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function compile(array $options)
$jsCode = $this->applyPrecompilation($jsCode, isset($options['precompilations']) ? $options['precompilations'] : []);

$data = [
'js_code' => $jsCode,
'compilation_level' => $options['compile']['level'],
'output_format' => 'json',
'output_info' => ['warnings', 'errors', 'statistics', 'compiled_code'],
Expand All @@ -43,8 +42,7 @@ public function compile(array $options)
$data['js_externs'] = $this->extractJsCode($options['compile']['js_externs']);
}

$query = http_build_query($data);
$query = preg_replace('/%5B[0-9]+%5D/simU', '', $query);
$query = http_build_query(['js_code' => $jsCode]) . '&' . preg_replace('/%5B[0-9]+%5D/simU', '', http_build_query($data));

$request = Factory::makeRequest();
$request
Expand Down Expand Up @@ -109,7 +107,19 @@ private function getDirFiles($path)
{
$files = [];

foreach (glob($path . '/*') as $item) {
$paths = glob($path . '/*');

usort($paths, function ($a, $b) {
if (is_file($a)) {
return -1;
}
if (is_file($b)) {
return 1;
}
return 0;
});

foreach ($paths as $item) {
if (is_dir($item)) {
$files = array_merge($files, $this->getDirFiles($item));
} elseif (is_file($item)) {
Expand Down
26 changes: 15 additions & 11 deletions src/Neutrino/Auth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Neutrino\Constants\Services;
use Neutrino\Foundation\Auth\User;
use Neutrino\Interfaces\Auth\Authenticable as AuthenticableInterface;
use Phalcon\Di\Injectable;
use Neutrino\Support\Arr;
use Neutrino\Support\Str;
use Phalcon\Di\Injectable;

/**
* Class Auth
Expand Down Expand Up @@ -58,17 +58,20 @@ public function user()
$user = $this->retrieveUserByIdentifier($id);
}

/** @var \Phalcon\Http\Response\Cookies $cookies */
$cookies = $this->{Services::COOKIES};
if (empty($user) && $cookies->has('remember_me')) {
$recaller = $cookies->get('remember_me');
list($identifier, $token) = explode('|', $recaller);
if (empty($user)) {
/** @var \Phalcon\Http\Response\Cookies $cookies */
$cookies = $this->{Services::COOKIES};
if ($cookies->has('remember_me')) {
$recaller = $cookies->get('remember_me')->getValue();

list($identifier, $token) = explode('|', $recaller);

if ($identifier && $token) {
$user = $this->retrieveUserByToken($identifier, $token);
if ($identifier && $token) {
$user = $this->retrieveUserByToken($identifier, $token);

if ($user) {
$this->{Services::SESSION}->set($this->sessionKey(), $user->getAuthIdentifier());
if ($user) {
$this->{Services::SESSION}->set($this->sessionKey(), $user->getAuthIdentifier());
}
}
}
}
Expand Down Expand Up @@ -128,6 +131,7 @@ public function logout()
$this->loggedOut = true;

$this->{Services::SESSION}->destroy();
$this->{Services::COOKIES}->delete('remember_me');
}

/**
Expand Down Expand Up @@ -163,7 +167,7 @@ public function login(User $user, $remember = false)

/** @var \Phalcon\Http\Response\Cookies|\Phalcon\Http\Response\CookiesInterface $cookies */
$cookies = $this->{Services::COOKIES};
$cookies->set('remember_me', $user->getAuthIdentifier() . '|' . $rememberToken);
$cookies->set('remember_me', $user->getAuthIdentifier() . '|' . $rememberToken, time() + (100 * 365 * 24 * 60 * 60));

$user->setRememberToken($rememberToken);

Expand Down
38 changes: 38 additions & 0 deletions src/Neutrino/Auth/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Neutrino\Auth\Middleware;

use Neutrino\Constants\Services;
use Neutrino\Foundation\Middleware\Controller as ControllerMiddleware;
use Neutrino\Interfaces\Middleware\BeforeInterface;
use Phalcon\Events\Event;

/**
* Class Authenticate
*
* @package Neutrino\Auth\Middleware
*/
class Authenticate extends ControllerMiddleware implements BeforeInterface
{

/**
* Called before the execution of handler
*
* @param \Phalcon\Events\Event $event
* @param \Phalcon\Dispatcher|mixed $source
* @param mixed|null $data
*
* @throws \Exception
* @return bool
*/
public function before(Event $event, $source, $data = null)
{
if ($this->{Services::AUTH}->check()) {
return true;
}

$this->response->setStatusCode(401, 'Unauthorized');

return false;
}
}
2 changes: 1 addition & 1 deletion src/Neutrino/Cli/Output/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function draw($lines = [])

$_lines = [];
foreach ($lines as $line) {
$_lines = array_merge($_lines, explode(PHP_EOL, $line));
$_lines = array_merge($_lines, explode("\n", $line));
}

$lines = $_lines;
Expand Down
22 changes: 19 additions & 3 deletions src/Neutrino/Cli/Output/Decorate.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,38 @@ class Decorate
'conceal' => ['set' => 8, 'unset' => 28],
];

private static $hasColorSupport;

/**
* Check if console has color support
*
* @return bool
*/
private static function hasColorSupport()
{
if (isset(self::$hasColorSupport)) {
return self::$hasColorSupport;
}

if (DIRECTORY_SEPARATOR === '\\') {
return
'10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD
return self::$hasColorSupport =
(10 == PHP_WINDOWS_VERSION_MAJOR && PHP_WINDOWS_VERSION_BUILD >= 10586)
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
}

return function_exists('posix_isatty') && @posix_isatty(STDOUT);
return self::$hasColorSupport = function_exists('posix_isatty') && @posix_isatty(STDOUT);
}

/**
* Force color support.
*
* @param bool $support
*/
public static function setColorSupport($support)
{
self::$hasColorSupport = $support;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Neutrino/Cli/Output/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public static function getTaskInfos($class, $methodName)
try {
$method = $reflection->getMethod($methodName);
} catch (\Exception $e) {

return ['__exception' => "Methods $class::$methodName not found."];
}
$description = '';

if (!empty($method)) {
$docBlock = $method->getDocComment();

Expand Down Expand Up @@ -183,7 +183,7 @@ public static function getTaskInfos($class, $methodName)
*/
public static function neutrinoVersion()
{
return Decorate::info('Neutrino framework') . ' ' . Decorate::notice('v' . Version::get() . ' ['. Version::getId().']');
return Decorate::info('Neutrino framework') . ' version ' . Decorate::notice('v' . Version::get() . ' ['. Version::getId().']');
}

/**
Expand Down
88 changes: 88 additions & 0 deletions src/Neutrino/Config/ConfigPreloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Neutrino\Config;

use Neutrino\PhpPreloader\Exceptions\DirConstantException;
use Neutrino\PhpPreloader\Exceptions\FileConstantException;
use Neutrino\PhpPreloader\Factory;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Return_;

/**
* Class ConfigPreloader
*
* @package Neutrino\Config
*/
class ConfigPreloader
{
private $preloader;
private $returnConverter;

public function __construct()
{
$this->preloader = (new Factory())->create();
$this->returnConverter = new ReturnConverter('config');
$this->preloader->getTraverser()->addVisitor($this->returnConverter);
}

/**
* @throws \Neutrino\PhpPreloader\Exceptions\DirConstantException
* @throws \Neutrino\PhpPreloader\Exceptions\FileConstantException
* @throws \Exception
*/
public function compile()
{
$outputFile = BASE_PATH . '/bootstrap/compile/config.php';
try {
$r = $this->preloader->prepareOutput($outputFile);

$nodes = [
new Assign(
new Variable('config'),
new Array_([], ['kind' => Array_::KIND_SHORT])
)
];

foreach (glob(BASE_PATH . '/config/*.php') as $file) {
$name = pathinfo($file, PATHINFO_FILENAME);

if ($name === 'compile') {
continue;
}

$this->returnConverter->setName($name);

$stmts = $this->preloader->parse($file);
$stmts = $this->preloader->traverse($stmts);

$nodes = array_merge($nodes, $stmts);
}

$nodes[] = new Return_(
new Variable('config')
);

fwrite($r, $this->preloader->prettyPrint($nodes));

} catch (DirConstantException $e) {
throw new DirConstantException(
"Usage of __DIR__ constant is prohibited. Use BASE_PATH . '/path_to_dir' instead.\nin : $file",
$e->getCode()
);
} catch (FileConstantException $e) {
throw new FileConstantException(
"Usage of __FILE__ constant is prohibited. Use BASE_PATH . '/path_to_file' instead.\nin : $file",
$e->getCode()
);
} finally {
if (isset($r) && is_resource($r)) {
fclose($r);
}
if (isset($e)) {
@unlink($outputFile);
}
}
}
}
Loading

0 comments on commit 1333dd8

Please sign in to comment.