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

Createphp Laravel Package

midgard/createphp

CreatePHP is a lightweight PHP library to integrate Create.js into existing apps and frameworks. Implement RdfMapperInterface to map domain models to RDF metadata, enabling in-place content editing and semantic data handling.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer:

    composer require midgard/createphp
    

    (Note: Due to age, verify compatibility with your PHP version—this package was last updated in 2015.)

  2. Basic Integration:

    • Implement RdfMapperInterface for your domain models (e.g., User, Post).
    • Use the provided abstract mappers in Mapper/ (e.g., AbstractRdfMapper) to reduce boilerplate.
    • Example minimal mapper:
      use Midgard\CreatePHP\RdfMapperInterface;
      
      class UserMapper implements RdfMapperInterface {
          public function objectToName($object) { return 'user'; }
          public function objectToRdf($object) { /* Convert to RDF */ }
          public function rdfToObject($rdf) { /* Convert RDF to PHP object */ }
          public function store($entity, $object) { /* Save to backend */ }
      }
      
  3. First Use Case:

    • Register your mapper with the Manager:
      $manager = new \Midgard\CreatePHP\Manager();
      $manager->setMapper('user', new UserMapper());
      
    • Use the RestService to handle Create.js requests (e.g., CRUD operations):
      $restService = $manager->getRestHandler();
      $restService->handleRequest(); // Process incoming Create.js API calls
      
  4. Quick Demo:

    • Test with the demo (MidCOM integration) to visualize expected RDF structures.

Implementation Patterns

Core Workflow

  1. Model Mapping:

    • Bidirectional Sync: Map PHP objects ↔ RDF triples (e.g., Useruser:hasName, user:hasEmail).
    • Hierarchies: Use ChainRdfMapper (since v1.1.0) to combine mappers for complex models (e.g., Post + Author).
      $chainMapper = new \Midgard\CreatePHP\ChainRdfMapper([$userMapper, $postMapper]);
      
  2. REST API Integration:

    • Laravel Route Binding:
      Route::post('/api/createjs', function () {
          $manager = app(\Midgard\CreatePHP\Manager::class);
          return $manager->getRestHandler()->handleRequest();
      });
      
    • Request Handling: The RestService auto-parses Create.js payloads (JSON) and returns RDF responses.
  3. Data Persistence:

    • Implement store() in your mapper to save RDF to your backend (e.g., Doctrine, Eloquent, or raw SQL).
    • Example with Eloquent:
      public function store($entity, $object) {
          $model = User::create([
              'name' => $object->name,
              'email' => $object->email,
          ]);
          return $model->toArray(); // Return data for Create.js
      }
      
  4. Workflow Management (v1.0.0+):

    • Register workflows via RestService (not Manager):
      $restService->registerWorkflow('publish_post', function ($data) {
          // Custom logic (e.g., publish logic)
          return ['status' => 'success'];
      });
      

Laravel-Specific Tips

  • Service Provider: Bind the Manager and RestService in AppServiceProvider:
    public function register() {
        $this->app->singleton(\Midgard\CreatePHP\Manager::class, function ($app) {
            $manager = new \Midgard\CreatePHP\Manager();
            $manager->setMapper('user', new UserMapper());
            return $manager;
        });
    }
    
  • Middleware: Protect Create.js endpoints with auth middleware:
    Route::post('/api/createjs', [CreateJSController::class, 'handle'])
         ->middleware('auth:api');
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warnings:

    • BC Breaks: Check release notes for changes (e.g., RdfMapperInterface::objectToName added in v1.1.0).
    • Manager vs. RestService: Workflows moved from Manager to RestService in v1.0.0 (update calls if using older code).
  2. RDF Complexity:

    • Schema Design: Create.js expects specific RDF structures. Validate your objectToRdf() output against the demo.
    • Circular References: Avoid infinite loops in rdfToObject() when models reference each other (e.g., UserPost).
  3. Performance:

    • Large Datasets: The package isn’t optimized for bulk operations. Consider batching or caching RDF conversions.
    • Memory Usage: RDF parsing can be memory-intensive for deep object graphs. Test with memory_get_usage().
  4. Archived Status:

    • No Active Maintenance: Use with caution in production. Fork or extend if critical bugs arise.
    • PHP Version: Test compatibility (e.g., PHP 7+ may break due to deprecated functions like json_encode() flags).

Debugging

  1. Logging RDF: Add debug output in mappers:

    public function objectToRdf($object) {
        $rdf = $this->buildRdf($object);
        \Log::debug('RDF Output:', ['rdf' => $rdf]);
        return $rdf;
    }
    
  2. Create.js Payloads:

    • Inspect raw requests/response with:
      $requestData = json_decode(file_get_contents('php://input'), true);
      \Log::debug('Create.js Request:', $requestData);
      
  3. Mapper Validation:

    • Test edge cases:
      // Test empty objects
      $mapper->rdfToObject([]);
      
      // Test nested objects
      $mapper->objectToRdf((object) ['name' => 'Test', 'children' => []]);
      

Extension Points

  1. Custom RDF Vocabulary: Extend AbstractRdfMapper to add domain-specific predicates:

    class CustomRdfMapper extends \Midgard\CreatePHP\AbstractRdfMapper {
        protected function getCustomPredicates() {
            return [
                'http://example.com#customProperty' => 'custom_property',
            ];
        }
    }
    
  2. Event Hooks: Use Laravel events to trigger actions on RDF operations:

    // In your mapper's store() method:
    event(new \App\Events\RdfStored($entity, $object));
    
  3. Alternative Backends: Replace the default store() implementation to integrate with:

    • Graph Databases: Use libraries like rdflib-php for SPARQL endpoints.
    • NoSQL: Map RDF to MongoDB/Elasticsearch documents.

Configuration Quirks

  1. Node Types: The config format changed in v0.9.0. Ensure your nodeType and childtypes are defined as arrays:

    // Old (pre-0.9.0)
    'nodeType' => 'user',
    
    // New (0.9.0+)
    'nodeType' => ['user'],
    'childtypes' => ['post' => ['type' => 'post']],
    
  2. Chained Mappers:

    • Order Matters: Mappers in ChainRdfMapper are executed in sequence. Place more specific mappers first.
    • Conflicts: Handle property name collisions explicitly (e.g., user:email vs. author:email).
  3. Error Handling:

    • Create.js expects HTTP 200 for success, even with warnings. Use Laravel’s response()->json() to customize:
      return response()->json(['success' => true, 'warnings' => ['field' => 'Invalid value']], 200);
      
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle