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

Allow external operator use #16

Closed
wants to merge 2 commits into from

Conversation

tophsic
Copy link
Contributor

@tophsic tophsic commented Sep 9, 2013

Allowing to implement specific operators using Ruler API and store them in a specific namespace. Implementation can surely be improved.

Maybe I didn't undersand well how to bring my porcelain :)

@bobthecow
Copy link
Owner

I've been thinking a bit about extensibility, but this isn't exactly the direction I'd take. One question first: are you using PHP 5.4+?

(The way I word my suggestion depends on this answer :))

@tophsic
Copy link
Contributor Author

tophsic commented Sep 9, 2013

For my personal use, I surely answer yes but unfortunately, I also have a job where we always use PHP 5.3 :)

@devantoine
Copy link

I personally love this pull request and find it so useful.

Nowadays there's no way to easily add operators without forking the project, and that's a real problem.

@bobthecow
Copy link
Owner

@tophsic I've cherry-picked this change into a branch made from the current develop:

develop...feature/external-operators

Aside from updating it to match the new class structure and constructor arguments, the one big change I made is that operator namespaces are registered on the RuleBuilder instance, rather than being registered statically on the Variable class.

As a test, I removed all the operator methods from RuleBuilder\Variable and all tests pass:

https://gist.github.com/bobthecow/30e7b9c83897a5f3f30d

Note that for this test I had to make a bunch of operator class aliases so that methods would work as expected (Multiplication -> Multiply, etc).

I'm not completely sold on this implementation, but I think it might be workable.

@jwage @ludicruz @devantoine what do you think?

@bobthecow
Copy link
Owner

And a bonus thing:

brevity

With a fairly simple change:

diff --git a/src/Ruler/Operator/Brevity/Eq.php b/src/Ruler/Operator/Brevity/Eq.php
new file mode 100644
index 0000000..b1aba02
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Eq.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\EqualTo;
+
+class Eq extends EqualTo
+{
+}
diff --git a/src/Ruler/Operator/Brevity/Gt.php b/src/Ruler/Operator/Brevity/Gt.php
new file mode 100644
index 0000000..69981c7
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Gt.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\GreaterThan;
+
+class Gt extends GreaterThan
+{
+}
diff --git a/src/Ruler/Operator/Brevity/Gte.php b/src/Ruler/Operator/Brevity/Gte.php
new file mode 100644
index 0000000..dadba9f
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Gte.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\GreaterThanOrEqualTo;
+
+class Gte extends GreaterThanOrEqualTo
+{
+}
diff --git a/src/Ruler/Operator/Brevity/Lt.php b/src/Ruler/Operator/Brevity/Lt.php
new file mode 100644
index 0000000..aaa02e2
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Lt.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\LessThan;
+
+class Lt extends LessThan
+{
+}
diff --git a/src/Ruler/Operator/Brevity/Lte.php b/src/Ruler/Operator/Brevity/Lte.php
new file mode 100644
index 0000000..74e0d41
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Lte.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\LessThanOrEqualTo;
+
+class Lte extends LessThanOrEqualTo
+{
+}
diff --git a/src/Ruler/Operator/Brevity/Neq.php b/src/Ruler/Operator/Brevity/Neq.php
new file mode 100644
index 0000000..a1d937d
--- /dev/null
+++ b/src/Ruler/Operator/Brevity/Neq.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Ruler\Operator\Brevity;
+
+use Ruler\Operator\NotEqualTo;
+
+class Neq extends NotEqualTo
+{
+}

@bobthecow
Copy link
Owner

Closing this in favor of #30

@bobthecow bobthecow closed this Apr 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants