public function get_detail($id) { $figure = Figure::with('FigureDesc')->find($id); if (is_null($figure)) { return json_encode('Figure not found', 404); } else { return json_encode($figure); } }
public function __construct($shape) { parent::__construct($shape); }
public function __construct($x_center, $y_center, $color, $line_dim, $length) { parent::__construct('square', $x_center, $y_center, $color, $line_dim); $this->length = $length; }
function __construct($centerX, $centerY, $side) { parent::__construct($centerX, $centerY); $this->side = $side; }
/** * * @param \Figure $figure Фигура вывода * @return string контент изображения */ public function output(\Figure $figure) { return $figure->drawImage(); }
} function square() { return 3.14 * 3.14 * $this->radius / 2; } } class Rectangle extends Figure { private $a; private $b; function __construct($a, $b) { $this->a = (double) $a; $this->b = (double) $b; self::$sum += $this->square(); } function square() { return $this->a * $this->b; } } $arr = array(new Circle(5), new Rectangle(39, 33), new Rectangle(21, 9), new Circle(11.4), new Rectangle(15, 2)); /*$square = 0; foreach($arr as $obj){ $obj->test(); die; // Полиморфизм! $square += $obj->square(); }*/ //echo "Общая площадь: {$square}"; echo "Общая площадь: " . Figure::getSum();
<?php //header("Content-Type: application/json"); require_once __DIR__ . "/Figure.php"; global $config; $request = (object) $_REQUEST; $post = json_decode(file_get_contents("php://input")); $get = (object) $_GET; if (!empty($request->method) || !empty($post->method)) { $fgr = new Figure(); $method = empty($request->method) ? $post->method : $request->method; switch ($method) { case "saveF": $data = $fgr->saveFigureData($request->data, $request->type, $request->name); die(json_encode($data)); break; case "getByName": $data = $fgr->getByNames($request->fileName); die(json_encode($data)); break; default: die(json_encode(array('error' => "false request"))); break; } } else { die(json_encode(array('error' => "Empty request method!"))); }
function __construct($a, $b, $c, $p, $name) { $this->b = $b; $this->c = $c; parent::__construct($a, $p, $name); }
/** * * @param \Figure $figure Фигура вывода * @return array массив точек */ public function output(\Figure $figure) { return $figure->returnArray(); }
<?php require_once __DIR__ . DIRECTORY_SEPARATOR . 'Autoloader.php'; Autoloader::register(); // Предположим получение входных данных и валидацию здесь $name_figure = 'Rectangle'; $params = array(); $outpuer = 'Image'; $figure = \Figure::makeFigure($name_figure, $params); \Outputer::createOutputer($outpuer)->output($figure);