承接 internetpixels/repository-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

internetpixels/repository-manager

Composer 安装命令:

composer require internetpixels/repository-manager

包简介

Manage your entities and create simple repositories using this abstract vendor

README 文档

README

Manage your entities and repositories with this simple repository manager. An all in one solution for building repositories and entities.

License Build Status Maintainability

Basic examples

Create your first entity

The entity will contain the data for a specific object (Also known as DAO) and will mediate between the application and the database. An entity has to use getters and setters.

<?php

namespace YourProject\People;

use InternetPixels\RepositoryManager\Entities\AbstractEntity;
use InternetPixels\RepositoryManager\Entities\EntityInterface;

class PersonEntity extends AbstractEntity implements EntityInterface
{

    /**
     * @var string
     */
    private $name;

    /**
     * @var int
     */
    private $age;

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name)
    {
        $this->name = $name;
    }

    /**
     * @return int
     */
    public function getAge(): int
    {
        return $this->age;
    }

    /**
     * @param int $age
     */
    public function setAge(int $age)
    {
        $this->age = $age;
    }
}

Create your first repository

A repository will handle all data transfers between an entity and your database. The repository will build queries to execute those actions.

Note: The entityName needs to map to your database table name.

<?php

namespace YourProject\People;

use InternetPixels\RepositoryManager\Entities\AbstractEntity;
use InternetPixels\RepositoryManager\Factories\EntityFactory;
use InternetPixels\RepositoryManager\Repositories\AbstractRepository;

class PeopleRepository extends AbstractRepository
{

    protected $entityName = 'people';

    public function update(AbstractEntity $entity)
    {
        $query = $this->queryBuilder->new($this->entityName)
            ->update([
                'name' => $this->dataManager->sanitize($entity->getName()),
                'age' => $this->dataManager->sanitize($entity->getAge()),
            ])
            ->where(['id' => $entity->getId()])
            ->limit(1)
            ->get();

        return $this->executeQuery($query);
    }
    
    /**
     * @param array $data
     * @return PersonEntity
     */
    protected function dataToEntity(array $data): PersonEntity
    {    
        /** @var PersonEntity $entity */
        $entity = EntityFactory::create('people');

        $entity->setName($data['name']);
        $entity->setAge($data['age']);
        
        return $entity;
    }
}

Register the Data manager

You only need to register the RepositoryDataManager and the new entity in the EntityFactory. The Data manager needs an (existing) Mysqli connection.

$mysqliConnection = new \Mysqli(
    $config['mysql.host'],
    $config['mysql.user'],
    $config['mysql.password'],
    $config['mysql.database']
);

$repositoryDataManager = new \InternetPixels\RepositoryManager\Managers\RepositoryDataManager($mysqliConnection);

// Add all your entities:
\InternetPixels\RepositoryManager\Factories\EntityFactory::register('people', new PersonEntity());

$peopleRepository = new PeopleRepository($repositoryDataManager);

Usage of the repository

In a service of your application you can implement the PeopleRepository and use them for basic CRUD actions or your custom implementations.

$peopleRepository = new PeopleRepository($repositoryDataManager);

// Get all records:
$people = $peopleRepository->read();

// Update a person
$person = EntityFactory::create('people');
$person->setId(1);
$person->setName('Person name');
$person->setAge(26); // update the age

$peopleRepository->update($person);

// Delete a person
$person = EntityFactory::create('people');
$person->setId(1);

$peopleRepository->delete($person);

Usage of the SQL Query builder

This package contains a simple query builder. Please use the functionality to prevent basic SQL issues.

// Sanitize input in a repository before pushing to the database:
$safe = $this->dataManager->sanitize($entity->getName());

// Build a new select query in a repository
$query = $this->queryBuilder->new($this->entityName)
            ->select()
            ->get();
            
// Build a new select query in a repository with a limit
$query = $this->queryBuilder->new($this->entityName)
            ->select()
            ->limit(2)
            ->get();
            
// Build a new select query in a repository with a where clause
$query = $this->queryBuilder->new($this->entityName)
            ->select()
            ->where(['age' => 25])
            ->get();

internetpixels/repository-manager 适用场景与选型建议

internetpixels/repository-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.36k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 internetpixels/repository-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 internetpixels/repository-manager 我们能提供哪些服务?
定制开发 / 二次开发

基于 internetpixels/repository-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-04-30