20240719#1
This commit is contained in:
@@ -9,5 +9,5 @@ composer create-project rmphp/skeleton project-name
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer create-project rmphp/skeleton:"^4.3" project-name
|
composer create-project rmphp/skeleton:"^4.4" project-name
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,6 +9,5 @@
|
|||||||
# ['key'=>'/', 'router'=>[]],
|
# ['key'=>'/', 'router'=>[]],
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['key'=>'/', 'router'=>'application/config/routes/main/routes.php'],
|
['key'=>'/', 'router'=>'application/config/routes/routes.php'],
|
||||||
];
|
];
|
||||||
|
|
||||||
0
application/config/routes/main/.gitkeep
Normal file
0
application/config/routes/main/.gitkeep
Normal file
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$routes = glob(__DIR__."/{*.yaml}", GLOB_BRACE);
|
|
||||||
|
|
||||||
$routesCollection = array_map(function ($routesFile){
|
|
||||||
return file_get_contents($routesFile).PHP_EOL;
|
|
||||||
}, $routes);
|
|
||||||
|
|
||||||
return yaml_parse(implode($routesCollection));
|
|
||||||
17
application/config/routes/routes.php
Normal file
17
application/config/routes/routes.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if(getenv("APP_MODE") == "PROD" && file_exists(dirname(__DIR__,3).'/var/routes/routes')){
|
||||||
|
return unserialize(file_get_contents(dirname(__DIR__,3).'/var/routes/routes'));
|
||||||
|
} else {
|
||||||
|
$routesCollection = array_map(function ($routesFile){
|
||||||
|
return file_get_contents($routesFile).PHP_EOL;
|
||||||
|
}, array_merge(glob(__DIR__."/*/{*.yaml}", GLOB_BRACE), glob(__DIR__."/{*.yaml}", GLOB_BRACE)));
|
||||||
|
|
||||||
|
$routes = yaml_parse(implode($routesCollection));
|
||||||
|
|
||||||
|
if(getenv("APP_MODE") == "PROD") {
|
||||||
|
if (!is_dir(dirname(__DIR__, 3).'/var/routes')) mkdir(dirname(__DIR__, 3).'/var/routes', 0777, true);
|
||||||
|
file_put_contents(dirname(__DIR__, 3).'/var/routes/routes', serialize($routes));
|
||||||
|
}
|
||||||
|
return $routes;
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ use Rmphp\Storage\Mysql\MysqlStorageInterface;
|
|||||||
|
|
||||||
abstract class AbstractMysqlRepository extends AbstractRepository {
|
abstract class AbstractMysqlRepository extends AbstractRepository {
|
||||||
|
|
||||||
|
public const DEBUG = false;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly MysqlStorageInterface $mysql
|
public readonly MysqlStorageInterface $mysql
|
||||||
) {}
|
) {}
|
||||||
@@ -21,7 +23,7 @@ abstract class AbstractMysqlRepository extends AbstractRepository {
|
|||||||
$in = $this->getProperties($object, function ($value){
|
$in = $this->getProperties($object, function ($value){
|
||||||
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
return (is_string($value)) ? $this->mysql->escapeStr($value) : $value;
|
||||||
});
|
});
|
||||||
//dd($object, $in);
|
if(static::DEBUG) dd($object, $in, $table);
|
||||||
try {
|
try {
|
||||||
if (!empty($object->getId()) && !empty($this->mysql->findById($table, $object->getId()))) {
|
if (!empty($object->getId()) && !empty($this->mysql->findById($table, $object->getId()))) {
|
||||||
$this->mysql->updateById($table, $in, $object->getId());
|
$this->mysql->updateById($table, $in, $object->getId());
|
||||||
@@ -32,8 +34,4 @@ abstract class AbstractMysqlRepository extends AbstractRepository {
|
|||||||
}
|
}
|
||||||
} catch (\Throwable $throwable) {throw new RepositoryException($throwable->getMessage());}
|
} catch (\Throwable $throwable) {throw new RepositoryException($throwable->getMessage());}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user