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

Lorem Ipsum Bundle Laravel Package

bskton/lorem-ipsum-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require bskton/lorem-ipsum-bundle --dev
    

    For non-Flex projects, enable the bundle in AppKernel.php:

    new KnpU\LoremIpsumBundle\KnpULoremIpsumBundle(),
    
  2. First Use Case: Inject the service into a controller or service:

    use KnpU\LoremIpsumBundle\KnpUIpsum;
    
    class DemoController {
        public function show(KnpUIpsum $lorem) {
            $paragraphs = $lorem->getParagraphs(3); // 3 paragraphs
            return response()->json(['fake_text' => $paragraphs]);
        }
    }
    
  3. Check Default Config: Verify config/packages/knpu_lorem_ipsum.yaml exists (create if missing) to override defaults like unicorns_are_real.


Implementation Patterns

Core Workflows

  1. Generating Text:

    • Use getParagraphs(int $count) for structured content (e.g., blog posts, placeholders).
    • Use getWords(int $count) for short lists (e.g., tags, metadata).
    • Example:
      $lorem->getParagraphs(2); // 2 paragraphs
      $lorem->getWords(5);      // 5 words
      
  2. Integration with Laravel:

    • Service Providers: Bind the service in AppServiceProvider:
      $this->app->bind('knpu_lorem_ipsum.knpu_ipsum', function ($app) {
          return new \KnpU\LoremIpsumBundle\Service\KnpUIpsum();
      });
      
    • Facades: Create a facade for cleaner syntax:
      // app/Facades/LoremFacade.php
      public static function paragraphs(int $count) {
          return app('knpu_lorem_ipsum.knpu_ipsum')->getParagraphs($count);
      }
      
  3. Testing:

    • Mock the service in unit tests:
      $this->mock(KnpUIpsum::class)->shouldReceive('getParagraphs')->andReturn('Mocked text');
      
  4. Dynamic Placeholders:

    • Use in Blade templates via a helper:
      // app/Helpers/LoremHelper.php
      function lorem_paragraphs(int $count) {
          return app('knpu_lorem_ipsum.knpu_ipsum')->getParagraphs($count);
      }
      
      {{ lorem_paragraphs(1) }}
      

Gotchas and Tips

Pitfalls

  1. Service Not Found:

    • If autowiring fails, ensure the bundle is enabled (check AppKernel.php for non-Flex projects).
    • Verify the service ID (knpu_lorem_ipsum.knpu_ipsum) is correct.
  2. Configuration Overrides:

    • The bundle expects knpu_lorem_ipsum.yaml in config/packages/. If missing, defaults apply, but customizations won’t work.
    • Example of overriding config:
      knpu_lorem_ipsum:
          unicorns_are_real: false
          min_sunshine: 0
      
  3. WordProviderInterface Issues:

    • If extending the word list, ensure your class is autoloaded and tagged as a service:
      # config/services.yaml
      services:
          App\Services\CustomWordProvider:
              tags: ['knpu_lorem_ipsum.word_provider']
      

Debugging

  • Check Generated Text: Log the output to verify configuration changes:
    \Log::info('Generated text:', ['text' => $lorem->getParagraphs(1)]);
    
  • Validate Dependencies: Ensure knp-u/lorem-ipsum (Symfony bundle) is installed if the package relies on it.

Extension Points

  1. Custom Word Lists:

    • Implement WordProviderInterface and register it as a service with the knpu_lorem_ipsum.word_provider tag.
    • Example:
      class TechWordProvider implements WordProviderInterface {
          public function getWords(): array {
              return ['Laravel', 'Eloquent', 'Blade', 'Queue'];
          }
      }
      
  2. Override Defaults:

    • Extend the KnpUIpsum service by creating a decorator:
      class CustomKnpUIpsum extends KnpUIpsum {
          public function getParagraphs(int $count) {
              $text = parent::getParagraphs($count);
              return str_replace('unicorn', 'developer', $text); // Custom tweak
          }
      }
      
    • Bind the decorator in AppServiceProvider:
      $this->app->bind('knpu_lorem_ipsum.knpu_ipsum', function ($app) {
          return new CustomKnpUIpsum();
      });
      
  3. Localization:

    • Override word lists per locale by creating locale-specific WordProvider implementations and conditionally loading them based on the app’s locale.
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.
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
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle