lesson oop
This commit is contained in:
parent
3eb8c2c346
commit
2ceedb75f5
27
engine/mvc.php
Normal file
27
engine/mvc.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class MainModel {
|
||||
public function getData()
|
||||
{
|
||||
return ['title' => 'Main Page',
|
||||
'h3' => 'С новым годом!'];
|
||||
}
|
||||
}
|
||||
class MainController {
|
||||
public function index()
|
||||
{
|
||||
$model = new MainModel();
|
||||
$view = new MainView();
|
||||
$result = $model->getData();
|
||||
$view->render($result, 'main.tpl');
|
||||
}
|
||||
}
|
||||
class MainView {
|
||||
public function render($data, $tmpl)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
|
||||
$controll = new MainController();
|
||||
$controll->index();
|
92
engine/oop.php
Normal file
92
engine/oop.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
class SectionTree {
|
||||
protected $radius = 10;
|
||||
public $hight = 50; // в см
|
||||
public function __construct(int $r, int $h)
|
||||
{
|
||||
$this->radius = $r;
|
||||
$this->hight = $h;
|
||||
}
|
||||
}
|
||||
|
||||
class SectionTreeChild extends SectionTree {
|
||||
public $wight = 50;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(233, 23);
|
||||
}
|
||||
|
||||
public function getRadius()
|
||||
{
|
||||
return $this->radius;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$objChild = new SectionTreeChild(255, 22);
|
||||
|
||||
var_dump($objChild->getRadius());
|
||||
|
||||
// var_dump(SectionTree::$radius);
|
||||
|
||||
class ChristmasTree
|
||||
{
|
||||
private $sectionBox = [];
|
||||
protected $color = 'red';
|
||||
|
||||
public function getColor()
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
public function addSection($section)
|
||||
{
|
||||
array_push($this->sectionBox, $section);
|
||||
}
|
||||
|
||||
public function debug()
|
||||
{
|
||||
var_dump($this->sectionBox);
|
||||
}
|
||||
|
||||
}
|
||||
// () - вызов конструктора, оператор call
|
||||
|
||||
$s_1 = new SectionTree(12, 2);
|
||||
$s_2 = new SectionTree(3, 5);
|
||||
|
||||
$tree = new ChristmasTree();
|
||||
$tree->addSection($s_1);
|
||||
$tree->addSection($s_2);
|
||||
// $tree->addSection('ddd');
|
||||
// $tree->addSection(283746);
|
||||
$tree->debug();
|
||||
|
||||
|
||||
// var_dump($obj->getColor());
|
||||
|
||||
class DB {
|
||||
const SQL_SELECT_USER = 'select, id, name, login from user, where id = %';
|
||||
static private $_instanse;
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static public function getInstanse()
|
||||
{
|
||||
if (!self::$_instanse) {
|
||||
self::$_instanse = new self();
|
||||
}
|
||||
return self::$_instanse;
|
||||
}
|
||||
static public function runSQL()
|
||||
{
|
||||
var_dump(self::SQL_SELECT_USER);
|
||||
}
|
||||
}
|
||||
|
||||
$objInst = DB::getInstanse();
|
||||
DB::runSQL();
|
||||
var_dump($objInst);
|
Loading…
Reference in New Issue
Block a user