Finds a file using PSR0 while resetting composer PSR4 prefix this patch was loaded by.

@throws \LogicException
421875
public static function findClassFileUsingPsr(string $class): string
    {
        $classLoader = self::classLoader();
        $originalClassMap = $classLoader->getClassMap();
        $classMap = &Objects::getPropertyValue($classLoader, 'classMap', ClassLoader::class);
        $classMap = [];

        if (!$file = self::classLoader()->findFile($class)) {
            throw new \LogicException(sprintf('The class "%s" file was not found.', $class));
        }

        $classMap = $originalClassMap;

        return $file;
    }
894641
protected function getFileHandler()
    {
        if ($this->handle === null) {
            $isGzip = array_key_exists('gzip', $this->options);

            $filename = !$isGzip?
                $this->filename:
                sprintf('compress.zlib://%s', $this->filename);
            $fileHandler = @fopen($filename, 'r');

            if ($fileHandler === false) {
                throw new \LogicException('Can not open file.');
            }

            $this->handle = $fileHandler;
        }

        return $this->handle;
    }
1277704
private function modifyComposerFile()
    {
        if (!is_writeable('composer.json')) {
            throw new Exception('Make sure a composer.json file exists and is writable');
        }

        $json = file_get_contents('composer.json');
        $composer = json_decode($json);

        if (!isset($composer->autoload) || !isset($composer->autoload->{'psr-4'})) {
            $composer->autoload = new stdClass();
            $composer->autoload->{'psr-4'} = new stdClass();
        }

        // Composer namespaces requires an extra slash at the end
        $namespace = $this->namespace . '\\';
        $composer->autoload->{'psr-4'}->{$namespace} = 'src';

        file_put_contents('composer.json', json_encode($composer, JSON_PRETTY_PRINT));
    }
785574
public function findFile($strClass)
    {
        if (isset($this->classmap[$strClass])) {
            $strFile = $this->classmap[$strClass];
        }
        else {
            $strFile = $this->composerAutoloader->findFile($strClass);
        }

        if ($strFile && file_exists($strFile)) {
            return $strFile;
        }
        else {
            return null;
        }
    }
556826
public function getContent($asResource = FALSE) {

		$currentContentIsResource = is_resource($this->content);

		if (PHP_VERSION_ID < 50600 && FALSE === $this->content) {
			throw new \LogicException('getContent() can only be called once when using the resource return type and PHP below 5.6.');
		}

		if ($asResource) {

			if ($currentContentIsResource) {
				rewind($this->content);
				return $this->content;
			}

			// Content passed in parameter (test)

			if (is_string($this->content)) {
				$resource = fopen('php://temp', 'r+');
				fwrite($resource, $this->content);
				rewind($resource);
				return $resource;
			}

			$this->content = FALSE;
			return fopen('php://input', 'rb');

		}

		if ($currentContentIsResource) {
			rewind($this->content);
			return stream_get_contents($this->content);
		}

		if (NULL === $this->content) {
			$this->content = file_get_contents('php://input');
		}

		return $this->content;

	}
1032786
protected function updateIndex()
    {
        $configurator = $this->getIndexConfigurator();

        $indexPayload = (new IndexPayload($configurator))->get();

        $indices = ElasticClient::indices();

        if (! $indices->exists($indexPayload)) {
            throw new LogicException(sprintf(
                'Index %s doesn\'t exist',
                $configurator->getName()
            ));
        }

        try {
            $indices->close($indexPayload);

            if ($settings = $configurator->getSettings()) {
                $indexSettingsPayload = (new IndexPayload($configurator))
                    ->set('body.settings', $settings)
                    ->get();

                $indices->putSettings($indexSettingsPayload);
            }

            if ($defaultMapping = $configurator->getDefaultMapping()) {
                $indexMappingPayload = (new IndexPayload($configurator))
                    ->set('type', '_default_')
                    ->set('body._default_', $defaultMapping)
                    ->get();

                $indices->putMapping($indexMappingPayload);
            }

            $indices->open($indexPayload);
        } catch (Exception $exception) {
            $indices->open($indexPayload);

            throw $exception;
        }

        $this->info(sprintf(
            'The index %s was updated!',
            $configurator->getName()
        ));
    }
217723
public function getInstalledPackages()
    {
        $packages = [];

        $content = $this->getFileContents('composer.lock');

        foreach (['packages', 'packages-dev'] as $key) {
            if (!isset($content[$key])) {
                continue;
            }

            foreach ($content[$key] as $package) {
                $name = $package['name'];

                $packages[$name] = [
                    'name' => $name,
                    'version' => $package['version'],
                    'devDependency' => $key === 'packages-dev',
                ];
            }
        }

        if (empty($packages)) {
            throw new LogicException('We couldn\'t find any installed packages.');
        }

        return $packages;
    }
741869
public function getConfigFileManager()
    {
        if (!$this->started) {
            throw new LogicException('Puli was not started');
        }

        if (!$this->configFileManager && $this->context->getHomeDirectory()) {
            $this->configFileManager = new ConfigFileManagerImpl(
                $this->context,
                $this->getJsonStorage()
            );
        }

        return $this->configFileManager;
    }
1360335
public function beforeCompile(): void
	{
		$builder = $this->getContainerBuilder();

		if ($builder->getByType(User::class) === null) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', User::class));
		}

		if ($builder->getByType(EventDispatcherInterface::class) === null) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', EventDispatcherInterface::class));
		}

		$user = $builder->getDefinition($builder->getByType(User::class));
		$dispatcher = $builder->getDefinition($builder->getByType(EventDispatcherInterface::class));

		$user->addSetup('?->onLoggedIn[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			SecurityEvents::ON_LOGGED_IN,
			new PhpLiteral(LoggedInEvent::class),
		]);
		$user->addSetup('?->onLoggedOut[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			SecurityEvents::ON_LOGGED_OUT,
			new PhpLiteral(LoggedOutEvent::class),
		]);
	}
