Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firewall improvement #14450

Merged
merged 14 commits into from Oct 5, 2019
@@ -31,6 +31,9 @@
- Fixed `Phalcon\Http\Message\ServerRequestFactory::load` to correctly detect the protocol passed from `$_SERVER` [#14432](https://github.com/phalcon/cphalcon/issues/14432)
- Fixed `Phalcon\Cli\Router\Route` added missing `Phalcon\Cli\Router\RouteInterface`
- Fixed incorrect return types on `Phalcon\Mvc\View\Engine\AbstractEngine::partial` and `Phalcon\Mvc\View\Engine\EngineInterface::partial` [#14429](https://github.com/phalcon/cphalcon/issues/14429)
- Fixed `Phalcon\Firewall\Adapter\AbstractAdapter::getRoleCallback` and `Phalcon\Firewall\Adapter\AbstractAdapter::setRoleCallback` to correctly accept and return a `Closure` [#14450](https://github.com/phalcon/cphalcon/issues/14450)
- Fixed `Phalcon\Firewall\Adapter\AdapterInterface::getRoleCallback` and `Phalcon\Firewall\Adapter\AbstractAdapter::setRoleCallback` to correctly accept and return a `Closure` [#14450](https://github.com/phalcon/cphalcon/issues/14450)
- Fixed `Phalcon\Events\Event::__constructor` to correctly accept an `object` as the `source` parameter [#14449](https://github.com/phalcon/cphalcon/issues/14449)

## Removed
- Removed `Phalcon\Application\AbstractApplication::handle()` as it does not serve any purpose and causing issues with type hinting. [#14407](https://github.com/phalcon/cphalcon/pull/14407)
@@ -10,11 +10,22 @@

namespace Phalcon\Events;

use Phalcon\Events\Exception;

/**
* Phalcon\Events\Event
*
* This class offers contextual information of a fired event in the
* EventsManager
*
*```php
* Phalcon\Events\Event;
*
* $event = new Event("db:afterQuery", $this, ["data" => "mydata"], true);
* if ($event->isCancelable()) {
* $event->stop();
* }
* ```
*/
class Event implements EventInterface
{
@@ -58,8 +69,13 @@ class Event implements EventInterface
*
* @param object source
*/
public function __construct(string! type, source, var data = null, bool cancelable = true)
public function __construct(string! type, object source, var data = null, bool cancelable = true)
{
if unlikely typeof source != "object" {
throw new Exception(
"The source of " . type . " event must be an object, got " . (typeof source)
);
}
let this->type = type,
this->source = source,
this->data = data,
@@ -131,11 +131,8 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
/**
* Sets role callback to fetch role name
*/
public function setRoleCallback(var callback) -> <AdapterInterface>
public function setRoleCallback(<Closure> callback) -> <AdapterInterface>
{
if !is_callable(callback) {
throw new Exception("Role callback must be function.");
}
let this->roleCallback = callback;

return this;
@@ -153,16 +150,27 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
{
var roleCallback, identity;

let roleCallback = this->roleCallback,
identity = {roleCallback}(container);
let roleCallback = this->roleCallback;

if unlikely !roleCallback {
throw new Exception(
"You must set the roleCallback"
);
}

let identity = {roleCallback}(container);

if empty identity {
throw new Exception("Function defined as roleCallback must return something.");
throw new Exception(
"Function defined as roleCallback must return something."
);
}

if typeof identity == "object" {
if !(identity instanceof RoleAware) {
throw new Exception("Role passed as object must implement 'Phalcon\\Acl\\RoleAware'");
throw new Exception(
"Role passed as object must implement 'Phalcon\\Acl\\RoleAware'"
);
}
let this->activeIdentity = identity,
this->activeRole = identity->getRoleName();
@@ -10,6 +10,7 @@

namespace Phalcon\Firewall\Adapter;

use Closure;
use Phalcon\Mvc\DispatcherInterface;
use Phalcon\Cache\Adapter\AdapterInterface as CacheAdapterInterface;

@@ -26,7 +27,7 @@ interface AdapterInterface
/**
* Gets role callback to fetch role name
*/
public function getRoleCallback();
public function getRoleCallback() -> <Closure>;

/**
* Gets always resolving role option
@@ -51,5 +52,5 @@ interface AdapterInterface
/**
* Sets role callback to fetch role name
*/
public function setRoleCallback(var callback) -> <AdapterInterface>;
public function setRoleCallback(<Closure> callback) -> <AdapterInterface>;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.