1. Go to this page and download the library: Download redgem/servicesio-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redgem / servicesio-bundle example snippets
php
class MessageController
{
public function singleAction(int $id, DocumentManager $documentManager)
{
$single = $documentManager
->getRepository(Message::class)->find($id);
}
public function listingAction(DocumentManager $documentManager)
{
$listing = $documentManager
->getRepository(Message::class)->findAll();
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class SingleView extends View
{
public function content()
{
return $this->createItem()
->set('message', $this->createItem()
->set('id', $this->params['single']->id)
->set('title', $this->params['single']->title);
->set('description', $this->params['single']->description)
);
}
}
php
use Redgem\ServicesIOBundle\Lib\View\Service as View;
class MessageController
{
public function singleAction(int $id, DocumentManager $documentManager, View $view)
{
$single = $documentManager
->getRepository(Message::class)->find($id);
return $view->render(
SingleView::class,
['single' => $single]
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class ListingView extends View
{
public function content()
{
$collection = $this->createCollection();
foreach($this->params['listing'] as $message) {
$collection->push(
$this->createItem()
->set('id', $this->params['message']->id)
->set('title', $this->params['message']->title);
->set('description', $this->params['message']->description)
);
);
}
return $this->createItem()
->set('listing', $collection);
}
}
php
use Redgem\ServicesIOBundle\Lib\View\Service as View;
class MessageController
{
public function listingAction(DocumentManager $documentManager, View $view)
{
$listing = $documentManager
->getRepository(Message::class)->findAll();
return $view->render(
ListingView::class,
['listing' => $listing]
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class MessageView extends View
{
public function content()
{
return $this->createItem()
->set('id', $this->params['message']->id)
->set('title', $this->params['message']->title);
->set('description', $this->params['message']->description)
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class SingleView extends View
{
public function content()
{
return $this->createItem()
->set('message', $this->partial(MessageView::class, ['message' => $this->params['single']]));
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class ListingView extends View
{
public function content()
{
$collection = $this->createCollection();
foreach($this->params['listing'] as $message) {
$collection->push(
$this->partial(MessageView::class, ['message' => $message])
);
}
return $this->createItem()
->set('listing', $collection);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class UserView extends View
{
public function content()
{
return $this->createItem()
->set('id', $this->params['user']->id)
->set('name', $this->params['user']->name);
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class MessageView extends View
{
public function content()
{
return $this->createItem()
->set('id', $this->params['message']->id)
->set('title', $this->params['message']->title);
->set('description', $this->params['message']->description)
->set('user', ($this->params['message']->user == null) ? null
: $this->partial(UserView:class, ['user' => $this->params['message']])
)
);
}
}
php
public function visitorAction(View $view)
{
return $view->render(
UserView::class,
['user' => $this->getUser()] //returns a User object
);
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class SingleView extends View
{
public function content()
{
return $this->createItem()
->set('visitor', $this->controller('App\MyController\VisitorAction'))
->set('response', $this->createItem()
->set('message', $this->partial(MessageView::class, ['message' => $this->params['single']]))
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class ListingView extends View
{
public function content()
{
$collection = $this->createCollection();
foreach($this->params['listing'] as $message) {
$collection->push(
$this->partial(MessageView::class, ['message' => $message])
);
}
return $this->createItem()
->set('visitor', $this->controller('App\MyController\VisitorAction'))
->set('response', $this->createItem()
->set('listing', $collection)
);
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class DecoratorView extends View
{
public function content()
{
return $this->createItem()
->set('visitor', $this->controller('App\MyController\VisitorAction'))
->set('response', null, 'fullResponse');
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class SingleView extends View
{
public function getParent()
{
return DecoratorView::class;
}
public function blockFullResponse()
{
return $this->createItem()
->set('message', $this->partial(MessageView::class, ['message' => $this->params['single']]));
}
}
php
namespace MyBundle\View;
use Redgem\ServicesIOBundle\Lib\View\View;
class ListingView extends View
{
public function getParent()
{
return DecoratorView::class;
}
public function blockFullResponse()
{
$collection = $this->createCollection();
foreach($this->params['listing'] as $message) {
$collection->push(
$this->partial(MessageView::class, ['message' => $message])
);
}
return $this->createItem()
->set('listing', $collection);
}
}
php
public function getParent()
{
return array(MyFriendBundleView::class, MyBundleDecoratorView::class);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.