/**
  * Decorates an entity or an array of entities
  * @param mixed $components SystemComponent or array of SystemComponents
  * @return mixed SystemComponentController or array of SystemComponentControllers
  */
 protected function decorate($components)
 {
     if (!$components) {
         return $components;
     }
     if (!is_array($components)) {
         $yamlDir = $this->cx->getClassLoader()->getFilePath($components->getDirectory(false) . '/Model/Yaml');
         if (file_exists($yamlDir)) {
             $this->cx->getDb()->addSchemaFileDirectories(array($yamlDir));
         }
         $entity = $this->decorateEntity($components);
         return $entity;
     }
     $yamlDirs = array();
     foreach ($components as $component) {
         if (isset($this->loadedComponents[$component->getId()])) {
             continue;
         }
         $yamlDir = $this->cx->getClassLoader()->getFilePath($component->getDirectory(false) . '/Model/Yaml');
         if ($yamlDir) {
             $yamlDirs[] = $yamlDir;
         }
     }
     $this->cx->getDb()->addSchemaFileDirectories($yamlDirs);
     foreach ($components as &$component) {
         if (isset($this->loadedComponents[$component->getId()])) {
             $component = $this->loadedComponents[$component->getId()];
             continue;
         }
         $component = $this->decorateEntity($component);
         \Cx\Core\Json\JsonData::addAdapter($component->getControllersAccessableByJson(), $component->getNamespace() . '\\Controller');
     }
     return $components;
 }
 /**
  * Loads the systemComponent using the doctrine entity manager for the existing SystemComponentController and adds it to the repository
  * @param array $preLoadedComponents An array containing the preloaded components
  */
 public function setPreLoadedComponents($preLoadedComponents)
 {
     foreach ($preLoadedComponents as $componentName => $preLoadedComponent) {
         // get systemComponent by name
         $systemComponent = parent::findOneBy(array('name' => $componentName));
         // set systemComponent on existing systemComponentController
         $preLoadedComponent->setSystemComponent($systemComponent);
         // add yaml directory
         $yamlDir = $this->cx->getClassLoader()->getFilePath($preLoadedComponent->getDirectory(false) . '/Model/Yaml');
         if (file_exists($yamlDir)) {
             $this->cx->getDb()->addSchemaFileDirectories(array($yamlDir));
         }
         // store the systemComponent with its now loaded id as key to the array of loaded components
         $this->loadedComponents[$preLoadedComponent->getId()] = $preLoadedComponent;
         // Add JSON adapter
         \Cx\Core\Json\JsonData::addAdapter($preLoadedComponent->getControllersAccessableByJson(), $preLoadedComponent->getNamespace() . '\\Controller');
     }
 }