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

File Search Bundle Laravel Package

alexkomaralex/file-search-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require alexkomaralex/file-search-bundle dev-master
    

    Add to AppKernel.php:

    new Alexkomaralex\FileSearchBundle\AlexkomaralexFileSearchBundle(),
    
  2. First Use Case: Search for files containing "database" in app/config/:

    php app/console fsearch:find --path=app/config database
    

Key Files to Review

  • Configuration: Resources/config/services.yml (default adapter setup).
  • Command: Command/FileSearchCommand.php (core logic).
  • Adapters: Adapter/ (Symfony Finder and DirectoryIterator implementations).

Implementation Patterns

Core Workflow

  1. Define Search Scope: Use --path to specify directories (e.g., --path=src,config for multiple paths). Defaults to project root if omitted.

  2. Query Execution: The bundle splits the search into two phases:

    • File Listing: Uses adapters (Finder or DirectoryIterator) to traverse directories.
    • Content Search: Scans file contents line-by-line for matches (case-insensitive by default).
  3. Adapter Integration:

    • Symfony Finder: Best for large projects (caches results, excludes patterns). Configure in services.yml:
      alexkomaralex_file_search.finder:
          class: Symfony\Component\Finder\Finder
          calls:
              - [exclude, ['vendor', 'node_modules']]
      
    • DirectoryIterator: Lightweight, no dependencies. Use when Symfony Finder is overkill.
  4. Extending Adapters: Implement Alexkomaralex\FileSearchBundle\Adapter\AdapterInterface:

    class CustomAdapter implements AdapterInterface {
        public function findFiles($path) { ... }
    }
    

    Register as a service and tag it with alexkomaralex_file_search.adapter.

Integration Tips

  • Symfony Events: Trigger post-search events by listening to file_search.post_find.
  • Logging: Wrap the command in a service to log results:
    $this->get('logger')->info('Found files:', ['files' => $results]);
    
  • Performance: For large codebases, pre-filter files by extension (e.g., *.php) in the adapter.

Gotchas and Tips

Pitfalls

  1. Case Sensitivity: The bundle uses mb_strpos (UTF-8 safe) but defaults to case-insensitive search. Override in a custom adapter if needed:

    if (stripos($line, $query) !== false) { ... }
    
  2. Memory Limits: Scanning large directories (e.g., vendor/) may hit PHP’s memory_limit. Use --path to restrict scope.

  3. Binary Files: The bundle reads files as text. Binary files (e.g., .zip) may cause warnings. Exclude them in the adapter:

    if ($file->isDir() || $file->getExtension() === 'zip') continue;
    
  4. Symfony 2.5 Dependency: The bundle is tied to Symfony 2.5. Upgrade paths may require adapter refactoring.

Debugging

  • Verbose Output: Add -v to the command to see file traversal logs.
  • Adapter Validation: Check if your custom adapter is autowired by running:
    php app/console debug:container alexkomaralex_file_search
    

Extension Points

  1. Pre/Post-Processing: Override FileSearchCommand to modify results:

    protected function processResults(array $files) {
        return array_filter($files, function($file) {
            return strpos($file, 'test') !== false;
        });
    }
    
  2. Custom Matching Logic: Extend the findInFile method in adapters to support regex or fuzzy matching.

  3. Parallel Search: Use ReactPHP or SplFileInfo + pcntl_fork to parallelize file scanning (not bundled by default).

Configuration Quirks

  • Default Path: If --path is omitted, the bundle uses getcwd(). Override in services.yml:

    alexkomaralex_file_search.command.class: AppBundle\Command\CustomFileSearchCommand
    

    Then set a default path in the constructor.

  • Adapter Priority: Services tagged with alexkomaralex_file_search.adapter are loaded in alphabetical order. Use priority tags to control order.

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui