-
Notifications
You must be signed in to change notification settings - Fork 30
Factories
Eustáquio Rangel edited this page Aug 5, 2013
·
6 revisions
Create a directory, say, factories
, to store all your factories there. Then tell TORM where the factories are using
TORM\Factory::setFactoriesPath("./factories");
Then, on the dir, create .php
files. They can have the name you want, but it's a good idea make them reflect your models, so, we can have a user.php
file with the following contents:
TORM\Factory::define("user",array("name"=>"Mary Doe","email"=>"[email protected]","level"=>1));
We just need the factory name where is mandatory that it reflects the class name (no problem if it's lower case) and then some data to use with the new object of the specified class.
To get the attributes of the example above, we can use
$data = TORM\Factory::attributes_for("user");
To build a new and not saved object, we can use
$user = TORM\Factory::build("user");
To create a new object and save a new record on the database specified by the connection, we can use
$user = TORM\Factory::create("user");