Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Allow invokable classes as predicate (solves #270) #272

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

heyphilllie
Copy link

This PR solves #270 .
Predicates can now created from an invokable class. Like closures, the new predicates should directly added to the Select, Where or Update instance.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple and clean: review comments are just about improvements

@@ -78,7 +78,7 @@ public function addPredicates($predicates, $combination = self::OP_AND)
$this->addPredicate($predicates, $combination);
return $this;
}
if ($predicates instanceof \Closure) {
if ($predicates instanceof \Closure || is_callable($predicates)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to \is_callable($predicates)


class WhereInvokable
{
private $value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docblock

$this->value = $value;
}

public function __invoke($select)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a type declaration to $select

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is also used for Delete and Update test cases. If I add the declaration the UnitTest will fail, because an instance of Update and Delete is injected into the function.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@I3ekka I've not read the code but I usually solve 'multi-type' by introducing an interface(with or without methods). If this commends totally misses the point, ignore it :P

* WhereInvokable constructor.
* @param $value
*/
public function __construct($value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a type declaration to $value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not add the type declaration because the composer.json says this module is still on php 5.5. If this is an outdated information, I'll add the type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, weird that it is still on 5.5. develop should be on 7.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, also travis runs with an old configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@I3ekka we are going to support PHP 5.6+ with zend-db 2.9.0. We'll move to PHP 7.1 with zend-db 3.0.0

@mwillbanks
Copy link
Contributor

@Ocramius the status of this one is hard... do we have someone willing to update this library for PHP 7? Or at a minimum get the travis and composer config moving in the right direction?

@Ocramius
Copy link
Member

IMO we should hold back new features until 7.1 is the minimum version. Everything we add without explicit type declarations will just come back like a boomerang.

@ezimuel ezimuel added this to the 3.0.0 milestone Nov 23, 2017
@ezimuel
Copy link
Contributor

ezimuel commented Nov 23, 2017

@Ocramius I tagged this as 3.0 release.

@baileylo
Copy link

baileylo commented Feb 5, 2018

@Ocramius I was wondering if you could go into detail how explicit type declarations would help in this situation or conversely if there is any foreseeable boomerang?

@weierophinney
Copy link
Member

This repository has been moved to laminas/laminas-db. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone laminas/laminas-db to another directory.
  • Copy the files from the second bullet point to the clone of laminas/laminas-db.
  • In your clone of laminas/laminas-db, commit the files, push to your fork, and open the new PR.
    We will be providing tooling via laminas/laminas-migration soon to help automate the process.

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#62.

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

Successfully merging this pull request may close these issues.

8 participants