hoaproject/Ruler

New added operators list

ncosmin2001 opened this issue · 7 comments

It would be nice if we had a list of new added operators if is the case

For example for the rule :

$rule = 'isConnection(user1,user2) and group in ("customer", "guest") and points > 30';

will return something like

array(
'operator' => isConnection,
'context' => array ('user1', 'user2')
)

how about

protected static $_extraOperators = array();

    public static function addExtraOperators($op) {
        array_push(self::$_extraOperators, $op);
    }

    public function getExtraOperators() {
        return self::$_extraOperators;
    }

in Ruler class and

public function _operator ( $name, Array $arguments, $isFunction ) {

        $operator = new Operator(mb_strtolower($name), $arguments, $isFunction);

        if ($isFunction) {
            $newOperator['method'] = $operator->getName();
            $newOperator['context'] = array();
            foreach ($operator->getArguments() as $context) {
                array_push($newOperator['context'], $context->getId());
            }
            \Hoa\Ruler\Ruler::addExtraOperators($newOperator);
        }

        return $operator;
    }

in Model

Operators are held by the asserter, not the model :-). The model only holds “abstract” operators.

Do you have other suggestion? :)

@ncosmin2001 The only solution I'm thinking about is to create a protected method to add operators. This protect method will only add default operator. And we create a new public method to add operators. This public one will call the protected one but it will also copy the name of newly added opeartors in a specific array. Of course, on the asserter.

What about letting the user do it by itself (with a simple array_diff on two results of getOperators)?

Hi, i'm sorry but i'm not sure to understand what you are talking about.

You would like to be able to easily add new one operators ? or this is related to #13 and you would like to know which operators are used into a rule ?

@stephpy: Nop. Just to know what operators have been added. But knowing all the operators in used is a much better idea I think!