Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

New added operators list #15

Open
ncosmin2001 opened this issue Mar 27, 2014 · 7 comments
Open

New added operators list #15

ncosmin2001 opened this issue Mar 27, 2014 · 7 comments

Comments

@ncosmin2001
Copy link

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')
)
@Hywan Hywan self-assigned this Mar 27, 2014
@ncosmin2001
Copy link
Author

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

@Hywan
Copy link
Member

Hywan commented Mar 27, 2014

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

@ncosmin2001
Copy link
Author

Do you have other suggestion? :)

@Hywan
Copy link
Member

Hywan commented Mar 27, 2014

@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.

@Hywan
Copy link
Member

Hywan commented Apr 6, 2014

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

@stephpy
Copy link
Member

stephpy commented Apr 6, 2014

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 ?

@Hywan
Copy link
Member

Hywan commented Apr 6, 2014

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants