Skip to content

Solo Base RepositoryLightweight PHP Repository Pattern

Built-in soft delete, eager loading, and rich criteria syntax. Powered by Doctrine DBAL.

Solo Base Repository

Deprecated

Solo Base Repository is no longer maintained and will receive no new features or fixes. Use Solo Repository instead (composer require solophp/repository). It is a new package with its own API, not a drop-in replacement.

Quick Example ​

php
use Solo\BaseRepository\BaseRepository;
use Solo\BaseRepository\Relation\BelongsTo;
use Solo\BaseRepository\Relation\HasMany;

class PostRepository extends BaseRepository
{
    protected ?string $deletedAtColumn = 'deleted_at';
    protected array $relationConfig = [];

    public function __construct(
        Connection $connection,
        public UserRepository $userRepository,
        public CommentRepository $commentRepository
    ) {
        $this->relationConfig = [
            'user' => new BelongsTo(
                repository: 'userRepository',
                foreignKey: 'user_id',
                setter: 'setUser',
            ),
            'comments' => new HasMany(
                repository: 'commentRepository',
                foreignKey: 'post_id',
                setter: 'setComments',
            ),
        ];

        parent::__construct($connection, Post::class, 'posts');
    }
}

// Usage
$posts = $postRepository
    ->with(['user', 'comments'])
    ->findBy(['status' => 'published'], ['created_at' => 'DESC'], 20, 1);

Installation ​

bash
composer require solophp/base-repository

Requirements: PHP 8.3+, Doctrine DBAL ^4.3

Released under the MIT License.