### Symfony Bundle Registration Source: https://context7.com/21torr/embedhelpersbundle/llms.txt Register the TorrEmbedHelpersBundle in your Symfony application. For Symfony Flex projects, this is often automatic. For manual setup, add the bundle to config/bundles.php. ```php ['all' => true], ]; ``` -------------------------------- ### Implement Custom Video Platform Parser Source: https://context7.com/21torr/embedhelpersbundle/llms.txt Implement VideoUrlParserInterface to create custom parsers for new video platforms. Use the AutoconfigureTag attribute for automatic registration with Symfony's dependency injection. Note: The VideoPlatform enum should be extended for a real implementation. ```php [a-zA-Z0-9]+)~', $path, $matches)) { // Note: Would need to extend VideoPlatform enum for real implementation return new VideoDetails( VideoPlatform::YouTube, // Placeholder - extend enum in practice $matches["id"], ); } return null; } } // The parser will be automatically registered with VideoUrlParser // via Symfony's tagged service iterator ``` -------------------------------- ### Parse Video URLs with VideoUrlParser Source: https://context7.com/21torr/embedhelpersbundle/llms.txt Use VideoUrlParser to parse various video URLs. It supports YouTube and Vimeo, returning null for unrecognized or invalid URLs. Autowired in Symfony controllers or can be instantiated manually. ```php videoUrlParser->parseVideoUrl($userProvidedUrl); if ($details === null) { // URL not recognized or invalid return null; } // Get the platform and video ID echo $details->platform->value; // "youtube", "youtube-short", or "vimeo" echo $details->id; // "dQw4w9WgXcQ" // Generate embed URL return $details->getEmbedUrl(); // "https://www.youtube.com/embed/dQw4w9WgXcQ" } } // Manual instantiation (for testing or non-Symfony usage) $parser = new VideoUrlParser([ new YouTubeUrlParser(), new VimeoUrlParser(), ]); $result = $parser->parseVideoUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } $result = $parser->parseVideoUrl("https://youtu.be/dQw4w9WgXcQ"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } $result = $parser->parseVideoUrl("https://vimeo.com/123456789"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } $result = $parser->parseVideoUrl("https://invalid-url.com/video"); // Result: null ``` -------------------------------- ### Configure services.yaml for EmbedHelpersBundle Source: https://context7.com/21torr/embedhelpersbundle/llms.txt This configuration automatically includes the EmbedHelpersBundle services in your Symfony application. Ensure this file is present in your config directory. ```yaml services: _defaults: autoconfigure: true autowire: true Torr\EmbedHelpers\: resource: ../src/* exclude: - ../src/Exception - ../src/TorrEmbedHelpersBundle.php ``` -------------------------------- ### VideoDetails Data Object for Video Information Source: https://context7.com/21torr/embedhelpersbundle/llms.txt The VideoDetails object holds parsed video information, including platform and ID. It offers a convenience method to generate the embed URL and can be used to construct iframe HTML. ```php platform->value; // "youtube" echo $details->id; // "dQw4w9WgXcQ" // Generate embed URL echo $details->getEmbedUrl(); // "https://www.youtube.com/embed/dQw4w9WgXcQ" // Example: Generate iframe HTML $embedUrl = $details->getEmbedUrl(); $iframe = sprintf( '', htmlspecialchars($embedUrl, ENT_QUOTES) ); ``` -------------------------------- ### Parse Vimeo Video URLs Source: https://context7.com/21torr/embedhelpersbundle/llms.txt Use VimeoUrlParser to parse standard Vimeo video pages, channel URLs, and staff picks. It validates that video IDs are numeric. Invalid URLs return null. ```php parseUrl("https://vimeo.com/123456789"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } // With query parameters $parser->parseUrl("https://vimeo.com/123456789?autoplay=1"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } // With fragment $parser->parseUrl("https://vimeo.com/123456789#t=30s"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } // Channel/Staff Picks URLs $parser->parseUrl("https://vimeo.com/channels/staffpicks/123456789"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } // HTTP URLs also supported $parser->parseUrl("http://vimeo.com/123456789"); // Result: VideoDetails { platform: Vimeo, id: "123456789" } // Invalid URLs return null $parser->parseUrl("https://vimeo.com/user/123456789"); // null (user page) $parser->parseUrl("https://vimeo.com/123456789/settings"); // null (path after ID) $parser->parseUrl("https://player.vimeo.com/video/123456789"); // null (wrong subdomain) ``` -------------------------------- ### VideoPlatform Enum for Embed URL Generation Source: https://context7.com/21torr/embedhelpersbundle/llms.txt The VideoPlatform enum represents supported video platforms and provides a method to generate platform-specific embed URLs. Useful for conditional logic based on video platform. ```php getEmbedUrl("dQw4w9WgXcQ"); // Result: "https://www.youtube.com/embed/dQw4w9WgXcQ" $shortsEmbed = VideoPlatform::YouTubeShort->getEmbedUrl("abc12345xyz"); // Result: "https://www.youtube.com/embed/abc12345xyz" $vimeoEmbed = VideoPlatform::Vimeo->getEmbedUrl("123456789"); // Result: "https://vimeo.com/123456789" // Use in conditionals $details = $parser->parseVideoUrl($url); if ($details?->platform === VideoPlatform::Vimeo) { // Handle Vimeo-specific logic } ``` -------------------------------- ### Parse YouTube Video URLs Source: https://context7.com/21torr/embedhelpersbundle/llms.txt Use YouTubeUrlParser to parse various YouTube URL formats. It validates video IDs and distinguishes between standard YouTube videos and YouTube Shorts. Invalid URLs return null. ```php parseUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } // Short URLs (youtu.be) $parser->parseUrl("https://youtu.be/dQw4w9WgXcQ"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } // Embed URLs $parser->parseUrl("https://www.youtube.com/embed/dQw4w9WgXcQ"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } // YouTube Shorts (returns YouTubeShort platform) $parser->parseUrl("https://www.youtube.com/shorts/abc12345xyz"); // Result: VideoDetails { platform: YouTubeShort, id: "abc12345xyz" } // Legacy /v/ URLs $parser->parseUrl("https://www.youtube.com/v/dQw4w9WgXcQ?autoplay=1"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } // oEmbed URLs (recursive parsing) $parser->parseUrl("https://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DdQw4w9WgXcQ&format=json"); // Result: VideoDetails { platform: YouTube, id: "dQw4w9WgXcQ" } // Invalid URLs return null $parser->parseUrl("https://www.youtube.com/watch?v=invalid"); // null (ID wrong length) $parser->parseUrl("https://www.youtube.com/channel/UCxyz"); // null (not a video URL) $parser->parseUrl("https://example.com/video"); // null (wrong domain) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.