1. Go to this page and download the library: Download larapackages/interceptor 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/ */
larapackages / interceptor example snippets
class SomeClass implements \Larapackages\Interceptor\InterceptorInterface {
public static function interceptors(): array
{
return [
// Classes namespaces that will intercept this class
];
}
};
class ArgInterceptor {
public function getName($name) {
$name = mb_strtoupper($name);
return compact('name');
}
};
class ArgClass implements \Larapackages\Interceptor\InterceptorInterface {
public function getName($name) {
return $name;
}
public static function interceptors(): array
{
return [
ArgInterceptor::class
];
}
};
$class = app()->make(ArgClass::class)->getName('fake'); //Will return Fake
class ArgInterceptor {
public function getValidData(array $data) {
$validator = \Illuminate\Support\Facades\Validator::make($data, [
'id' => 'return $data;
}
public static function interceptors(): array
{
return [
ArgInterceptor::class
];
}
};
$class = app()->make(ArgClass::class)->getValidData(['name' => 'fake']); //Will throw a validation exception
$class = app()->make(ArgClass::class)->getValidData(['id' => 1]); //Will return ['id' => 1]
class ArgInterceptor {
public function getName(string $name) {
if ($name === 'test') {
return 'Test Name';
}
}
};
class ArgClass implements \Larapackages\Interceptor\InterceptorInterface {
public function getName(string $name) {
return $name;
}
public static function interceptors(): array
{
return [
ArgInterceptor::class
];
}
};
$class = app()->make(ArgClass::class)->getName('test'); //Will return Test Name
$class = app()->make(ArgClass::class)->getName('second test'); //Will return second test
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.