1. Go to this page and download the library: Download eureka/component-orm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/*
* Copyright (c) Romain Cottard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Application\Domain\Blog\Infrastructure\Mapper;
use Application\Domain\Blog\Entity\Post;
use Application\Domain\Blog\Repository\PostRepositoryInterface;
use Eureka\Component\Orm\EntityInterface;
use Eureka\Component\Orm\Exception\EntityNotExistsException;
use Eureka\Component\Orm\Exception\InvalidQueryException;
use Eureka\Component\Orm\Exception\OrmException;
use Eureka\Component\Orm\Query\SelectBuilder;
/**
* Mapper class for table "blog_post"
*
* @author Eureka Orm Generator
*/
class PostMapper extends Abstracts\AbstractPostMapper implements PostRepositoryInterface
{
/**
* @param int $number
* @return Post[]
* @throws InvalidQueryException
* @throws OrmException
*/
public function findLatest(int $number = 10): iterable
{
//~ Create new query builder (for select)
$queryBuilder = new SelectBuilder($this);
//~ Add some restriction
$queryBuilder->addWhere('blog_post_status', 3);
//~ Ordering results
$queryBuilder->addOrder('blog_post_id', 'DESC');
//~ Limit number of results
$queryBuilder->setLimit($number);
//~ select result & return result
return $this->select($queryBuilder);
}
/**
* @param int $postId
* @return Post[]
* @throws OrmException
*/
public function findPostWithUser(int $postId): iterable
{
//~ Create new query builder (for select)
$queryBuilder = new SelectBuilder($this);
//~ Add some restriction
$queryBuilder->addWhere('blog_post_id', $postId);
//~ Use eager loading to load user attach with Post (join only on user is this example)
return $this->selectJoin($queryBuilder, ['user']);
}
/**
* @return Post|EntityInterface
* @throws EntityNotExistsException
* @throws OrmException
*/
public function findLast(): Post
{
//~ Create new query builder (for select)
$queryBuilder = new SelectBuilder($this);
//~ Add some restriction
$queryBuilder->addWhere('blog_post_status', 3);
//~ Ordering results
$queryBuilder->addOrder('blog_post_id', 'DESC');
//~ When use selectOne(), not found entity will throw an EntityNotExistsException
return $this->selectOne($queryBuilder);
}
}
/*
* Copyright (c) Romain Cottard
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Domain\Blog\Repository;
use Application\Domain\Blog\Entity\Post;
use Eureka\Component\Orm\EntityInterface;
use Eureka\Component\Orm\Exception\EntityNotExistsException;
use Eureka\Component\Orm\Exception\InvalidQueryException;
use Eureka\Component\Orm\Exception\OrmException;
use Eureka\Component\Orm\RepositoryInterface;
/**
* Post repository interface.
*
* @author Eureka Orm Generator
*/
interface PostRepositoryInterface extends RepositoryInterface
{
/**
* @param int $number
* @return Post[]
* @throws InvalidQueryException
* @throws OrmException
*/
public function findLatest(int $number = 10): iterable;
/**
* @param int $postId
* @return Post[]
* @throws OrmException
*/
public function findPostWithUser(int $postId): iterable;
/**
* @return Post|EntityInterface
* @throws EntityNotExistsException
* @throws OrmException
*/
public function findLast(): Post;
}
bash
make php/check # run checks on check style
make php/fix # run check style auto fix
bash
make php/min-compatibility # run compatibility check on current minimal version of php we support
make php/max-compatibility # run compatibility check on last version of php we will support in future
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.