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

Ip Store Bundle Laravel Package

dmykos/ip-store-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dmykos/ip-store-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        Dmykos\IpStoreBundle\DmykosIpStoreBundle::class => ['all' => true],
    ];
    
  2. Database Configuration Create config/packages/ip_store.yaml:

    dmykos_ip_store:
        store_driver: dmykos_ip_store.database_store_driver
        database:
            table_name: ip_store
            id_column_name: id
            id_column_value: ip_address
            key_column_name: count
    

    Ensure the table exists (e.g., via a migration):

    // src/Migration/VersionYYYYMMDDHHMMSS.php
    public function up(Schema $schema)
    {
        $this->addSql('CREATE TABLE ip_store (
            id INT AUTO_INCREMENT PRIMARY KEY,
            ip_address VARCHAR(45) NOT NULL,
            count INT DEFAULT 0
        )');
    }
    
  3. First Use Case Add an IP via REST:

    curl -X POST http://your-app.com/ip/add/192.168.1.1
    

    Query its count:

    curl http://your-app.com/ip/query/192.168.1.1
    

Implementation Patterns

Core Workflows

  1. Storing IPs

    • Use the REST endpoint (/ip/add/{ip}) for quick integration.
    • For programmatic use, inject the IpStore service:
      use Dmykos\IpStoreBundle\Service\IpStore;
      
      public function __construct(private IpStore $ipStore) {}
      
      $this->ipStore->add('192.168.1.1');
      
  2. Querying IPs

    • REST: GET /ip/query/{ip} returns the count.
    • Programmatically:
      $count = $this->ipStore->query('192.168.1.1');
      
  3. Batch Operations

    • Loop through IPs and store/query in bulk:
      foreach ($ips as $ip) {
          $this->ipStore->add($ip);
      }
      

Integration Tips

  • Validation: Validate IPs before storage (e.g., with FilterVar::IP).
  • Caching: Cache frequent queries (e.g., Symfony\Contracts\Cache\CacheInterface).
  • Events: Extend with Symfony events (e.g., IpAddedEvent) for side effects.

Gotchas and Tips

Pitfalls

  1. Table Schema Mismatch

    • Ensure id_column_name, id_column_value, and key_column_name match your table columns exactly.
    • Debug with:
      bin/console debug:container dmykos_ip_store.database_store_driver
      
  2. IPv6 Handling

    • The bundle supports IPv6, but ensure your database column (e.g., ip_address) uses VARCHAR(45) to accommodate full IPv6 addresses.
  3. REST Endpoint Quirks

    • The /ip/add endpoint overwrites counts if the IP exists. Use increment logic if needed:
      $this->ipStore->query('192.168.1.1'); // Get current count
      $this->ipStore->add('192.168.1.1');   // Increment by 1
      

Debugging

  • Driver Issues: Verify the store_driver in ip_store.yaml matches the registered service name.
  • Doctrine Errors: Check for missing Doctrine mappings or connection issues:
    bin/console doctrine:schema:validate
    

Extension Points

  1. Custom Drivers

    • Implement Dmykos\IpStoreBundle\Driver\StoreDriverInterface for non-database stores (e.g., Redis):
      class RedisStoreDriver implements StoreDriverInterface {
          public function add($ip) { /* ... */ }
          public function query($ip) { /* ... */ }
      }
      
    • Register in services.yaml:
      services:
          dmykos_ip_store.redis_driver:
              class: App\Driver\RedisStoreDriver
              tags: ['dmykos_ip_store.driver']
      
  2. Middleware

    • Add IP tracking middleware:
      // src/EventListener/IpTracker.php
      public function onKernelRequest(GetResponseEvent $event) {
          $ip = $event->getRequest()->getClientIp();
          $this->ipStore->add($ip);
      }
      
      Register in services.yaml:
      services:
          App\EventListener\IpTracker:
              tags: [kernel.event_listener, kernel.request]
      
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.
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
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