Skip to content
Devin Smith edited this page Feb 3, 2016 · 2 revisions

Factory provides an in memory cache of objects with a type, key, value store system. This is enabled by default for Resource.


Use with Resource

When objects are loaded from the database using the load method they are automatically added to the factory cache.

$user = User::o(1);
$user->name = 'new name';

$user = User::o(1); // load the item from memory instead of another database call
echo $user->name; // prints "new name"

Standalone usage

The factory method gets or sets an object by classname, or passed object

$object = new User([
	id => 1
]);

$u = $tipsy->factory($object);
// or
$u = $tipsy->factory('User', $object);

Disabling

Disable in php

$tipsy->config(['tipsy' => ['factory' => false]]);

or in a config file

tipsy:
  factory: false