public function __invoke($params)
 {
     $service = new PortableElementService();
     $service->setServiceLocator(ServiceManager::getServiceManager());
     $sourceDirectory = $this->getSourceDirectory();
     if (empty($sourceDirectory)) {
         return $this->createFailure('the source directory is empty');
     }
     if (!is_readable($sourceDirectory)) {
         return $this->createFailure('the source directory does not exists or is not readable ' . $sourceDirectory);
     }
     try {
         $model = $service->getValidPortableElementFromDirectorySource($sourceDirectory);
         if (!empty($params)) {
             $minRequiredVersion = $params[0];
             // if the minimal required version number string "x.y.z" is given in the parameter, the new target version should be equal or higher than it
             if (version_compare($model->getVersion(), $minRequiredVersion) < 0) {
                 return $this->createFailure('the version in manifest "' . $model->getVersion() . '" cannot be lower than the given minimum required version "' . $minRequiredVersion . '"', $model);
             }
         }
         $service->registerFromDirectorySource($sourceDirectory);
     } catch (PortableElementVersionIncompatibilityException $e) {
         return $this->createFailure('incompatible version: ' . $e->getMessage(), $model);
     }
     return Report::createSuccess('registered portable element "' . $model->getTypeIdentifier() . '" in version "' . $model->getVersion() . '""');
 }
 /**
 * Re-register a portable element from its source directory
 * The list of portable elements to re-register is configure in the config file {TAO_ROOT}/config/taoQtiItem/debug_portable_element.conf.php
 * e.g.
    return [
        'myPci1' => 'qtiItemPci/views/js/pciCreator/dev/myPci1/',
        'myPci2' => '/home/sam/dev/pcis/myPci2/'
    ];
 *
 * @param ItemCreatorLoad $event
 * @throws \common_Exception
 * @throws \common_ext_ExtensionException
 */
 public static function reloadPortableDevDirectory(ItemCreatorLoad $event)
 {
     $customInteractionDirs = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('debug_portable_element');
     if (is_array($customInteractionDirs)) {
         $service = new PortableElementService();
         $service->setServiceLocator(ServiceManager::getServiceManager());
         foreach ($customInteractionDirs as $path) {
             if (is_dir(ROOT_PATH . $path)) {
                 $sourceDir = ROOT_PATH . $path;
             } else {
                 if (is_dir($path)) {
                     $sourceDir = $path;
                 } else {
                     throw new \common_Exception('No directory found on path ' . $path);
                 }
             }
             $service->registerFromDirectorySource($sourceDir);
             \common_Logger::i('Re-registered portable element from the source ' . $sourceDir);
         }
     }
 }