Get processes ordered based on their dependencies.

@return array

@throws CircularDependencyException
@throws UnresolvedDependencyException
493334
public function getOrderedProcesses()
    {
        $graph = new DependencyGraph();
        $root = new DependencyGraphNode(self::ROOT_NODE_NAME);
        $graph->addRoot($root);

        $processes = $this->getProcesses();
        $nodes = [];
        foreach ($processes as $process) {
            $processName = $this->getProcessName($process);
            $node = new DependencyGraphNode($processName);
            $graph->addDependency($root, $node);
            $nodes[$processName] = [$process, $node];
        }

        foreach ($nodes as $processName => $nodeDescription) {
            list($process, $node) = $nodeDescription;
            if (!$process instanceof DependentChainProcessInterface) {
                $graph->addDependency($root, $node);
                continue;
            }

            foreach ($process->dependsOn() as $dependencyName) {
                if (!array_key_exists($dependencyName, $nodes)) {
                    throw new UnresolvedDependencyException(sprintf(
                        'Process "%s" is dependent of "%s" which is not found',
                        $processName,
                        $dependencyName
                    ));
                }

                if ($graph->addDependency($node, $nodes[$dependencyName][1]) instanceof Left) {
                    throw new CircularDependencyException(sprintf(
                        'Circular dependency found: %s already depends on %s',
                        $dependencyName, $processName
                    ));
                }
            }
        }

        return array_map(function ($nodeName) use ($nodes) {
            return $nodes[$nodeName][0];
        }, array_filter($graph->flatten(), function ($nodeName) {
            return $nodeName !== self::ROOT_NODE_NAME;
        }));
    }
805292
public function getProcess()
    {
        $parentClass = get_parent_class($this);
        $this_prefix = \Closure::bind(function(ProcessBuilder $builder){return $builder->prefix;}, null, $parentClass);
        $this_prefix = $this_prefix($this);
        $this_arguments = \Closure::bind(function(ProcessBuilder $builder){return $builder->arguments;}, null, $parentClass);
        $this_arguments = $this_arguments($this);
        $this_options = \Closure::bind(function(ProcessBuilder $builder){return $builder->options;}, null, $parentClass);
        $this_options = $this_options($this);
        $this_inheritEnv = \Closure::bind(function(ProcessBuilder $builder){return $builder->inheritEnv;}, null, $parentClass);
        $this_inheritEnv = $this_inheritEnv($this);
        $this_env = \Closure::bind(function(ProcessBuilder $builder){return $builder->env;}, null, $parentClass);
        $this_env = $this_env($this);
        $this_cwd = \Closure::bind(function(ProcessBuilder $builder){return $builder->cwd;}, null, $parentClass);
        $this_cwd = $this_cwd($this);
        $this_input = \Closure::bind(function(ProcessBuilder $builder){return $builder->input;}, null, $parentClass);
        $this_input = $this_input($this);
        $this_timeout = \Closure::bind(function(ProcessBuilder $builder){return $builder->timeout;}, null, $parentClass);
        $this_timeout = $this_timeout($this);
        $this_outputDisabled = \Closure::bind(function(ProcessBuilder $builder){return $builder->outputDisabled;}, null, $parentClass);
        $this_outputDisabled = $this_outputDisabled($this);

        if (0 === count($this_prefix) && 0 === count($this_arguments)) {
            throw new LogicException('You must add() command arguments before calling getProcess().');
        }

        $options = $this_options;

        $arguments = array_merge($this_prefix, $this_arguments);
        $script = implode(' ', array_map(array('Symfony\\Component\\Process\\ProcessUtils', 'escapeArgument'), $arguments));

        if ($this_inheritEnv) {
            // include $_ENV for BC purposes
            $env = array_replace($_ENV, $_SERVER, $this_env);
        } else {
            $env = $this_env;
        }

        $process = new Process($script, $this_cwd, $env, $this_input, $this_timeout, $options);

        if ($this_outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }
606720
public function getDependencyPackages()
    {
        $this->_dependencyPackages = array();
        if (!isset($this->_packageXml->dependencies->required->package)) {
            return $this->_dependencyPackages;
        }
        foreach($this->_packageXml->dependencies->required->package as $_package) {
            $add = array(
                'name'    => (string)$_package->name,
                'channel' => (string)$_package->channel,
                'min'     => (string)$_package->min,
                'max'     => (string)$_package->max,
            );
            if(isset($_package->files)) {
                $add['files'] = array();
                foreach($_package->files as $node) {
                    if(isset($node->file)) {

                        $add['files'][] = array('target' => (string) $node->file['target'], 'path'=> (string) $node->file['path']);
                    }
                }
            }
            $this->_dependencyPackages[] = $add;
        }
        return $this->_dependencyPackages;
    }
1049658
public function getDependentStructures()
    {
        $dependents         = parent::getDependentStructures();
        $dependentContent   = $this->getDependentContent();

        if ( $dependentContent )
        {
            $dependents[] = $dependentContent;
        }

        return $dependents;
    }
296637
public static function sortByDependencies($extensions) {
        $sorted = array();
        $unsorted = array();
        foreach ($extensions as $ext) {
            $unsorted[$ext->getId()] = array_keys($ext->getDependencies());
        }
        while (!empty($unsorted)) {
            $before = count($unsorted);
            foreach (array_keys($unsorted) as $id) {
                $missing = array_diff($unsorted[$id], $sorted);
                if (empty($missing)) {
                    $sorted[] = $id;
                    unset($unsorted[$id]);
                }
            }
            if (count($unsorted) == $before) {
                $notfound = array_diff($missing, array_keys($unsorted));
                if (!empty($notfound)) {
                    throw new common_exception_Error('Missing extensions '.implode(',', $notfound).' for: '.implode(',', array_keys($unsorted)));
                } else {
                    throw new common_exception_Error('Cyclic extension dependencies for: '.implode(',', array_keys($unsorted)));
                }
            }
        }
        
        $returnValue = array();
        foreach ($sorted as $id) {
            foreach ($extensions as $ext) {
                if ($ext->getId() == $id) {
                    $returnValue[$id] = $ext;
                }
            }
        }
        return $returnValue;
    }
993962
private function orderInstallersByDependencies()
    {
        $sequenceForClasses = [];

        // If installers were already ordered by number then we need
        // to remove classes which are not instances of OrderedInstallerInterface
        // in case installers implementing DependentInstallerInterface exist.
        // This is because, in that case, the method orderInstallersByDependencies
        // will handle all installers which are not instances of
        // OrderedInstallerInterface
        if ($this->orderInstallersByNumber) {
            $count = count($this->orderedInstallers);

            for ($i = 0; $i < $count; ++$i) {
                if (!($this->orderedInstallers[$i] instanceof OrderedInstallerInterface)) {
                    unset($this->orderedInstallers[$i]);
                }
            }
        }

        // First we determine which classes has dependencies and which don't
        foreach ($this->installers as $installer) {
            $installerClass = get_class($installer);

            if ($installer instanceof OrderedInstallerInterface) {
                continue;
            } elseif ($installer instanceof DependentInstallerInterface) {
                $dependenciesClasses = $installer->getDependencies();

                $this->validateDependencies($dependenciesClasses);

                if (!is_array($dependenciesClasses) || empty($dependenciesClasses)) {
                    throw new \InvalidArgumentException(sprintf(
                        'Method "%s" in class "%s" must return an array of classes which are '.
                            'dependencies for the installer, and it must be NOT empty.',
                        'getDependencies',
                        $installerClass
                    ));
                }

                if (in_array($installerClass, $dependenciesClasses)) {
                    throw new \InvalidArgumentException(sprintf(
                        'Class "%s" can\'t have itself as a dependency',
                        $installerClass
                    ));
                }

                // We mark this class as unsequenced
                $sequenceForClasses[$installerClass] = -1;
            } else {
                // This class has no dependencies, so we assign 0
                $sequenceForClasses[$installerClass] = 0;
            }
        }

        // Now we order installers by sequence
        $sequence = 1;
        $lastCount = -1;

        while (($count = count($unsequencedClasses = $this->getUnsequencedClasses($sequenceForClasses))) > 0
                && $count !== $lastCount) {
            foreach ($unsequencedClasses as $key => $class) {
                /** @var DependentInstallerInterface $installer */
                $installer = $this->installers[$class];
                $dependencies = $installer->getDependencies();
                $unsequencedDependencies = $this->getUnsequencedClasses($sequenceForClasses, $dependencies);

                if (count($unsequencedDependencies) === 0) {
                    $sequenceForClasses[$class] = $sequence++;
                }
            }

            $lastCount = $count;
        }

        $orderedInstallers = [];

        // If there are installers unsequenced left and they couldn't be sequenced,
        // it means we have a circular reference
        if ($count > 0) {
            $msg = 'Classes "%s" have produced a circular reference exception. ';
            $msg .= 'An example of this problem would be the following: Class C has class B as its dependency. ';
            $msg .= 'Then, class B has class A has its dependency. Finally, class A has class C as its dependency. ';
            $msg .= 'This case would produce a circular reference exception.';

            throw new \RuntimeException(sprintf($msg, implode(',', $unsequencedClasses)));
        } else {
            // We order the classes by sequence
            asort($sequenceForClasses);

            foreach ($sequenceForClasses as $class => $sequence) {
                // If installers were ordered
                $orderedInstallers[] = $this->installers[$class];
            }
        }

        $this->orderedInstallers = array_merge($this->orderedInstallers, $orderedInstallers);
    }
17339
public function getDependencyConfig(): array
    {
        return [
            'aliases' => [
                Storage::class => StorageInterface::class
            ],
            'factories' => [
                StorageInterface::class                 => Factory\ImageStorageFactory::class,
                Processor\ProcessorPluginManager::class => Processor\ProcessorPluginManagerFactory::class,
            ]
        ];
    }
348759
private function sort(array $stageSteps)
    {
        if (empty($stageSteps)) {
            return [];
        }

        $dependencyGraphBuilder = new StepDependencyGraphBuilder($stageSteps);
        return $dependencyGraphBuilder->build()->sort();
    }
618275
protected function sortResolvers()
    {
        $sortedResolvers = array();
        krsort($this->resolvers);

        foreach ($this->resolvers as $resolvers) {
            $sortedResolvers = array_merge($sortedResolvers, $resolvers);
        }

        return $sortedResolvers;
    }
210392
public function getHasChanged()
	{
		if($this->_dependencies!==null)
		{
			foreach($this->_dependencies as $dependency)
				if($dependency->getHasChanged())
					return true;
		}
		return false;
	}
692208
public function getLocaleDependencies($locale) {
		$dependencies = array();
		if (isset($this->localeDependencies[$locale])) {
			$dependencies = $this->localeDependencies[$locale];

				// Search for dependencies recursively
			$localeDependencies = $dependencies;
			foreach ($localeDependencies as $dependency) {
				if (isset($this->localeDependencies[$dependency])) {
					$dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency));
				}
			}
		}
		return $dependencies;
	}
600088
private function dependencyDefs()
    {
        return [
            Logger::class => function () {
                $level = $this->getCfgValue('deasilworks.log.level', 10);

                $gelfHandler = new GelfHandler(
                    new Publisher(
                        new UdpTransport(
                            $this->getCfgValue('deasilworks.log.host', '4klift-graylog'),
                            $this->getCfgValue('deasilworks.log.port', 12201)
                        )
                    ),
                    $level
                );

                $nullHandler = new NullHandler($level);

                $logger = new Logger($this->getCfgValue('deasilworks.log.name', '4klift'));

                $wfgh = new WhatFailureGroupHandler([
                    $gelfHandler,
                    $nullHandler,
                ]);

                $logger->pushHandler($wfgh);

                return $logger;
            },
            CFG::class => function () {
                return $this->config->getCfg();
            },
        ];
    }
382443
public function getActiveProcessList() {
		$em = $this->getEntityManager ();
		$params = array (
				'active' => true 
		);
		$processes = $em->getRepository ( 'Minibus\Model\Entity\Process' )->findBy ( $params );
		return $processes;
	}
1109301
public function getDependencies(): array
    {
        $dependencies = [];
        foreach ($this->config['dependencies'] as $dependency) {
            $dependencies[] = $this->wire($dependency);
        }

        return $dependencies;
    }
999057
public function sort()
    {
        $deps = $this->all();
        $sorted = $this->sortDeps($deps);

        return $this->dependency->getSorted($sorted);
    }
800966
public function formatDependencies()
    {
        $variablesVariable = $this->getOption('pug_variables_variable_name');

        $dependencies = $variablesVariable ? implode("\n", [
            '<?php',
            '$'.$variablesVariable.' = [];',
            'foreach (array_keys(get_defined_vars()) as $__pug_key) {',
            '    $'.$variablesVariable.'[$__pug_key] = &$$__pug_key;',
            '}',
            '?>',
        ]) : '';

        if ($this->dependencies->countRequiredDependencies() > 0) {
            $dependenciesExport = $this->dependencies->export(
                $this->getOption('dependencies_storage')
            );

            $dependencies .= $this->format(new CodeElement(trim($dependenciesExport)));
        }

        foreach ($this->mixins->getRequirementsStates() as $key => $value) {
            if ($value || $this->mixinsAllRequired || in_array($key, $this->mixinsPreCalled)) {
                $dependencies .= $this->mixins->get($key);
            }
        }

        return $dependencies;
    }
1059988
protected function getDependencies($parameters)
	{
		$dependencies = array();

		foreach ($parameters as $parameter)
		{
			$dependency = $parameter->getClass();

			// If the class is null, it means the dependency is a string or some other
			// primitive type which we can not resolve since it is not a class and
			// we'll just bomb out with an error since we have no-where to go.
			if (is_null($dependency))
			{
				$dependencies[] = $this->resolveNonClass($parameter);
			}
			else
			{
				$dependencies[] = $this->resolveClass($parameter);
			}
		}

		return (array) $dependencies;
	}