### Complete File Manager Controller Integration (PHP) Source: https://context7.com/mezcalito/ux-filemanager/llms.txt This PHP code provides a full controller implementation for the Mezcalito File Manager within a Symfony application. It demonstrates how to use `FilesystemFactory` to get a filesystem instance and `EncryptionService` to generate secure download URLs, rendering file information in a Twig template. ```php render('files/index.html.twig', [ 'storage' => 'local', ]); } #[Route('/files/api/list/{path}', name: 'app_files_list', requirements: ['path' => '.+'])] public function listFiles(string $path = '/'): Response { $filesystem = $this->filesystemFactory->get('local'); $nodes = iterator_to_array($filesystem->listDirectory($path)); $files = array_map(fn($node) => [ 'id' => $node->getId(), 'name' => $node->getFilename(), 'type' => $node->isFile() ? 'file' : 'directory', 'size' => $node->getSize(), 'modified' => $node->getLastModified()?->format('Y-m-d H:i:s'), 'url' => $node->getUrl(), 'downloadUrl' => $node->isFile() ? $this->generateUrl('mezcalito_filemanager_download', [ 'path' => $this->encryptionService->encrypt($node->getPathname()), 'name' => $node->getFilename(), ]) : null, ], $nodes); return $this->json(['files' => $files]); } } ``` -------------------------------- ### Install Mezcalito UX FileManager with Composer Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This command adds the Mezcalito UX FileManager package to your Symfony project's dependencies using Composer. Ensure you have Composer installed and configured for your project. ```bash composer require mezcalito/ux-filemanager ``` -------------------------------- ### Filesystem Core Operations in PHP Source: https://context7.com/mezcalito/ux-filemanager/llms.txt The `Filesystem` class provides a unified interface for common file and directory operations such as reading, writing, creating, deleting, moving, copying, and searching. It requires a `FilesystemFactory` for initialization and returns `Node` objects for file/directory information. ```php factory->get('local'); // Get file/directory information $node = $filesystem->info('/documents/report.pdf'); echo $node->getId(); // '/documents/report.pdf' echo $node->getFilename(); // 'report.pdf' echo $node->getExtension(); // 'pdf' echo $node->getSize(); // 1024 (bytes) echo $node->getUrl(); // 'https://media.yourdomain.com/documents/report.pdf' echo $node->isFile(); // true echo $node->isDir(); // false // Read file contents $contents = $filesystem->read('/documents/report.txt'); // Write file $filesystem->write('/documents/new-file.txt', 'File contents here'); // Create directory $filesystem->createDirectory('/documents/archives', 0o755); // List directory contents foreach ($filesystem->listDirectory('/documents') as $node) { if ($node->isFile()) { echo "File: " . $node->getFilename(); } else { echo "Dir: " . $node->getFilename(); } } // List directory recursively foreach ($filesystem->listDirectory('/documents', recursive: true) as $node) { echo $node->getPath(); } // Move file or directory $filesystem->move('/documents/old-name.txt', '/documents/new-name.txt'); // Copy file $filesystem->copy('/documents/original.txt', '/documents/backup.txt'); // Search for files foreach ($filesystem->search('report') as $node) { echo "Found: " . $node->getPath(); } // Delete file $filesystem->delete('/documents/old-file.txt'); // Delete directory (recursive) $filesystem->deleteDirectory('/documents/old-folder'); } } ``` -------------------------------- ### Local Filesystem Provider Usage in PHP Source: https://context7.com/mezcalito/ux-filemanager/llms.txt The `LocalFilesystemProvider` class directly handles local filesystem operations. It can be instantiated with a base location, media URL, and an option to ignore dot files. It offers the same core filesystem methods as the `Filesystem` class. ```php info('/images/photo.jpg'); $contents = $provider->read('/data/config.json'); $provider->write('/logs/app.log', 'Log entry'); $provider->createDirectory('/backups/2024'); $provider->delete('/temp/cache.tmp'); $provider->move('/draft.txt', '/published/article.txt'); $provider->copy('/template.html', '/pages/new-page.html'); $provider->deleteDirectory('/old-data'); // Search returns a Generator of Node objects foreach ($provider->search('invoice') as $node) { echo $node->getPath() . " - " . $node->getSize() . " bytes\n"; } ``` -------------------------------- ### Registering TenantConfigurator as a Service (YAML) Source: https://context7.com/mezcalito/ux-filemanager/llms.txt This YAML configuration demonstrates how to register the `TenantConfigurator` class as a service in Symfony. By tagging it with `mezcalito_file_manager.configurator`, the file manager bundle recognizes and utilizes this custom configurator for dynamic storage settings. ```yaml # config/services.yaml services: App\FileManager\TenantConfigurator: tags: ['mezcalito_file_manager.configurator'] ``` -------------------------------- ### List Files API Source: https://context7.com/mezcalito/ux-filemanager/llms.txt API endpoint to list files and directories within a specified path. It returns detailed information about each file or directory, including its name, type, size, modification date, URL, and a secure download URL if applicable. ```APIDOC ## List Files API ### Description Lists files and directories within a given path. ### Method GET ### Endpoint `/files/api/list/{path}` ### Parameters #### Path Parameters - **path** (string) - Optional - The path to list directory contents from. Defaults to '/'. ### Request Example N/A (This is a route definition, not a direct request) ### Response #### Success Response (200) - **files** (array) - An array of file and directory objects. - **id** (string) - Unique identifier for the file/directory. - **name** (string) - The filename or directory name. - **type** (string) - 'file' or 'directory'. - **size** (integer) - Size of the file in bytes. - **modified** (string) - Last modified date in 'YYYY-MM-DD HH:MM:SS' format. - **url** (string) - The direct URL to the file/directory. - **downloadUrl** (string|null) - A secure download URL for files, or null for directories. #### Response Example ```json { "files": [ { "id": "60c72b2f9b1e8a001f4e1d3b", "name": "document.pdf", "type": "file", "size": 102400, "modified": "2023-10-27 10:30:00", "url": "https://example.com/files/document.pdf", "downloadUrl": "/filemanager/download/encrypted_path_here/document.pdf" }, { "id": "60c72b2f9b1e8a001f4e1d3c", "name": "images", "type": "directory", "size": 0, "modified": "2023-10-26 15:00:00", "url": "https://example.com/files/images", "downloadUrl": null } ] } ``` ``` -------------------------------- ### Override Storage Configuration Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Demonstrates how to create custom configurators to dynamically modify storage configuration at runtime. This involves implementing the ConfiguratorInterface and registering the service with the correct tag. ```APIDOC ## Override Storage Configuration ### Description Create custom configurators to dynamically modify storage configuration based on application logic. ### Method N/A (This is a conceptual configuration, not an API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```php tenantService->getCurrentTenant(); // Modify path per tenant $configuration['path'] = sprintf( '/var/www/storage/tenants/%s/files', $tenant->getId() ); // Set tenant-specific media URL $configuration['media_url'] = sprintf( 'https://%s.cdn.example.com/', $tenant->getSubdomain() ); return $configuration; } } ``` ### Response N/A ### Service Registration ```yaml # config/services.yaml services: App\FileManager\TenantConfigurator: tags: ['mezcalito_file_manager.configurator'] ``` ``` -------------------------------- ### Configure Local Storage for Mezcalito UX FileManager Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This YAML configuration sets up a 'local' storage for the Mezcalito UX FileManager. It defines the URI prefix, specifies the 'local' provider, and configures options such as the storage path, media URL, and whether to ignore dot files. This configuration is essential for defining where and how files are managed. ```yaml mezcalito_file_manager: storages: local: uri_prefix: /media provider: local options: path: '%kernel.project_dir%/public/uploads/storages/local' media_url: 'https://media.yourdomain.com/' ignore_dot_files: true ``` -------------------------------- ### Configure Local Storage for Mezcalito UX FileManager Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Configures local file storage within the Mezcalito UX FileManager bundle. This involves setting the storage's URI prefix, provider type, and specific options like the file system path and media URL. ```yaml # config/packages/mezcalito_file_manager.yaml mexicalito_file_manager: storages: local: uri_prefix: /media provider: local options: path: '%kernel.project_dir%/public/uploads/storages/local' media_url: 'https://media.yourdomain.com/' ignore_dot_files: true documents: uri_prefix: /documents provider: local options: path: '%kernel.project_dir%/var/documents' ignore_dot_files: false ``` -------------------------------- ### Configure MezcalitoFileManagerBundle Routes Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Adds the necessary routes for the Mezcalito UX FileManager bundle to your Symfony application. This makes the file manager accessible via the specified prefix. ```yaml # config/routes/mezcalito_file_manager.yaml mexicalito_file_manager: resource: '@MezcalitoFileManagerBundle/config/routes.php' prefix: '/filemanager' ``` -------------------------------- ### Secure File Downloads Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Provides a download controller that utilizes encrypted paths to ensure secure file downloads. This endpoint is designed to protect sensitive files from unauthorized access. ```APIDOC ## Download Controller ### Secure File Downloads ### Description The bundle provides a download controller that uses encrypted paths for secure file downloads. ### Method GET ### Endpoint `/filemanager/download/{path}/{name}` ### Parameters #### Path Parameters - **path** (string) - Required - The encrypted path to the file. - **name** (string) - Required - The name of the file. ### Request Example N/A (This is a route definition, not a direct request) ### Response - **Success Response (200)**: Returns the requested file. - **Error Response**: May return 404 if the file is not found or other errors if the path is invalid. ### Example Usage (Controller) ```php encryptionService->encrypt($filePath); return $this->urlGenerator->generate('mezcalito_filemanager_download', [ 'path' => $encryptedPath, 'name' => basename($filePath), ]); } } ``` ``` -------------------------------- ### Configure Mezcalito UX FileManager Routes in Symfony Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This YAML configuration file defines the routes for the Mezcalito UX FileManager bundle within your Symfony application. It specifies a resource file for routes and sets a base prefix for all file manager related URLs. This allows the bundle to handle file management requests. ```yaml # config/routes/mezcalito_file_manager.yaml mezcalito_file_manager: resource: '@MezcalitoFileManagerBundle/config/routes.php' prefix: '/filemanager' ``` -------------------------------- ### Register Mezcalito UX FileManager Bundle in Symfony Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This PHP code snippet shows how to register the MezcalitoFileManagerBundle in your Symfony application's `config/bundles.php` file. This step is crucial for Symfony to recognize and load the bundle's services. It's often handled automatically by Symfony Flex. ```php // config/bundles.php return [ // ... Mezcalito\FileManagerBundle\MezcalitoFileManagerBundle::class => ['all' => true], ]; ``` -------------------------------- ### Enums Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Lists available enum values for sorting options and modal actions within the file manager. ```APIDOC ## Enums ### Sort Options #### Description Enumerations for defining sorting order. #### Values - **NAME_ASC**: 'name-asc' - Alphabetical A-Z - **NAME_DESC**: 'name-desc' - Alphabetical Z-A - **DATE_ASC**: 'date-asc' - Oldest first - **DATE_DESC**: 'date-desc' - Newest first #### Example Usage ```php tenantService->getCurrentTenant(); // Modify path per tenant $configuration['path'] = sprintf( '/var/www/storage/tenants/%s/files', $tenant->getId() ); // Set tenant-specific media URL $configuration['media_url'] = sprintf( 'https://%s.cdn.example.com/', $tenant->getSubdomain() ); return $configuration; } } ``` -------------------------------- ### Node Class Representation in PHP Source: https://context7.com/mezcalito/ux-filemanager/llms.txt The `Node` class is used to represent files and directories within the filesystem. It provides methods to access metadata such as ID, path, filename, extension, URL, size, last modification date, and type (file or directory). ```php getId(); // Unique identifier (path) $node->getPath(); // Relative path within storage $node->getFilename(); // File/folder name only $node->getExtension(); // File extension (null for directories) $node->getPathname(); // Full absolute filesystem path $node->getUrl(); // Public URL (null for directories) $node->getSize(); // File size in bytes (null for directories) $node->getLastModified(); // DateTime of last modification $node->isFile(); // true if file $node->isDir(); // true if directory // Node type constants Node::TYPE_FILE; // 'file' Node::TYPE_DIR; // 'dir' ``` -------------------------------- ### Include Mezcalito File Manager in Twig Template (HTML-like Syntax) Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This Twig code snippet shows an alternative way to include the Mezcalito File Manager component in a Twig template using HTML-like syntax. It also specifies the 'local' storage. This syntax provides a more declarative approach to integrating components. ```twig ``` -------------------------------- ### Render File Manager UI in Twig Source: https://context7.com/mezcalito/ux-filemanager/llms.txt This Twig template demonstrates how to embed the Mezcalito FileManager component into a Symfony application. It assumes the `storage` variable is available in the Twig context, typically configured in the Symfony services or parameters. The component renders a complete file manager interface. ```twig {# templates/files/index.html.twig #} {% extends 'base.html.twig' %} {% block body %}

