Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created November 7, 2019 18:26
Show Gist options
  • Save wilcorrea/7f11809c447268ae543dba04200af0b5 to your computer and use it in GitHub Desktop.
Save wilcorrea/7f11809c447268ae543dba04200af0b5 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Domain\Admin;
use App\Infrastructure\Entity\AbstractEntity;
/**
* Class Profile
* @package App\Domain\Admin
*/
class Profile extends AbstractEntity
{
/**
*/
public function construct()
{
$this->addField('name')
->isFieldString(40)
->validationRequired();
$this->addStatement('example', '[id] = ?');
}
}
<?php
declare(strict_types=1);
namespace App\Http\Admin\Profile;
use App\Application\Exceptions\ErrorInvalidArgument;
use App\Application\Http\ActionController;
use App\Domain\Admin\Profile\ProfileRepository;
/**
* Class ProfileExampleAction
* @package App\Http\Admin\Profile
*/
class ProfileExampleController extends ActionController
{
/**
* @param ProfileRepository $repository
* @param string $id
* @return array
* @throws ErrorInvalidArgument
*/
protected function run(ProfileRepository $repository, string $id)
{
return [
'readWithQueryBuilder' => $repository->readWithQueryBuilder($id),
'readWithWhere' => $repository->readWithWhere($id),
'readWithStatement' => $repository->readWithStatement($id),
];
}
}
<?php
declare(strict_types=1);
namespace App\Domain\Admin\Profile;
use App\Application\Exceptions\ErrorInvalidArgument;
use App\Domain\Admin\Profile;
use App\Infrastructure\Persistence\AbstractRepository;
/**
* Class ProfileRepository
* @package App\Domain\Admin\Profile
*/
class ProfileRepository extends AbstractRepository
{
/**
* @param string $id
* @return array
*/
public function readWithQueryBuilder(string $id): array
{
return $this->createQueryBuilder()
->table('profile')
->fields(['id', 'name'])
->where('id = ?')
->parameters($id)
->read();
}
/**
* @param string $id
* @return array
*/
public function readWithWhere(string $id): array
{
return $this->createManager()->where('id = ?')->parameters($id)->read();
}
/**
* @param string $id
* @return array
* @throws ErrorInvalidArgument
*/
public function readWithStatement(string $id): array
{
return $this->createManager()->statement('example', $id)->read();
}
/**
* @return string
*/
protected function entity()
{
return Profile::class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment