Skip to content

Commit

Permalink
rules with data and args
Browse files Browse the repository at this point in the history
  • Loading branch information
rafageist committed Dec 13, 2019
1 parent e15cf6c commit fc83147
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Dec 12, 2019
-------------------
- `new`: passing data and args to rules

```php
<?php

ways::rule('is-admin-section', function($data, $args){
return $args['section'] === 'admin';
});

ways::listen("/{section}/login", function(){
echo "admin login";
}, ['rules' => ['is-admin-section']]);

```
- `release`: version 2.4.0

Aug 23, 2019
-------------------
- `fix`: fix flow of the data before bootstrap and invoke
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Div PHP Ways 2.3.3
# Div PHP Ways 2.4.0

A "way" is different to a "route". We need a path for found
a specific resource, but we need a way for do something.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"controllers"
],
"homepage": "https://divengine.com/ways",
"version": "2.3.3",
"version": "2.4.0",
"require": {
"php": ">=5.4.0",
"ext-json": "*"
Expand Down
10 changes: 5 additions & 5 deletions src/ways.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @package divengine/ways
* @author Rafa Rodriguez [@rafageist] <[email protected]>
* @version 2.3.3
* @version 2.4.0
*
* @link https://divengine.com
* @link https://divengine.com/ways
Expand Down Expand Up @@ -57,7 +57,7 @@ class ways

const PROPERTY_RULES = 'rules';

private static $__version = '2.3.3';
private static $__version = '2.4.0';

private static $__way_var;

Expand Down Expand Up @@ -1099,7 +1099,7 @@ public static function call($controller, $data = [], $args = [], &$output = '',
foreach ($rules as $rule) {
$check = true;
if (is_string($rule) && array_key_exists($rule, self::$__rules)) {
$check = self::checkRule($rule);
$check = self::checkRule($rule, $data, $args);
} elseif (is_callable($rule)) {
$check = $rule();
}
Expand Down Expand Up @@ -1734,11 +1734,11 @@ public static function rule($ruleName, $rule)
*
* @return bool
*/
public static function checkRule($ruleName)
public static function checkRule($ruleName, $data, $args)
{
$rule = self::$__rules[$ruleName];

return (bool)$rule();
return (bool) $rule($data, $args);
}

/**
Expand Down

0 comments on commit fc83147

Please sign in to comment.