File Manager

{# Render the complete file manager UI #}
{% endblock %} ``` -------------------------------- ### Secure File Download URL Generation (PHP) Source: https://context7.com/mezcalito/ux-filemanager/llms.txt This PHP code snippet shows how to generate a secure download URL for files using the Mezcalito File Manager's built-in download controller. It utilizes an `EncryptionService` to encrypt the file path before passing it to the `urlGenerator` for the `mezcalito_filemanager_download` route. ```php // Route: /filemanager/download/{path}/{name} // Route name: mezcalito_filemanager_download use Mezcalito\FileManagerBundle\Service\EncryptionService; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class DocumentController { public function __construct( private readonly EncryptionService $encryptionService, private readonly UrlGeneratorInterface $urlGenerator, ) {} public function getSecureDownloadUrl(string $filePath): string { // Encrypt the file path for security $encryptedPath = $this->encryptionService->encrypt($filePath); return $this->urlGenerator->generate('mezcalito_filemanager_download', [ 'path' => $encryptedPath, 'name' => basename($filePath), ]); } } ``` -------------------------------- ### Render Mezcalito FileSystem Component in Twig Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Renders the main file manager interface using the Mezcalito:FileManager:FileSystem Twig component. It supports specifying the storage to be used. ```twig {# Using Twig syntax #} {{ component('Mezcalito:FileManager:FileSystem', { storage: 'local' }) }} {# Using HTML-like syntax #} {# With custom attributes #} ``` -------------------------------- ### File Manager Sort Options Enum (PHP) Source: https://context7.com/mezcalito/ux-filemanager/llms.txt This PHP code illustrates the available sorting options provided by the Mezcalito File Manager's `Sort` enum. It lists constants for ascending and descending sorts based on file name and modification date, along with their corresponding string values. ```php ``` -------------------------------- ### Render Mezcalito Modal Component in Twig Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Adds the modal dialog component for file operations (create, upload, rename, move, delete) in Mezcalito UX FileManager. It requires the storage to be specified. ```twig ``` -------------------------------- ### Render Mezcalito Content Component in Twig Source: https://context7.com/mezcalito/ux-filemanager/llms.txt Embeds the directory listing component for Mezcalito UX FileManager within Twig templates. It accepts a storage variable and supports sorting options. ```twig {# Embedded in templates #} {# The component exposes sorting options #} {# Available sort values: name-asc, name-desc, date-asc, date-desc #} ``` -------------------------------- ### Include Mezcalito File Manager in Twig Template (Twig Syntax) Source: https://github.com/mezcalito/ux-filemanager/blob/main/README.md This Twig code snippet demonstrates how to embed the Mezcalito File Manager component directly into a Twig template using the `component` function. It specifies the 'local' storage to be used. This method leverages Symfony's Twig Component system for dynamic rendering. ```twig {{ component('Mezcalito:FileManager:FileSystem', { storage: 'local' }) }} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.