beloop/core
Core component of the Beloop LMS suite: shared foundations used by other Beloop components and bundles built on Symfony. MIT licensed. Read-only split package—use the main beloop/components repository for issues, questions, and PRs.
Installation Update Composer to ensure compatibility with PHP 7.2+:
composer require beloop/core:^1.0 --with-all-dependencies
Verify your PHP version (php -v) meets the 7.2+ requirement.
Service Provider
Register the provider in config/app.php:
'providers' => [
Beloop\Core\BeloopServiceProvider::class,
],
Publish Config Publish the updated config file:
php artisan vendor:publish --provider="Beloop\Core\BeloopServiceProvider" --tag="config"
Review config/beloop.php for PHP 7.2+ optimizations.
First Use Case Use the facade or container binding (if available):
use Beloop\Core\Facades\Beloop;
$result = Beloop::process('input', ['schema' => 'new_schema']); // Updated method signature
PHP 7.2+ Features
array/iterable support in newer PHP versions.$transformed = Beloop::transform(iterable $data): array;
Schema Validation
config/beloop.php with PHP 7.2+ syntax:
'schemas' => [
'new_schema' => [
'fields' => [
'name' => ['type' => 'string', 'nullable' => true],
],
],
],
Event Handling with PHP 7.2+
Event::listen(BeloopEvents::PROCESSED, function (ProcessedEvent $event) {
Log::debug('Processed data:', $event->getData());
});
Middleware Integration
namespace App\Http\Middleware;
use Beloop\Core\Beloop;
use Closure;
class BeloopMiddleware
{
public function __invoke($request, Closure $next): Response
{
$request->merge(['processed' => Beloop::sanitize($request->all())]);
return $next($request);
}
}
PHP Version Mismatch
FatalErrorException: Class 'Beloop\Core\Processor' not found or similar.php -v). Use a .php-version file or Docker if needed.Deprecated Features
Undefined Methods
Beloop::debug() may not exist in v1.0.Log::debug() directly or check the src/ for alternatives.Config Changes
config/beloop.php with the package’s default config for breaking changes.Enable Strict Typing
Add to composer.json for stricter checks:
"config": {
"platform-check": true,
"preferred-install": "dist"
}
Then run:
composer install --prefer-dist --no-dev
Dump Processed Data Use PHP 7.2+ features for debugging:
dd(Beloop::process($data, ['schema' => 'new_schema']));
Check for Nullable Returns
If a method returns ?array, handle null cases:
$result = Beloop::fetchData();
if ($result === null) {
return response()->json(['error' => 'Data not found'], 404);
}
Custom Processors with PHP 7.2+ Extend core classes with typed properties:
namespace App\Extensions;
use Beloop\Core\Processor;
class CustomProcessor extends Processor
{
public function __construct(private array $config) {}
public function extraLogic(array $data): array
{
return array_merge($data, ['processed_at' => now()->toIso8601String()]);
}
}
Add New Schemas with Type Safety
Define schemas with strict typing in config/beloop.php:
'schemas' => [
'user' => [
'fields' => [
'id' => ['type' => 'int', 'required' => true],
'email' => ['type' => 'string', 'format' => 'email'],
],
],
],
Override Default Config
Use PHP 7.2+ array merging in config/beloop.php:
return array_merge([
'debug' => env('BELOOP_DEBUG', false),
], config('beloop.custom', []));
How can I help you explore Laravel packages today?