Skip to content

Commit

Permalink
Merge pull request #14 from phalcon-nucleon/1.2
Browse files Browse the repository at this point in the history
1.2
  • Loading branch information
Ark4ne authored Mar 19, 2018
2 parents d358ffd + 84172a2 commit 07f4b92
Show file tree
Hide file tree
Showing 97 changed files with 7,481 additions and 381 deletions.
6 changes: 3 additions & 3 deletions .const.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
path = @php/dir

[app]
env = @php/const:Neutrino\Constants\Env::PRODUCTION
env = @php/env:APP_ENV:development
debug = true

[db]
host = 'localhost'
user = 'root'
password = 'abc123'
name = 'localhost'
name = 'nucleon'

[session]
id = nucleon-session-id
id = nucleon-session-id
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/.idea
/.sass-cache
/vendor
composer.phar
composer.lock
.php_cs.cache
.DS_Store
Thumbs.db
Thumbs.db
32 changes: 32 additions & 0 deletions CHANGELOG-1.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Release Note

## v1.2.0

### Added
- View
- Configuring extensions, filters and functions to add to the compiler
- StrExtension :
- Allow to call all Support\Str function in volt.
Use `str_{name}` will generate `Neutrino\Support\Str::{name}`.
- Add `slug` filter (call `Neutrino\Support\Str::slug`)
- Add `limit` filter (call `Neutrino\Support\Str::limit`)
- Add `words` filter (call `Neutrino\Support\Str::words`)
- MergeFilter :
- Add `merge` filter (call `array_merge`)
- RoundFilter :
- Add `round` filter (call `round` | `floor` | `ceil` [@see twig\round](https://twig.symfony.com/doc/2.x/filters/round.html))
- SliceFilter :
- Add `slice` filter (call `array_slice`)
- SplitFilter :
- Add `split` filter (call `str_split` | `explode` [@see twig\split](https://twig.symfony.com/doc/2.x/filters/split.html))
- View engines :
- Allow to configuring multiple engines.
- Built-in Server
- `php quark server:run` : run php built-in server
- Assets
- JS Compilation (via Closure API)
- Sass Compilation (via sass)
- Debug/Profiler toolbar feature
- Debug VarDumd feature
- use `Neutrino\Debug\VarDump::dump`
- use in `.volt` `{{ dump(var) }}`
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,110 @@ class ExampleMiddleware extends ControllerMiddleware implements BeforeInterface
}
```

## View
### Added Functions
`dump` : Dump a variable via `Neutrino\Debug\VarDump::dump`

### Added Extensions
#### PhpFunctionExtension
Add to compilation all php functions.

#### StrExtension
Add to compilation all functions in `Neutrino\Support\Str`.
Called via `str_{func}`

### Added Filters
| filter | do : |
|----------|--------------------------------------|
| `merge` | `array_merge` |
| `split` | `str_split` \ `explode` |
| `slice` | `array_slice` |
| `round` | `round` \ `floor` \ `ceil` |
| `slug` | `Neutrino\Support\Str::slug` |
| `limit` | `Neutrino\Support\Str::limit` |
| `words` | `Neutrino\Support\Str::words` |

### Customize
#### Filters
You can simply add your own filter to volt engine.

First : Create a filter Class :
```php
class MyFilter extends \Neutrino\View\Engines\Volt\Compiler\FilterExtend {

public function compileFilter($resolvedArgs, $exprArgs)
{
return "array_pop($resolvedArgs)";
}
}
```

Then : register your extension in `config\view.php`
```php
// ...
'filters' => [
'pop' => MyFilter::class
]
];
```

#### Functions
You can simply add your own function to volt engine.

First : Create a filter Class :
```php
class MyFunction extends \Neutrino\View\Engines\Volt\Compiler\FunctionExtend{

public function compileFunction($resolvedArgs, $exprArgs)
{
return "str_replace($resolvedArgs)";
}
}
```

Then : register your extension in `config\view.php`
```php
// ...
'functions' => [
'replace' => MyFunction::class
]
];
```

#### Extensions
You can simply add your own extensions to volt engine.

First : Create a extension Class :
```php
class MyExtension extends Neutrino\View\Engines\Volt\Compiler\ExtensionExtend {

public function compileFunction($name, $arguments, $funcArguments) {
// Compile a function
}

public function compileFilter($name, $arguments, $funcArguments) {
// Compile a filter
}

public function resolveExpression($expr) {
// Resolve an expression
}

public function compileStatement($statement) {
// Compile a statement
}
}
```

Then : register your extension in `config\view.php`
```php
// ...
'extensions' => [
MyExtension::class
]
];
```

## Modules (HMVC)
Modules is optional, and only available for the Http Kernels.

Expand Down Expand Up @@ -1060,6 +1164,9 @@ $builder->enableForeignKeyConstraints();
$builder->disableForeignKeyConstraints();
```

# Built-In Server
Use `php quark server:run` to run php built-in server on your application.

# Config and Environment

To work, nucleon, and neutrino, need to have 3 constants defined :
Expand Down
1 change: 1 addition & 0 deletions app/Kernels/Http/Controllers/ControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ControllerBase extends Controller
*/
public function initialize()
{
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}

