From a4642d17e0e1ea018b128efdcc3db281461458b1 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Wed, 4 Apr 2018 15:21:13 -0700 Subject: Move custom libs to the source tree --- libs/SimpleValidator/Validators/Exists.php | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libs/SimpleValidator/Validators/Exists.php (limited to 'libs/SimpleValidator/Validators/Exists.php') diff --git a/libs/SimpleValidator/Validators/Exists.php b/libs/SimpleValidator/Validators/Exists.php new file mode 100644 index 00000000..1998e673 --- /dev/null +++ b/libs/SimpleValidator/Validators/Exists.php @@ -0,0 +1,38 @@ +pdo = $pdo; + $this->table = $table; + $this->key = $key; + } + + + public function execute(array $data) + { + if (! $this->isFieldNotEmpty($data)) { + return true; + } + + if ($this->key === '') { + $this->key = $this->field; + } + + $rq = $this->pdo->prepare('SELECT 1 FROM '.$this->table.' WHERE '.$this->key.'=?'); + $rq->execute(array($data[$this->field])); + + return $rq->fetchColumn() == 1; + } +} -- cgit v1.2.3