Pheasant::initialize PHP Method

initialize() public method

Initializes a domain objects schema if it has not yet been initialized
public initialize ( $subject, $callback = null ) : string
$subject either an object or classname to initialize
$callback a callback to call instead of the initialize method
return string the classname of the object
    public function initialize($subject, $callback = null)
    {
        $class = is_string($subject) ? ltrim($subject, '\\') : $subject::className();
        // initialize the object if needed
        if (!isset($this->_schema[$class])) {
            $builder = new \Pheasant\SchemaBuilder($this);
            $initializer = $callback ? $callback : $class . '::initialize';
            $this->events()->trigger('beforeInitialize', $builder);
            call_user_func($initializer, $builder, $this);
            $schema = $builder->build($class);
            $this->_schema[$class] = $schema;
            $this->events()->trigger('afterInitialize', $schema);
        }
        return $class;
    }