/**
  * Return the top-level layout component for this view.
  * This assumes that the construction of the view always has a layout component at the root.
  */
 protected function getLayout()
 {
     if (!$this->layout) {
         // get the view definition. We give it the raw component hierarchy and let
         // the factory component sort out what classes are actually required.
         $this->layout = NLComponent::factory($this->rawComponents, $this);
     }
     return $this->layout;
 }
 /**
  * Given an NLComponent object hierarchy, generate the actual NLComponent instances. The object passed in
  * is an object structure that is a deserialised json object, so the objects are untyped. We use the ClassName
  * property in each to determine the actual type. Bindings are done lazily; the component only interprets the
  * binding definitions in $object later if it needs to.
  * @static
  * @param $object
  * @param $context
  * @return void
  */
 public static function factory($object, $view)
 {
     if (!isset($object->ClassName)) {
         throw new Exception("NLComponent has no class information");
     }
     $className = $object->ClassName;
     $real = new $className($object);
     // Store the raw bindings for later, only interpret this on demand.
     $real->rawBindings = null;
     if (isset($object->bindings)) {
         $real->rawBindings = $object->bindings;
     }
     $real->layoutValues = null;
     if (isset($object->layout)) {
         $real->layoutValues = $object->layout;
     }
     $real->view = $view;
     // Now recursively create the real components for each child of this component.
     $real->children = array();
     if (isset($object->children)) {
         foreach ($object->children as $child) {
             $real->children[] = NLComponent::factory($child, $view);
         }
     }
     return $real;
 }