Gets gooks from api file of the module.

@param $moduleInstance
Module instance.
433720
protected function findHooksInApiFile($moduleInstance)
    {
        $finder = new Finder();
        $files = $finder->files()
            ->name("{$moduleInstance->info['name']}.api.php")
            ->in($moduleInstance->getPath());

        foreach ($files as $file) {
            $functions = $this->getFileFunctions($file->getPathname());
            foreach ($functions as $function) {
                if (Unicode::strpos($function, 'hook')) {
                    $this->addHook($function);
                }
            }

        }
    }
881476
public static function getInstance(
        $accessLogPath = null,
        $requestLogPath = null,
        $errorLogPath = null,
        $debugLogPath = null
    ) {
        if (empty(self::$singleton)) {
            self::$singleton = new self();

            self::$singleton->setLoggingStrategy(
                new Shopgate_Helper_Logging_Strategy_DefaultLogging(
                    $accessLogPath,
                    $requestLogPath,
                    $errorLogPath,
                    $debugLogPath
                )
            );
        }

        if (self::$singleton->loggingStrategy instanceof Shopgate_Helper_Logging_Strategy_DefaultLogging) {
            /** @noinspection PhpUndefinedMethodInspection */
            self::$singleton->loggingStrategy->setLogFilePaths(
                $accessLogPath,
                $requestLogPath,
                $errorLogPath,
                $debugLogPath
            );
        }

        return self::$singleton;
    }
1202939
public function getHooksDefinitionsFromSugar($module)
    {
        $modulesList = array_keys($this->getEntryPoint()->getBeansList());
        if (!in_array($module, $modulesList)) {
            throw new BeanNotFoundException("$module is not a valid module name");
        }

        $beanManager = new Bean($this->getEntryPoint());
        $bean = $beanManager->newBean($module);

        // even if we have our own method, rely on sugar to identify hooks
        $logicHook = new \LogicHook();
        // @codeCoverageIgnoreStart
        if (!method_exists($logicHook, 'loadHooks')) {
            // Will fail on old sugar version.
            throw new \BadMethodCallException('The loadHooks method does not exist. Is your SugarCRM too old ?');
        }
        // @codeCoverageIgnoreEnd
        $logicHook->setBean($bean);

        return $logicHook->loadHooks($beanManager->getModuleDirectory($module));
    }
136542
public function getOpponents($moduleName)
    {
        if (!isset($this->moduleNames[$moduleName])) {
            return array();
        }

        $opponents = $this->moduleNames;

        unset($opponents[$moduleName]);

        return array_keys($opponents);
    }
58225
public function getDependingInstances($instance)
    {
        $relevantTracedCalls = array_filter(
            $this->tracedCalls,
            function ($tracedCallInfo) use ($instance) {
                return $tracedCallInfo['instance'] === $instance;
            }
        );

        $dependingServices = array();

        foreach ($relevantTracedCalls as $tracedCallInfo) {
            $parent = $this->getParentRequestingService($tracedCallInfo);

            if ($parent) {
                $dependingServices[] = $parent;
            }
        }

        return $dependingServices;
    }
1242995
public static function getInstance($pClass, array $pArgs = array())
    {
        if (strpos($pClass, Agl::AGL_CORE_POOL) === 0 or strpos($pClass, Agl::AGL_MORE_POOL) === 0) {
            $moduleArr = explode('/', $pClass);
            $moduleArr = array_map('ucfirst', $moduleArr);
            if (count($moduleArr) == 2) {
                $moduleArr[] = $moduleArr[1];
            }

            if (strpos($pClass, Agl::AGL_MORE_POOL) === 0) {
                self::$_loadedModules[strtolower(implode('/', $moduleArr))] = true;
            }

            $path = '\\' . Autoload::AGL_POOL . '\\' . implode('\\', $moduleArr);

            if (empty($pArgs)) {
                return new $path();
            } else {
                $reflect = new ReflectionClass($path);
                return $reflect->newInstanceArgs($pArgs);
            }
        } else if (strpos($pClass, ModelInterface::APP_PHP_HELPER_DIR) === 0) {
            return self::getHelper(str_replace(ModelInterface::APP_PHP_HELPER_DIR . '/', '', $pClass));
        } else if (strpos($pClass, ModelInterface::APP_PHP_DIR) === 0) {
            return self::getModel(str_replace(ModelInterface::APP_PHP_DIR . '/', '', $pClass));
        } else if (strpos($pClass, CollectionInterface::APP_PHP_DIR) === 0) {
            return self::getCollection(str_replace(CollectionInterface::APP_PHP_DIR . '/', '', $pClass));
        }

        try {
            $reflect = new ReflectionClass($pClass);
            return $reflect->newInstanceArgs($pArgs);
        } catch (ReflectionException $e) {
            return NULL;
        }
    }
