Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dezbyte committed Oct 6, 2017
1 parent a12b055 commit 78740e2
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 83 deletions.
8 changes: 8 additions & 0 deletions src/Colibri/Core/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public function setVirtual($offset, $value = null)
return $this;
}

/**
* @inheritdoc
*/
public function hashCode()
{

}

/**
* @inheritDoc
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Colibri/Core/Entity/EntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ public function beforePersist();
* @return $this
*/
public function beforeRemove();

/**
* @return string
*/
public function hashCode();

}
6 changes: 6 additions & 0 deletions src/Colibri/Core/Entity/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public function getConnection();
*/
public function getHydrator();

/**
* @param AbstractHydratorEntity $hydrator
* @return $this
*/
public function setHydrator(AbstractHydratorEntity $hydrator);

/**
* @return DispatcherInterface
*/
Expand Down
103 changes: 103 additions & 0 deletions src/Colibri/Core/EntityManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Colibri\Core;

use Colibri\Core\Entity\EntityInterface;
use Colibri\ServiceContainer\ServiceLocatorInterface;

/**
* Class EntityManager
* @package Colibri\Core
*/
class EntityManager
{

/**
* @var ServiceLocatorInterface
*/
protected $serviceLocator;

protected $toPersistEntities;

/**
* EntityManager constructor.
* @param ServiceLocatorInterface $serviceLocator
*/
public function __construct(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}

/**
* @param EntityInterface $entity
* @param bool $forcePersist
* @return $this
*/
public function persist(EntityInterface $entity, $forcePersist = false)
{

return $this;
}

/**
* @param EntityInterface $entity
* @param bool $forceRemove
* @return $this
*/
public function remove(EntityInterface $entity, $forceRemove = false)
{

return $this;
}

/**
* @param $class
* @return Metadata
*/
public function getMetadataFor($class)
{
return $this->getMetadataManager()->getMetadataFor($class);
}

/**
* @param $class
* @return Entity\RepositoryInterface
*/
public function getRepositoryFor($class)
{
return $this->getRepositoryManager()->getRepositoryFor($class);
}

/**
* @return MetadataManager
*/
public function getMetadataManager()
{
return $this->getServiceLocator()->getMetadataManager();
}

/**
* @return RepositoryManager
*/
public function getRepositoryManager()
{
return $this->getServiceLocator()->getRepositoryManager();
}

/**
* @return ClassManager
*/
public function getClassManager()
{
return $this->getServiceLocator()->getClassManager();
}

/**
* @return ServiceLocatorInterface
*/
public function getServiceLocator(): ServiceLocatorInterface
{
return $this->serviceLocator;
}

}
36 changes: 32 additions & 4 deletions src/Colibri/Core/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Colibri\Core\Event\EntityLifecycleEvent;
use Colibri\Core\Hydrator\AbstractHydratorEntity;
use Colibri\Core\Hydrator\EntityHydrator;
use Colibri\Core\Repository\GenericRepositoryQueryFactory;
use Colibri\Core\Repository\BasicRepositoryQueryFactory;
use Colibri\Core\Repository\RepositoryQueryFactory;
use Colibri\Core\ResultSet\ResultSet;
use Colibri\Core\ResultSet\ResultSetIterator;
Expand Down Expand Up @@ -83,6 +83,11 @@ abstract class Repository implements RepositoryInterface
*/
protected $queryFactory;

/**
* @var EntityManager
*/
protected $entityManager;

