{"id":275097,"date":"2016-02-28T22:12:02","date_gmt":"2016-02-28T19:12:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=275097"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=275097","title":{"rendered":"Symfony \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FOSRestBundle"},"content":{"rendered":"<p>       \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c RESTfull API \u0434\u043b\u044f AngularJS \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0441 \u0431\u0435\u043a\u0435\u043d\u0434\u043e\u043c \u043d\u0430 Symfony.<br \/>  \u0418, \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FOSRestBundle \u2014 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 bundle, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c backend.<br \/>  \u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u043e\u043c, \u044f \u0431\u0443\u0434\u0443 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Symfony FosRestBundle.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043c \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"http:\/\/jmsyst.com\/bundles\/JMSSerializerBundle\">JMSSerializerBundle<\/a> \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Entity \u0432 JSON \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f API \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439) \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  <b>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/b><br \/>  <i>1)\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c composer.json<\/i><\/p>\n<p>  <code>&quot;friendsofsymfony\/rest-bundle&quot;: &quot;^1.7&quot;,<br \/>  &quot;jms\/serializer-bundle&quot;: &quot;^1.1&quot;<br \/>  <\/code><\/p>\n<p>  <i>2)\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/i>  <\/p>\n<pre><code class=\"php\">\/\/ app\/AppKernel.php class AppKernel extends Kernel {     public function registerBundles()     {         $bundles = array(             \/\/ ...             new JMS\\SerializerBundle\\JMSSerializerBundle(),             new FOS\\RestBundle\\FOSRestBundle(),         );          \/\/ ...     } } <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 config.yml<br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0448 FOSRestBundle  <\/p>\n<pre><code>fos_rest:     body_listener: true     view:       view_response_listener: true     body_converter:         enabled: true         format_listener:         rules:             - { path: '^\/api',  priorities: ['json'], fallback_format: json, exception_fallback_format: html, prefer_extension: true }             - { path: '^\/', priorities: [ 'html', '*\/*'], fallback_format: html, prefer_extension: true } <\/code><\/pre>\n<p>  <b>body_listener<\/b> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 EventListener \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u0435\u0433\u043e Accept-* \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445<br \/>  <b>view_response_listener<\/b> \u2014 \u044d\u0442\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c View \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<br \/>  <b>body_converter.rules<\/b> \u2014 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a, \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0430\u0434\u0440\u0435\u0441, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <i>\/api<\/i> \u0432 \u0430\u0434\u0440\u0435\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f JSON, \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u2014 html.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u043d\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043d\u0430\u0448\u0435\u0433\u043e JMSSerializeBundle  <\/p>\n<pre><code>jms_serializer:     property_naming:         separator:  _         lower_case: true      metadata:         cache: file         debug: &quot;%kernel.debug%&quot;         file_cache:             dir: &quot;%kernel.cache_dir%\/serializer&quot;         directories:             FOSUserBundle:                 namespace_prefix: FOS\\UserBundle                 path: %kernel.root_dir%\/config\/serializer\/FosUserBundle             AppBundle:                 namespace_prefix: AppBundle                 path: %kernel.root_dir%\/config\/serializer\/AppBundle         auto_detection: true <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442\u0435 \u0441 <b>jms_serializer.metadata.directories<\/b><br \/>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c serializer-\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0430\u043c-\u0442\u043e \u0438\u043b\u0438 \u0442\u0430\u043c-\u0442\u043e \ud83d\ude42<br \/>  \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u044f \u043b\u0438\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e FosUserBundle \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0438 \u0432\u043e\u0442 \u043c\u043e\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c:  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace AppBundle\\Entity;  use JMS\\Serializer\\Annotation\\Expose; use JMS\\Serializer\\Annotation\\Groups; use JMS\\Serializer\\Annotation\\Exclude; use JMS\\Serializer\\Annotation\\VirtualProperty; use JMS\\Serializer\\Annotation\\ExclusionPolicy;  use Doctrine\\ORM\\Mapping as ORM; use FOS\\UserBundle\\Model\\User as BaseUser; use FOS\\UserBundle\\Model\\Group;  \/**  * User  *  * @ORM\\Table(name=&quot;user&quot;)  * @ORM\\Entity(repositoryClass=&quot;AppBundle\\Repository\\UserRepository&quot;)  * @ExclusionPolicy(&quot;all&quot;)  *\/ class User extends BaseUser {     \/**      * @ORM\\Id      * @ORM\\Column(type=&quot;integer&quot;)      * @ORM\\GeneratedValue(strategy=&quot;AUTO&quot;)      * @Exclude      *\/     protected $id;      \/**      * @ORM\\Column(type=&quot;integer&quot;)      * @Groups({&quot;user&quot;})      * @Expose      *\/     private $balance = 0;      \/**      * Set balance      *      * @param integer $balance      *      * @return User      *\/     public function setBalance($balance)     {         $this-&gt;balance = $balance;          return $this;     }      \/**      * Get balance      *      * @return integer      *\/     public function getBalance()     {         return $this-&gt;balance;     } }  <\/code><\/pre>\n<p>  \u042f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 FosUserBundle. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0431\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f JmsSerializerBundle \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<br \/>  \u0418\u0442\u0430\u043a, \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f <b>jms_serializer.metadata.directories<\/b>:  <\/p>\n<pre><code>directories:             FOSUserBundle:                 namespace_prefix: FOS\\UserBundle                 path: %kernel.root_dir%\/config\/serializer\/FosUserBundle             AppBundle:                 namespace_prefix: AppBundle                 path: %kernel.root_dir%\/config\/serializer\/AppBundle <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043b\u044f AppBundle \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 app\/config\/serializer\/AppBundle, \u0430 \u0434\u043b\u044f FosUserBundle \u2014 \u0432 app\/config\/serializer\/FosUserBundle.<br \/>  \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<br \/>  \u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 AppBundle\\Entity\\User \u2014 app\/config\/serializer\/AppBundle\/Entity.User.(yml|xml|php)<br \/>  \u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 FosUserBundle \u2014 app\/config\/serializer\/FosUserBundle\/Model.User.(yml|xml|php)<\/p>\n<p>  \u041b\u0438\u0447\u043d\u043e \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c YAML. \u041d\u0430\u0447\u043d\u0435\u043c \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u0430\u043a\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c JMSSerializer \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441.<br \/>  <i>app\/config\/serializer\/AppBundle\/Entity.User.yml<\/i>  <\/p>\n<pre><code>AppBundle\\Entity\\User:     exclusion_policy: ALL     properties:         balance:             expose: true <\/code><\/pre>\n<p>  <i>app\/config\/serializer\/FosUserBundle\/Model.User.yml<\/i>  <\/p>\n<pre><code>FOS\\UserBundle\\Model\\User:     exclusion_policy: ALL     group: user     properties:         id:             expose: true         username:             expose: true         email:             expose: true         balance:             expose: true <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 1 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:  <\/p>\n<pre><code>{&quot;id&quot;:1,&quot;username&quot;:&quot;admin&quot;,&quot;email&quot;:&quot;admin&quot;,&quot;balance&quot;:0}<\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0435\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0435\u0449\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0435, \u043a\u0430\u043a \u043f\u0430\u0440\u043e\u043b\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b \u043d\u0443\u0436\u043d\u044b\u043c \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438 \u0442\u0430\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  <b>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/b><br \/>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u043e\u0443\u0442:  <\/p>\n<pre><code>backend_user:     resource: &quot;@BackendUserBundle\/Resources\/config\/routing.yml&quot;     prefix:   \/api <\/code><\/pre>\n<p>  <i>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \/api \u2014 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0433\u043e, \u0430 \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044f\u0442\u044c \u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f fos_rest \u0432 config.yml<\/i><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c BackendUserBundle\/Resources\/config\/routing.yml:  <\/p>\n<pre><code>backend_user_users:   type: rest   resource: &quot;@BackendUserBundle\/Controller\/UsersController.php&quot;   prefix: \/v1 <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430:  <\/p>\n<pre><code class=\"php\">&lt;?php  namespace Backend\\UserBundle\\Controller;  use AppBundle\\Entity\\User; use FOS\\RestBundle\\Controller\\FOSRestController; use FOS\\RestBundle\\Controller\\Annotations as Rest; use FOS\\RestBundle\\Controller\\Annotations\\View; use Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;  \/**  * Class UsersController  * @package Backend\\UserBundle\\Controller  *\/ class UsersController extends FOSRestController {     \/**      * @return \\Symfony\\Component\\HttpFoundation\\Response      * @View(serializerGroups={&quot;user&quot;})      *\/     public function getUsersAllAction()     {         $users = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:User')-&gt;findAll();          $view = $this-&gt;view($users, 200);         return $this-&gt;handleView($view);     }       \/**      * @param $id      * @return \\Symfony\\Component\\HttpFoundation\\Response      * @View(serializerGroups={&quot;user&quot;})      *\/     public function getUserAction($id)     {         $user = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:User')-&gt;find($id);          if (!$user instanceof User) {             throw new NotFoundHttpException('User not found');         }          $view = $this-&gt;view($user, 200);         return $this-&gt;handleView($view);     } }  <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442 <b>FOS\\RestBundle\\Controller\\FOSRestController<\/b>.<br \/>  \u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e  <a href=\"https:\/\/habrahabr.ru\/users\/view\/\" class=\"user_link\">View<\/a>(serializerGroups={\u00abuser\u00bb}).<br \/>  \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442.\u043a. \u043c\u044b \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u0438\u0434\u0435\u0442\u044c \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 App\\Entity\\User \u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 FosUserBundle, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u00abuser\u00bb.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 2 \u044d\u043a\u0448\u0435\u043d\u0430 getUserAction \u0438 getUsersAllAction. \u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u044b \u043f\u043e\u0439\u043c\u0435\u0442\u0435 \u0441\u0443\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<br \/>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c debug \u0432\u0441\u0435\u0445 \u0440\u043e\u0443\u0442\u043e\u0432:<br \/>  $ app\/console debug:route | grep api<br \/>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:  <\/p>\n<pre><code>get_users_all                              GET        ANY      ANY    \/api\/v1\/users\/all.{_format}                          get_user                                      GET        ANY      ANY    \/api\/v1\/users\/{id}.{_format}  <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:  <\/p>\n<pre><code class=\"php\">&lt;?php class UsersComment extends Controller {     public function postUser($id)     {} \/\/ &quot;post_user_comment_vote&quot; [POST] \/users\/{id}      public function getUser($id)     {} \/\/ &quot;get_user_comments&quot;   [GET] \/users\/{id}      public function deleteUserAction($id)     {} \/\/ &quot;delete_user_comment&quot; [DELETE] \/users\/{id}      public function newUserAction($id)     {} \/\/ &quot;new_user_comments&quot;   [GET] \/users\/{id}\/new      public function editUserAction($slug, $id)     {} \/\/ &quot;edit_user_comment&quot;   [GET] \/users\/{id}\/edit      public function removeUserAction($slug)     {} \/\/ &quot;remove_user_comment&quot; [GET] \/users\/{slug}\/remove } <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443 \u0438 \u043c\u0435\u0442\u043e\u0434\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0442\u043e\u0442 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434.<br \/>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FOSRestBundle \u0434\u043b\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443: &quot;\/users\/{id}\/comments&quot; \u0438 \u0442.\u043f.               <\/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\/278123\/\"> https:\/\/habrahabr.ru\/post\/278123\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c RESTfull API \u0434\u043b\u044f AngularJS \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0441 \u0431\u0435\u043a\u0435\u043d\u0434\u043e\u043c \u043d\u0430 Symfony.<br \/>  \u0418, \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FOSRestBundle \u2014 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 bundle, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c backend.<br \/>  \u0417\u0434\u0435\u0441\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u0410\u043d\u0433\u0443\u043b\u044f\u0440\u043e\u043c, \u044f \u0431\u0443\u0434\u0443 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Symfony FosRestBundle.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043c \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"http:\/\/jmsyst.com\/bundles\/JMSSerializerBundle\">JMSSerializerBundle<\/a> \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 Entity \u0432 JSON \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f API \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439) \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.  <\/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-275097","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275097","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=275097"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275097\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}