PHP code example of parasek / concretecms_utility

1. Go to this page and download the library: Download parasek/concretecms_utility 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/ */

    

parasek / concretecms_utility example snippets


// Hints for services
/** @var \ConcreteCmsUtility\FileUtility $fileUtility */
/** @var \ConcreteCmsUtility\ImageUtility $imageUtility */
/** @var \ConcreteCmsUtility\VideoUtility $videoUtility */

// Hints for returned objects
/** @var \ConcreteCmsUtility\DTO\FileData $file */
/** @var \ConcreteCmsUtility\DTO\GalleryImageData $image */
/** @var \ConcreteCmsUtility\DTO\ImageData $image */
/** @var \ConcreteCmsUtility\DTO\SliderImageData $image */
/** @var \ConcreteCmsUtility\DTO\VideoeData $video */

// Hints for arrays (when using foreach loop etc.).
/** @var \ConcreteCmsUtility\DTO\ImageData[] $images */

$file->url;

$image->url;
$image->width;
$image->height;

$image->file->url;

composer 

$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('ConcreteCmsUtility', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/' . 'ConcreteCmsUtility');
$classLoader->register();



'providers' => [
    'concrete_cms_utility' => ConcreteCmsUtility\ServiceProvider::class,
],

app('utils/image')->getPlaceholderString(width: 100, height: 100);
$app->make('utils/file')->getFile(file: 1)->url;
$this->app->make('utils/video')->getVideo(file: 1)->url;

use ConcreteCmsUtility\FileUtility;
use ConcreteCmsUtility\ImageUtility;

// Using Service container in controllers
$fileUtility = $this->app->make(FileUtility::class);
$imageUtility = $this->app->make(ImageUtility::class);

// Using Service container in view files
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$fileUtility = $app->make(FileUtility::class);
$imageUtility = $app->make(ImageUtility::class);

// Using app helper (everywhere)
$fileUtility = app(FileUtility::class);
$imageUtility = app(ImageUtility::class);

// Using dependency injection
class CustomClass
{
    protected FileUtility $fileUtility;
    protected ImageUtility $imageUtility;

    public function __construct(FileUtility $fileUtility, ImageUtility $imageUtility)
    {
        $this->fileUtility = $fileUtility;
        $this->imageUtility = $imageUtility;
    }
}


/** @var \ConcreteCmsUtility\ImageUtility $imageUtility */
/** @var \ConcreteCmsUtility\DTO\GalleryImageData $image */

$imageUtility = app(\ConcreteCmsUtility\ImageUtility::class);

$image = $imageUtility->getGalleryImage(
    file: 29,
    width: 300,
    height: 200,
    crop: true,
    alt: 'Custom alt',
    title: 'Custom Title for lightbox etc.',
    fullscreenWidth: 1600,
    fullscreenHeight: 1200,
    fullscreenCrop: false,
);
//dump($image);