PHP code example of survos / media-bundle

1. Go to this page and download the library: Download survos/media-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

survos / media-bundle example snippets


use Survos\DataContracts\Util\MediaKeyService;

$key = MediaKeyService::keyFromString('https://example.com/image.jpg');
$url = MediaKeyService::stringFromEncoded($key);   // round-trips

use Survos\DataContracts\Util\MediaIdentity;

$id = MediaIdentity::idFromOriginalUrl('https://example.com/image.jpg');
// => 16 lowercase hex chars, e.g. "0c05e2ff8ac3dd8f"

use Survos\MediaBundle\Entity\BaseMedia;
use Survos\MediaBundle\Workflow\MediaWorkflowDefinition;
use Survos\WorkflowExtrasBundle\Attribute\AsWorkflow;

#[AsWorkflow(supports: [BaseMedia::class], name: self::WORKFLOW_NAME)]
final class MediaWorkflow extends MediaWorkflowDefinition
{
    public const WORKFLOW_NAME = 'media';
}

$media = $mediaRegistry->ensureMedia($imageUrl);
$em->flush();   // → media.dispatch queued → mediary → callback → status applied

foreach ($data->images as $imageUrl) {
    $media = $mediaRegistry->ensureMedia($imageUrl);   // bulk-safe, no flush, no network
}

$data = $sidecarClient->read($mediaId, 'observe');          // null on a miss
$data = $sidecarClient->remember($mediaId, 'observe', fn () => $this->runAi(...));

$result = $mediaBatchDispatcher->dispatch('museum', [$url], [
    'callback_url' => 'https://my-app.example/webhook/media',
]);

$probe = $mediaBatchDispatcher->probe($result->media[0]->mediaKey);
if ($probe->isComplete()) {
    // $probe->meta / ->context / ->ocr / ->ai
}