/**
* EntityRepository constructor.
* @param string $entityName
Expand All @@ -95,8 +100,10 @@ public function __construct($entityName)
$this->entityName = $entityName;
$this->connection = $this->getServiceLocator()->getConnection($this->getEntityMetadata()->getConnectionName());

$this->hydrator = new EntityHydrator($this);
$this->queryFactory = new GenericRepositoryQueryFactory($this);
$this->entityManager = $this->getServiceLocator()->getEntityManager();

$this->setHydrator(new EntityHydrator($this));
$this->setQueryFactory(new BasicRepositoryQueryFactory($this));

$this->filterQuery = $this->createSelectQuery();
}
Expand Down Expand Up @@ -297,6 +304,8 @@ public function retrieve($id)
public function persist(EntityInterface $entity)
{
$reflection = $this->getEntityClassReflection();

$this->entityManager->persist($entity);

if ($reflection->isInstance($entity)) {

Expand Down Expand Up @@ -410,7 +419,7 @@ public function getEntityClassReflection()
*/
public function getEntityMetadata()
{
return $this->getServiceLocator()->getMetadataManager()->getMetadataFor($this->getEntityName());
return $this->getEntityManager()->getMetadataFor($this->getEntityName());
}

/**
Expand Down Expand Up @@ -475,6 +484,14 @@ public function getClassManager()
{
return $this->getServiceLocator()->getClassManager();
}

/**
* @return EntityManager
*/
public function getEntityManager(): EntityManager
{
return $this->entityManager;
}

/**
* @return ConnectionInterface
Expand All @@ -500,6 +517,17 @@ public function getHydrator()
return $this->hydrator;
}

/**
* @param AbstractHydratorEntity $hydrator
* @return $this
*/
public function setHydrator(AbstractHydratorEntity $hydrator)
{
$this->hydrator = $hydrator;

return $this;
}

/**
* @return DispatcherInterface
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Colibri/Core/Repository/BasicRepositoryQueryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Colibri\Core\Repository;

/**
* Class BasicRepositoryQueryFactory
* @package Colibri\Core\Repository
*/
class BasicRepositoryQueryFactory extends RepositoryQueryFactory
{

}
12 changes: 0 additions & 12 deletions src/Colibri/Core/Repository/GenericRepositoryQueryFactory.php

This file was deleted.

74 changes: 74 additions & 0 deletions src/Colibri/Core/Storage/AbstractDatabasePersister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Colibri\Core\Storage;

use Colibri\Core\EntityManager;
use Colibri\Query\Builder as QueryBuilder;

/**
* Class AbstractDatabasePersister
* @package Colibri\Core\Persisters
*/
abstract class AbstractDatabasePersister implements PersisterInterface
{

/**
* @var EntityManager
*/
protected $entityManager;


public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}


/**
* @return QueryBuilder\Insert
*/
public function createInsertQuery()
{
$metadata = $this->getEntityMetadata();
$query = new QueryBuilder\Insert($this->getConnection());

$query->setTableInto($metadata->getTableName());

return $query;
}

/**
* @return QueryBuilder\Delete
*/
public function createDeleteQuery()
{
$metadata = $this->getEntityMetadata();
$query = new QueryBuilder\Delete($this->getConnection());

$query->setFromTable($metadata->getTableName());

return $query;
}

/**
* @return QueryBuilder\Update
*/
public function createUpdateQuery()
{
$metadata = $this->getEntityMetadata();
$query = new QueryBuilder\Update($this->getConnection());

$query->table($metadata->getTableName());

return $query;
}

/**
* @return EntityManager
*/
public function getEntityManager(): EntityManager
{
return $this->entityManager;
}

}
38 changes: 38 additions & 0 deletions src/Colibri/Core/Storage/BasicEntityPersister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Colibri\Core\Storage;

use Colibri\Core\Entity\EntityInterface;

/**
* Class BasicEntityPersister
* @package Colibri\Core\Storage
*/
class BasicEntityPersister extends AbstractDatabasePersister
{

/**
* @inheritDoc
*/
public function create(EntityInterface $entity)
{
$this->getInsertQuery();
}

/**
* @inheritDoc
*/
public function update(EntityInterface $entity)
{

}

/**
* @inheritDoc
*/
public function remove(EntityInterface $entity)
{

}

}
Loading

0 comments on commit 78740e2

Please sign in to comment.