/**
Expand Down
34 changes: 16 additions & 18 deletions app/Kernels/Http/Controllers/ErrorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@

namespace App\Kernels\Http\Controllers;

use Phalcon\Mvc\View;

/**
* Class ErrorsController
*
* @package App\Kernels\Http\Modules\Frontend\Controllers
*/
class ErrorsController extends ControllerBase
{
public function initialize()
{
$this->assets->addCss('css/bootstrap.min.css');
}

public function indexAction()
{
/* @var \Neutrino\Error\Error $error */
$error = $this->dispatcher->getParam('error');

$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$this->view->error = $error;
$this->response->setStatusCode(500);

$this->view->setTemplateAfter('main');
$this->view->render('errors', 'index');
return $this->view->render('errors', 'http5xx');
}

public function http404Action()
{
$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$this->view->setTemplateAfter('main');
$this->view->render('errors', 'http404');
$this->response->setStatusCode(404);

return $this->view->render('errors', 'http404');
}

public function throwExceptionAction()
{
throw new \Exception('An uncaught exception');
$this->flash->success('success');

trigger_error('notice', E_USER_NOTICE);

trigger_error('warning', E_USER_WARNING);

try {
throw new \Exception('A catched exception');
} catch (\Exception $e) {
throw new \Phalcon\Exception('An uncaught exception', $e->getCode(), $e);
}
}
}
8 changes: 0 additions & 8 deletions app/Kernels/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Kernels\Http\Controllers;

use Phalcon\Mvc\View;

/**
* Class IndexController
*
Expand All @@ -13,12 +11,6 @@ class HomeController extends ControllerBase
{
public function indexAction()
{
$this->tag->setTitle('Nucleon Home');
$this->assets->addCss("css/home.css");
$this->assets->addCss("https://fonts.googleapis.com/css?family=Raleway:100,600");

$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$this->view->setTemplateAfter('main_light');
$this->view->render('home', 'index');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Kernels\Http\Modules\Backend\Controllers;

use Neutrino\Http\Controller;
use Phalcon\Mvc\View;

/**
* Class ControllerBase
Expand All @@ -18,6 +19,6 @@ class ControllerBase extends Controller
*/
public function initialize()
{
$this->assets->addCss('css/bootstrap.min.css');
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

namespace App\Kernels\Http\Modules\Backend\Controllers;

use Phalcon\Mvc\View;

class IndexController extends ControllerBase
{
public function indexAction()
{
$this->tag->setTitle('Nucleon Backend');
$this->assets->addCss("css/home.css");
$this->assets->addCss("https://fonts.googleapis.com/css?family=Raleway:100,600");

$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$this->view->setTemplateAfter('main_light');
$this->view->render('back/index', 'index');
}
}
}
14 changes: 5 additions & 9 deletions app/Kernels/Http/Modules/Frontend/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ protected function onConstruct()
parent::onConstruct();

$this->middleware(GuestMiddleware::class)->except(['logout']);
$this->view->setTemplateAfter('main');
}

/**
Expand All @@ -28,8 +27,6 @@ protected function onConstruct()
*/
public function registerAction()
{
$this->tag->setTitle('Nucleon Register');
$this->view->setTemplateAfter('main');
$this->view->render('front/auth', 'register');
}

Expand Down Expand Up @@ -98,9 +95,9 @@ public function postRegisterAction()
return;
}

$this->flash->success('User create successful !');
$this->flashSession->success('User create successful !');

$this->response->redirect('/');
$this->response->redirect('/index');
$this->view->disable();

return;
Expand All @@ -113,7 +110,6 @@ public function postRegisterAction()
*/
public function loginAction()
{
$this->tag->setTitle('Nucleon Login');
$this->view->render('front/auth', 'login');
}

Expand Down Expand Up @@ -145,10 +141,10 @@ public function postLoginAction()
return;
}

$this->flash->success('Welcome ' . $user->name);
$this->flashSession->success('Welcome ' . $user->name);

// Forward to the 'invoices' controller if the user is valid
$this->response->redirect('/');
$this->response->redirect('/index');
$this->view->disable();

return;
Expand All @@ -158,7 +154,7 @@ public function logoutAction()
{
Auth::logout();

$this->response->redirect('/');
$this->response->redirect('/index');
$this->view->disable();

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ControllerBase extends Controller
*/
public function initialize()
{
$this->assets->addCss('css/bootstrap.min.css');
$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Kernels\Http\Modules\Frontend\Controllers;

use Phalcon\Mvc\View;

/**
* Class IndexController
*
Expand All @@ -13,10 +11,6 @@ class IndexController extends ControllerBase
{
public function indexAction()
{
$this->tag->setTitle('Nucleon Frontend');
$this->assets->addCss("https://fonts.googleapis.com/css?family=Raleway:100,600");
$this->assets->addCss("css/home.css");
$this->view->setTemplateAfter('main_light');
$this->view->render('front/index', 'index');
}
}
Loading

0 comments on commit 07f4b92

Please sign in to comment.