-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Bunge
committed
Apr 13, 2016
1 parent
67eb8ac
commit ab00c8b
Showing
6 changed files
with
172 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* | ||
* (c) Marco Bunge <marco_bunge@web.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 13.04.2016 | ||
* Time: 17:23 | ||
* | ||
*/ | ||
|
||
namespace Blast\Orm; | ||
|
||
|
||
use Blast\Orm\Relations\RelationInterface; | ||
use Doctrine\DBAL\Schema\Column; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
class Gateway implements GatewayInterface, ConnectionAwareInterface | ||
{ | ||
|
||
use ConnectionAwareTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $table; | ||
|
||
/** | ||
* Create a new gateway for a single table | ||
* | ||
* @param $table | ||
*/ | ||
public function __construct($table) | ||
{ | ||
$this->table = $table; | ||
} | ||
|
||
/** | ||
* Prepare insert statement | ||
* | ||
* @param $data | ||
* | ||
* @param Column[] $fields | ||
* @return $this | ||
*/ | ||
public function insert($data, $fields = []) | ||
{ | ||
//cancel if $data has no entries | ||
if (count($data) < 1) { | ||
return false; | ||
} | ||
|
||
//prepare statement | ||
$query = $this->getConnection()->createQuery(); | ||
$query->insert($this->table); | ||
|
||
foreach ($data as $key => $value) { | ||
if ($value instanceof RelationInterface) { | ||
continue; | ||
}; | ||
|
||
$query->setValue($key, $query->createPositionalParameter( | ||
$value, array_key_exists($key, $fields) ? | ||
$fields[$key]->getType()->getName() : | ||
Type::STRING)); | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
/** | ||
* Prepare update statement | ||
* | ||
* @param $primaryKey | ||
* @param $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function update($primaryKey, $data) | ||
{ | ||
// TODO: Implement update() method. | ||
} | ||
|
||
/** | ||
* Prepare delete statement | ||
* | ||
* @param $primaryKey | ||
* | ||
* @return mixed | ||
*/ | ||
public function delete($primaryKey) | ||
{ | ||
// TODO: Implement delete() method. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* | ||
* (c) Marco Bunge <marco_bunge@web.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 13.04.2016 | ||
* Time: 17:08 | ||
* | ||
*/ | ||
|
||
namespace Blast\Orm; | ||
|
||
/** | ||
* The gateway is accessing a single table or view and interacts with database | ||
* | ||
* @package Blast\Orm | ||
*/ | ||
interface GatewayInterface | ||
{ | ||
|
||
/** | ||
* Create a new gateway for a single table | ||
* | ||
* @param $table | ||
*/ | ||
public function __construct($table); | ||
|
||
/** | ||
* Prepare insert statement | ||
* | ||
* @param $data | ||
* | ||
* @return $this | ||
*/ | ||
public function insert($data); | ||
|
||
/** | ||
* Prepare update statement | ||
* | ||
* @param $primaryKey | ||
* @param $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function update($primaryKey, $data); | ||
|
||
/** | ||
* Prepare delete statement | ||
* | ||
* @param $primaryKey | ||
* | ||
* @return mixed | ||
*/ | ||
public function delete($primaryKey); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters