->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))Įcho "Saving video in target formats.\n"
->resize(new FFMpeg\Coordinate\Dimension(320, 240)) $video = $this->ffmpeg->open('video.mpg') Įcho "Normalizing and resizing the video to smaller dimensions.\n" $this->youtube->saveAs($url, "video.mpg") $title = $this->youtube->fetchVideo($url)->getTitle() Įcho "Saving video file to a temporary file.\n" Public function downloadVideo(string $url): voidĮcho "Fetching video metadata from youtube.\n"
#Facade code#
* to a target format (for the sake of simplicity, the real-world code is * The Facade provides a simple method for downloading video and encoding it index.php: Real world example youtube = new YouTube($youtubeApiKey) Instead of working with dozens of classes, the client uses a simple method on the Facade. In this example, the Facade hides the complexity of the YouTube API and FFmpeg library from the client code. The Facade isolates complexity within a single class and allows other application code to use the straightforward interface. Think of the Facade as a simplicity adapter for some complex subsystem. Output.txt: Execution result Facade initializes subsystems:įacade orders subsystems to perform the action: $facade = new Facade($subsystem1, $subsystem2) * instead of letting the Facade create new instances. * this case, it might be worthwhile to initialize the Facade with these objects * The client code may have some of the subsystem's objects already created. * approach lets you keep the complexity under control. * the client might not even know about the existence of the subsystem. When a facade manages the lifecycle of the subsystem, * The client code works with complex subsystems through a simple interface * Some facades can work with multiple subsystems at the same time. * In any case, to the Subsystem, the Facade is yet another client, and it's not * The Subsystem can accept requests either from the facade or client directly. = "Facade orders subsystems to perform the action:\n" $result = "Facade initializes subsystems:\n"
* The Facade's methods are convenient shortcuts to the sophisticated $this->subsystem2 = $subsystem2 ?: new Subsystem2() index.php: Conceptual example subsystem1 = $subsystem1 ?: new Subsystem1()