@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use Ramsey\Uuid\Uuid; |
| 13 | 13 | |
| 14 | 14 | |
| 15 | -class Connection{ |
|
| 15 | +class Connection { |
|
| 16 | 16 | |
| 17 | 17 | private DBALConnection $connection; |
| 18 | 18 | private AbstractSchemaManager $SchemaManager; |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | public function __construct(array $connectionParams) |
| 27 | 27 | { |
| 28 | 28 | $this->connectionId = UUID::uuid4()->toString(); |
| 29 | - if(isset($connectionParams['useUUID']) && $connectionParams['useUUID']){ |
|
| 29 | + if (isset($connectionParams['useUUID']) && $connectionParams['useUUID']) { |
|
| 30 | 30 | $this->isUsingUUID = true; |
| 31 | - }else{ |
|
| 31 | + } else { |
|
| 32 | 32 | $this->isUsingUUID = false; |
| 33 | 33 | } |
| 34 | 34 | unset($connectionParams['useUUID']); |
@@ -36,36 +36,36 @@ discard block |
||
| 36 | 36 | $this->SchemaManager = $this->connection->createSchemaManager(); |
| 37 | 37 | $this->platform = $this->connection->getDatabasePlatform(); |
| 38 | 38 | $this->ModelManager = new ModelManager(); |
| 39 | - $this->RecordManager = new RecordManager($this->connection,$this->ModelManager,$this->isUsingUUID); |
|
| 40 | - $this->TableManager = new TableManager($this->connection,$this->isUsingUUID); |
|
| 39 | + $this->RecordManager = new RecordManager($this->connection, $this->ModelManager, $this->isUsingUUID); |
|
| 40 | + $this->TableManager = new TableManager($this->connection, $this->isUsingUUID); |
|
| 41 | 41 | $this->ModelManager->setConnection($this); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function getSchemaManager(){ |
|
| 44 | + public function getSchemaManager() { |
|
| 45 | 45 | return $this->SchemaManager; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function getPlatform(){ |
|
| 48 | + public function getPlatform() { |
|
| 49 | 49 | return $this->platform; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function isUsingUUID(){ |
|
| 52 | + public function isUsingUUID() { |
|
| 53 | 53 | return $this->isUsingUUID; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function getRecordManager(){ |
|
| 56 | + public function getRecordManager() { |
|
| 57 | 57 | return $this->RecordManager; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function getTableManager(){ |
|
| 60 | + public function getTableManager() { |
|
| 61 | 61 | return $this->TableManager; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function getModelManager(){ |
|
| 64 | + public function getModelManager() { |
|
| 65 | 65 | return $this->ModelManager; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function getConnectionId(){ |
|
| 68 | + public function getConnectionId() { |
|
| 69 | 69 | return $this->connectionId; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | $this->connectionId = UUID::uuid4()->toString(); |
| 29 | 29 | if(isset($connectionParams['useUUID']) && $connectionParams['useUUID']){ |
| 30 | 30 | $this->isUsingUUID = true; |
| 31 | - }else{ |
|
| 31 | + } else{ |
|
| 32 | 32 | $this->isUsingUUID = false; |
| 33 | 33 | } |
| 34 | 34 | unset($connectionParams['useUUID']); |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | private Connection $connection; |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - public function __construct(string $name,Connection $connection) |
|
| 18 | + public function __construct(string $name, Connection $connection) |
|
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | $this->table = $name; |
@@ -99,20 +99,20 @@ discard block |
||
| 99 | 99 | $parts = preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
| 100 | 100 | if (strtolower($parts[0]) == 'own') { |
| 101 | 101 | if (strtolower($parts[2]) == 'list') { |
| 102 | - return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
| 102 | + return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | if (strtolower($parts[0]) == 'shared') { |
| 106 | 106 | if (strtolower($parts[2]) == 'list') { |
| 107 | - $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table; |
|
| 108 | - $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
| 107 | + $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
|
| 108 | + $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
| 109 | 109 | $rel_ids = ''; |
| 110 | 110 | foreach ($relations as $relation) { |
| 111 | - $key = strtolower($parts[1]) . '_id'; |
|
| 112 | - $rel_ids .= "'" . $relation->$key . "',"; |
|
| 111 | + $key = strtolower($parts[1]).'_id'; |
|
| 112 | + $rel_ids .= "'".$relation->$key."',"; |
|
| 113 | 113 | } |
| 114 | 114 | $rel_ids = substr($rel_ids, 0, -1); |
| 115 | - return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); |
|
| 115 | + return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | return $this->__properties[$key]; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if (array_key_exists($key . '_id', $this->__properties)) { |
|
| 125 | - return $this->connection->getRecordManager()->getById($key, $this->__properties[$key . '_id']); |
|
| 124 | + if (array_key_exists($key.'_id', $this->__properties)) { |
|
| 125 | + return $this->connection->getRecordManager()->getById($key, $this->__properties[$key.'_id']); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | throw new Exception\KeyNotFoundException(); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | public static function connect(array $connectionParams) |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - $connection =new Connection($connectionParams); |
|
| 17 | + $connection = new Connection($connectionParams); |
|
| 18 | 18 | self::$database = new DB($connection); |
| 19 | 19 | return self::$database; |
| 20 | 20 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | return self::getDB()->exec($sql); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function delete($model){ |
|
| 48 | + public static function delete($model) { |
|
| 49 | 49 | return self::getDB()->delete($model); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | } |
| 43 | 43 | foreach (self::$events[$eventname] as $key => $weight) { |
| 44 | 44 | foreach ($weight as $callback) { |
| 45 | - call_user_func_array($callback, $params); |
|
| 45 | + call_user_func_array($callback, $params); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function registerEvents() |
| 32 | 32 | { |
| 33 | - Event::subscribeTo('system.model.save.'.$this->connection->getConnectionId(), function ($model) { |
|
| 33 | + Event::subscribeTo('system.model.save.'.$this->connection->getConnectionId(), function($model) { |
|
| 34 | 34 | return $this->save($model); |
| 35 | 35 | }); |
| 36 | - Event::subscribeTo('system.model.delete.'.$this->connection->getConnectionId(), function ($model) { |
|
| 36 | + Event::subscribeTo('system.model.delete.'.$this->connection->getConnectionId(), function($model) { |
|
| 37 | 37 | return $this->delete($model); |
| 38 | 38 | }); |
| 39 | 39 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param array $params |
| 46 | 46 | * @return integer |
| 47 | 47 | */ |
| 48 | - public function exec(string $sql, array $params=array()): int |
|
| 48 | + public function exec(string $sql, array $params = array()): int |
|
| 49 | 49 | { |
| 50 | 50 | return $this->connection->executeStatement($sql, $params); |
| 51 | 51 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param array $params |
| 58 | 58 | * @return array |
| 59 | 59 | */ |
| 60 | - public function getAll(string $sql, array $params=[]): array |
|
| 60 | + public function getAll(string $sql, array $params = []): array |
|
| 61 | 61 | { |
| 62 | 62 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative(); |
| 63 | 63 | } |
@@ -9,10 +9,10 @@ discard block |
||
| 9 | 9 | class QueryBuilder extends \Doctrine\DBAL\Query\QueryBuilder |
| 10 | 10 | { |
| 11 | 11 | private string $table; |
| 12 | - private array $relations= []; |
|
| 12 | + private array $relations = []; |
|
| 13 | 13 | private ModelManager $modelManager; |
| 14 | 14 | |
| 15 | - public function __construct(\Doctrine\DBAL\Connection $connection,ModelManager $modelManager) |
|
| 15 | + public function __construct(\Doctrine\DBAL\Connection $connection, ModelManager $modelManager) |
|
| 16 | 16 | { |
| 17 | 17 | $this->modelManager = $modelManager; |
| 18 | 18 | parent::__construct($connection); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | public function from($table, $alias = null): QueryBuilder |
| 28 | 28 | { |
| 29 | 29 | $this->table = $table; |
| 30 | - return parent::from($table,$alias); |
|
| 30 | + return parent::from($table, $alias); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function get(): Collection |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $table = new Table($model->getName()); |
| 71 | 71 | if ($this->isUsingUUID) { |
| 72 | - $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true,]); |
|
| 72 | + $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true, ]); |
|
| 73 | 73 | } else { |
| 74 | 74 | $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]); |
| 75 | 75 | } |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | foreach ($model->getProperties() as $key => $value) { |
| 78 | 78 | if ($key != 'id') { |
| 79 | 79 | $type = gettype($value); |
| 80 | - if($type == 'string'){ |
|
| 80 | + if ($type == 'string') { |
|
| 81 | 81 | $type = 'text'; |
| 82 | 82 | } |
| 83 | - $table->addColumn($key,$type , ['notnull' => false, 'comment' => $key]); |
|
| 83 | + $table->addColumn($key, $type, ['notnull' => false, 'comment' => $key]); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | return $table; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | try { |
| 134 | 134 | $this->getTable($table_name); |
| 135 | 135 | return true; |
| 136 | - }catch(TableDoesNotExist $e){ |
|
| 136 | + } catch (TableDoesNotExist $e) { |
|
| 137 | 137 | return false; |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -133,7 +133,7 @@ |
||
| 133 | 133 | try { |
| 134 | 134 | $this->getTable($table_name); |
| 135 | 135 | return true; |
| 136 | - }catch(TableDoesNotExist $e){ |
|
| 136 | + } catch(TableDoesNotExist $e){ |
|
| 137 | 137 | return false; |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | function setConnection(Connection $connection) |
| 23 | 23 | { |
| 24 | - $this->connection = $connection; |
|
| 24 | + $this->connection = $connection; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | private $connection; |
| 17 | 17 | function create(string $name): Model |
| 18 | 18 | { |
| 19 | - return new Model($name,$this->connection); |
|
| 19 | + return new Model($name, $this->connection); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | function setConnection(Connection $connection) |
@@ -69,15 +69,15 @@ |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Get single record by id |
|
| 73 | - * |
|
| 74 | - */ |
|
| 72 | + * Get single record by id |
|
| 73 | + * |
|
| 74 | + */ |
|
| 75 | 75 | public function getById($table, mixed $id): Model |
| 76 | 76 | { |
| 77 | 77 | $query = (new QueryBuilder($this->connection,$this->modelManager)) |
| 78 | - ->select('*') |
|
| 79 | - ->from($table, 't') |
|
| 80 | - ->where("t.id = '".$id."'"); |
|
| 78 | + ->select('*') |
|
| 79 | + ->from($table, 't') |
|
| 80 | + ->where("t.id = '".$id."'"); |
|
| 81 | 81 | $result = $this->connection->executeQuery($query)->fetchAssociative(); |
| 82 | 82 | $result = $result ? $result : []; |
| 83 | 83 | return $this->modelManager->create($table)->setProperties($result)->setLoaded(); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * Create RecordManager |
| 24 | 24 | */ |
| 25 | - public function __construct(Connection $connection, ModelManager $modelManager,bool $isUsingUUID = false) |
|
| 25 | + public function __construct(Connection $connection, ModelManager $modelManager, bool $isUsingUUID = false) |
|
| 26 | 26 | { |
| 27 | 27 | $this->connection = $connection; |
| 28 | 28 | $this->isUsingUUID = $isUsingUUID; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getById($table, mixed $id): Model |
| 76 | 76 | { |
| 77 | - $query = (new QueryBuilder($this->connection,$this->modelManager)) |
|
| 77 | + $query = (new QueryBuilder($this->connection, $this->modelManager)) |
|
| 78 | 78 | ->select('*') |
| 79 | 79 | ->from($table, 't') |
| 80 | 80 | ->where("t.id = '".$id."'"); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function getAll(string $tableName): Collection |
| 92 | 92 | { |
| 93 | - return (new QueryBuilder($this->connection,$this->modelManager)) |
|
| 93 | + return (new QueryBuilder($this->connection, $this->modelManager)) |
|
| 94 | 94 | ->select('*') |
| 95 | 95 | ->from($tableName, 't') |
| 96 | 96 | ->get(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function find(String $name) : QueryBuilder |
| 104 | 104 | { |
| 105 | - return (new QueryBuilder($this->connection,$this->modelManager)) |
|
| 105 | + return (new QueryBuilder($this->connection, $this->modelManager)) |
|
| 106 | 106 | ->select('*') |
| 107 | 107 | ->from($name, 't'); |
| 108 | 108 | } |