Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Json Schema Laravel Package

event-engine/php-json-schema

Event Engine JSON Schema package for PHP. Generate/use JSON Schema with ImmutableRecord type detection. v1.x detects types via method return hints (PHP 7.2–7.3); v2.x uses PHP 7.4+ typed properties for improved schema support.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Schema Validation Layer: Remains robust for JSON Schema validation in Laravel, particularly for APIs, event-driven workflows, and microservices. No architectural changes impact this fit.
  • Event-Driven Systems: Continues to enforce schema compliance for event payloads, reducing runtime errors in Laravel Events, Queues, or third-party brokers.
  • API Contracts: Still useful for OpenAPI/Swagger documentation or API contract enforcement between services.
  • Data Consistency: Validates database writes (Eloquent models) or external API payloads (webhooks, Stripe/PayPal events) unchanged.

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Now explicitly supports PHP 8.4 (previously had deprecations removed), aligning with Laravel 10+.
    • Continues to integrate natively with Laravel’s Validator facade, PSR-15 middleware, and FormRequest classes.
  • Event System Integration: Unchanged; remains compatible with Laravel’s event listeners, queues, and third-party event buses.
  • Database Layer: No changes; still validates Eloquent models via observers, accessors, or custom validation logic.

Technical Risk

  • Schema Complexity: Risk of over-engineering persists for simple validation needs (Laravel’s built-in Validator may still suffice).
  • Maintenance Burden:
    • Reduced: Removal of PHP 8.4 deprecations eliminates potential runtime warnings/errors, improving stability.
    • Dependency on a niche package remains (low stars/activity may still indicate limited long-term support).
  • Tooling Gaps: No new Laravel-specific utilities introduced; gaps in Artisan commands or Nova/Forge integrations persist.

Key Questions

  1. Use Case Clarity: Unchanged – Still critical to clarify if validation is for APIs, events, or database consistency.
  2. Alternatives Assessment: Updated – Now compare against Laravel’s Validator or symfony/validator with PHP 8.4 support in mind.
  3. Schema Management: Unchanged – Versioning and dynamic loading strategies remain relevant.
  4. Error Handling: Unchanged – Custom error formats (e.g., OpenAPI compliance) still require explicit handling.
  5. Testing Strategy: Unchanged – Schema tests in FeatureTests remain necessary.
  6. Performance: Updated – Benchmark against alternatives with PHP 8.4 optimizations (e.g., JIT, typed properties).
  7. Team Skills: Unchanged – JSON Schema (Draft-7/Draft-2020) expertise still needed.

Integration Approach

Stack Fit

  • Laravel Core:
    • Replace/extend Laravel’s Validator for JSON payloads in FormRequest classes, now fully compatible with PHP 8.4.
    • Integrate with Illuminate\Validation\ValidationException for consistent error handling.
  • API Layer:
    • Use PSR-15 middleware (e.g., ValidateJsonSchema) with PHP 8.4 support:
      public function handle($request, Closure $next) {
          $validator = new \EventEngine\JsonSchema\Validator();
          if (!$validator->validate($request->json()->all(), $this->schema)) {
              throw new \Illuminate\Validation\ValidationException($validator->errors());
          }
          return $next($request);
      }
      
  • Event System:
    • Validate event payloads in listeners/queues, now PHP 8.4-compatible:
      public function handle(ExampleEvent $event) {
          $validator = new \EventEngine\JsonSchema\Validator();
          if (!$validator->validate($event->payload, $this->eventSchema)) {
              Log::error('Invalid event payload', ['errors' => $validator->errors()]);
              throw new \RuntimeException('Invalid event schema');
          }
      }
      
  • Database Layer: Unchanged; validate Eloquent models via observers/accessors.

Migration Path

  1. Pilot Phase:
    • Test with a high-risk endpoint/event in PHP 8.4 to validate stability.
    • Compare performance/error handling with Laravel’s built-in Validator.
  2. Incremental Rollout:
    • Add schema validation to FormRequest classes for APIs.
    • Integrate with Laravel Events/Queues for internal validation.
  3. Tooling Integration:
    • Create custom Artisan commands for schema management (e.g., php artisan schema:validate).
    • Leverage PHP 8.4 features (e.g., typed properties) in validator services.

Compatibility

  • Laravel Versions:
    • Now fully compatible with Laravel 10+ (PHP 8.4). Backporting to older versions is no longer necessary unless explicitly required.
  • Dependency Conflicts:
    • No changes; still check for conflicts with other JSON Schema packages (e.g., webonyx/graphql-php).
  • Schema Standards:
    • Confirmed support for Draft-7/Draft-2020 in PHP 8.4. Test custom keywords/extensions if used.

Sequencing

  1. Schema Definition:
    • Define schemas in config/schemas.php or YAML/JSON files (e.g., storage/schemas/).
    • Example (unchanged):
      # storage/schemas/user_created.json
      {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "type": "object",
        "properties": { "id": { "type": "string" } },
        "required": ["id"]
      }
      
  2. Validation Layer:
    • Create a PHP 8.4-compatible validator service:
      // app/Services/JsonSchemaValidator.php
      class JsonSchemaValidator {
          public function validate(array $data, string $schemaPath): bool {
              $validator = new \EventEngine\JsonSchema\Validator();
              $schema = file_get_contents($schemaPath);
              return $validator->validate($data, json_decode($schema, true));
          }
      }
      
  3. Middleware/Listeners:
    • Register middleware globally or per-route (unchanged).
    • Attach to event listeners with PHP 8.4 support.
  4. Error Handling:
    • Customize error responses (e.g., API formats) in Handler.php (unchanged).
  5. Testing:
    • Add schema tests to FeatureTests (unchanged):
      public function test_json_schema_validation() {
          $response = $this->postJson('/api/webhook', ['invalid' => true]);
          $response->assertStatus(422);
      }
      

Operational Impact

Maintenance

  • Schema Updates:
    • Version schemas with semantic versioning (e.g., v1/user.json).
    • Use feature flags for breaking changes; PHP 8.4’s performance improvements may reduce validation overhead.
  • Dependency Management:
    • Reduced risk: Removal of PHP 8.4 deprecations eliminates runtime warnings.
    • Monitor for updates to the package (still niche; low activity may persist).
  • Schema Storage:
    • Store schemas in config/, storage/, or a database table (unchanged).
    • Consider PHP 8.4’s array_is_list() or typed properties for schema metadata.

Support

  • Debugging:
    • Leverage PHP 8.4’s error handling improvements (e.g., better type safety).
    • Use dd() or dump() for schema validation debugging (no changes).
  • Community:
    • Limited community support (low stars/activity); rely on Laravel/PHP forums if issues arise.

Scaling

  • Performance:
    • PHP 8.4 optimizations (JIT, typed properties) may improve validation speed.
    • Benchmark against alternatives (symfony/validator, respect/validation) in high-throughput systems.
  • Resource Usage:
    • Memory/CPU usage may benefit from PHP 8.4’s optimizations (test under load).

Failure Modes

  • Schema Mismatches:
    • Runtime errors if schemas are invalid or malformed (unchanged).
    • Mitigate with pre-deployment schema validation (e.g., Artisan commands).
  • Dependency Failures:
    • Package updates may introduce breaking changes (monitor changelog).
    • Fallback to Laravel’s Validator if critical issues arise.

Ramp-Up

  • Onboarding:
    • Train team on JSON Schema (Draft-7/Draft-2020) and PHP 8.4 features (e.g., typed properties).
    • Document schema authoring/maintenance workflows.
  • Documentation:
    • Update internal docs to reflect PHP 8.4 compatibility and new release notes.
  • Training:
    • Conduct workshops on schema validation patterns (e.g., middleware, events).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky