Skip to content

Commit c8c89d5

Browse files
committed
Code simplification: remove the AbstractInjector class as its code was so simple that it was meaningful to directly implement it in each injector.
So now `PDOPlusPlus` is a standalone class with no other dependency
1 parent 8794a07 commit c8c89d5

File tree

2 files changed

+45
-60
lines changed

2 files changed

+45
-60
lines changed

AbstractInjector.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

PDOPlusPlus.php

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
namespace rawsrc\PDOPlusPlus;
44

5-
include_once 'AbstractInjector.php';
6-
7-
use InvalidArgumentException;
8-
use rawsrc\PDOPlusPlus\AbstractInjector;
9-
105
use BadMethodCallException;
116
use Closure;
127
use Exception;
8+
use InvalidArgumentException;
139
use PDO;
1410
use PDOException;
1511
use PDOStatement;
@@ -545,12 +541,17 @@ protected function execTransaction(string $sql, string $func_name)
545541
* Plain escaped SQL value
546542
* Possible types: int str float double num numeric bool binary
547543
*
548-
* @return AbstractInjector
544+
* @return object
549545
* @throws TypeError
550546
*/
551-
public function getInjectorIn(): AbstractInjector
547+
public function getInjectorIn(): object
552548
{
553-
return new class($this->data) extends AbstractInjector {
549+
return new class($this->data) {
550+
/**
551+
* @param array $data
552+
*/
553+
public function __construct(protected array &$data) { }
554+
554555
/**
555556
* @param mixed $value
556557
* @param string $type among: int str float bool binary bigint
@@ -579,11 +580,15 @@ public function __invoke(mixed $value, string $type = 'str'): string
579580
* Plain escaped SQL values passed by reference
580581
* Possible types: int str float double num numeric bool binary
581582
*
582-
* @return AbstractInjector
583+
* @return object
583584
*/
584-
public function getInjectorInAsRef(): AbstractInjector
585+
public function getInjectorInAsRef(): object
585586
{
586-
return new class($this->data) extends AbstractInjector {
587+
return new class($this->data) {
588+
/**
589+
* @param array $data
590+
*/
591+
public function __construct(protected array &$data) { }
587592
/**
588593
* @param mixed $value
589594
* @param string $type among: int str float bool binary bigint
@@ -607,11 +612,15 @@ public function __invoke(mixed &$value, string $type = 'str'): string
607612
* Injector for values using a statement with ->bindValue()
608613
* Possible types: int str float double num numeric bool binary
609614
*
610-
* @return AbstractInjector
615+
* @return object
611616
*/
612-
public function getInjectorInByVal(): AbstractInjector
617+
public function getInjectorInByVal(): object
613618
{
614-
return new class($this->data) extends AbstractInjector {
619+
return new class($this->data) {
620+
/**
621+
* @param array $data
622+
*/
623+
public function __construct(protected array &$data) { }
615624
/**
616625
* @param mixed $value
617626
* @param string $type among: int str float bool binary bigint
@@ -639,11 +648,15 @@ public function __invoke(mixed $value, string $type = 'str'): string
639648
/**
640649
* Injector for referenced values using a statement with ->bindParam()
641650
*
642-
* @return AbstractInjector
651+
* @return object
643652
*/
644-
public function getInjectorInByRef(): AbstractInjector
653+
public function getInjectorInByRef(): object
645654
{
646-
return new class($this->data) extends AbstractInjector {
655+
return new class($this->data) {
656+
/**
657+
* @param array $data
658+
*/
659+
public function __construct(protected array &$data) { }
647660
/**
648661
* @param mixed $value
649662
* @param string $type among: int str float double num numeric bool binary bigint
@@ -673,11 +686,16 @@ public function __invoke(mixed &$value, string $type = 'str'): string
673686
/**
674687
* Injector for a plain sql escaped INOUT attribute
675688
*
676-
* @return AbstractInjector
689+
* @return object
677690
*/
678-
public function getInjectorInOut(): AbstractInjector
691+
public function getInjectorInOut(): object
679692
{
680-
return new class($this->data) extends AbstractInjector {
693+
return new class($this->data) {
694+
/**
695+
* @param array $data
696+
*/
697+
public function __construct(protected array &$data) { }
698+
681699
/**
682700
* @param mixed $value
683701
* @param string $inout_tag ex: '@id'
@@ -701,11 +719,16 @@ public function __invoke(mixed $value, string $inout_tag, string $type = 'str'):
701719
/**
702720
* Injector for an OUT attribute
703721
*
704-
* @return AbstractInjector
722+
* @return object
705723
*/
706724
public function getInjectorOut(): object
707725
{
708-
return new class($this->data) extends AbstractInjector {
726+
return new class($this->data) {
727+
/**
728+
* @param array $data
729+
*/
730+
public function __construct(protected array &$data) { }
731+
709732
/**
710733
* @param string $out_tag ex:'@id'
711734
* @return string

0 commit comments

Comments
 (0)