Этот коммит содержится в:
Igor V Belousov 2019-11-07 00:48:21 +03:00
родитель 2fbd0c43c4
Коммит 549fd7eaa2
7 изменённых файлов: 168 добавлений и 4 удалений

Просмотреть файл

@ -12,8 +12,12 @@ services:
MYSQL_USER: 'user' MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password' MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'rootPassword' MYSQL_ROOT_PASSWORD: 'rootPassword'
command: --default-authentication-plugin=mysql_native_password
ports: ports:
- 3306:3306 - 3306:3306
networks:
- backend
- frontend
app: app:
build: build:
context: ./docker context: ./docker
@ -23,6 +27,8 @@ services:
- "./src/:/app/src" - "./src/:/app/src"
depends_on: depends_on:
- mysql - mysql
networks:
- backend
nginx: nginx:
build: build:
context: ./docker context: ./docker
@ -33,5 +39,13 @@ services:
- 80:80 - 80:80
depends_on: depends_on:
- app - app
networks:
- frontend
- backend
volumes: volumes:
database: database:
networks:
frontend:
external:
name: proxy_proxy
backend:

Просмотреть файл

@ -0,0 +1,6 @@
body {
font-family: Verdana, "Geneva CY", "DejaVu Sans", sans-serif;
font-size: 1rem;
font-weight: normal;
}

Просмотреть файл

@ -18,6 +18,10 @@ class App
* @var Config * @var Config
*/ */
public $config; public $config;
/**
* @var \PDO
*/
public $db = null;
public function __construct() public function __construct()
{ {

Просмотреть файл

@ -13,5 +13,6 @@ class DefaultController extends Controller
public function index() public function index()
{ {
(new View())->index(); (new View())->index();
$Model = new \MyApp\Model\GroupsModel();
} }
} }

Просмотреть файл

@ -2,8 +2,10 @@
namespace MyApp\Core; namespace MyApp\Core;
use PDOException;
use ReflectionClass; use ReflectionClass;
use ReflectionProperty; use ReflectionProperty;
use PDO;
class Model class Model
{ {
@ -11,12 +13,47 @@ class Model
* @var array * @var array
*/ */
private $internalTableMap; private $internalTableMap;
/**
* @var \App
*/
protected $app;
public function __construct(?array $tableMap = null) public function __construct(?array $tableMap = null)
{ {
if (!is_array($tableMap)) { global $app;
$this->app = $app;
if ( ! is_array($tableMap)) {
$this->setInternalTableMap(); $this->setInternalTableMap();
} }
if ('db' === $this->getModelType()) {
$this->initDb();
}
}
private function initDb(): void
{
if (is_null($this->app->db)) {
try {
$this->app->db = new PDO(
'mysql:host=mysql;dbname='
. $this->app->config->getDbName()
. ';port='
. $this->app->config->getDbPort(),
$this->app->config->getDbUser(),
$this->app->config->getDbPassword(),
array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_ERRMODE => true,
PDO::ATTR_PERSISTENT => true,
));
} catch (PDOException $e) {
echo 'Подключение не удалось: ' . $e->getMessage();
}
}
} }
private function setInternalTableMap() private function setInternalTableMap()
@ -24,10 +61,10 @@ class Model
/* @var \App $app */ /* @var \App $app */
global $app; global $app;
$tableMap = ['type' => 'bd']; $tableMap = ['type' => 'db'];
$refClass = new ReflectionClass(get_called_class()); $refClass = new ReflectionClass(get_called_class());
$tags = $app->parseTagsFromComment($refClass->getDocComment(), $tags = $app->parseTagsFromComment($refClass->getDocComment(),
'TableName'); 'TableName');
if ($tags) { if ($tags) {
if (array_key_exists('TableName', $tags)) { if (array_key_exists('TableName', $tags)) {
@ -56,9 +93,16 @@ class Model
$this->internalTableMap = array_key_exists('id', $this->internalTableMap = array_key_exists('id',
$tableMap) ? $tableMap : ['type' => 'other']; $tableMap) ? $tableMap : ['type' => 'other'];
} }
if ( ! is_array($this->internalTableMap)) {
$this->internalTableMap = ['type' => 'other'];
}
} }
public function find($id) public static function find()
{
}
public static function findOne()
{ {
} }
@ -69,4 +113,9 @@ class Model
{ {
return $this->internalTableMap; return $this->internalTableMap;
} }
public function getModelType(): string
{
return $this->internalTableMap['type'];
}
} }

77
src/models/GroupsModel.php Обычный файл
Просмотреть файл

@ -0,0 +1,77 @@
<?php
namespace MyApp\Model;
use MyApp\Core\Model;
/**
* Class GroupsModel
*
* @TableName = "groups"
*
* @package MyApp\Model
*/
class GroupsModel extends Model
{
/**
* @ColumnName = "id"
* @ColumnOption = "id"
* @ColumnType = "int unsigned auto_increment primary key"
*
* @var int
*/
private $id;
/**
* @ColumnName = "name"
* @ColumnType = "varchar(255) null"
*
* @var string
*/
private $name;
/**
* @ColumnName = "parent_id"
* @ColumnType = "int unsigned null"
*
* @var int
*/
private $parent;
/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*
* @return GroupsModel
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @param int $parent
*
* @return GroupsModel
*/
public function setParent(int $parent): self
{
$this->parent = $parent;
return $this;
}
}

13
src/models/ServersModel.php Обычный файл
Просмотреть файл

@ -0,0 +1,13 @@
<?php
namespace MyApp\Model;
class ServersModel
{
private $id;
private $name;
private $ip;
private $group;
}