Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Darvin Fileman Bundle Laravel Package

darvinstudio/darvin-fileman-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require darvinstudio/darvin-fileman-bundle
    

    Register the bundle in config/bundles.php (Symfony 4.3+):

    return [
        // ...
        Darvin\DatabaserBundle\DarvinFilemanBundle::class => ['all' => true],
    ];
    
  2. First Use Case: Pull files from a remote server to your local Symfony project:

    php bin/console fileman:pull user@example.com:/remote/path /local/path
    
    • Replace user@example.com with the remote server credentials.
    • Replace /remote/path with the remote directory containing files.
    • Replace /local/path with your local Symfony project’s uploads directory (e.g., public/uploads).
  3. Configuration: Check config/packages/darvin_fileman.yaml (auto-generated) for default settings. Override as needed:

    darvin_fileman:
        default_port: 22  # SSH default port
        timeout: 30       # Connection timeout in seconds
    

Implementation Patterns

Workflows

  1. File Synchronization:

    • Pull Workflow: Use fileman:pull to sync files from a staging server to your local environment before testing.
      php bin/console fileman:pull --key=/path/to/ssh_key user@staging.example.com:/uploads public/uploads
      
    • Push Workflow: Deploy files from local to production after testing:
      php bin/console fileman:push --password user@prod.example.com:/uploads public/uploads
      
  2. Environment-Specific Paths: Store remote/local paths in .env for consistency:

    REMOTE_UPLOADS_PATH=/var/www/uploads
    LOCAL_UPLOADS_PATH=public/uploads
    

    Reference them in commands:

    php bin/console fileman:pull user@example.com:$REMOTE_UPLOADS_PATH $LOCAL_UPLOADS_PATH
    
  3. Integration with Symfony Events: Trigger file syncs post-deployment using Symfony’s kernel.terminate event:

    // src/EventListener/FileSyncListener.php
    namespace App\EventListener;
    
    use Symfony\Component\HttpKernel\Event\TerminateEvent;
    use Symfony\Component\HttpKernel\KernelEvents;
    
    class FileSyncListener
    {
        public function onTerminate(TerminateEvent $event)
        {
            if ($event->getRequest()->getPathInfo() === '/deploy') {
                shell_exec('php bin/console fileman:push user@prod.example.com:/uploads public/uploads');
            }
        }
    }
    

    Register the listener in config/services.yaml:

    services:
        App\EventListener\FileSyncListener:
            tags:
                - { name: kernel.event_listener, event: kernel.terminate }
    
  4. Batch Processing: Use --verbose to log progress and debug:

    php bin/console fileman:pull -v user@example.com:/large/dir public/large_dir
    

    For large directories, add --parameters="--exclude='*.log'" to skip unnecessary files.


Gotchas and Tips

Pitfalls

  1. SSH Key Authentication:

    • If using keys, ensure the private key is readable by the Symfony process:
      chmod 600 /path/to/ssh_key
      
    • Specify the key path explicitly with --key to avoid permission errors.
  2. Path Permissions:

    • Remote paths must be writable by the SSH user. Test with:
      php bin/console fileman:pull user@example.com:/test public/test
      
    • Local paths must be writable by the Symfony user (e.g., www-data):
      chown -R www-data:www-data public/uploads
      
  3. Firewall/Network Issues:

    • Default SSH port (22) may be blocked. Use --port to specify a custom port:
      php bin/console fileman:push -P 2222 user@example.com:/uploads public/uploads
      
    • Test connectivity manually first:
      ssh -p 2222 user@example.com "ls /uploads"
      
  4. File Overwrites:

    • The bundle does not merge changes by default. Use --parameters="--delete" to remove local files not present remotely (use with caution):
      php bin/console fileman:pull --parameters="--delete" user@example.com:/uploads public/uploads
      

Debugging

  1. Dry Runs: Use --verbose to log actions without executing them:

    php bin/console fileman:pull -vv user@example.com:/uploads public/uploads
    
  2. Error Logs: Check Symfony’s var/log/dev.log for SSH connection errors or file permission issues.

  3. Timeouts: Increase the timeout in config/packages/darvin_fileman.yaml for slow connections:

    darvin_fileman:
        timeout: 60
    

Extension Points

  1. Custom Commands: Extend the bundle by creating a custom command (e.g., fileman:sync):

    // src/Command/SyncCommand.php
    namespace App\Command;
    
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class SyncCommand extends Command
    {
        protected static $defaultName = 'fileman:sync';
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $output->writeln('Pulling files...');
            shell_exec('php bin/console fileman:pull user@example.com:/uploads public/uploads');
    
            $output->writeln('Pushing files...');
            shell_exec('php bin/console fileman:push user@example.com:/uploads public/uploads');
    
            return Command::SUCCESS;
        }
    }
    
  2. Pre/Post-Sync Hooks: Use Symfony’s kernel.terminal event to run scripts before/after sync:

    // src/EventListener/SyncHookListener.php
    namespace App\EventListener;
    
    use Symfony\Component\Console\ConsoleEvents;
    use Symfony\Component\Console\Event\ConsoleTerminateEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class SyncHookListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                ConsoleEvents::TERMINATE => 'onTerminate',
            ];
        }
    
        public function onTerminate(ConsoleTerminateEvent $event)
        {
            $command = $event->getCommand()->getName();
            if (strpos($command, 'fileman:') === 0) {
                // Run post-sync tasks (e.g., optimize images)
                shell_exec('php bin/console app:optimize-images');
            }
        }
    }
    
  3. Configuration Overrides: Dynamically override settings per environment using Symfony’s parameter bag:

    # config/packages/dev/darvin_fileman.yaml
    darvin_fileman:
        timeout: 120  # Longer timeout for dev
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium