Skip to content

Commit

Permalink
added more flexibility to configure the factories
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 3, 2015
1 parent b39b015 commit f31af29
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
24 changes: 22 additions & 2 deletions src/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setNamespace($namespace)
}

/**
* Set the queryFactory instance used by the entities.
* Set the QueryFactory instance used by the entities.
*
* @param QueryFactory $queryFactory
*
Expand All @@ -67,7 +67,17 @@ public function setQueryFactory(QueryFactory $queryFactory)
}

/**
* Set the fieldFactory instance used by the entities.
* Returns the QueryFactory instance used by the entities.
*
* @return QueryFactory
*/
public function getQueryFactory()
{
return $this->queryFactory;
}

/**
* Set the FieldFactory instance used by the entities.
*
* @param FieldFactory $fieldFactory
*
Expand All @@ -80,6 +90,16 @@ public function setFieldFactory(FieldFactory $fieldFactory)
return $this;
}

/**
* Returns the FieldFactory instance used by the entities.
*
* @return FieldFactory
*/
public function getFieldFactory(FieldFactory $fieldFactory)
{
return $this->fieldFactory;
}

/**
* Set whether the entities are autocreated or not.
*
Expand Down
27 changes: 22 additions & 5 deletions src/SimpleCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,32 @@ class SimpleCrud
*/
public function __construct(PDO $connection, EntityFactory $entityFactory = null)
{
if ($entityFactory === null) {
$entityFactory = (new EntityFactory())->setAutocreate();
}
$this->connection = $connection;
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$this->setEntityFactory($entityFactory ?: (new EntityFactory())->setAutocreate());
}

/**
* Set the EntityFactory instance used to create all entities.
*
* @param EntityFactory $entityFactory
*/
public function setEntityFactory(EntityFactory $entityFactory)
{
$entityFactory->setDb($this);

$this->entityFactory = $entityFactory;
}

$this->connection = $connection;
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/**
* Returns the EntityFactory instance used.
*
* @return EntityFactory
*/
public function getEntityFactory()
{
return $this->entityFactory;
}

/**
Expand Down

0 comments on commit f31af29

Please sign in to comment.