lib/CallBack.php
public function register($name, $closure = null, $options = array())
	{

		// Set default options
		$options = array_merge(array(
			'prepend' => false)
		, $options);

		// No method given?
		if (!$closure) {

			// Use the name instead
			$closure = $name;
		}

		// Not valid?
		if (!in_array($name,self::$validCallbacks)) {
			throw new ActiveRecordException("Invalid callback: $name");
		}

		// Is it a method?
		if (!($closure instanceof Closure))
		{

			// Load class its public methods
			if (!isset($this->publicMethods)) {
				$this->publicMethods = get_class_methods($this->klass->getName());
			}

			// Is there no public method by that name?
			if (!in_array($closure, $this->publicMethods)) {

				// Was the method private?
				if ($this->klass->hasMethod($closure)) {

					// Method is private or protected
					throw new ActiveRecordException("Callback methods need to be public (or anonymous closures). " .
						"Please change the visibility of " . $this->klass->getName() . "->" . $closure . "()");

				} else {

					// Just a non-existing method				
					throw new ActiveRecordException("Unknown method for callback: $name" .
						(is_string($closure) ? ": #$closure" : ""));

				}
			}
		}

		// Add method/closure to the registry
		if (!isset($this->registry[$name])) {
			$this->registry[$name] = array();
		}
		if ($options['prepend']) {
			array_unshift($this->registry[$name], $closure);
		} else {
			$this->registry[$name][] = $closure;
		}
	}
public function register($name, $closure = null, $options = array())
	{

		// Set default options
		$options = array_merge(array(
			'prepend' => false)
		, $options);

		// No method given?
		if (!$closure) {

			// Use the name instead
			$closure = $name;
		}

		// Not valid?
		if (!in_array($name,self::$validCallbacks)) {
			throw new ActiveRecordException("Invalid callback: $name");
		}

		// Is it a method?
		if (!($closure instanceof Closure))
		{

			// Load class its public methods
			if (!isset($this->publicMethods)) {
				$this->publicMethods = get_class_methods($this->klass->getName());
			}

			// Is there no public method by that name?
			if (!in_array($closure, $this->publicMethods)) {

				// Was the method private?
				if ($this->klass->hasMethod($closure)) {

					// Method is private or protected
					throw new ActiveRecordException("Callback methods need to be public (or anonymous closures). " .
						"Please change the visibility of " . $this->klass->getName() . "->" . $closure . "()");

				} else {

					// Just a non-existing method				
					throw new ActiveRecordException("Unknown method for callback: $name" .
						(is_string($closure) ? ": #$closure" : ""));

				}
			}
		}

		// Add method/closure to the registry
		if (!isset($this->registry[$name])) {
			$this->registry[$name] = array();
		}
		if ($options['prepend']) {
			array_unshift($this->registry[$name], $closure);
		} else {
			$this->registry[$name][] = $closure;
		}
	}
public function register ( $ name , $ closure = null , $ options = array ( ) ) { // Set default options $ options = array_merge ( array ( 'prepend' => false ) , $ options ) ; // No method given? if ( ! $ closure ) { // Use the name instead $ closure = $ name ; } // Not valid? if ( ! in_array ( $ name , self :: $ validCallbacks ) ) { throw new ActiveRecordException ( "Invalid callback: $name" ) ; } // Is it a method? if ( ! ( $ closure instanceof Closure ) ) { // Load class its public methods if ( ! isset ( $ this -> publicMethods ) ) { $ this -> publicMethods = get_class_methods ( $ this -> klass -> getName ( ) ) ; } // Is there no public method by that name? if ( ! in_array ( $ closure , $ this -> publicMethods ) ) { // Was the method private? if ( $ this -> klass -> hasMethod ( $ closure ) ) { // Method is private or protected throw new ActiveRecordException ( "Callback methods need to be public (or anonymous closures). " . "Please change the visibility of " . $ this -> klass -> getName ( ) . "->" . $ closure . "()" ) ; } else { // Just a non-existing method				 throw new ActiveRecordException ( "Unknown method for callback: $name" . ( is_string ( $ closure ) ? ": #$closure" : "" ) ) ; } } } // Add method/closure to the registry if ( ! isset ( $ this -> registry [ $ name ] ) ) { $ this -> registry [ $ name ] = array ( ) ; } if ( $ options [ 'prepend' ] ) { array_unshift ( $ this -> registry [ $ name ] , $ closure ) ; } else { $ this -> registry [ $ name ] [ ] = $ closure ; } }
Register a new callback.

The option array can contain the following parameters:
<ul>
<li><b>prepend:</b> Add this callback at the beginning of the existing callbacks (true) or at the end (false, default)</li>
</ul>

@param string  	Name of callback type (see $validCallbacks)
@param mixed  	Either a closure or the name of a method on the {@link Model}
@param array  	Options array
@return void
@throws ActiveRecordException if invalid callback type or callback method was not found
Register a new callback .