diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index 5c20761..0fb0e47 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -12,13 +12,6 @@ use App\Controller\ControllerBase, class AuthController extends ControllerBase { - public function initialize() - { - // We need event manager here from DI. - $eventManager = $this->di->get('eventsManager'); - $this->setEventsManager($eventManager); - } - public function indexAction() { $form = new LoginForm(); @@ -74,7 +67,7 @@ class AuthController extends ControllerBase $user->{'set' . $name . 'Id'}($data->getId()); $user->save(); - $this->getEventsManager()->fire('user:onOAuthConnected', $user, $data); + $this->eventsManager->fire('user:onOAuthConnected', $user, $data); $this->flash->message('success', sprintf("OAuth provider %s was connected!", $name)); $this->response->redirect('/settings'); diff --git a/app/controllers/CallbackController.php b/app/controllers/CallbackController.php index 64354d1..83376ee 100644 --- a/app/controllers/CallbackController.php +++ b/app/controllers/CallbackController.php @@ -25,11 +25,11 @@ class CallbackController extends ControllerBase { $paginator = CallbackModel::getPaginationList($this->_user->getId(), $page, 10); - if ($paginator->getPaginate()->current > $paginator->getPaginate()->total_pages) { + if ($paginator->paginate()->current > $paginator->paginate()->last) { $paginator->setCurrentPage(1); } - $this->view->page = $paginator->getPaginate(); + $this->view->page = $paginator->paginate(); $this->view->pagination_url = '/callback/list/'; } @@ -111,7 +111,7 @@ class CallbackController extends ControllerBase $paginator = $callback->getRequestPaginator($page, 30); $this->view->item = $callback; - $this->view->page = $paginator->getPaginate(); + $this->view->page = $paginator->paginate(); $this->view->pagination_url = '/callback/show/' . $id . '/'; } } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 436f35e..3439c00 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -10,13 +10,6 @@ use App\Controller\ControllerBase, class UserController extends ControllerBase { - public function initialize() - { - // We need event manager here from DI. - $eventManager = $this->di->get('eventsManager'); - $this->setEventsManager($eventManager); - } - public function settingsAction() { $user = $this->_getAuth()->getUser(); @@ -112,7 +105,7 @@ class UserController extends ControllerBase $paginator = ActivityLog::getPaginationList($user->getId(), $page); - $this->view->page = $paginator->getPaginate(); + $this->view->page = $paginator->pageinate(); $this->view->pagination_url = '/user/activity/'; } @@ -156,7 +149,7 @@ class UserController extends ControllerBase $user->{'set' . $provider . 'Id'}(null); $user->save(); - $this->getEventsManager()->fire('user:onOAuthDisconnect', $user, $provider); + $this->eventsManager->fire('user:onOAuthDisconnect', $user, $provider); $this->flash->message('success', "
{$provider} was disconnected
"); diff --git a/app/controllers/backend/LogController.php b/app/controllers/backend/LogController.php index dcbe8fb..df0dba9 100644 --- a/app/controllers/backend/LogController.php +++ b/app/controllers/backend/LogController.php @@ -15,7 +15,7 @@ class LogController extends \Phalcon\Mvc\Controller { $paginator = ActivityLog::getAllPaginationList($page); - $this->view->page = $paginator->getPaginate(); + $this->view->page = $paginator->paginate(); $this->view->pagination_url = '/admin/log/'; } } diff --git a/app/controllers/backend/UserController.php b/app/controllers/backend/UserController.php index bde79ac..0bea10c 100644 --- a/app/controllers/backend/UserController.php +++ b/app/controllers/backend/UserController.php @@ -19,6 +19,6 @@ class UserController extends \Phalcon\Mvc\Controller $paginator = User::getPaginationList($page,15); $this->view->pagination_url = '/admin/user/list/'; - $this->view->page = $paginator->getPaginate(); + $this->view->page = $paginator->paginate(); } } diff --git a/app/forms/Registration.php b/app/forms/Registration.php index 33cad4c..9e8d292 100644 --- a/app/forms/Registration.php +++ b/app/forms/Registration.php @@ -10,8 +10,7 @@ use App\Model\Data\User; /** * Phalcon Form */ -use Httpcb\Form as FormBase, - Phalcon\Forms\Element as FormElement; +use Httpcb\Form as FormBase; /** * Element types diff --git a/app/forms/UserSettings.php b/app/forms/UserSettings.php index c003f67..91c022a 100644 --- a/app/forms/UserSettings.php +++ b/app/forms/UserSettings.php @@ -11,7 +11,7 @@ use App\Model\Data\User as UserModel; * Phalcon Form */ use Phalcon\Forms\Form as FormBase, - Phalcon\Forms\Element as FormElement; + Phalcon\Forms\Element\AbstractElement; /** * Element types @@ -210,7 +210,7 @@ class UserSettings extends FormBase return $this->_render($ele, $options); } - protected function _render(FormElement $ele, $opt) + protected function _render(AbstractElement $ele, $opt) { $xhtml = ''; diff --git a/app/library/Acl.php b/app/library/Acl.php index f00ac8c..cfaada1 100644 --- a/app/library/Acl.php +++ b/app/library/Acl.php @@ -3,6 +3,7 @@ namespace Httpcb; use Phalcon\Config, + Phalcon\Acl\Enum, Phalcon\Acl\Role, Phalcon\Acl\Adapter\Memory as Adapter; @@ -21,7 +22,7 @@ class Acl $this->_adapter = new Adapter(); // Deny access to everything by default. - $this->_adapter->setDefaultAction(\Phalcon\Acl::DENY); + $this->_adapter->setDefaultAction(Enum::DENY); $this->fromConfig($config); } @@ -46,7 +47,7 @@ class Acl $resource = $wildcard; } } - return $this->_adapter->isAllowed($role, $resource, 'All') == \Phalcon\Acl::ALLOW; + return $this->_adapter->isAllowed($role, $resource, 'All') == Enum::ALLOW; } /** @@ -55,7 +56,7 @@ class Acl */ public function hasResource($resource) { - return $this->_adapter->isResource($resource); + return $this->_adapter->isComponent($resource); } public function fromConfig(Config $config) @@ -84,7 +85,7 @@ class Acl } foreach($resources as $resource) { - $this->_adapter->addResource($resource, 'All'); + $this->_adapter->addComponent($resource, 'All'); } } @@ -98,9 +99,12 @@ class Acl } foreach($zones as $zone) { - $resources = (array) $config->zones->get($zone); + $resources = $config->zones->get($zone); + if (!($resources instanceof Config)) { + $resources = new Config([ $resources ]); + } foreach($resources as $resource) { - $this->_adapter->allow($name, $resource, 'All'); + $this->_adapter->allow($name, $resource, 'All'); } } } diff --git a/app/library/Auth.php b/app/library/Auth.php index ade7a70..7c837d0 100644 --- a/app/library/Auth.php +++ b/app/library/Auth.php @@ -5,9 +5,9 @@ namespace Httpcb; use App\Model\Data\User, Httpcb\OAuth\UserData\UserDataInterface, Httpcb\Auth\Result, - Phalcon\Mvc\User\Component; + Phalcon\Di\Injectable; -class Auth extends Component +class Auth extends Injectable { const SESSION_KEY = 'auth'; diff --git a/app/library/Bootstrap.php b/app/library/Bootstrap.php index d1eaa63..86b89cd 100644 --- a/app/library/Bootstrap.php +++ b/app/library/Bootstrap.php @@ -4,7 +4,7 @@ namespace Httpcb; use Phalcon\Di\FactoryDefault as DiDefault; use Phalcon\Di\Injectable; -use Phalcon\DiInterface; +use Phalcon\Di\DiInterface; use Phalcon\Mvc\Application; class Bootstrap extends Injectable @@ -54,12 +54,16 @@ class Bootstrap extends Injectable /** * Runs the application. - * - * @return string */ - public function run() + public function run($uri) { $this->_app->setDI($this->getDI()); - return $this->_app->handle()->getContent(); + + try { + $response = $this->_app->handle($uri); + $response->send(); + } catch(\Exception $ex) { + echo $ex->getMessage(); + } } } diff --git a/app/library/Mvc/Model/Behavior/RandomId.php b/app/library/Mvc/Model/Behavior/RandomId.php index 93d3c2a..185c188 100644 --- a/app/library/Mvc/Model/Behavior/RandomId.php +++ b/app/library/Mvc/Model/Behavior/RandomId.php @@ -57,11 +57,11 @@ class RandomId extends Behavior implements BehaviorInterface */ public function generateId(\Phalcon\Mvc\ModelInterface $model) { - $field = $this->_options['field']; - $len = $this->_options['length']; + $field = $this->options['field']; + $len = $this->options['length']; - if (isset($this->_options['expression'])) { - $expr = 'AND ' . $this->_options['expression']; + if (isset($this->options['expression'])) { + $expr = 'AND ' . $this->options['expression']; } else { $expr = ''; } diff --git a/app/library/Services.php b/app/library/Services.php index a6157f5..470623e 100644 --- a/app/library/Services.php +++ b/app/library/Services.php @@ -2,23 +2,21 @@ namespace Httpcb; -use Phalcon\DiInterface, - Phalcon\Di\FactoryDefault as DiDefault, +use Phalcon\Di\FactoryDefault as DiDefault, Phalcon\Config\Adapter\Yaml as Config, Phalcon\Mvc\View, Phalcon\Mvc\View\Simple as SimpleView, Phalcon\Assets\Manager as AssetsManager, - Phalcon\Mvc\Url as UrlResolver, + Phalcon\Url as UrlResolver, Phalcon\Mvc\View\Engine\Volt as VoltEngine, Phalcon\Flash\Direct as FlashDirect, Phalcon\Mvc\Model\Metadata\Memory as MemoryMetaData, Phalcon\Mvc\Model\MetaData\Apc as ApcMetaData, + Phalcon\Mvc\ViewBaseInterface, Phalcon\Cache\Frontend\Data as FrontendDataCache, Phalcon\Cache\Backend\Apc as BackendApcCache, Phalcon\Translate\Adapter\NativeArray as TranslateAdapter, Phalcon\Logger, - Phalcon\Logger\Adapter\File as FileLogAdapter, - Phalcon\Session\Adapter\Files as SessionAdapter, Phalcon\Mvc\Router; use Httpcb\Auth, @@ -155,7 +153,7 @@ class Services extends DiDefault $eventsManager->attach('db', function ($event, $connection) use ($logger) { if ($event->getType() == 'beforeQuery') { - $logger->log($connection->getRealSQLStatement(), Logger::INFO); + $logger->info($connection->getRealSQLStatement()); } }); @@ -190,25 +188,23 @@ class Services extends DiDefault protected function _initSession() { $config = $this->get('config'); + $session = new \Phalcon\Session\Manager(); if (isset($config->session)) { $data = $config->session->toArray(); - $adapter = isset($data['adapter']) ? $data['adapter'] : 'Files'; + $adapter_name = isset($data['adapter']) ? $data['adapter'] : 'Stream'; $options = $data['options']; - // For "Files": Set session path if defined. - if ($adapter === 'Files' && isset($options['path'])) { - session_save_path($config->application->path); - } - - $class = 'Phalcon\Session\Adapter\\' . $adapter; - $session = new $class($options); + $class = 'Phalcon\Session\Adapter\\' . $adapter_name; + $adapter = new $class($options); } - // Default to File storage + // Default to Stream else { - $session = new \Phalcon\Session\Adapter\Files(); + $adapter = new \Phalcon\Session\Adapter\Stream(); } + $session->setAdapter($adapter); + // Start session. $session->start(); return $session; @@ -228,23 +224,23 @@ class Services extends DiDefault $view->setPartialsDir('_partials/'); $view->registerEngines(array( - '.volt' => function ($view, $di) use ($config) { + '.volt' => function (ViewBaseInterface $view) use ($config) { - $volt = new VoltEngine($view, $di); + $volt = new VoltEngine($view, $this); $volt->setOptions(array( - 'compiledPath' => $config->application->viewCacheDir, - 'compiledSeparator' => '_', - 'compileAlways' => true, + 'path' => $config->application->viewCacheDir, + 'separator' => '_', + 'always' => true, )); // Register view helpers $compiler = $volt->getCompiler(); - $compiler->addExtension(new ViewHelperVoltExtension($di)); + $compiler->addExtension(new ViewHelperVoltExtension($this)); return $volt; }, - '.phtml' => 'Phalcon\Mvc\View\Engine\Php' + '.phtml' => \Phalcon\Mvc\View\Engine\Php::class )); // Set default main layout. @@ -347,9 +343,7 @@ class Services extends DiDefault protected function _initAuth() { - $auth = new Auth($this->get('config')); - $auth->setEventsManager($this->get('eventsManager')); - return $auth; + return new Auth($this->get('config')); } protected function _initAcl() @@ -359,8 +353,10 @@ class Services extends DiDefault protected function _initSharedLogger() { - $path = $this->get('config')->application->logDir; - return new FileLogAdapter($path . "app.txt"); + $path = $this->get('config')->application->logDir; + return new \Phalcon\Logger('default', [ + 'main' => new \Phalcon\Logger\Adapter\Stream($path . 'app.txt') + ]); } protected function _initTemplate() @@ -370,17 +366,17 @@ class Services extends DiDefault $view = new SimpleView(); $view->setViewsDir($config->application->templateDir); $view->registerEngines([ - '.volt' => function ($view, $di) use ($config) { - $volt = new VoltEngine($view, $di); + '.volt' => function (ViewBaseInterface $view) use ($config) { + $volt = new VoltEngine($view, $this); $volt->setOptions(array( - 'compiledPath' => $config->application->viewCacheDir, - 'compiledSeparator' => '_', + 'path' => $config->application->viewCacheDir, + 'separator' => '_', )); return $volt; }, - '.phtml' => 'Phalcon\Mvc\View\Engine\Php' + '.phtml' => \Phalcon\Mvc\View\Engine\Php::class, ]); return $view; } diff --git a/app/library/Validation/Validator/Alpha.php b/app/library/Validation/Validator/Alpha.php index b15cd0d..540766f 100644 --- a/app/library/Validation/Validator/Alpha.php +++ b/app/library/Validation/Validator/Alpha.php @@ -3,7 +3,7 @@ namespace Httpcb\Validation\Validator; use Phalcon\Validation\Message; -use Phalcon\Validation\Validator as BaseValidator; +use Phalcon\Validation\AbstractValidator; /** * The same as the default Alpha validator shipped with phalcon. @@ -12,16 +12,16 @@ use Phalcon\Validation\Validator as BaseValidator; * * @package Validation\Validator */ -class Alpha extends BaseValidator +class Alpha extends AbstractValidator { /** * Executes the validation * * @param mixed $validation - * @param string $attribute + * @param string $field * @return bool */ - public function validate(\Phalcon\Validation $validation, $attribute) + public function validate(\Phalcon\Validation $validation, $field) : bool { $allowSpace = $this->getOption('allowSpace', false); @@ -30,13 +30,13 @@ class Alpha extends BaseValidator $charlist .= '[:space:]'; } - $value = $validation->getValue($attribute); + $value = $validation->getValue($field); if (preg_match("/[^{$charlist}]/imu", $value)) { $label = $this->getOption('label'); if (empty($label)) { - $label = $validation->getLabel($attribute); + $label = $validation->getLabel($field); } $message = $this->getOption('message'); @@ -48,12 +48,12 @@ class Alpha extends BaseValidator $code = $this->getOption("code"); if (is_array($code)) { - $code = $code[$attribute]; + $code = $code[$field]; } $message = str_replace(array_keys($replace), $replace, $message); - $msg = new Message($message, $attribute, "Alpha", $code); + $msg = new Message($message, $field, "Alpha", $code); $validation->appendMessage($msg); return false; diff --git a/app/library/ViewHelper/AbstractHelper.php b/app/library/ViewHelper/AbstractHelper.php index 916f4a2..ff5fe01 100644 --- a/app/library/ViewHelper/AbstractHelper.php +++ b/app/library/ViewHelper/AbstractHelper.php @@ -2,7 +2,7 @@ namespace Httpcb\ViewHelper; -use Phalcon\DiInterface; +use Phalcon\Di\DiInterface; use Phalcon\Di\InjectionAwareInterface; abstract class AbstractHelper implements InjectionAwareInterface @@ -12,19 +12,19 @@ abstract class AbstractHelper implements InjectionAwareInterface /** * Sets the dependency injector * - * @param mixed $dependencyInjector + * @param DiInterface $container */ - public function setDI(DiInterface $dependencyInjector) + public function setDI(DiInterface $container) : void { - $this->_di = $dependencyInjector; + $this->_di = $container; } /** * Returns the internal dependency injector * - * @return \Phalcon\DiInterface + * @return DiInterface */ - public function getDI() + public function getDI() : DiInterface { return $this->_di; } diff --git a/app/library/ViewHelper/Service.php b/app/library/ViewHelper/Service.php index 2a11d2b..1e20f72 100644 --- a/app/library/ViewHelper/Service.php +++ b/app/library/ViewHelper/Service.php @@ -2,7 +2,7 @@ namespace Httpcb\ViewHelper; -use Phalcon\DiInterface, +use Phalcon\Di\DiInterface, Phalcon\Di\InjectionAwareInterface; class Service implements InjectionAwareInterface @@ -14,19 +14,19 @@ class Service implements InjectionAwareInterface /** * Sets the dependency injector * - * @param mixed $dependencyInjector + * @param DiInterface $container */ - public function setDI(DiInterface $dependencyInjector) + public function setDI(DiInterface $container) : void { - $this->_di = $dependencyInjector; + $this->_di = $container; } /** * Returns the internal dependency injector * - * @return \Phalcon\DiInterface + * @return DiInterface */ - public function getDI() + public function getDI() : DiInterface { return $this->_di; } diff --git a/app/library/ViewHelper/Volt/Extension.php b/app/library/ViewHelper/Volt/Extension.php index c9f4550..b38eb34 100644 --- a/app/library/ViewHelper/Volt/Extension.php +++ b/app/library/ViewHelper/Volt/Extension.php @@ -2,7 +2,7 @@ namespace Httpcb\ViewHelper\Volt; -use Phalcon\DiInterface, +use Phalcon\Di\DiInterface, Phalcon\Di\InjectionAwareInterface; class Extension implements InjectionAwareInterface @@ -38,19 +38,19 @@ class Extension implements InjectionAwareInterface /** * Sets the dependency injector * - * @param mixed $dependencyInjector + * @param DiInterface $container */ - public function setDI(DiInterface $dependencyInjector) + public function setDI(DiInterface $container) : void { - $this->_di = $dependencyInjector; + $this->_di = $container; } /** * Returns the internal dependency injector * - * @return \Phalcon\DiInterface + * @return DiInterface */ - public function getDI() + public function getDI() : DiInterface { return $this->_di; } diff --git a/app/listeners/AccessListener.php b/app/listeners/AccessListener.php index e51301c..4f6099a 100644 --- a/app/listeners/AccessListener.php +++ b/app/listeners/AccessListener.php @@ -2,14 +2,14 @@ namespace App\Listener; -use Phalcon\Events\Event, +use Phalcon\Di\Injectable, + Phalcon\Events\Event, Phalcon\Mvc\Dispatcher, - Phalcon\Mvc\User\Plugin, Phalcon\Mvc\Dispatcher\Exception as DispatcherException; use Httpcb\Acl; -class AccessListener extends Plugin +class AccessListener extends Injectable { protected $_ignored_resources = [ 'index', diff --git a/app/listeners/ActivityLog.php b/app/listeners/ActivityLog.php index f7f281e..6bd6a66 100644 --- a/app/listeners/ActivityLog.php +++ b/app/listeners/ActivityLog.php @@ -2,20 +2,15 @@ namespace App\Listener; -use Phalcon\Mvc\User\Plugin, +use Phalcon\Di\Injectable, Phalcon\Events\Event, App\Model\Data\User, App\Model\Data\ActivityLog as ActivityLogger, Httpcb\OAuth\UserData\UserDataInterface as OAuthUserDataInterface, Httpcb\Auth; -class ActivityLog extends Plugin +class ActivityLog extends Injectable { - /** - * @var ActivityLogger - */ - protected $_table = null; - /** * On login event. * @@ -74,20 +69,10 @@ class ActivityLog extends Plugin { $ip = (new \Phalcon\Http\Request())->getClientAddress(); - $data = [ + return (new ActivityLogger())->assign([ 'user_id' => $user->getId(), 'ip' => $ip, 'message' => $message - ]; - - return $this->_getLogger()->create($data); - } - - protected function _getLogger() - { - if ($this->_table === null) { - $this->_table = new ActivityLogger(); - } - return $this->_table; + ])->create(); } } diff --git a/app/listeners/DispatchListener.php b/app/listeners/DispatchListener.php index 1cd9ff1..650c4e3 100644 --- a/app/listeners/DispatchListener.php +++ b/app/listeners/DispatchListener.php @@ -4,7 +4,7 @@ namespace App\Listener; use Exception, Phalcon\Events\Event, - Phalcon\Mvc\User\Plugin, + Phalcon\Di\Injectable, Phalcon\Mvc\Dispatcher, Phalcon\Mvc\Dispatcher\Exception as DispatcherException; @@ -14,7 +14,7 @@ use Exception, * Plugin for forwarding user to 404 (not found) page * if a request could not be dispatched. */ -class DispatchListener extends Plugin +class DispatchListener extends Injectable { protected $_route_notfound = array( 'controller' => 'error', diff --git a/app/models/Data/Base.php b/app/models/Data/Base.php index 59a92be..ed81300 100644 --- a/app/models/Data/Base.php +++ b/app/models/Data/Base.php @@ -18,7 +18,7 @@ class Base extends Model * @param boolean $allFields * @return bool */ - public function hasChanged($fieldName = null, $allFields = false) + public function hasChanged($fieldName = null, bool $allFields = false) : bool { return $this->hasSnapshotData() === false || parent::hasChanged($fieldName, $allFields); diff --git a/app/models/Data/Callback.php b/app/models/Data/Callback.php index e739302..d28c44d 100644 --- a/app/models/Data/Callback.php +++ b/app/models/Data/Callback.php @@ -216,6 +216,9 @@ class Callback extends Model */ public function initialize() { + // Set table name mapped in the model. + $this->setSource('callback'); + $this->useDynamicUpdate(true); $this->hasMany('id', RequestMeta::class, 'callbackid', array('foreignKey' => true, 'alias' => 'Requests')); @@ -227,16 +230,6 @@ class Callback extends Model ))); } - /** - * Returns table name mapped in the model. - * - * @return string - */ - public function getSource() - { - return 'callback'; - } - public function getRequestPaginator($page = 1, $limit = 30) { return RequestMeta::getPaginator($this, $page, $limit); diff --git a/app/modules/Base.php b/app/modules/Base.php index 85e1c69..2e2b5a3 100644 --- a/app/modules/Base.php +++ b/app/modules/Base.php @@ -3,7 +3,7 @@ namespace App\Module; use Phalcon\Loader, - Phalcon\DiInterface, + Phalcon\Di\DiInterface, Phalcon\Mvc\Dispatcher, Phalcon\Mvc\ModuleDefinitionInterface; diff --git a/app/views/_common/_partials/pagination.volt b/app/views/_common/_partials/pagination.volt index 4720288..1dd6644 100644 --- a/app/views/_common/_partials/pagination.volt +++ b/app/views/_common/_partials/pagination.volt @@ -9,19 +9,19 @@ {% set pagination_slider = 3 %} -{% if (page.total_pages > 1) %} +{% if (page.last > 1) %}