1. Go to this page and download the library: Download cesurapp/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/ */
cesurapp / media-bundle example snippets
use Cesurapp\MediaBundle\Entity\MediaSuperClass;
use Cesurapp\MediaBundle\Entity\Traits\MediaTrait;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\HasLifecycleCallbacks]
class Post extends MediaSuperClass
{
use MediaTrait;
// Columns whose media are removed together with the entity
public function getMediaColumns(): array
{
return ['media'];
}
}
$media = $post->getMedia(); // array<string, Media>
$first = $user->getAvatarFirst();
$media->toString($storage); // public or signed URL
$media->getResponse($storage); // HTTP response (nosniff, private files never shared-cached)
$media->getContent($storage);
// Media columns hold lazy references: load a whole list in one query
$mediaRepository->preload(array_map(fn (User $u) => $u->getAvatar(), $users));
$em->remove($media);
$em->flush(); // object deleted from storage once the transaction commits
$em->remove($post);
$em->flush(); // MediaSuperClass removes the post's media in the same flush
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.