{"id":262055,"date":"2015-07-22T16:02:02","date_gmt":"2015-07-22T12:02:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=262055"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=262055","title":{"rendered":"\u041a\u0438\u0441\u043a\u0438: \u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433. \u0427\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u043b\u0438 \u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/389\/bf3\/282\/389bf3282a848b64b37aa11a60bce887.jpg\" alt=\"image\" title=\"Franz Marc - Girl with cat II, 1912\" align=\"left\"\/> \u042d\u0442\u043e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"http:\/\/habrahabr.ru\/post\/262995\/\">\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c<\/a> \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043e\u0442 Matthias Noback. <\/p>\n<h4>\u041c\u0438\u0440 \u043d\u0435 \u0442\u0430\u043a \u043d\u0430\u0434\u0435\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0435\u0433\u043e \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f<\/h4>\n<p>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u0441\u0440\u0435\u0434\u0430 \u0431\u044b\u043b\u0430 \u0432\u043e\u0432\u043b\u0435\u0447\u0435\u043d\u0430 \u0432 \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u044b, \u0432\u044b \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442\u0435 \u0442\u0435\u0441\u0442\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u043f\u0430\u043b \u0438\u043b\u0438 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2014 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442 \u0443\u043f\u0430\u0434\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u0440\u043d\u043e. \u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0430\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e, \u0447\u0435\u0433\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d.<\/p>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 (CachedCatApi \u0438 RealCatApi) \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u044b \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u044d\u0442\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0438 \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>  \u041e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0448\u0435\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 file_get_contents() \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c FileGetContentsHttpClient.<\/p>\n<pre><code class=\"php\">class FileGetContentsHttpClient {     public function get($url)     {         return @file_get_contents($url);     } } <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h4>\n<p>  \u041a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0432\u0437\u044f\u0442\u044c \u0438 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0441. \u0414\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0440\u0443\u0434\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"php\">interface HttpClient {     \/**      * @return string|false Response body      *\/     public function get($url); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c HttpClient \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 RealCatApi:<\/p>\n<pre><code class=\"php\">class RealCatApi implements CatAPi {     private $httpClient;      public function __construct(HttpClient $httpClient)     {         $this-&gt;httpClient = $httpClient;     }      public function getRandomImage()     {         $responseXml = $this-&gt;httpClient-&gt;get('http:\/\/thecatapi.com\/api\/images\/get?format=xml&type=jpg');          ...     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442<\/h4>\n<p>  \u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u0443\u0442\u043e\u0439 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442 \u0434\u043b\u044f RealCatApi. \u041d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c (stand-in?) HttpClient, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 XML-\u043e\u0442\u0432\u0435\u0442:<\/p>\n<pre><code class=\"php\">class RealCatApiTest extends \\PHPUnit_Framework_TestCase {     \/** @test *\/     public function it_fetches_a_random_url_of_a_cat_gif()     {         $xmlResponse = &lt;&lt;&lt;EOD &lt;response&gt;     &lt;data&gt;         &lt;images&gt;             &lt;image&gt;                 &lt;url&gt;http:\/\/24.media.tumblr.com\/tumblr_lgg3m9tRY41qgnva2o1_500.jpg&lt;\/url&gt;                 &lt;id&gt;bie&lt;\/id&gt;                 &lt;source_url&gt;http:\/\/thecatapi.com\/?id=bie&lt;\/source_url&gt;             &lt;\/image&gt;         &lt;\/images&gt;     &lt;\/data&gt; &lt;\/response&gt; EOD;         $httpClient = $this-&gt;getMock('HttpClient');         $httpClient             -&gt;expect($this-&gt;once())             -&gt;method('get')             -&gt;with('http:\/\/thecatapi.com\/api\/images\/get?format=xml&type=jpg')             -&gt;will($this-&gt;returnValue($xmlResponse));         $catApi = new RealCatApi($httpClient);          $url = $catApi-&gt;getRandomImage();          $this-&gt;assertSame(             'http:\/\/24.media.tumblr.com\/tumblr_lgg3m9tRY41qgnva2o1_500.jpg',             $url         );     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 RealCatApi: \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u0432\u0430\u0442\u044c HttpClient \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c URL \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f  \u0438\u0437 XML \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<h4>\u041e\u0442\u0434\u0435\u043b\u044f\u0435\u043c API \u043e\u0442 file_get_contents()<\/h4>\n<p>  \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0444\u0438\u043a\u0441\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442 \u2014 \u043c\u0435\u0442\u043e\u0434 get() \u043a\u043b\u0430\u0441\u0441\u0430 HttpClient \u0432\u0441\u0435 \u0435\u0449\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f file_get_contents(), \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 false, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u044b\u043c, \u0438\u043b\u0438 \u0436\u0435 \u0442\u0435\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0441\u043f\u0435\u0448\u0435\u043d. \u041c\u044b \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043c\u043e\u0436\u0435\u043c <i>\u0441\u043a\u0440\u044b\u0442\u044c \u044d\u0442\u0443 \u0434\u0435\u0442\u0430\u043b\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/i>, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u043a\u0430\u043a false, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440) \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0438\u0445 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u044d\u043a\u0441\u0435\u043f\u0448\u043d). \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0448\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043b\u0438\u0448\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043b\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"php\">class FileGetContentsHttpClient implements HttpClient {     public function get($url)     {         $response = @file_get_contents($url);         if ($response === false) {             throw new HttpRequestFailed();         }          return $response;     } }  interface HttpClient {     \/**      * @return string Response body      * @throws HttpRequestFailed      *\/     public function get($url); }  class HttpRequestFailed extends \\RuntimeException { } <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c RealCatApi, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0442 \u043c\u043e\u0433 \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 false:<\/p>\n<pre><code class=\"php\">class RealCatApi implements CatAPi {     public function getRandomImage()     {         try {             $responseXml = $this-&gt;httpClient-&gt;get('http:\/\/thecatapi.com\/api\/images\/get?format=xml&type=jpg');              ...         } catch (HttpRequestFailed $exception) {             return 'http:\/\/cdn.my-cool-website.com\/default.jpg';         }          ...     } } <\/code><\/pre>\n<p>  \u0412\u044b \u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430? \u041c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 file_get_contents() \u0441 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c XML \u043e\u0442\u0432\u0435\u0442\u043e\u043c. \u041d\u0435 \u0431\u044b\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043f\u0430\u0432\u0448\u0438\u0439 HTTP \u0437\u0430\u043f\u0440\u043e\u0441, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u00ab\u0437\u0430\u0432\u0430\u043b\u0438\u0442\u044c\u00bb HTTP \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u0443, \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u0432\u044b\u0442\u0430\u0449\u0438\u0432 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043a\u0430\u0431\u0435\u043b\u044c?<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 HttpClient \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 HttpRequestFailed:<\/p>\n<pre><code class=\"php\">class RealCatApiTest extends \\PHPUnit_Framework_TestCase {     ...      \/** @test *\/     public function it_returns_a_default_url_when_the_http_request_fails()     {         $httpClient = $this-&gt;getMock('HttpClient');         $httpClient             -&gt;expect($this-&gt;once())             -&gt;method('get')             -&gt;with('http:\/\/thecatapi.com\/api\/images\/get?format=xml&type=jpg')             -&gt;will($this-&gt;throwException(new HttpRequestFailed());         $catApi = new RealCatApi($httpClient);          $url = $catApi-&gt;getRandomImage();          $this-&gt;assertSame(             'http:\/\/cdn.my-cool-website.com\/default.jpg',             $url         );     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/h4>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0448\u0430\u0433\u0438 \u0434\u043b\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 CachedCatApi \u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b: <\/p>\n<pre><code class=\"php\">interface Cache {     public function isNotFresh($lifetime);      public function put($url);      public function get(); }  class FileCache implements Cache {     private $cacheFilePath;      public function __construct()     {         $this-&gt;cacheFilePath = __DIR__ . '\/..\/..\/cache\/random';     }      public function isNotFresh($lifetime)     {         return !file_exists($this-&gt;cacheFilePath)                  || time() - filemtime($this-&gt;cacheFilePath) &gt; $lifetime     }      public function put($url)     {         file_put_contents($this-&gt;cacheFilePath, $url);     }      public function get()     {          return file_get_contents($this-&gt;cacheFilePath);     } }  class CachedCatApi implements CatApi {     ...     private $cache;      public function __construct(CatApi $realCatApi, Cache $cache)     {         ...         $this-&gt;cache = $cache;     }      public function getRandomImage()     {         if ($this-&gt;cache-&gt;isNotFresh()) {             ...              $this-&gt;cache-&gt;put($url);              return $url;         }          return $this-&gt;cache-&gt;get();     } } <\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u044d\u0442\u0438\u0445 \u0441\u0442\u0440\u0430\u0448\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 sleep() \u0432 CachedCatApiTest! \u0418 \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0434\u043b\u044f Cache. \u042f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043a\u0430\u043a \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  \u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c:<\/p>\n<ol>\n<li>\u041c\u043d\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f API \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 Cache. \u041c\u0435\u0442\u043e\u0434 isNotFresh() \u0442\u044f\u0436\u0435\u043b\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043c, \u0447\u0442\u043e \u0438\u0437 Doctrine), \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0434\u043b\u044f \u043b\u044e\u0434\u0435\u0439, \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u0441 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 PHP.<\/li>\n<li>\u041f\u0443\u0442\u044c \u0434\u043b\u044f \u043a\u044d\u0448\u0430 \u0432\u0441\u0435 \u0435\u0449\u0435 \u0437\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0435\u043d \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 FileCache. \u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c.<\/li>\n<\/ol>\n<p>  \u041f\u0435\u0440\u0432\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0430 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u043b\u0435\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0412\u0442\u043e\u0440\u0430\u044f \u0436\u0435 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u043f\u0443\u0442\u0438 \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0441\u043a\u0440\u044b\u043b\u0438 \u0441 \u0433\u043b\u0430\u0437 \u0434\u043e\u043b\u043e\u0439 \u043c\u043d\u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0438 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u044b.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u043e\u0434 \u0432 FileCache \u0438 FileGetContentsHttpClient \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0441\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0430 \u0442\u0435\u0441\u0442\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u0445\u0440\u0443\u043f\u043a\u0438\u0435. \u041d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u043e\u0442 \u0447\u0442\u043e: \u043e\u0442\u043a\u0430\u0436\u0438\u0442\u0435\u0441\u044c \u043e\u0442 \u0438\u0445 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f <a href=\"https:\/\/github.com\/thephpleague\/flysystem\">\u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/github.com\/guzzle\/guzzle\">\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/a>. \u0411\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043b\u0435\u0436\u0438\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 \u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u0445, \u043d\u043e \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0441\u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0432\u0430\u0436\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/p>\n<p>  <i>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442&#8230;<\/i>   \t<\/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=\"http:\/\/habrahabr.ru\/post\/263139\/\"> http:\/\/habrahabr.ru\/post\/263139\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/389\/bf3\/282\/389bf3282a848b64b37aa11a60bce887.jpg\" alt=\"image\" title=\"Franz Marc - Girl with cat II, 1912\" align=\"left\"\/> \u042d\u0442\u043e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"http:\/\/habrahabr.ru\/post\/262995\/\">\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435\u043c<\/a> \u0446\u0438\u043a\u043b\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043e\u0442 Matthias Noback. <\/p>\n<h4>\u041c\u0438\u0440 \u043d\u0435 \u0442\u0430\u043a \u043d\u0430\u0434\u0435\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043d\u0435\u0433\u043e \u043e\u043f\u0438\u0440\u0430\u0442\u044c\u0441\u044f<\/h4>\n<p>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u0441\u0440\u0435\u0434\u0430 \u0431\u044b\u043b\u0430 \u0432\u043e\u0432\u043b\u0435\u0447\u0435\u043d\u0430 \u0432 \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u044b, \u0432\u044b \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442\u0435 \u0442\u0435\u0441\u0442\u044b, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u043f\u0430\u043b \u0438\u043b\u0438 \u0436\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2014 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442 \u0443\u043f\u0430\u0434\u0435\u0442 \u0434\u0430\u0436\u0435 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u0440\u043d\u043e. \u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0430\u0434\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e, \u0447\u0435\u0433\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d.<\/p>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 (CachedCatApi \u0438 RealCatApi) \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u044b \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u044d\u0442\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0438 \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>  \u041e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0448\u0435\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u043e\u0432\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0440\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432 file_get_contents() \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c FileGetContentsHttpClient.<\/p>\n<pre><code class=\"php\">class FileGetContentsHttpClient {     public function get($url)     {         return @file_get_contents($url);     } } <\/code><\/pre>\n<p>  <\/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-262055","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/262055","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=262055"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/262055\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}