যদিও GrabzIt এর পিএইচপি লাইব্রেরি একটি লাইব্রেরি প্রদানের উপর ফোকাস করে যা যেকোনো পিএইচপি প্রকল্পে ব্যবহার করা যেতে পারে। Symfony পিএইচপি প্রকল্পগুলি একটি অনন্য উপায়ে একত্রিত করা হয় যার জন্য একটু বেশি কাজ করা প্রয়োজন।
সিমফনি বর্তমানে ব্যবহৃত সবচেয়ে বড় পিএইচপি ফ্রেমওয়ার্কগুলির মধ্যে একটি এটি লাইব্রেরি এবং উপাদানগুলির একটি পুনঃব্যবহারযোগ্য সেট সরবরাহ করে ওয়েব বিকাশের গতি বাড়ায়। যে GrabzIt এখন একটি অংশ, Torben Lundsgaard ধন্যবাদ টিএলএমিডিয়া যিনি Symfony-এর জন্য GrabzIt-এর একটি বান্ডিল তৈরি করেছেন। এই ওপেন সোর্স সফটওয়্যারটি ব্যবহার করে এমআইটি লাইসেন্স.
GrabzIt বান্ডেল পেতে আপনাকে প্রথমে এটি কম্পোজারের সাথে ইনস্টল করতে হবে।
composer require tlamedia/grabzit-bundle
তারপর এটি আপনার কার্নেলে যোগ করুন।
public function registerBundles() { $bundles = array( //... new Tla\GrabzitBundle\TlaGrabzitBundle(), //…
আপনার পেতে API কী এবং গোপন এবং সেগুলিকে আপনার কনফিগার ফাইলে যুক্ত করুন।
# config.yml tla_grabzit: key: 'Sign in to view your Application Key' secret: 'Sign in to view your Application Secret'
বান্ডেলটি বেশ কয়েকটি পরিষেবা নিবন্ধন করে যেগুলিকে ডাকা হলে উপযুক্ত GrabzIt ক্লাস ফেরত দেয়।
পরিষেবা শনাক্তকারী | GrabzIt ক্লাস |
---|---|
tla_grabzit.client | GrabzItClient |
tla_grabzit.imageoptions | GrabzItImageOptions |
tla_grabzit.pdfoptions | GrabzItPDFOptions |
tla_grabzit.docxoptions | GrabzItDOCXOptions |
tla_grabzit.animationoptions | GrabzItAnimationOptions |
tla_grabzit.tableoptions | GrabzItTableOptions |
সিমফনি ফ্রেমওয়ার্কে কিভাবে থাম্বনেইল তৈরি করতে হয় তার একটি উদাহরণ।
namespace App\Service; use Symfony\Component\DependencyInjection\ContainerInterface as Container; class ThumbnailGenerator { private $container; public function __construct(Container $container) { $this->router = $router; $this->container = $container; } public function generateThumbnail($url) { $grabzItHandlerUrl = 'https://www.my-grabzit-thumbnail-site.com/api/thumbmail-ready'; $options = $this->container->get('tla_grabzit.imageoptions'); $options->setBrowserWidth(1366); $options->setBrowserHeight(768); $options->setFormat("png"); $options->setWidth(320); $options->setHeight(240); $options->setCustomId($domain); $grabzIt = $this->container->get('tla_grabzit.client'); $grabzIt->URLToImage($url, $options); $grabzIt->Save($grabzItHandlerUrl); try { $grabzIt->URLToImage($url, $options); $grabzIt->Save($grabzItHandlerUrl); $result = true; } catch (\Throwable $t) { $result = false; } return $result; } }
Symfony ফ্রেমওয়ার্কের একটি হ্যান্ডলার ব্যবহার করে GrabzIt থেকে কীভাবে ক্যাপচার গ্রহণ করা যায় তার একটি উদাহরণ। অবশ্যই আপনার নিজের প্রয়োজনীয়তা মেলে এটি পরিবর্তন করতে হবে।
namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class ApiController extends Controller { public function thumbnailReadyAction(Request $request) { $id = urldecode($request->query->get('id')); $customId = $request->query->get('customid'); $thumbnailFormat = $request->query->get('format'); if ($id && $customId && $thumbnailFormat) { $grabzItApplicationKey = $this->container->getParameter('tla_grabzit.key'); if (0 === strpos($id, $grabzItApplicationKey)) { $grabzIt = $this->container->get('tla_grabzit.client'); $result = $grabzIt->GetResult($id); if ($result) { $rootPath = $this->get('kernel')->getRootDir() . '/../'; $thumbnailsPath = $rootPath . 'var/thumbnails/'; $fileName = $customId. '.' .$thumbnailFormat; file_put_contents($thumbnailsPath . $fileName, $result); } else { throw $this->createNotFoundException('GrabzIt did not return a file'); } } else { throw $this->createNotFoundException('Wrong key - Unauthorized access'); } } else { throw $this->createNotFoundException('Missing parameters'); } return new Response(null, 200); } }
এই সাহায্য নিবন্ধটি থেকে প্রসারিত করা হয়েছে GitHub এ বিস্তারিত এই বান্ডিলের জন্য সাহায্য.