li3_behaviors\data\model\Behaviors::bindBehavior()

public static method

Binds a new instance of a behavior to the model using given config or entirely replacing an existing behavior instance with new config.

Parameters

  • string|object $name

    The name of the behavior or an instance of it.

  • array $config

    Configuration for the behavior instance.

Source

	public static function bindBehavior($name, array $config = []) {
		list($model, $class) = static::_classesForBehavior($name);
		static::_initializeBehaviors();

		if (is_object($name)) {
			$name->config($config);
		} else {
			if (!class_exists($class)) {
				$message  = "Behavior class `{$class}` does not exist. ";
				$message .= "Its name might be misspelled. Behavior was requested by ";
				$message .= "model `{$model}`.";
				throw new Exception($message);
			}
			$name = new $class($config + compact('model'));
		}
		static::$_behaviors[$model][$class] = $name;
	}