The Factory takes an array of info and turns it into objects. It's use within ADM is to receive from the Repository some data grabbed from the persistence layer via the Gateway. It then turns this data into one or more objects and gives these objects back to the Repository.
Creating a Factory
Normally you shouldn't be creating Factories yourself. If you refer to the Repository documentation and use the recommended Repository creation method of utilizing the RepositoryFactory class, then it will create a Factory for you and handle passing it off to the Repository.
If for some reason you do need to create your own Factory object and you're using Cora's default Factory, then do so like this:
// Create a User factory $factory = new Factory('User');
Optionally you can include a 2nd argument in the form of a Cora database adaptor. If you do this, the adaptor will get passed on to any objects created by the Factory. The reason for this is when you want to override the default database for a model. If for instance you have a model that normally is found in your main database, but for unit testing you want to use a separate test database, you can pass in a connection to the test database this way so it gets used.
$db = \Cora\Database::getDb('name_of_db_connection_to_use'); $factory = new Factory('User', $db);