1319035
public function data()
    {

        if( isset( $this->filePath ) ) {

            return file_get_contents( $this->filePath );

        } elseif( $this->oid ) {

            $pg = $this->oid->pg;
            $pg->query( new Query( 'BEGIN' ) );

            $handle = pg_lo_open( $pg->resource->get(), $this->oid->oid, 'r' );

            $result = '';
            while( ( $data = pg_lo_read( $handle ) ) ){
                $result .= $data;
            }

            pg_lo_close( $handle );

            $pg->query( new Query( 'COMMIT' ) );

            return $result;

        }

        throw \LogicException("Shouldn't ever get tripped");

    }
124476
public function findFile($class)
    {
        // Remove first backslash
        if ('\\' == $class[0]) {
            $class = substr($class, 1);
        }

        if (false !== $pos = strrpos($class, '\\')) {
            // Namespaced class name
            $namespace = substr($class, 0, $pos);

            // Iterate in normal namespaces
            foreach ($this->namespaces as $ns => $dirs) {
                //Don't interfere with other autoloaders
                if (0 !== strpos($namespace, $ns)) {
                    continue;
                }

                foreach ($dirs as $dir) {
                    $className = substr($class, $pos + 1);

                    $file = $dir . DIRECTORY_SEPARATOR .
                        str_replace('\\', DIRECTORY_SEPARATOR, $namespace) .
                        DIRECTORY_SEPARATOR .
                        $className . '.php';

                    if (file_exists($file)) {
                        return $file;
                    }
                }
            }

            // Iterate in Thrift namespaces

            // Remove first part of namespace
            $m = explode('\\', $class);

            // Ignore wrong call
            if (count($m) <= 1) {
                return;
            }

            $class = array_pop($m);
            $namespace = implode('\\', $m);

            foreach ($this->definitions as $ns => $dirs) {
                //Don't interfere with other autoloaders
                if (0 !== strpos($namespace, $ns)) {
                    continue;
                }

                foreach ($dirs as $dir) {
                    /**
                     * Available in service: Interface, Client, Processor, Rest
                     * And every service methods (_.+)
                     */
                    if (0 === preg_match('#(.+)(if|client|processor|rest)$#i', $class, $n) and
                        0 === preg_match('#(.+)_[a-z0-9]+_(args|result)$#i', $class, $n)
                    ) {
                        $className = 'Types';
                    } else {
                        $className = $n[1];
                    }

                    $file = $dir . DIRECTORY_SEPARATOR .
                        str_replace('\\', DIRECTORY_SEPARATOR, $namespace) .
                        DIRECTORY_SEPARATOR .
                        $className . '.php';

                    if (file_exists($file)) {
                        return $file;
                    }
                }
            }
        }
    }
109820
protected function initialize()
    {
        if ('input' !== $this->node->nodeName) {
            throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
        }

        if ('file' !== strtolower($this->node->getAttribute('type'))) {
            throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type')));
        }

        $this->setValue(null);
    }
645598
private function getTemplatePath($name)
    {
        if (strpos($name, '::') !== false) {
            $parts = explode('::', $name);
            $ns = array_shift($parts);

            if (isset($this->manager->namespaces[$ns])) {
                $path = $this->manager->namespaces[$ns] . '/' . join('/', $parts) . $this->manager->filesExtension;
            } else {
                throw new LogicException(sprintf("Template namespace '%s::' not defined", $ns));
            }
        } else {
            $path = $this->manager->defaultDirectory . '/' . $name . $this->manager->filesExtension;
        }

        if (file_exists($path)) {
            return $path;
        }

        throw new LogicException(sprintf("Template file '%s' not found", $path));
    }
168501
public function boot()
    {
        if ($this->booted) {
            return;
        }

        if (!$this->name) {
            throw new \LogicException('Package: ' . get_class($this) . ' name property should not be empty.');
        }

        $this->getConfig();

        $this->registerProviders($this->getContainer());

        $this->registerListeners($this->getDispatcher());

        $this->registerMiddlewares();

        $this->booted = true;
    }
1048337
protected function findPackage()
    {
        if ($this->package !== null) {
            return;
        }

        $file = $this->getFile();

        $parts = explode(DIRECTORY_SEPARATOR, $file);

        $key = array_search('src', array_reverse($parts, true), true);
        if ($key === false) {
            $this->package = new \stdClass();
            return;
        }

        $composerFile = implode(DIRECTORY_SEPARATOR, array_slice($parts, 0, $key)).DIRECTORY_SEPARATOR.'composer.json';
        if (!file_exists($composerFile)) {
            $this->package = new \stdClass();
            return;
        }

        $composerContent = file_get_contents($composerFile);
        if ($composerContent === false) {
            $this->package = new \stdClass();
            return;
        }

        $this->package = json_decode($composerContent);
        if ($this->package === null) {
            $this->package = new \stdClass();
        }
    }
765544
private function map(): \Generator
    {
        $path = realpath($this->path) . '/composer/autoload_psr4.php';

        if (file_exists($path) && is_array($map = require $path)) {
            yield from $map;
        }
    }
451855
public function resolve()
    {
        if (!($prev = $this->handler)) {
            throw new \LogicException('No handler has been specified');
        }

        if ($this->sorted === null) {
            $this->sortMiddleware();
        }

        foreach ($this->sorted as $fn) {
            $prev = $fn($prev);
        }

        return $prev;
    }