1. Go to this page and download the library: Download meuhmeuhconcept/processor 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/ */
meuhmeuhconcept / processor example snippets
$object; // The object is the reason of your request.
$request = ['action' => 'validate', 'item' => $object];
$chainProcessor; // We considere that this processors is already init with several processors
$request; // We considere that you already build the request
if ($chainProcessor->supports($request) { // Test if the processor can do the job
$response = $chainProcessor->proccess($request); //Do the job
}
use Mmc\Processor\Component\ResponseStatusCode;
if ($response->getStatusCode() == ResponseStatusCode::OK) {
// the job had been correctly done.
} else {
$reasonPhrase = $response->getReasonPhrase();
// The message who explain the cause of the status code
}
$response->getExtra('name');
$response->getOutput();
use Mmc\Processor\Component\Processor;
use Mmc\Processor\Component\Response;
use Mmc\Processor\Component\ResponseStatusCode;
class CustomProcessor implements Processor
{
public function supports($request)
{
// With the $request you have to decide if this processor can do the job
// i.e.
return $request instanceof MyClass;
}
public function process($request)
{
// Advice : check the method 'supports'
if (!$this->supports($request)) {
return new Response($request, null, ResponseStatusCode::NOT_SUPPORTED);
}
// do the job
// and return the Response
return Response($request, $output); // $output had been create during the job was doing
}
}
$chainProcessor->add(new CustomProcessor());
use Mmc\Processor\Component\AbstractProcessor;
class CustomProcessor extends AbstractProcessor
{
public function supports($request)
{
// With the $request you have to decide if this processor can do the job
// i.e.
return $request instanceof MyClass;
}
protected function doPocess($request)
{
// No need to check if $request is supported
// do the job
// and return the Response
// or nothing for bad response
// or throw exception for bad response
// or directly the ouput for bood response
}
}
use Mmc\Processor\Component\Processor;
use Mmc\Processor\Component\ProcessorTrait;
class CustomProcessor implements Processor
{
use ProcessorTrait;
public function supports($request)
{
// With the $request you have to decide if this processor can do the job
// i.e.
return $request instanceof MyClass;
}
protected function doPocess($request)
{
return $this->otherMethod($request);
}
}
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Mmc\Processor\Bridge\Symfony\Bundle\MmcProcessorBundle(),
];
// ...
return $bundles;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.