Skip to content

Commit

Permalink
Merge pull request #312 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Migrate to PHP 7.1
  • Loading branch information
Anton committed Nov 16, 2017
2 parents b8b4c0d + 07734d6 commit f01bd23
Show file tree
Hide file tree
Showing 71 changed files with 280 additions and 278 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- master
Expand Down
3 changes: 1 addition & 2 deletions application/layouts/helpers/Username.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function () {
*/
if ($user = Auth::getIdentity()) {
return $user->login;
} else {
return __('Guest');
}
return __('Guest');
};
7 changes: 2 additions & 5 deletions application/layouts/partial/nav-bar.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@
</li>
<?php endif; ?>
</ul>
<div id="loading" data-ajax-loading-show data-ajax-loading-hide></div>
<div id="loading" data-ajax-loading></div>
<span class="navbar-text">
<?php if ($identity = $this->user()) : ?>
<?= __(
'Logged in as %s',
$this->ahref($identity->login, ['users', 'profile'])
) ?>
<?= __('Logged in as %s', $this->ahref($identity->login, ['users', 'profile'])) ?>
(<?= $this->ahref(__('Sign Out'), ['users', 'signout']) ?>)
<?php else: ?>
<?= $this->ahref(__('Sign In'), ['users', 'signin'], ['data-ajax-dialog', 'data-ajax-method' => 'get']) ?>
Expand Down
2 changes: 1 addition & 1 deletion application/layouts/partial/nav-menu.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<?php /** @var \Bluz\Layout\Layout $this */ ?>
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar">
<hr/>
<ul class="nav nav-pills flex-column">
Expand Down
22 changes: 12 additions & 10 deletions application/library/Application/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

use Application\Auth;
use Bluz\Application\Application;
use Bluz\Application\Exception\ForbiddenException;
use Bluz\Auth\AuthException;
use Bluz\Controller\Controller;
use Bluz\Http\Exception\ForbiddenException;
use Bluz\Http\Exception\RedirectException;
use Bluz\Proxy\Auth as AuthProxy;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Logger;
Expand All @@ -36,7 +37,7 @@ class Bootstrap extends Application
/**
* {@inheritdoc}
*/
protected function preProcess()
protected function preProcess() : void
{
parent::preProcess();

Expand All @@ -56,7 +57,7 @@ protected function preProcess()
* @throws \Bluz\Auth\AuthException
* @throws \InvalidArgumentException
*/
protected function preDispatch($controller)
protected function preDispatch($controller) : void
{
// example of setup default title
Layout::title('Bluz Skeleton');
Expand Down Expand Up @@ -84,7 +85,7 @@ protected function preDispatch($controller)
*
* @return \Bluz\Controller\Controller|null
*/
public function forbidden(ForbiddenException $exception)
public function forbidden(ForbiddenException $exception) : ?Controller
{
// for AJAX and API calls (over JSON)
$jsonOrApi = Request::isXmlHttpRequest()
Expand All @@ -97,8 +98,9 @@ public function forbidden(ForbiddenException $exception)
// add error notice
Messages::addError('You don\'t have permissions, please sign in');
// redirect to Sign In page
$url = Router::getUrl('users', 'signin');
return $this->redirect($url);
$redirect = new RedirectException();
$redirect->setUrl(Router::getUrl('users', 'signin'));
return $this->redirect($redirect);
}
return $this->error($exception);
}
Expand All @@ -108,7 +110,7 @@ public function forbidden(ForbiddenException $exception)
*
* @return void
*/
public function render()
public function render() : void
{
Logger::info('app:render');
Logger::info('app:files:' . count(get_included_files()));
Expand All @@ -130,7 +132,7 @@ public function render()
*
* @return void
*/
public function end()
public function end() : void
{
if ($errors = Logger::get('error')) {
$this->sendErrors($errors);
Expand All @@ -142,7 +144,7 @@ public function end()
*
* @return void
*/
protected function sendInfoHeaders()
protected function sendInfoHeaders() : void
{
$debugString = sprintf(
'%fsec; %skb',
Expand All @@ -167,7 +169,7 @@ protected function sendInfoHeaders()
*
* @return void
*/
protected function sendErrors($errors)
protected function sendErrors($errors) : void
{
foreach ($errors as $message) {
errorLog(new \ErrorException($message, 0, E_USER_ERROR));
Expand Down
5 changes: 3 additions & 2 deletions application/models/Auth/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractProvider
* @throws \Application\Exception
* @throws \Bluz\Auth\AuthException
*/
abstract public static function authenticate($token);
abstract public static function authenticate($token) : void;

/**
* Check if supplied cookie is valid
Expand Down Expand Up @@ -60,9 +60,10 @@ abstract public static function create($user) : Row;
* @param integer $id User ID
*
* @return void
* @throws \Bluz\Common\Exception\ConfigurationException
* @throws \Bluz\Db\Exception\DbException
*/
public static function remove($id)
public static function remove($id) : void
{
// clear previous generated Auth record
// works with change password
Expand Down
2 changes: 1 addition & 1 deletion application/models/Auth/Provider/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Cookie extends AbstractProvider
{
const PROVIDER = Table::PROVIDER_COOKIE;

public static function authenticate($token)
public static function authenticate($token) : void
{
$authRow = self::verify($token);
$user = UsersTable::findRow($authRow->userId);
Expand Down
2 changes: 1 addition & 1 deletion application/models/Auth/Provider/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Equals extends AbstractProvider
{
const PROVIDER = Table::PROVIDER_EQUALS;

public static function authenticate($username, $password = '')
public static function authenticate($username, $password = '') : void
{
$authRow = self::verify($username, $password);
$user = UsersTable::findRow($authRow->userId);
Expand Down
2 changes: 1 addition & 1 deletion application/models/Auth/Provider/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Token extends AbstractProvider
{
const PROVIDER = Table::PROVIDER_TOKEN;

public static function authenticate($token)
public static function authenticate($token) : void
{
$authRow = self::verify($token);
$user = UsersTable::findRow($authRow->userId);
Expand Down
14 changes: 5 additions & 9 deletions application/models/Auth/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Application\Auth;

use Bluz\Auth\AbstractRow;
use Bluz\Auth\Model\AbstractRow;

/**
* Auth Row
Expand All @@ -24,21 +24,17 @@
class Row extends AbstractRow
{
/**
* __insert
*
* @return void
* {@inheritdoc}
*/
public function beforeInsert()
public function beforeInsert() : void
{
$this->created = gmdate('Y-m-d H:i:s');
}

/**
* __update
*
* @return void
* {@inheritdoc}
*/
public function beforeUpdate()
public function beforeUpdate() : void
{
$this->updated = gmdate('Y-m-d H:i:s');
}
Expand Down
16 changes: 8 additions & 8 deletions application/models/Auth/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
use Application\Exception;
use Application\Users;
use Bluz\Application;
use Bluz\Auth\AbstractTable;

use Bluz\Auth\AuthException;
use Bluz\Auth\Model\AbstractTable;
use Bluz\Proxy\Auth;
use Bluz\Proxy\Session;

/**
* Auth Table
*
* @package Application\Auth
*
* @method static Row findRow($primaryKey)
* @see \Bluz\Db\Table::findRow()
* @see \Bluz\Db\Table::findRow()
* @method static Row findRowWhere($whereList)
* @see \Bluz\Db\Table::findRowWhere()
* @see \Bluz\Db\Table::findRowWhere()
*
* @author Anton Shevchuk
* @created 12.07.11 15:28
Expand All @@ -39,7 +39,7 @@ class Table extends AbstractTable
* @throws \Application\Exception
* @return string
*/
public static function hash($password)
public static function hash($password) : string
{
$hash = Auth::getInstance()->getOption('hash');

Expand All @@ -58,9 +58,9 @@ public static function hash($password)
* @param string $hash
*
* @throws \Application\Exception
* @return string
* @return bool
*/
public static function verify($password, $hash)
public static function verify($password, $hash) : bool
{
$verify = Auth::getInstance()->getOption('verify');

Expand All @@ -79,7 +79,7 @@ public static function verify($password, $hash)
*
* @throws AuthException
*/
public static function tryLogin($user)
public static function tryLogin($user) : void
{
switch ($user->status) {
case (Users\Table::STATUS_PENDING):
Expand Down
8 changes: 3 additions & 5 deletions application/models/Pages/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Grid extends \Bluz\Grid\Grid
protected $uid = 'pages';

/**
* init
* {@inheritdoc}
*
* @return self
* @throws \Bluz\Grid\GridException
*/
public function init()
public function init() : void
{
// Setup source
$adapter = new SqlSource();
Expand All @@ -37,7 +37,5 @@ public function init()
$this->setDefaultLimit(25);
$this->setAllowOrders(['title', 'id', 'created', 'updated']);
$this->setAllowFilters(['title', 'alias', 'description', 'content', 'id']);

return $this;
}
}
10 changes: 5 additions & 5 deletions application/models/Pages/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Row extends \Bluz\Db\Row
/**
* {@inheritdoc}
*
* @return void
* @throws \Bluz\Validator\Exception\ComponentException
*/
public function beforeSave()
public function beforeSave() : void
{
// title validator
$this->addValidator('title')
Expand Down Expand Up @@ -104,13 +104,13 @@ function ($input) {
*
* @return void
*/
public function beforeInsert()
public function beforeInsert() : void
{
$this->created = gmdate('Y-m-d H:i:s');

/* @var \Application\Users\Row $user */
if ($user = Auth::getIdentity()) {
$this->userId = $user->id;
$this->userId = $user->getId();
} else {
$this->userId = Users\Table::SYSTEM_USER;
}
Expand All @@ -121,7 +121,7 @@ public function beforeInsert()
*
* @return void
*/
public function beforeUpdate()
public function beforeUpdate() : void
{
$this->updated = gmdate('Y-m-d H:i:s');
}
Expand Down
6 changes: 3 additions & 3 deletions application/models/Pages/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Table extends \Bluz\Db\Table
*
* @var array
*/
protected $primary = array('id');
protected $primary = ['id'];

/**
* Get page by Alias
Expand All @@ -41,15 +41,15 @@ class Table extends \Bluz\Db\Table
*/
public function getByAlias($alias)
{
return self::findRowWhere(['alias' => $alias]);
return static::findRowWhere(['alias' => $alias]);
}

/**
* Init table relations
*
* @return void
*/
public function init()
public function init() : void
{
$this->linkTo('userId', 'Users', 'id');
}
Expand Down
10 changes: 5 additions & 5 deletions application/models/Privileges/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
* @package Application\Privileges
*
* @method static Row findRow($primaryKey)
* @method static Row findRowWhere($whereList)
* @method static ?Row findRow($primaryKey)
* @method static ?Row findRowWhere($whereList)
*/
class Table extends \Bluz\Db\Table
{
Expand All @@ -34,7 +34,7 @@ class Table extends \Bluz\Db\Table
*
* @var array
*/
protected $primary = array('roleId', 'module', 'privilege');
protected $primary = ['roleId', 'module', 'privilege'];

/**
* Get all privileges
Expand Down Expand Up @@ -80,7 +80,7 @@ public function getUserPrivileges($userId)
FROM acl_privileges AS p, acl_roles AS r, acl_users_roles AS u2r
WHERE p.roleId = r.id AND r.id = u2r.roleId AND u2r.userId = ?
ORDER BY module, privilege",
array((int) $userId)
[(int) $userId]
);
Cache::set($cacheKey, $data, Cache::TTL_NO_EXPIRY);
Expand All @@ -106,7 +106,7 @@ public function getRolePrivileges($roleId)
FROM acl_privileges AS p, acl_roles AS r
WHERE p.roleId = r.id AND r.id = ?
ORDER BY CONCAT(p.module, ':', p.privilege)",
array((int)$roleId)
[(int)$roleId]
);

Cache::set($cacheKey, $data, Cache::TTL_NO_EXPIRY, ['system', 'roles', 'privileges']);
Expand Down
Loading

0 comments on commit f01bd23

Please sign in to comment.