-
Notifications
You must be signed in to change notification settings - Fork 1
Entity Factories
A factory is a way to find and instantiate one or many entities from the database. It accesses to database to fetch corresponding data and build entities. The entity instanciation is directly lent to the entities so the factory only include the required methods to find and launch instanciations.
This feature requires prior knowledge of the Entity Model and Database Access
The ApineEntityFactory
class on its own can't create anything. It's an abstract class containning methods to be implemented by concrete factories. Because it is a abstract class, the concrete factory must extend from ApineEntityFactory
.
Concrete entities must implement these three methods :
Boolean ApineEntityFactory::is_exists_id(string $a_id)
Verify if an entry has the provided ID value
ApineEntityModel ApineEntityFactory::create_by_id(string $a_id)
Return an entity instantiated from the provided ID
Liste<ApineEntityModel> ApineEntityFactory::create_all()
Return a collection of instantiated every entries
class SampleFactory extends ApineEntityFactory {
public static function is_id_exist ($entity_id) {
$id_sql = (new Database());
$id_sql = $database->select("SELECT `id` FROM `apine_entities` WHERE `id`=$entity_id");
if ($id_sql) {
return true;
}
return false;
}
public static function create_all () {
$request = (new Database());
$request = $database->select('SELECT `id` from `apine_entities`');
$liste = new Liste();
if ($request != null && count($request) > 0) {
foreach ($request as $item) {
$liste->add_item(new ApineEntity('apine_entities', $item['id']));
}
}
return $liste;
}
public static function create_by_id ($a_id) {
$database=new Database();
$sql_id = $database->prepare('SELECT `id` FROM `apine_entities` WHERE `id`=?');
$ar_sql = $database->execute(array(
$a_id
), $sql_id);
if ($ar_sql) {
$return = new ApineEntities('apine_entities', $ar_sql[0]['id']);
} else {
$return = null;
}
return $return;
}
}
- Introduction
- Getting Started
- Requirements & Installation
- Application Configuration
- Database Connection
- How to use Controllers
- How to use Views
- How to Manage Session
- How to use the api (Coming Soon)
- Utilities
- Entity Manager
- File Manager
- Access and Save File (Coming Soon)
- Image Methods (Coming Soon)
- XML Manager
- XML Class (Coming Soon)
- Parser (Coming Soon)
- Writer (Coming Soon)
- Advanced Topics
- Extended Users
- Routes
- Templating (Coming Soon)
- Translations and Locales