public function getMockModelArray($model_name, array $params) { $items = array(); foreach ($params as $id => $item_params) { $item = $this->getMockFromParams(Jam::class_name($model_name), $item_params, array($model_name))->set(array('id' => $id)); $items[] = $item; } return $items; }
private function _resource(Resource $resource, array $route_params, $is_parent = FALSE) { $resource->param($route_params); $output = ''; if (isset($route_params['id'])) { $output = (string) $resource->object(); } elseif ($resource->option('singular')) { if ($model = $resource->option('model')) { $output = 'Singular model: ' . Minion_CLI::color(Jam::class_name($model), 'light_red'); } } else { $output = 'Collection of: ' . Minion_CLI::color(Jam::class_name($resource->option('model')), 'light_red'); } if ($is_parent) { $output = 'Parent: ' . $output; } Minion_CLI::write($output); }
/** * Get / Set individual behaviors. * * @param string $name name of the association * @param mixed $association the association alias or object * @return Jam_Association|Jam_Meta|null */ public function behavior($name, $behavior = NULL, $prepend = FALSE) { if ($behavior === NULL) { // Get the behavior return Arr::get($this->_behaviors, $name); } if ($this->_initialized) { // Cannot set after initialization throw new Kohana_Exception(':class already initialized, cannot set :behavior', array(':class' => Jam::class_name($this->_model), ':behavior' => $name)); } // Set the behavior if ($prepend) { $this->_behaviors = array($name => $behavior) + $this->_behaviors; } else { $this->_behaviors[$name] = $behavior; } // Return Jam_Meta return $this; }
/** * Tests Jam::class_name() * * @dataProvider provider_class_name */ public function test_class_name($model, $expected) { $this->assertSame($expected, Jam::class_name($model)); }
/** * Automatically loads a model, if it exists, * into the meta table. * * Models are not required to register * themselves; it happens automatically. * * @param string $model * @return boolean */ public static function register($model) { $class = Jam::class_name($model); $model = Jam::model_name($model); // Don't re-initialize! if (isset(Jam::$_models[$model])) { return TRUE; } // Can we find the class? if (class_exists($class)) { // Prevent accidentally trying to load ORM or Sprig models if (!is_subclass_of($class, 'Jam_Validated')) { return FALSE; } } else { return FALSE; } // Load it into the registry Jam::$_models[$model] = $meta = new Jam_Meta($model); // Let the intialize() method override defaults. call_user_func(array($class, 'initialize'), $meta); // Finalize the changes $meta->finalize($model); return TRUE; }