本文整理汇总了PHP中Jelly::behavior_prefix方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::behavior_prefix方法的具体用法?PHP Jelly::behavior_prefix怎么用?PHP Jelly::behavior_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::behavior_prefix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finalize
/**
* This is called after initialization to
* finalize any changes to the meta object.
*
* @param string $model
* @return
*/
public function finalize($model)
{
if ($this->_initialized) {
return;
}
// Set up event system
$this->_events = new Jelly_Event($model);
// Set the name of a possible behavior class
$behavior_class = Jelly::behavior_prefix() . $model;
// See if we have a special behavior class to use
if (class_exists($behavior_class)) {
// Load behavior
$behavior = new $behavior_class();
if (!in_array($behavior, $this->_behaviors)) {
// Add to behaviors
$this->_behaviors[] = $behavior;
}
}
foreach ($this->_behaviors as $name => $behavior) {
if (!$behavior instanceof Jelly_Behavior) {
throw new Kohana_Exception('Behavior at index [ :key ] is not an instance of Jelly_Behavior, :type found.', array(':type' => is_object($behavior) ? 'instance of ' . get_class($behavior) : gettype($behavior), ':key' => $name));
}
// Initialize behavior
$behavior->initialize($this->_events, $model, $name);
}
// Allow modification of this meta object by the behaviors
$this->_events->trigger('meta.before_finalize', $this);
// Ensure certain fields are not overridden
$this->_model = $model;
$this->_columns = $this->_defaults = $this->_field_cache = $this->_aliases = array();
if (!$this->_errors_filename) {
// Default errors filename to the model's name
$this->_errors_filename = $this->_model;
}
// Table should be a sensible default
if (empty($this->_table)) {
$this->_table = Inflector::plural($model);
}
// See if we have a special builder class to use
if (empty($this->_builder)) {
$builder = Jelly::model_prefix() . 'builder_' . $model;
if (class_exists($builder)) {
$this->_builder = $builder;
} else {
$this->_builder = 'Jelly_Builder';
}
}
// Can we set a sensible foreign key?
if (empty($this->_foreign_key)) {
$this->_foreign_key = $model . '_id';
}
// Initialize all of the fields with their column and the model name
foreach ($this->_fields as $column => $field) {
// Allow aliasing fields
if (is_string($field)) {
if (isset($this->_fields[$field])) {
$this->_aliases[$column] = $field;
}
// Aliases shouldn't pollute fields
unset($this->_fields[$column]);
continue;
}
$field->initialize($model, $column);
// Ensure a default primary key is set
if ($field->primary and empty($this->_primary_key)) {
$this->_primary_key = $column;
}
// Search for a polymorphic key
if (!empty($field->polymorphic)) {
$this->_polymorphic_key = $field->name;
// Add this class as a child if it hasn't been added yet
if (!in_array($this->_model, $this->_children)) {
$this->_children[] = $this->_model;
}
}
// Set the defaults so they're actually persistent
$this->_defaults[$column] = $field->default;
}
// Meta object is initialized and no longer writable
$this->_initialized = TRUE;
// Final meta callback
$this->_events->trigger('meta.after_finalize', $this);
}