Skip to content

Instantly share code, notes, and snippets.

@dersonsena
Created February 8, 2020 17:40
Show Gist options
  • Save dersonsena/c892be60179f37d780b1888375a7c2c0 to your computer and use it in GitHub Desktop.
Save dersonsena/c892be60179f37d780b1888375a7c2c0 to your computer and use it in GitHub Desktop.
<?php
namespace App\Infra\DomainActions;
use App\Infra\ActiveRecord\ActiveRecordAbstract;
abstract class ActionsAbstract
{
/**
* @return string
*/
abstract public static function getPath(): string;
/**
* @param ActiveRecordAbstract $model
* @param array $options
* @return array
*/
public static function create(ActiveRecordAbstract $model, array $options = []): array
{
return [
'to' => [static::getPath() . '/create'],
'text' => 'Novo ' . $model::getEntityDescription(),
'htmlOptions' => ($options['htmlOptions'] ?? [])
];
}
/**
* @param ActiveRecordAbstract $model
* @param array $options
* @return array
*/
public static function update(ActiveRecordAbstract $model, array $options = []): array
{
return [
'to' => [static::getPath() . '/update/' . $model->id],
'text' => 'Editar ' . $model::getEntityDescription(),
'htmlOptions' => ($options['htmlOptions'] ?? [])
];
}
/**
* @param ActiveRecordAbstract $model
* @param array $options
* @return array
*/
public static function view(ActiveRecordAbstract $model, array $options = []): array
{
return [
'to' => [static::getPath() . '/view/' . $model->id],
'text' => 'Ver ' . $model::getEntityDescription(),
'htmlOptions' => ($options['htmlOptions'] ?? [])
];
}
/**
* @param ActiveRecordAbstract $model
* @param array $options
* @return array
*/
public static function delete(ActiveRecordAbstract $model, array $options = []): array
{
return [
'to' => [static::getPath() . '/delete/' . $model->id],
'text' => 'Deletar ' . $model::getEntityDescription(),
'htmlOptions' => ($options['htmlOptions'] ?? [])
];
}
}
<?php
namespace App\Domains\Client;
use App\Infra\DomainActions\ActionsAbstract;
class ClientActions extends ActionsAbstract
{
/**
* @inheritDoc
*/
public static function getPath(): string
{
return '/clients';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment