Skip to content

Casting

Eldar Shahmaliyev edited this page Jan 27, 2025 · 1 revision

The SDK uses type-safe response objects that automatically cast API responses into convenient PHP objects.

Example: Getting a Profile

Retrieve a profile and access its attributes:

$profile = bskyFacade($client)->getProfile()
    ->actor($client->authenticated()->handle())
    ->send();

// Access profile data
echo $profile->displayName();    // Returns string
echo $profile->followersCount(); // Returns int

/** @var \Carbon\Carbon $createdAt */
$createdAt = $profile->createdAt(); // Returns Carbon instance

Iterating Over Response Objects

Response objects representing collections are iterable:

/** @var \Atproto\Responses\Objects\FollowersObject $response */
$response = bskyFacade()->getFollowers()
    ->actor($profile->handle())
    ->send();

foreach ($response->followers() as $follower) {
    /** @var \Atproto\Responses\Objects\FollowerObject $follower */
    echo sprintf(
        "%s joined on %s\n",
        $follower->handle(),
        $follower->createdAt()->format('Y-m-d')
    );
}
  • 🏠 Home
    Introduction to the SDK and its features

  • 🚀 Quick Start
    Get started quickly with the basics of using the Bluesky SDK

  • ⚙️ Installation
    Step-by-step guide to installing the SDK

  • 🛠️ Architecture Overview
    Learn about the SDK's structure and design principles

  • 📖 BskyFacade
    Simplify API interactions with the facade

  • 💾 Serialization
    Serialize and deserialize data effectively

  • 🔄 Session Management
    Manage authentication and session reuse

  • 🧹 Casting
    Explore type-safe response casting in the SDK

  • 💡 Examples
    Practical usage examples for various features

Clone this wiki locally