{"id":276918,"date":"2016-03-24T22:52:02","date_gmt":"2016-03-24T19:52:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=276918"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=276918","title":{"rendered":"RestAPI \u0434\u043b\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 PHP \u0438\u043b\u0438 \u043f\u043e\u0437\u043d\u0430\u0435\u043c \u0434\u0437\u0435\u043d \u0432 \u0447\u0438\u0441\u0442\u043e\u0442\u0435"},"content":{"rendered":"<p>       \u0412 \u043d\u044b\u043d\u0435\u0448\u043d\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0441\u0435 \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f \u043a \u0447\u0438\u0441\u0442\u043e\u0442\u0435. \u0427\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0414\u0436\u0443\u043d\u0438\u043e\u0440\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u2013 \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e \u0437\u0430\u043b\u043e\u0433 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0434\u043e\u043b\u0433\u043e\u0438\u0433\u0440\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0449\u0435 \u043d\u0435 \u0441\u043a\u043e\u0440\u043e \u0441\u043e\u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442 \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a, \u0432 \u043c\u043e\u0435\u043c \u0432\u0438\u0434\u0435\u043d\u0438\u0438, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Restfull API \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430 PHP. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044f \u0432 \u043a\u0443\u0440\u0441\u0435, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430 \u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0432\u043e\u0451 API. \u041d\u043e, \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u043e\u043b\u0435\u0432\u0430\u043b\u0438 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0445 \u0441\u0447\u0435\u0442. \u041b\u0438\u0447\u043d\u043e \u044f \u2013 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043b\u044e\u0431\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434. \u0421\u043d\u0430\u0447\u0430\u043b\u0430: \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 100% \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u041f\u043e\u0437\u0434\u043d\u0435\u0435: \u0438\u0437 \u0437\u0430 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u0439 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u2013 \u043b\u0443\u0447\u0448\u0435\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0434\u043b\u044f \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0412\u044b \u2013 \u044f\u0440\u044b\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u043c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440: \u043d\u0430\u0448\u0435\u043b <a href=\"https:\/\/habrahabr.ru\/post\/141477\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0449\u0443\u044e \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0412\u044b \u0435\u0449\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 RestAPI \u0434\u043b\u044f \u0412\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u043c\u043e\u0438\u043c \u2013 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434!<br \/>  <a name=\"habracut\"><\/a><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0412\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0412\u0430\u0448 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440, \u0447\u0442\u043e-\u0431\u044b \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043b\u0435\u0442\u0435\u043b\u0438 \u0432 index.php, \u0435\u0441\u043b\u0438 \u0412\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2013 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f Nginx.<\/b><\/p>\n<div class=\"spoiler_text\">location ~ \\.php$ {<br \/>   fastcgi_pass 127.0.0.1:9000;<br \/>   fastcgi_index index.php;<br \/>   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br \/>   include fastcgi_params;<br \/>  }<\/p>\n<p>  location \/css\/ {}<br \/>  location \/ {<br \/>   rewrite ^ \/index.php last;<br \/>  }  <\/div>\n<\/div>\n<p>  <b>\u041d\u0430\u0447\u043d\u0435\u043c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441 index.php:<\/b><br \/>  <i>\u0412 \u043a\u043e\u0442\u043e\u0440\u043e\u043c, \u043a\u0430\u043a \u043d\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u043e \u0434\u043b\u044f MVC \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442.<\/i><\/p>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 API \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"php\">$action = explode('\/', $_SERVER['REQUEST_URI']); if(!isset($action[1]))     $page = NULL; else     $page = $action[1];  if($page == 'api') {     include_once 'api\/main\/api.class.php';     new api; } else {     \/\/\u0442\u0443\u0442 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0437\u0430\u0438\u043d\u043a\u043b\u044e\u0434\u0438\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, index.html  } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0442\u0435\u043f\u0435\u0440\u044c, \u043b\u044e\u0431\u044b\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043d\u0430 URL <b><a href=\"http:\/\/sitename.com\/api\/\u0447\u0442\u043e_\u0442\u043e_\u0442\u0430\u043c_\u0435\u0449\u0435\">sitename.com\/api\/\u0447\u0442\u043e_\u0442\u043e_\u0442\u0430\u043c_\u0435\u0449\u0435<\/a><\/b> \u0431\u0443\u0434\u0443\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u0443 \u043a\u043b\u0430\u0441\u0441\u0430 API \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435, \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043a\u0438\u043d\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u0434\u043e\u043c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/341\/535\/ffe\/341535ffe7644c99ae18d2c74ef594b8.png\" alt=\"image\"\/><\/p>\n<p>  \u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u044f\u043c\u043e \u0441 \u0431\u043e\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0430 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0437\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u043b\u0438\u0448\u044c \u043f\u0430\u043f\u043a\u0443 api \u0438 \u0444\u0430\u0439\u043b index.php.<\/p>\n<h4>\u0424\u0430\u0439\u043b\u044b api \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/h4>\n<p>  <b>api.class.php<\/b><br \/>  \u0423 \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u0434 \u0433\u043b\u0430\u0437\u0430\u043c\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432\u0441\u044f \u0441\u0443\u0442\u044c \u043c\u043e\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430: \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0433\u0440\u0430\u0435\u0442 \u0440\u043e\u043b\u044c \u0440\u043e\u0443\u0442\u0435\u0440\u0430 \u2013 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443 API, \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<pre><code class=\"php\">include_once 'model.class.php'; include_once 'view.class.php'; include_once 'factory.class.php';  class api {     private $db;     private $view;     private $factory;     private $args = array();     private $userID;      function __construct() {          $this-&gt;db = new db();$this-&gt;view = new view();$this-&gt;factory = new factory();         $url = parse_url($_SERVER['REQUEST_URI']);         $action = explode('\/', $url['path']);         $action = end($action);          if (!empty($action)) {              if (!empty($_POST) || (substr($action, 0, 4) == 'get_')) {                  if (file_exists('api\/methods\/' . $action . '\/controller.php')) {                      if (file_exists('api\/methods\/' . $action . '\/parameters.inc.php')) {                          $parameters = array();                         $missing_parameters = array();                         $wrong_types = array();                          include_once('api\/methods\/' . $action . '\/parameters.inc.php');                          foreach ($parameters as $param =&gt; $value ) {                              if (!empty($_POST[$param])) {                                 if(factory::check_parameter_type($_POST[$param], $value[1]))                                     $this-&gt;args[$param] = factory::sanitize(factory::set_parameter_type($_POST[$param], $value[1])); \/\/sanitize arguments from request body and assign argument                                 else                                     $wrong_types[] = $param;                              } elseif ($value[0] == 1)                                 $missing_parameters[] = $param;                              else                                 $this-&gt;args[$param] = NULL;                          }                          if (empty($missing_parameters)) {                             if (empty($wrong_types)) {                                  try {                                      call_user_func_array(array($this, $action), $this-&gt;args); \/\/request api method                                  } catch (ErrorException $e) {                                      view::error($_POST, 503);                                  }                              } else                                 view::error(&quot;Incorrect data type for: &quot; . implode(', ', $wrong_types), 204);                         } else                             view::error(&quot;Missing parameters: &quot; . implode(', ', $missing_parameters), 204);                     } else                         view::error(&quot;Method in developing.&quot;, 503);                 } else                     view::error(&quot;The method '&quot; . $action . &quot;' does not exist.&quot;, 204);             } else                 view::error(&quot;No params received.&quot;, 204);         } else             view::error(&quot;Method was not received.&quot;, 204);     }      public function __call($method, $args) { \/\/create new api method from called arguments         @include_once('api\/methods\/' . $method . '\/controller.php');         return true;     } } <\/code><\/pre>\n<p>  \u0421\u0430\u043c \u043a\u043e\u0434 \u0434\u0430\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d \u2013 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f, \u0432\u044b\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u0438\u0437 URL \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u2026 \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 POST \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u0443\u0436\u0435 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c, \u0431\u0443\u0434\u0435\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0440\u043e\u043b\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  <b>factory.class.php<\/b><br \/>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u044f \u043a\u043e\u043f\u043b\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0436\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0437\u0430\u0441\u0443\u043d\u0443\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0430\u043d\u0438\u0442\u0430\u0439\u0437\u0430 \u0438\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<\/p>\n<pre><code class=\"php\">class factory {    public static function check_parameter_type($var, $type) {         switch($type){             case 'string':                 return true;                 break;             case 'boolean':                 if(($var === 'true') || ($var === true))                     return true;                 elseif(($var === 'false') || ($var === false))                     return true;                 else                     return false;                 break;             case 'integer':                 return is_numeric($var) ? true : false;                 break;             case 'smallint':                 return (is_numeric($var) && (strlen($var) == 1)) ? true : false;                 break;             default:                 return false;         }     }      public static function set_parameter_type($var, $type) {         switch($type){             case 'string':                 return $var;                 break;             case 'boolean':                 if(($var === 'true') || ($var === true))                     return 1;                 elseif(($var === 'false') || ($var === false))                     return 0;                 else                     return false;                 break;             case 'integer':                 return $var;                 break;             case 'smallint':                 return $var;                 break;             default:                 return false;         }     }  } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0412\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 api.class.php  <\/p>\n<blockquote><p>$this-&gt;args[$param] = factory::sanitize(factory::set_parameter_type($_POST[$param], $value[1]));<\/p><\/blockquote>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0411\u0414 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<br \/>  <b>model.class.php<\/b>  <\/p>\n<pre><code class=\"php\">class db {     public $current;     private $_db;      function __construct() {         try {             include 'db.config.php';             $this-&gt;_db-&gt;exec('SET NAMES utf8mb4');         } catch (PDOException $e) {          }     }      function __destruct()     {         $this-&gt;_db = NULL;     }      protected function catch_db_error($query) {               $dbh = $this-&gt;_db-&gt;query($query);          if (!$dbh) {             print $query;             die(json_encode(array(&quot;Error&quot; =&gt; &quot;Syntax error.&quot;)));         }         return $dbh;     }      public function orm($sql, $array, $type){          $this-&gt;_db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);          try {             $query = $this-&gt;_db-&gt;prepare($sql.';', array(PDO::ATTR_CURSOR =&gt; PDO::CURSOR_FWDONLY));             $query-&gt;execute($array);         } catch (Exception $e) {             echo $e-&gt;getMessage();             die();         }          switch($type) {             case 'select_one':                 return $query-&gt;fetch(PDO::FETCH_ASSOC);                 break;             case 'select':                 $query = $query-&gt;fetchAll(PDO::FETCH_ASSOC);                 if(is_array($query))                     return $query;                 else                     return array();                 break;             case 'insert':                 return $this-&gt;_db-&gt;lastInsertId();                 break;             case 'replace':                 return $this-&gt;_db-&gt;lastInsertId();                 break;             case 'delete':                 return true;                 break;             case 'update':                 return true;                 break;             default:                 return true;         }     } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0441\u044e\u0434\u0430 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043d\u0435\u043c \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <b>view.class.php<\/b><br \/>  View \u0435\u0441\u0442\u044c view \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043e\u043d \u0437\u0430 \u043e\u0442\u0432\u0435\u0442 API. \u041e\u0442\u0432\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0443\u0432\u0438\u0434\u0438\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0432\u0448\u0438\u0439 \u0432 \u043e\u043a\u043d\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"php\">class view {     static function encode($array) {          array_walk_recursive($array, function (&$value) {             if (!empty($value))                 $value = is_numeric($value) ? intval($value) : $value;             else {                 if (($value === '') or ($value === NULL))                     $value = NULL;                 elseif (($value === '0') or ($value === 0))                     $value = 0;             }         });          print json_encode($array);     }      static function error($text,$code = 400)     {         $result = array(             'error' =&gt; $text,             'status' =&gt; $code         );          return print json_encode($result);     }      static function state($state)     {         print $state == true ? json_encode(array('Status' =&gt; 'Successful.')) : json_encode(array('Status' =&gt; 'Invalid token.'));     }      static function status($text,$code) {         $result = array(             'message' =&gt; $text,             'status' =&gt; $code         );         return print json_encode($result);     } } <\/code><\/pre>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043e\u0431\u0440\u0430\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043d\u0430 JSON.<\/p>\n<h5>\u0418\u0442\u0430\u043a, \u043c\u044b \u0434\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u2013 \u043a\u0430\u043a \u0436\u0435 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435?<\/h5>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/34c\/867\/bfd\/34c867bfdec24d5fbae7dbafb71cb03a.png\" alt=\"image\"\/><\/p>\n<p>  \u0418 \u0441\u043d\u043e\u0432\u0430 \u2013 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0430\u0439\u043b\u044b \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/p>\n<p>  \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u0444\u0430\u0439\u043b\u0430 <b>parameters.inc.php<\/b> \u2013 \u043c\u0435\u0447\u0442\u0430 \u043f\u0430\u0440\u0430\u043d\u043e\u0438\u043a\u0430. <br \/>  <i>\u041f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u043a\u0440\u0443\u0442\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0438\u0448\u0435\u0442 \u043d\u0430 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0441\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0432 \u043c\u0435\u0442\u043e\u0434.<\/i><\/p>\n<pre><code class=\"php\">$parameters = array(     'login' =&gt; array(1, 'string'),     'password' =&gt; array(1, 'string') ); <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0447\u0442\u043e \u0442\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u2013 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u0430. 0 \u2014 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439, 1 \u2014 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u0434\u0430\u043b\u0435\u0435 \u2013 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u0443 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 <b>factory.class.php<\/b>. \u0415\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0439\u0434\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 <b>api.class.php<\/b>.<\/p>\n<p>  \u0421\u0435\u0440\u0434\u0446\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440.<br \/>  <b>controller.php<\/b><\/p>\n<pre><code class=\"php\">require('model.php'); $model = new model(); \/\/ load database methods  const SALT = '\u0412\u0430\u0429\u0435\u041e\u0447\u0435\u043d\u044c\u041a\u0440\u0443\u0422\u0430\u044f\u0421\u043e\u041b\u044c';  if((!empty($this-&gt;args['login'])) and (!empty($this-&gt;args['password']))) {      if($userID = $model-&gt;login($this-&gt;args['login'], md5(crypt($this-&gt;args['password'],SALT)))) {         @session_start();         $_SESSION['userID'] = $userID;          view::encode(array(                 &quot;userID&quot; =&gt; $userID             )         );      } else         view::error(&quot;Wrong login or password.&quot;, 200); } else {     view::error(&quot;Fill all fields.&quot;, 200); } <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430, \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0438\u043c\u043f\u0440\u043e\u0432\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 ORM, \u0430 \u0442\u0430\u043a\u0436\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 view \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<p>  \u041a\u0443\u0434\u0430 \u0436\u0435 \u043c\u044b \u0431\u0435\u0437 \u0431\u0430\u0437\u044b<br \/>  <b>model.php<\/b><\/p>\n<pre><code class=\"php\">class model extends db {     public function login($phone,$password) {          $query = $this-&gt;orm('SELECT `UserID` FROM `UserPrivate` WHERE `Password` = :password AND `Phone` = :phone', array(             ':phone' =&gt; $phone,             ':password' =&gt; $password         ), 'select_one');          return $this-&gt;return_field($query, 'UserID');     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0430\u043f\u043a\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0444\u0430\u0439\u043b model.php \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u0438\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0411\u0414, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2013 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a <b><a href=\"http:\/\/sitename.com\/api\/login\">sitename.com\/api\/login<\/a><\/b> \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0435\u0433\u043e Restfull API \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u0432\u043e\u0435\u043c\u0443 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e. \u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u043e\u0448\u0443 \u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0437\u0430 \u043a\u0443\u0447\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0438 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/280121\/\"> https:\/\/habrahabr.ru\/post\/280121\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u043d\u044b\u043d\u0435\u0448\u043d\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0441\u0435 \u0441\u0442\u0440\u0435\u043c\u044f\u0442\u0441\u044f \u043a \u0447\u0438\u0441\u0442\u043e\u0442\u0435. \u0427\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0414\u0436\u0443\u043d\u0438\u043e\u0440\u0430 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u2013 \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e \u0437\u0430\u043b\u043e\u0433 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0434\u043e\u043b\u0433\u043e\u0438\u0433\u0440\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0449\u0435 \u043d\u0435 \u0441\u043a\u043e\u0440\u043e \u0441\u043e\u0431\u0435\u0440\u0443\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442 \u044f \u043f\u0440\u0438\u0448\u0435\u043b \u043a, \u0432 \u043c\u043e\u0435\u043c \u0432\u0438\u0434\u0435\u043d\u0438\u0438, \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Restfull API \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0430 PHP. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044f \u0432 \u043a\u0443\u0440\u0441\u0435, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0435\u0441\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430 \u043f\u0430\u0440\u0443 \u043c\u0438\u043d\u0443\u0442 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0432\u043e\u0451 API. \u041d\u043e, \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u043e\u043b\u0435\u0432\u0430\u043b\u0438 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0438\u0445 \u0441\u0447\u0435\u0442. \u041b\u0438\u0447\u043d\u043e \u044f \u2013 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043b\u044e\u0431\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434. \u0421\u043d\u0430\u0447\u0430\u043b\u0430: \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 100% \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u041f\u043e\u0437\u0434\u043d\u0435\u0435: \u0438\u0437 \u0437\u0430 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u0439 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u2013 \u043b\u0443\u0447\u0448\u0435\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0434\u043b\u044f \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0412\u044b \u2013 \u044f\u0440\u044b\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043a \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u043c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440: \u043d\u0430\u0448\u0435\u043b <a href=\"https:\/\/habrahabr.ru\/post\/141477\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a> \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u044e\u0449\u0443\u044e \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0412\u044b \u0435\u0449\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 RestAPI \u0434\u043b\u044f \u0412\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u043c\u043e\u0438\u043c \u2013 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u043e\u0434!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-276918","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/276918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=276918"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/276918\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=276918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=276918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=276918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}