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

Helper Bundle Laravel Package

amare53/helper-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require amare53/helper-bundle
    

    Add to config/bundles.php:

    Amare53\HelperBundle\Amare53HelperBundle::class => ['all' => true],
    
  2. First Use Case: Dynamic Property Access Use the PropertyAccessHelper for safe property access (avoids UndefinedPropertyException):

    use Amare53\HelperBundle\Helper\PropertyAccessHelper;
    
    $helper = new PropertyAccessHelper();
    $value = $helper->getValue($object, 'nested.property', 'default');
    
  3. Key Entry Points

    • PropertyAccessHelper (safe property access)
    • SerializerHelper (JSON/XML serialization)
    • ValidatorHelper (Symfony Validator wrapper)
    • PaginatorHelper (KNP Paginator integration)

Implementation Patterns

Common Workflows

1. Safe Property Access in Controllers/Repositories

Replace manual isset() checks with PropertyAccessHelper:

public function show(User $user)
{
    $profilePicture = $this->propertyAccessHelper->getValue($user, 'profile.picture');
    return view('user.profile', compact('profilePicture'));
}

2. Data Transformation with Serialization

Convert complex objects to arrays/JSON:

$serialized = $this->serializerHelper->serialize($entity, 'json');
return response()->json($serialized);

3. Validation in Forms

Reuse ValidatorHelper for consistent validation logic:

$errors = $this->validatorHelper->validate($data, [
    'email' => 'email|required',
    'age'   => 'integer|min:18'
]);

4. Pagination in API Responses

Integrate with KNP Paginator:

$paginated = $this->paginatorHelper->paginate(
    $queryBuilder,
    $request->query->getInt('page', 1),
    20
);
return $this->serializerHelper->serialize($paginated, 'json');

5. Dependency Injection

Bind helpers in services.php:

$app->bind(PropertyAccessHelper::class, function ($app) {
    return new PropertyAccessHelper();
});

Integration Tips

  • Doctrine ORM: Use PropertyAccessHelper to avoid hydration issues with nested associations.
  • APIs: Combine SerializerHelper + ValidatorHelper for request/response handling.
  • Legacy Code: Replace isset($obj->prop) with $helper->hasValue($obj, 'prop').
  • Testing: Mock PropertyAccessHelper to isolate property access logic.

Gotchas and Tips

Pitfalls

  1. Doctrine ORM Caching

    • PropertyAccessHelper may bypass Doctrine’s proxy hydration. Use ->getValue($entity, 'prop', null) to avoid LazyLoadingException.
  2. Symfony Validator Conflicts

    • If using Symfony’s built-in validator, ensure ValidatorHelper constraints don’t override global validation rules.
  3. KNP Paginator Version Mismatch

    • The bundle targets knp-paginator-bundle:^5.6. Downgrade or upgrade dependencies to avoid:
      Class 'Knp\Bundle\PaginatorBundle\Paginator\AbstractPaginator' not found
      
  4. Serialization Edge Cases

    • Circular references in SerializerHelper may cause infinite loops. Use ignore_circular_references: true in config.

Debugging Tips

  • Property Access Issues Enable debug mode and check for:

    $helper->getValue($obj, 'invalid.path'); // Returns `null` (not throws exception)
    
  • Validator Errors Inspect raw errors:

    $errors = $this->validatorHelper->validate($data, $rules);
    foreach ($errors as $error) {
        logger($error->getMessage());
    }
    

Extension Points

  1. Custom Property Access Strategies Extend PropertyAccessHelper to add custom accessors:

    class CustomPropertyAccessHelper extends PropertyAccessHelper
    {
        public function getValue($object, $property, $default = null)
        {
            if ($property === 'custom_method') {
                return $object->customMethod();
            }
            return parent::getValue($object, $property, $default);
        }
    }
    
  2. Serializer Encoders Register custom encoders in services.yaml:

    amare53_helper.serializer.encoder.custom:
        class: App\Serializer\CustomEncoder
        tags: ['amare53_helper.serializer.encoder']
    
  3. Validator Constraints Add custom constraints to ValidatorHelper:

    $this->validatorHelper->addConstraint('custom_rule', new CustomConstraint());
    

Configuration Quirks

  • Default Serialization Groups Override in config/packages/amare53_helper.yaml:

    amare53_helper:
        serializer:
            default_groups: ['api', 'default']
    
  • Paginator Defaults Set global pagination settings:

    amare53_helper:
        paginator:
            default_items_per_page: 15
            max_items_per_page: 100
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware