coderockr/parse
PHP package for parsing and extracting data from strings and text sources with a simple API. Useful for building lightweight parsers, reading structured patterns, and turning raw input into usable values in Laravel or any PHP project.
Installation
composer require coderockr/parse
Add the package to config/app.php under providers if using Laravel’s service container.
Configuration Publish the config file:
php artisan vendor:publish --provider="Coderockr\Parse\ParseServiceProvider"
Update .env with your Parse credentials:
PARSE_APP_ID=your_app_id
PARSE_REST_API_KEY=your_rest_key
PARSE_MASTER_KEY=your_master_key (if needed)
First Use Case: Querying Objects
use Coderockr\Parse\ParseClient;
$client = app(ParseClient::class);
$results = $client->get('GameScore')->query()->get();
CRUD Operations
$client->get('GameScore')->create([
'score' => 100,
'playerName' => 'John',
]);
$client->get('GameScore')->get('objectId');
$client->get('GameScore')->update('objectId', ['score' => 200]);
$client->get('GameScore')->delete('objectId');
Querying with Conditions
$query = $client->get('GameScore')
->query()
->equalTo('playerName', 'John')
->greaterThan('score', 50)
->get();
File Operations
$file = $client->getFile('profilePic.jpg', file_get_contents('path/to/file'));
$file->save();
Cloud Code Execution
$client->executeCloudFunction('myFunction', ['param' => 'value']);
Laravel Facades: Extend the package with a facade for cleaner syntax:
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Facade;
Facade::register('Parse', function () {
return app('parse');
});
Usage:
Parse::get('GameScore')->query()->get();
Middleware for Auth: Protect routes using Parse’s session tokens:
Route::middleware('parse.auth')->group(function () {
// Protected routes
});
Event Listeners: Subscribe to Parse webhooks for real-time updates:
// routes/web.php
Route::post('/parse-webhook', 'ParseWebhookController@handle');
Master Key Exposure
PARSE_MASTER_KEY in environment files for production. Use Laravel’s secure secrets or a secrets manager.Rate Limiting
Query Complexity
include() with multiple relations) may fail silently. Test thoroughly with small datasets.File Handling
ParseFile::saveWithChunks() if needed.Enable Debug Mode:
$client = app(ParseClient::class)->setDebug(true);
Logs will appear in storage/logs/parse.log.
HTTP Errors:
Parse returns HTTP errors (e.g., 404 for missing objects). Use Laravel’s try-catch with Coderockr\Parse\Exceptions\ParseException:
try {
$client->get('NonExistentClass')->get('fakeId');
} catch (ParseException $e) {
Log::error($e->getMessage());
}
Custom Classes
Extend Coderockr\Parse\ParseObject for domain-specific logic:
class User extends ParseObject
{
public function getFullName()
{
return $this->get('firstName') . ' ' . $this->get('lastName');
}
}
Hooks for Lifecycle Events
Use Laravel’s observers or model events to trigger actions on Parse object changes:
// app/Providers/AppServiceProvider.php
ParseObject::observe('GameScore', function ($model) {
if ($model->wasRecentlyCreated) {
// Send notification
}
});
Batch Operations
For bulk updates, use ParseObject::updateAll():
ParseObject::updateAll('GameScore', ['score' => 0], ['playerName' => 'John']);
How can I help you explore Laravel packages today?