Weave 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

Parse Bundle Laravel Package

devtrw/parse-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require devtrw/parse-bundle
    

    Ensure your AppKernel.php includes the bundle:

    $bundles[] = new Devtrw\ParseBundle\DevtrwParseBundle();
    
  2. Configuration: Add Parse credentials to config/packages/devtrw_parse.yaml:

    devtrw_parse:
        application_id: 'YOUR_APP_ID'
        rest_api_key: 'YOUR_REST_API_KEY'
        master_key: 'YOUR_MASTER_KEY'  # Optional, for admin operations
    
  3. First Use Case: Fetch a Parse class (e.g., Post) in a controller:

    use Devtrw\ParseBundle\Service\ParseService;
    
    class PostController extends AbstractController
    {
        public function index(ParseService $parseService)
        {
            $posts = $parseService->getClass('Post')->find();
            return $this->json($posts);
        }
    }
    

Implementation Patterns

Core Workflows

  1. CRUD Operations: Use the ParseService to interact with Parse classes:

    // Create
    $post = $parseService->getClass('Post')->create(['title' => 'Hello', 'content' => 'World']);
    
    // Read
    $posts = $parseService->getClass('Post')->find(['title' => 'Hello']);
    
    // Update
    $post->set('content', 'Updated!')->save();
    
    // Delete
    $post->delete();
    
  2. Querying: Chain query methods for complex filters:

    $posts = $parseService->getClass('Post')
        ->where('author', 'user123')
        ->greaterThan('createdAt', '2023-01-01')
        ->limit(10)
        ->find();
    
  3. File Handling: Upload/download files via ParseFile:

    $file = $parseService->getFile('profile.jpg', file_get_contents('path/to/file'));
    $file->save();
    
    // Download later
    $file->getContent();
    
  4. Event Hooks: Subscribe to Parse events (e.g., beforeSave) via the ParseEventDispatcher:

    $dispatcher = $parseService->getEventDispatcher();
    $dispatcher->addListener('beforeSave', function ($event) {
        $object = $event->getObject();
        $object->set('updatedAt', new \DateTime());
    });
    

Integration Tips

  1. Symfony Forms: Bind Parse objects to Symfony forms for validation:

    $form = $this->createForm(PostType::class, $post);
    if ($form->isSubmitted() && $form->isValid()) {
        $post->save(); // Uses ParseService under the hood
    }
    
  2. API Versioning: Override the default API version in config:

    devtrw_parse:
        api_version: '1.16.0'  # Default is '1.13.0'
    
  3. Caching: Cache frequent queries using Symfony’s cache system:

    $cacheKey = 'posts:user123';
    $posts = $this->cache->get($cacheKey, function () use ($parseService) {
        return $parseService->getClass('Post')->where('author', 'user123')->find();
    });
    
  4. Testing: Use the ParseService in tests with a mock client:

    $parseService = $this->createMock(ParseService::class);
    $parseService->method('getClass')->willReturn($mockClass);
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warnings: Parse.com’s API is deprecated. Use this bundle only for legacy projects or as a learning tool. Migrate to Parse Server or Back4App for production.

  2. Rate Limits: Parse.com enforces strict rate limits. Implement exponential backoff for retries:

    try {
        $result = $parseService->getClass('Post')->find();
    } catch (RateLimitException $e) {
        sleep($e->getRetryAfter());
        retry();
    }
    
  3. Master Key Exposure: Avoid committing master_key to version control. Use environment variables:

    # .env
    PARSE_MASTER_KEY=your_master_key_here
    
  4. Class Name Collisions: Parse class names are case-sensitive. Ensure consistency between Laravel and Parse:

    // Laravel model: Post
    // Parse class: "Post" (not "posts" or "POST")
    

Debugging

  1. Enable Debug Mode: Toggle debug logs in config:

    devtrw_parse:
        debug: true  # Logs all API requests/responses
    
  2. Common Errors:

    • InvalidQueryException: Validate query syntax (e.g., where() conditions).
    • ConnectionException: Check application_id/api_key and network connectivity.
    • ClassNotFoundException: Ensure the Parse class exists and is spelled correctly.
  3. Stuck Queries: Parse queries may hang on malformed input. Validate data before sending:

    $data = ['title' => 'Test', 'content' => null]; // Ensure no invalid types
    

Extension Points

  1. Custom Clients: Extend ParseClient to add custom endpoints:

    class CustomParseClient extends ParseClient
    {
        public function customEndpoint($path, $data = [])
        {
            return $this->request('POST', "/1/custom/{$path}", $data);
        }
    }
    
  2. Event Subscribers: Create subscribers for Parse events (e.g., afterDelete):

    class PostSubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return ['afterDelete' => 'onPostDelete'];
        }
    
        public function onPostDelete(ParseEvent $event)
        {
            // Log or trigger side effects
        }
    }
    
  3. Model Bindings: Bind Laravel models to Parse classes dynamically:

    $parseService->bindModel(Post::class, 'Post'); // Maps Post model to Parse "Post" class
    
  4. Middleware: Add middleware to transform requests/responses:

    $parseService->addMiddleware(function ($request) {
        $request->setHeader('X-Custom-Header', 'value');
    });
    
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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log