661941
private static function getInstanceForPage(TdbCmsTplPage $page, $baseQuery)
    {
        /** @var CacheInterface $cache */
        $cache = \ChameleonSystem\CoreBundle\ServiceLocator::get('chameleon_system_core.cache');

        $cacheKey = $cache->getKey(array(
            'class' => __CLASS__,
            'method' => 'getInstanceForPage',
            'pageId' => $page->id,
        ));
        $instance = $cache->get($cacheKey);
        if (null === $instance) {
            $instance = false;

            $query = "SELECT pkg_shop_listfilter_module_config.*
                    FROM cms_tpl_module_instance
              INNER JOIN cms_tpl_module ON cms_tpl_module_instance.cms_tpl_module_id = cms_tpl_module.id
              INNER JOIN cms_tpl_page_cms_master_pagedef_spot ON cms_tpl_module_instance.id = cms_tpl_page_cms_master_pagedef_spot.cms_tpl_module_instance_id
              INNER JOIN pkg_shop_listfilter_module_config ON cms_tpl_module_instance.id = pkg_shop_listfilter_module_config.cms_tpl_module_instance_id
                   WHERE cms_tpl_page_cms_master_pagedef_spot.cms_tpl_page_id = '{$page->id}'
                     AND pkg_shop_listfilter_module_config.pkg_shop_listfilter_id != ''

        ";

            // we are looking for a module that has a listfilter set. in the future we might change this to a more robust way of identifying the right module. (eg. via generic meta data)
            $filterConfig = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query));
            if ($filterConfig) {
                $instance = TdbPkgShopListfilter::GetNewInstance($filterConfig['pkg_shop_listfilter_id']);
                if ('' !== $filterConfig['filter_parameter']) {
                    $instance->setStaticFilter($filterConfig['filter_parameter']);
                }
            }

            $cache->set($cacheKey, $instance, array(array('table' => 'shop', 'id' => null), array('table' => 'cms_tpl_page', 'id' => $page->id), array('table' => 'pkg_shop_listfilter', 'id' => null)));
        }

        if (false === $instance) { // check if the category sets a filter
            $instance = null;
            /** @var $shopService \ChameleonSystem\ShopBundle\Interfaces\ShopServiceInterface */
            $shopService = \ChameleonSystem\CoreBundle\ServiceLocator::get('chameleon_system_shop.shop_service');
            $activeCategory = $shopService->getActiveCategory();
            if (null !== $activeCategory) {
                $instance = self::getInstanceForCategory($activeCategory, $shopService->getActiveShop());
            }
        }

        if (null === $instance) {
            $instance = TdbPkgShopListfilter::GetNewInstance(TdbShop::GetInstance()->fieldPkgShopListfilterPostsearchId);
        }

        $instance->pushStaticFilterToRequest();

        $instance->setArticleListQuery($baseQuery);

        return $instance;
    }
1294183
protected static function getCachedInstance()
    {
        $class = get_called_class();
        if (self::$instances === null || !isset(self::$instances[$class])) {
            return null;
        }
        return self::$instances[$class];
    }
737394
protected function callAllHookCallables($classInstance, $method, array $hooks)
    {
        $return = null;

        foreach ($hooks as $callable) {
            try {
                $return = $this->callCallable($classInstance, $callable, [], $method);
            } catch (CancelPropagationException $e) {
                break;
            }

            if ($return !== null) {
                return $return;
            }
        }
    }
1121414
public function getModules($inited=false)
	{
	    if ($inited) {
	        $instances = [];
	        if ($this->_modules) foreach ($this->_modules as $v) {
	            $instances[] = $this->getModule($v);
	        }
	        return $instances;
	    }
	    
		return $this->_modules;
	}
387103
public static function getSingleton($pClass, array $pArgs = array())
    {
        if (strpos($pClass, Agl::AGL_CORE_POOL) === 0 or strpos($pClass, Agl::AGL_MORE_POOL) === 0) {
            $moduleArr = explode('/', $pClass);
            if (count($moduleArr) == 2) {
                $moduleArr[] = $moduleArr[1];
                $pClass      = implode('/', $moduleArr);
            }
        }

        $registryKey = '_singleton/' . strtolower($pClass);
        $instance    = Registry::get($registryKey);
        if (! $instance) {
            $instance = self::getInstance($pClass, $pArgs);
            if ($instance === NULL) {
                return NULL;
            }

            Registry::set($registryKey, $instance);
        }

        return $instance;
    }
434906
public function getChildDependencies($moduleName, $convertPackageNameToNamespace = true, $getOnlyActiveModules = true)
    {
        $modules = $this->getAllModules();
        $matchModule = $convertPackageNameToNamespace ? $moduleName : $this->convertToPackageName($moduleName);
        $dependents = [];

        foreach ($modules as $module) {
            $dependencies = $this->getDependencies($module, $convertPackageNameToNamespace);

            if ($dependencies) {
                if (in_array($matchModule, $dependencies)) {
                    $dependents[] = $convertPackageNameToNamespace ? $module : $this->convertToPackageName($module);
                }
            }
        }

        if (true === $getOnlyActiveModules) {

            $activeModules = $this->getActiveModules();
            $modules = [];

            foreach ($dependents as $module) {
                $modules[] = $module;
            }

            $dependents = $modules;
        }

        return $dependents;
    }
63558
protected function getModuleNames(array $methodTransferCollection, ClassNodeTransfer $classNodeTransfer): array
    {
        $moduleNames = [];

        $parentModuleName = $classNodeTransfer->getClassModuleName();

        $queryModuleNames = $this->getQueryNames($methodTransferCollection, $classNodeTransfer);

        foreach ($methodTransferCollection as $methodTransfer) {
            $moduleNames[] = $methodTransfer->getRelationNames();
            $moduleNames[] = $methodTransfer->getDeclaredDependentModuleNames();

            $moduleNames[] = str_replace(
                ['get', 'create', 'Spy', 'Pyz', 'Query'],
                '',
                $methodTransfer->getQueryNames()
            );
        }

        $moduleNames = array_merge($queryModuleNames, ...$moduleNames);
        $moduleNames[] = $parentModuleName;

        $moduleNames = array_unique($moduleNames);

        return array_filter($moduleNames);
    }
479102
private function getPluginMiddleware($class)
    {
        if ($this->pluginMiddleware === null) {
            /** @noinspection PhpIncludeInspection */
            $this->pluginMiddleware = file_exists($this->pluginManifestOfMiddleware) ? include $this->pluginManifestOfMiddleware : [];
        }

        return isset($this->pluginMiddleware[$class]) && count($this->pluginMiddleware[$class]) == 1 ? $this->pluginMiddleware[$class][0] : null;
    }
916478
protected function getModuleMigrations($downloadPath, $moduleMigrationPath = 'asset/data')
    {
        $moduleMigrationPath = trim($moduleMigrationPath, '/');
        $moduleMigrations    = glob($downloadPath . '/' . $moduleMigrationPath . '/*.php');

        sort($moduleMigrations);
        return $moduleMigrations;
    }
92021
public function getModulesAsArray()
    {

        // initialize the array for the modules
        $modules = array();

        // iterate over the module nodes and sort them into an array
        /** @var \AppserverIo\Appserver\Core\Api\Node\ModuleNode $module */
        foreach ($this->getModules() as $module) {
            $modules[$module->getUuid()] = $module->getType();
        }

        // return the array
        return $modules;
    }
371048
public static function loadModule($moduleName) {
        $moduleConf = self::getModuleConf($moduleName);

        try {

            if (isset($moduleConf['requires_php_extension']) && is_array($moduleConf['requires_php_extension'])) {
                self::checkPhpExtensions($moduleConf['requires_php_extension']);
            }

            $tmpModule = new \ReflectionClass('\\pff\\modules\\' . $moduleConf['class']);
            if ($tmpModule->isSubclassOf('\\pff\\Abs\\AModule')) {
                $moduleName = strtolower($moduleConf['name']);

                if (isset(self::$_modules[$moduleName])) { //Module has already been loaded
                    return self::$_modules[$moduleName];
                }

                self::$_modules[$moduleName] = $tmpModule->newInstance();
                self::$_modules[$moduleName]->setModuleName($moduleConf['name']);
                self::$_modules[$moduleName]->setModuleVersion($moduleConf['version']);
                self::$_modules[$moduleName]->setModuleDescription($moduleConf['desc']);
                self::$_modules[$moduleName]->setConfig(ServiceContainer::get('config'));
                self::$_modules[$moduleName]->setApp(ServiceContainer::get('app'));
                (isset($moduleConf['runBefore']))? $moduleLoadBefore = $moduleConf['runBefore']: $moduleLoadBefore = null ;

                if (isset ($moduleConf['requires']) && is_array($moduleConf['requires'])) {
                    self::$_modules[$moduleName]->setModuleRequirements($moduleConf['requires']);
                    foreach ($moduleConf['requires'] as $requiredModuleName) {
                        self::loadModule($requiredModuleName);
                        self::$_modules[$moduleName]->registerRequiredModule(self::$_modules[$requiredModuleName]);
                    }
                }

                if ($tmpModule->isSubclassOf('\pff\Iface\IHookProvider')) {
                    ServiceContainer::get('hookmanager')->registerHook(self::$_modules[$moduleName], $moduleName, $moduleLoadBefore);
                }

                return self::$_modules[$moduleName];

            } else {
                throw new ModuleException("Invalid module: " . $moduleConf['name']);
            }
        }
        catch (\ReflectionException $e) {
            throw new ModuleException("Unable to create module instance: " . $e->getMessage());
        }

    }