PHP code example of chocofamilyme / restapi-model-listener
1. Go to this page and download the library: Download chocofamilyme/restapi-model-listener 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/ */
chocofamilyme / restapi-model-listener example snippets
composer
class ServiceProvider extends AbstractServiceProvider
{
protected $serviceName = 'eventsManager';
public function register()
{
$this->di->setShared(
$this->serviceName,
function () {
$eventsManager = new Manager();
$eventsManager->attach('model', new ModelsListener());
return $eventsManager;
}
);
}
}
class Order extends Model implements HasEvents
{
const EVENTS = [
'paid' => 'rahmet.order.paid',
'created' => 'rahmet.order.created',
'updated' => 'rahmet.order.updated'
];
/**
* @param string $eventName
* @return string
*/
public function getQueueName(string $eventName) : string
{
return self::EVENTS[$eventName];
}
/**
* @param Model $model
* @return array
*/
public function getAttributes(Model $model): array
{
return [
'id' => $model->getId(),
'custom' => 'some-custom'
];
}
//other logic..
}
public function register()
{
$this->di->setShared(
$this->serviceName,
function () {
$serializer = new CustomSerializer();
$listener = new ModelsListener();
$listener->setObjectSerializer($serializer);
$eventsManager = new Manager();
$eventsManager->attach('model', $listener);
return $eventsManager;
}
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.