/** * Return Hook for Post Parsing or Post Convert * * @param string $event Hook we want * @param object $import Import Model * @return object Closure */ private function _hooks($event, $import) { // Array to hold callbacks $callbacks = array(); // Get hooks on import $hooks = json_decode($import->get('hooks')); // Make sure we have this type of hook if (!isset($hooks->{$event})) { return $callbacks; } // Loop through each hook foreach ($hooks->{$event} as $hook) { // Load hook object $importHook = new \Hubzero\Content\Import\Model\Hook($hook); // Make sure we have an object if (!$importHook) { continue; } // Build path to script $hookFile = $importHook->fileSpacePath() . DS . $importHook->get('file'); // Make sure we have a file if (!is_file($hookFile)) { continue; } // Add callback $callbacks[] = function ($data, $dryRun) use($hookFile) { return include $hookFile; }; } // Return closures as callbacks return $callbacks; }