Skip to content

Instantly share code, notes, and snippets.

@shakkurcwb
Created October 15, 2019 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakkurcwb/22023b41902201b2fcb1d083831fd0ee to your computer and use it in GitHub Desktop.
Save shakkurcwb/22023b41902201b2fcb1d083831fd0ee to your computer and use it in GitHub Desktop.
<?php
namespace App\Services;
use Illuminate\Support\Arr;
abstract class Service
{
/** Parameters */
private $parameters = [];
/** Attributes */
private $attributes = [];
/** Constructor */
public function __construct()
{
//
}
/** Reset Service Properties */
public function reset(): Void
{
$this->parameters = [];
$this->attributes = [];
}
/** Set Parameters */
public function setParameters(Array $parameters = []): Void
{
$this->parameters = array_merge($this->parameters, $parameters);
}
/** Set Attributes */
public function setAttributes(Array $attributes = []): Void
{
$this->attributes = array_merge($this->attributes, $attributes);
}
/** Get Parameters */
public function getParameters(String $key = "")
{
if (!empty($key)) {
return Arr::get($this->parameters, $key);
}
return $this->parameters;
}
/** Get Attributes */
public function getAttributes(String $key = "")
{
if (!empty($key)) {
return Arr::get($this->attributes, $key);
}
return $this->attributes;
}
/**
* Adapter to report an exception.
*
* @param \Exception $e
* @return Void
*/
public function report(\Exception $e): Void
{
throw new \Exception($e);
}
}
<?php
namespace App\Services;
interface ServiceContract
{
/** Execute the Service */
public function execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment