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

System Bundle Laravel Package

ano/system-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require ano/system-bundle
    

    Register it in config/bundles.php:

    return [
        // ...
        Ano\SystemBundle\AnoSystemBundle::class => ['all' => true],
    ];
    
  2. First Use Case: Basic Anonymization The bundle provides core anonymization utilities. Start by injecting the AnoSystemBundle services into a controller or command:

    use Ano\SystemBundle\Service\Anonymizer;
    
    class UserController extends Controller
    {
        public function anonymize(Request $request, Anonymizer $anonymizer)
        {
            $data = $request->request->all();
            $anonymized = $anonymizer->anonymize($data);
            return response()->json($anonymized);
        }
    }
    
  3. Key Classes to Explore

    • Ano\SystemBundle\Service\Anonymizer: Core service for anonymizing data.
    • Ano\SystemBundle\Strategy\* (e.g., EmailStrategy, PhoneStrategy): Predefined anonymization strategies.
    • Ano\SystemBundle\Event\AnonymizationEvent: For extending anonymization logic via events.

Implementation Patterns

Workflow: Anonymizing Sensitive Data

  1. Define Strategies Extend or use built-in strategies (e.g., EmailStrategy for masking emails):

    $anonymizer->addStrategy('email', new EmailStrategy());
    
  2. Anonymize Data Pass an array or object to the anonymizer->anonymize() method:

    $userData = [
        'email' => '[email protected]',
        'phone' => '1234567890',
    ];
    $anonymized = $anonymizer->anonymize($userData);
    // Output: ['email' => '*****@example.com', 'phone' => '****1890']
    
  3. Integrate with Forms/Requests Use middleware to anonymize request data before processing:

    namespace App\Http\Middleware;
    
    use Ano\SystemBundle\Service\Anonymizer;
    use Closure;
    
    class AnonymizeRequestData
    {
        public function __construct(private Anonymizer $anonymizer) {}
    
        public function handle($request, Closure $next)
        {
            $request->merge($this->anonymizer->anonymize($request->all()));
            return $next($request);
        }
    }
    
  4. Database Anonymization Use the Anonymizer in a repository or query builder:

    $queryBuilder->select(['id', 'anonymized_email' => 'email']);
    $results = $queryBuilder->getQuery()->getResult();
    $anonymizedResults = $this->anonymizer->anonymize($results);
    

Integration Tips

  • Symfony Events: Listen to AnonymizationEvent to customize anonymization:
    $eventDispatcher->addListener(AnonymizationEvent::ANONYMIZATION, function (AnonymizationEvent $event) {
        if ($event->getKey() === 'phone') {
            $event->setValue('****' . substr($event->getValue(), -2));
        }
    });
    
  • Configuration: Override default strategies in config/packages/ano_system.yaml:
    ano_system:
        strategies:
            email: App\Strategy\CustomEmailStrategy
    

Gotchas and Tips

Pitfalls

  1. Strategy Registration

    • Issue: Strategies must be registered before use. Forgetting to add a strategy will skip anonymization for that field.
    • Fix: Always call addStrategy() or configure via YAML before anonymizing.
  2. Nested Data

    • Issue: The bundle does not recursively anonymize nested arrays/objects by default.
    • Fix: Use anonymizer->anonymizeRecursively($data) or extend the Anonymizer class.
  3. Symfony Version Mismatch

    • Issue: The bundle requires Symfony 2.x, which may conflict with modern Laravel projects (even though this is a Symfony bundle, some developers might attempt to use it in Laravel).
    • Fix: Ensure compatibility by checking the bundle’s composer.json and adapting usage patterns (e.g., using Symfony’s HttpFoundation components in Laravel via symfony/http-foundation).
  4. Event Dispatcher Dependency

    • Issue: The bundle relies on Symfony’s EventDispatcher. If not autowired, you’ll need to manually inject it:
      $eventDispatcher = $container->get('event_dispatcher');
      

Debugging

  • Log Anonymization: Enable debug mode to log anonymized values:
    $anonymizer->setDebug(true);
    
  • Check Strategies: Verify registered strategies with:
    $anonymizer->getStrategies(); // Returns array of registered strategies
    

Extension Points

  1. Custom Strategies Create a new strategy by implementing Ano\SystemBundle\Strategy\StrategyInterface:

    class CustomStrategy implements StrategyInterface
    {
        public function anonymize($value): string
        {
            return '*****' . substr($value, -3);
        }
    }
    
  2. Override Default Behavior Extend the Anonymizer class to modify core logic:

    class CustomAnonymizer extends Anonymizer
    {
        protected function defaultStrategy($key)
        {
            return new CustomStrategy(); // Override default strategy resolution
        }
    }
    
  3. Event Listeners Use AnonymizationEvent to dynamically alter values:

    $event->setValue(strtoupper($event->getValue())); // Convert to uppercase
    

Configuration Quirks

  • YAML Overrides: Ensure your ano_system.yaml is loaded after the bundle’s default config.
  • Service Autowiring: If using Symfony autowiring, ensure the Anonymizer is tagged as a service:
    services:
        Ano\SystemBundle\Service\Anonymizer:
            tags: ['ano.anonymizer']
    
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle