Skip to content

Commit 59f8ab8

Browse files
Jeckersonsergeyklay
authored andcommitted
[Iteration 5] v4.0-beta (#110)
1 parent 7a88694 commit 59f8ab8

File tree

118 files changed

+1721
-774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1721
-774
lines changed

.ci/install-phalcon.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This file is part of the Phalcon Framework.
4+
#
5+
# (c) Phalcon Team <[email protected]>
6+
#
7+
# For the full copyright and license information, please view the
8+
# LICENSE.txt file that was distributed with this source code.
9+
10+
git clone --depth=1 -v https://github.com/phalcon/cphalcon.git -b ${PHALCON_VERSION:=master} /tmp/phalcon
11+
cd /tmp/phalcon/build
12+
./install --phpize $(phpenv which phpize) --php-config $(phpenv which php-config)

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ MAIL_SMTP_PORT=587
1616
MAIL_SMTP_SECURITY=tls
1717
MAIL_SMTP_USERNAME=
1818
MAIL_SMTP_PASSWORD=
19+
20+
DB_TESTING_ADAPTER=mysql
21+
DB_TESTING_HOST=127.0.0.1
22+
DB_TESTING_NAME=vokuro_test
23+
DB_TESTING_USERNAME=root
24+
DB_TESTING_PASSWORD=
25+
DB_TESTING_PORT=3306
26+
27+
CODECEPTION_URL=127.0.0.1
28+
CODECEPTION_PORT=8888

.htrouter.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Vökuró.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
$uri = urldecode(
13+
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
14+
);
15+
16+
if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) {
17+
return false;
18+
}
19+
20+
$_GET['_url'] = $_SERVER['REQUEST_URI'];
21+
22+
require_once __DIR__ . '/public/index.php';

.travis.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
language: php
2+
3+
php:
4+
- '7.3'
5+
- '7.2'
6+
7+
dist: xenial
8+
9+
services:
10+
- mysql
11+
12+
env:
13+
global:
14+
- PHALCON_VERSION=v4.0.0-beta.2
15+
- DB_NAME=vokuro_test
16+
17+
cache:
18+
timeout: 604800
19+
directories:
20+
- ${HOME}/.composer/cache
21+
22+
before_install:
23+
- |
24+
# Hide "You are in 'detached HEAD' state" message
25+
git config --global advice.detachedHead false
26+
27+
install:
28+
- pecl install --force psr
29+
- .ci/install-phalcon.sh
30+
- echo extension=phalcon.so | tee -a "$(phpenv prefix)/etc/php.ini"
31+
32+
before_script:
33+
- mysql -e 'CREATE DATABASE IF NOT EXISTS vokuro_test CHARSET=utf8 COLLATE=utf8_unicode_ci;'
34+
- php -S 127.0.0.1:8888 -t public/ .htrouter.php &
35+
- travis_retry composer install --no-interaction --no-ansi --no-progress --no-suggest
36+
- cp .env.example .env
37+
38+
script:
39+
- vendor/bin/phinx migrate -e testing
40+
- vendor/bin/phinx seed:run -e testing
41+
- vendor/bin/codecept build --quiet
42+
- vendor/bin/codecept run
43+
- vendor/bin/psalm --show-info=false
44+
45+
notifications:
46+
email: false

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ Please write us if you have any feedback.
77

88
Thanks.
99

10-
## NOTE
11-
12-
The master branch will always contain the latest stable version.
13-
If you wish to check older versions or newer ones currently under development, please switch to the relevant branch.
14-
1510
## Get Started
1611

1712
### Requirements
@@ -24,15 +19,6 @@ To run this application on your machine, you need at least:
2419
* Apache Web Server with `mod_rewrite enabled`, and `AllowOverride Options` (or `All`) in your `httpd.conf` or Nginx Web Server
2520
* Latest [Phalcon Framework](https://github.com/phalcon/cphalcon) extension installed/enabled
2621

27-
Then you'll need to create the database and initialize schema:
28-
29-
```bash
30-
echo 'CREATE DATABASE vokuro' | mysql -u root
31-
cat schemas/vokuro.sql | mysql -u root vokuro
32-
```
33-
34-
Also you can override application config by creating `app/config/config.dev.php` (already gitignored).
35-
3622
### Installing Dependencies via Composer
3723

3824
Vökuró's dependencies must be installed using Composer. Install composer in a common location or in your project:
@@ -45,7 +31,7 @@ Run the composer installer:
4531

4632
```bash
4733
cd vokuro
48-
php composer.phar install
34+
composer install
4935
cp .env.example .env
5036
vendor/bin/phinx migrate
5137
vendor/bin/phinx seed:run
@@ -54,6 +40,11 @@ vendor/bin/phinx seed:run
5440
**NOTE** After the installation, please ensure that the following folders have write permissions set:
5541
- `cache`
5642

43+
## NOTE
44+
45+
The master branch will always contain the latest stable version.
46+
If you wish to check older versions or newer ones currently under development, please switch to the relevant branch.
47+
5748
## Improving this Sample
5849

5950
Phalcon is an open source project and a volunteer effort.

app/Application.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This file is part of the Vökuró.
6+
*
7+
* (c) Phalcon Team <[email protected]>
8+
*
9+
* For the full copyright and license information, please view
10+
* the LICENSE file that was distributed with this source code.
11+
*/
12+
13+
namespace Vokuro;
14+
15+
use Exception;
16+
use Phalcon\Application\AbstractApplication;
17+
use Phalcon\Di\DiInterface;
18+
use Phalcon\Di\FactoryDefault;
19+
use Phalcon\Di\ServiceProviderInterface;
20+
use Phalcon\Mvc\Application as MvcApplication;
21+
22+
/**
23+
* Vökuró Application
24+
*/
25+
class Application
26+
{
27+
const APPLICATION_PROVIDER = 'bootstrap';
28+
29+
/**
30+
* @var AbstractApplication
31+
*/
32+
protected $app;
33+
34+
/**
35+
* @var DiInterface
36+
*/
37+
protected $di;
38+
39+
/**
40+
* Project root path
41+
*
42+
* @var string
43+
*/
44+
protected $rootPath;
45+
46+
/**
47+
* @param string $rootPath
48+
* @throws Exception
49+
*/
50+
public function __construct(string $rootPath)
51+
{
52+
$this->di = new FactoryDefault();
53+
$this->app = $this->createApplication();
54+
$this->rootPath = $rootPath;
55+
56+
$this->di->setShared(self::APPLICATION_PROVIDER, $this);
57+
58+
$this->initializeProviders();
59+
}
60+
61+
/**
62+
* Run Vökuró Application
63+
*
64+
* @return string
65+
* @throws Exception
66+
*/
67+
public function run(): string
68+
{
69+
return (string) $this->app->handle($_SERVER['REQUEST_URI'])->getContent();
70+
}
71+
72+
/**
73+
* Get Project root path
74+
*
75+
* @return string
76+
*/
77+
public function getRootPath(): string
78+
{
79+
return $this->rootPath;
80+
}
81+
82+
/**
83+
* @return AbstractApplication
84+
*/
85+
protected function createApplication(): AbstractApplication
86+
{
87+
return new MvcApplication($this->di);
88+
}
89+
90+
/**
91+
* @throws Exception
92+
*/
93+
protected function initializeProviders(): void
94+
{
95+
$filename = $this->rootPath . '/configs/providers.php';
96+
if (!file_exists($filename) || !is_readable($filename)) {
97+
throw new Exception('File providers.php does not exist or is not readable.');
98+
}
99+
100+
$providers = include_once $filename;
101+
foreach ($providers as $providerClass) {
102+
/** @var ServiceProviderInterface $provider */
103+
$provider = new $providerClass;
104+
$provider->register($this->di);
105+
}
106+
}
107+
}

app/controllers/AboutController.php renamed to app/Controllers/AboutController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file is part of the Vökuró.
56
*
6-
* (c) Phalcon Team <team@phalconphp.com>
7+
* (c) Phalcon Team <team@phalcon.io>
78
*
89
* For the full copyright and license information, please view
910
* the LICENSE file that was distributed with this source code.
@@ -14,12 +15,12 @@
1415
/**
1516
* Display the "About" page.
1617
*/
17-
class AboutController extends ControllerBase
18+
final class AboutController extends ControllerBase
1819
{
1920
/**
2021
* Default action. Set the public layout (layouts/public.volt)
2122
*/
22-
public function indexAction()
23+
public function indexAction(): void
2324
{
2425
$this->view->setVar('logged_in', is_array($this->auth->getIdentity()));
2526
$this->view->setTemplateBefore('public');

app/controllers/ControllerBase.php renamed to app/Controllers/ControllerBase.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file is part of the Vökuró.
56
*
6-
* (c) Phalcon Team <team@phalconphp.com>
7+
* (c) Phalcon Team <team@phalcon.io>
78
*
89
* For the full copyright and license information, please view
910
* the LICENSE file that was distributed with this source code.
@@ -13,12 +14,15 @@
1314

1415
use Phalcon\Mvc\Controller;
1516
use Phalcon\Mvc\Dispatcher;
17+
use Vokuro\Plugins\Acl\Acl;
18+
use Vokuro\Plugins\Auth\Auth;
1619

1720
/**
1821
* ControllerBase
1922
* This is the base controller for all controllers in the application
2023
*
21-
* @property \Vokuro\Auth\Auth auth
24+
* @property Auth auth
25+
* @property Acl acl
2226
*/
2327
class ControllerBase extends Controller
2428
{
@@ -29,9 +33,10 @@ class ControllerBase extends Controller
2933
* @param Dispatcher $dispatcher
3034
* @return boolean
3135
*/
32-
public function beforeExecuteRoute(Dispatcher $dispatcher)
36+
public function beforeExecuteRoute(Dispatcher $dispatcher): bool
3337
{
3438
$controllerName = $dispatcher->getControllerName();
39+
$actionName = $dispatcher->getActionName();
3540

3641
// Only check permissions on private controllers
3742
if ($this->acl->isPrivate($controllerName)) {
@@ -50,7 +55,6 @@ public function beforeExecuteRoute(Dispatcher $dispatcher)
5055
}
5156

5257
// Check if the user have permission to the current option
53-
$actionName = $dispatcher->getActionName();
5458
if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
5559
$this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
5660

@@ -69,5 +73,7 @@ public function beforeExecuteRoute(Dispatcher $dispatcher)
6973
return false;
7074
}
7175
}
76+
77+
return true;
7278
}
7379
}

app/controllers/IndexController.php renamed to app/Controllers/IndexController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file is part of the Vökuró.
56
*
6-
* (c) Phalcon Team <team@phalconphp.com>
7+
* (c) Phalcon Team <team@phalcon.io>
78
*
89
* For the full copyright and license information, please view
910
* the LICENSE file that was distributed with this source code.
@@ -14,12 +15,12 @@
1415
/**
1516
* Display the default index page.
1617
*/
17-
class IndexController extends ControllerBase
18+
final class IndexController extends ControllerBase
1819
{
1920
/**
2021
* Default action. Set the public layout (layouts/public.volt)
2122
*/
22-
public function indexAction()
23+
public function indexAction(): void
2324
{
2425
$this->view->setVar('logged_in', is_array($this->auth->getIdentity()));
2526
$this->view->setTemplateBefore('public');

app/controllers/PermissionsController.php renamed to app/Controllers/PermissionsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
declare(strict_types=1);
23

34
/**
45
* This file is part of the Vökuró.
56
*
6-
* (c) Phalcon Team <team@phalconphp.com>
7+
* (c) Phalcon Team <team@phalcon.io>
78
*
89
* For the full copyright and license information, please view
910
* the LICENSE file that was distributed with this source code.
@@ -17,12 +18,12 @@
1718
/**
1819
* View and define permissions for the various profile levels.
1920
*/
20-
class PermissionsController extends ControllerBase
21+
final class PermissionsController extends ControllerBase
2122
{
2223
/**
2324
* View the permissions for a profile level, and change them if we have a POST.
2425
*/
25-
public function indexAction()
26+
public function indexAction(): void
2627
{
2728
$this->view->setTemplateBefore('private');
2829

0 commit comments

Comments
 (0)