1. Go to this page and download the library: Download dotkernel/dot-mapper 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/ */
dotkernel / dot-mapper example snippets
namespace SomeNamespace;
use Dot\Mapper\Entity\Entity;
//...
class MyEntity extends Entity
{
protected $id;
protected $field1;
protected $field2;
/**
* This field is inherited from the base Entity class and it indicates to the mappers what hydrator to be used
* The default value is ClassMethodsCamelCase so you don't have to write the following line if you are using that
*/
protected $hydrator = ClassMethodsCamelCase::class;
//...
public function getField1()
{
return $this->field1;
}
public function setField1($value)
{
$this->field1 = $value;
}
// etc...
}
//...
class MyEntityDbMapper extends AbstractDbMapper
{
// an empty db mapper does support CRUD operations and has already implemented the MapperInterface's methods
}
public function find(string $type = 'all', array $options = []): array
return [
'dot_mapper' => [
'mapper_manager' => [
//...
],
'options' => [
'mapper' => [
//under this key you can setup or override mapper options
//the mapper options must be specified using the associated alias(its entity class name)
MyEntityDbMapper::class => [
'adapter' => 'name of the db adapter service(database by default)',
'table' => 'database table name(by default it will be generated from the mapper class name converting the camel case to underscore notation)',
'alias' => 'alias of the table to use(autogenerated by default)',
'event_listeners' => [
//array of mapper event listeners, to listen for mapper CRUD operation events(detailed later in the documentation)
]
]
]
]
]
];
//...
class MyService implements MapperManagerAwareInterface
{
use MapperManagerAwareTrait;
//...
public function saveAnEntity(MyEntity $entity)
{
/** @var MapperInterface $mapper **/
$mapper = $this->getMapperManager()->get(MyEntity::class);
return $mapper->save($entity);
}
//...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.