Installation:
composer require beloop/squarespace
composer.json for PHP 7.2+ compatibility and Symfony dependencies.Service Provider Setup:
Since the package lacks Laravel-native integration, manually bind the Symfony-based SquarespaceManager in AppServiceProvider:
use Beloop\Squarespace\SquarespaceManager;
use Symfony\Component\HttpClient\HttpClient;
public function register()
{
$this->app->singleton(SquarespaceManager::class, function ($app) {
return new SquarespaceManager(
HttpClient::create(['base_uri' => config('squarespace.api_url')]),
config('squarespace.api_key')
);
});
}
Configuration:
Add to config/services.php or a new config/squarespace.php:
'squarespace' => [
'api_url' => 'https://api.squarespace.com/1.0',
'api_key' => env('SQUARESPACE_API_KEY'),
'site_id' => env('SQUARESPACE_SITE_ID'),
],
First Use Case: Fetch a Squarespace site’s collections (e.g., courses):
use Beloop\Squarespace\SquarespaceManager;
public function getCollections(SquarespaceManager $squarespace)
{
$response = $squarespace->get('/collections');
return json_decode($response->getContent(), true);
}
(Note: Replace /collections with the actual endpoint from the package’s docs.)
Pattern: Use the package as a Symfony HTTP client wrapper for Squarespace’s REST API.
public function syncUsers(SquarespaceManager $squarespace)
{
$laravelUsers = User::all();
foreach ($laravelUsers as $user) {
$squarespace->post('/users', [
'email' => $user->email,
'name' => $user->name,
]);
}
}
Http client if the package’s abstraction is too rigid.Pattern: Leverage Symfony’s EventDispatcher (if available) to trigger Laravel events.
use Symfony\Component\EventDispatcher\EventDispatcher;
use Illuminate\Support\Facades\Event;
$eventDispatcher = new EventDispatcher();
$eventDispatcher->addListener('squarespace.webhook.received', function ($event) {
Event::dispatch(new SquarespaceWebhookReceived($event->getData()));
});
Pattern: Use Symfony’s Console component (if present) for CLI tasks.
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncSquarespaceCourses extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$squarespace = app(SquarespaceManager::class);
$courses = $squarespace->get('/courses');
// Process courses...
}
}
AppServiceProvider:
$this->app->singleton(SyncSquarespaceCourses::class);
Pattern: Offload long-running tasks (e.g., bulk data sync) to Laravel queues.
public function syncCourses(SquarespaceManager $squarespace)
{
SyncCoursesJob::dispatch($squarespace)->onQueue('squarespace');
}
class SyncCoursesJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue;
public function handle(SquarespaceManager $squarespace)
{
$courses = $squarespace->get('/courses');
// Process and store courses...
}
}
Pattern: Expose a Laravel route to receive Squarespace webhooks and delegate to the package.
Route::post('/squarespace/webhook', [SquarespaceWebhookController::class, 'handle']);
public function handle(Request $request, SquarespaceManager $squarespace)
{
$webhookData = $request->json()->all();
$squarespace->processWebhook($webhookData); // Hypothetical method
}
Pattern: Use Laravel’s Collection or Transformer packages to map Squarespace responses to Eloquent models.
use Illuminate\Support\Collection;
public function transformCourses(Collection $squarespaceCourses)
{
return $squarespaceCourses->map(function ($course) {
return new Course([
'title' => $course['title'],
'slug' => $course['url'],
'squarespace_id' => $course['id'],
]);
});
}
Symfony Dependency Hell:
HttpClient, EventDispatcher).composer why-not symfony/* to identify conflicts and replace with Laravel equivalents.Deprecated API Endpoints:
$squarespace->setClient(HttpClient::create(['base_uri' => 'https://api.squarespace.com/2.0']));
No Laravel Facades:
Squarespace::get()), forcing manual DI.app/Facades/Squarespace.php:
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Squarespace extends Facade
{
protected static function getFacadeAccessor() { return 'squarespace.manager'; }
}
Event System Mismatch:
EventDispatcher won’t integrate seamlessly with Laravel’s Events.$eventDispatcher->addListener('squarespace.user.created', function ($event) {
event(new UserCreated($event->getUser()));
});
Missing Error Handling:
try {
$response = $squarespace->get('/nonexistent');
} catch (\Symfony\Contracts\HttpClient\Exception\ClientException $e) {
Log::error('Squarespace API error: ' . $e->getMessage());
}
No Webhook Verification:
public function handle(Request $request)
{
$signature = $request->header('X-Squarespace-Signature');
if (!hash_equals($signature, $this->generateSignature($request->getContent()))) {
abort(403);
}
// Process webhook...
}
Log API Requests/Responses: Add a middleware to log Squarespace API calls:
$squarespace->getClient()->setOptions([
'on_request' => function ($request) {
Log::debug('Squarespace Request:', [
'url' => $request->getUri(),
'method' => $request->getMethod(),
]);
},
'on_response' => function ($response) {
Log::debug('Squarespace Response:', [
'status' => $response->getStatusCode(),
'body' => $response->getContent(false),
]);
},
]);
Test with Postman: Manually test endpoints using Postman to isolate whether issues are with the package or Squarespace’s API.
Symfony Debug Dump:
Use Symfony’s var_dump() or dump() (if available) for debugging:
$data = $squarespace->get('/collections');
\Symfony\Component\VarDumper\VarDumper::dump($data);
How can I help you explore Laravel packages today?