Processes a single file

@param SplFileInfo $file            The path to the file
@param bool        $replaceExisting True to replace existing license header
@param bool        $dryRun          True to report a modified file and to not make modifications
763400
private function processFile(SplFileInfo $file, $replaceExisting, $dryRun)
    {
        if ($file->isDir()) {
            return;
        }

        $tokens = token_get_all($file->getContents());

        $licenseTokenIndex = $this->getLicenseTokenIndex($tokens);

        if (null !== $licenseTokenIndex && true === $replaceExisting) {
            $this->removeExistingLicense($file, $tokens, $licenseTokenIndex, $dryRun);
        }

        if (null === $licenseTokenIndex || true === $replaceExisting) {
            $this->log(sprintf('<fg=green>[+]</> Adding license header for <options=bold>%s</>', $file->getRealPath()));

            if (true === $dryRun) {
                return;
            }

            $license = $this->getLicenseAsComment();
            $content = preg_replace('/<\?php/', '<?php' . PHP_EOL . PHP_EOL . $license, $file->getContents(), 1);
            file_put_contents($file->getRealPath(), $content);
        } else {
            $this->log(sprintf('<fg=cyan>[S]</> Skipping <options=bold>%s</>', $file->getRealPath()));
        }
    }
985595
public function fileDelete($file)
    {
        foreach ($this->files($file) as $f) {
            if (!unlink($f) && $this->fileExists($f)) {
                throw new RuntimeException(['delete `:file` failed: :last_error_message', 'file' => $f]);
            }
        }
    }
126702
private function lintFile(\SplFileInfo $file)
    {
        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $this->output->write('lint file ' . $file . ' ... ');
        }

        $report = FileReport::create($file);
        $this->reports[] = $report;
        $status = $this->validator->validateFile($report);

        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            if (false === $status) {
                $this->output->writeln('<error>errors</error>');
            } else {
                $this->output->writeln('<info>passed.</info>');
            }
        } else {
            if (false === $status) {
                $this->output->write('<error>F</error>');
            } else {
                $this->output->write('.');
            }
        }

        return $status;
    }
1099187
protected function isExcluded(SplFileInfo $file, Collection $excludes)
    {
        return $excludes->contains(function ($exclude) use ($file) {
            return Str::startsWith($file->getPathname(), $exclude);
        });
    }
581053
public function clean(SplFileInfo $file)
    {
        $name = $file->getFilename();
        if ($file->isFile()) {
            $name = pathinfo($name, PATHINFO_FILENAME);
        }

        $name = str_replace("\t\n\r\0\x0B", ' ', $name); // remove control characters
        $name = str_replace('_', ' ', $name);

        $name = preg_replace('/\[[^\[\]]*\]/', ' ', $name); // remove [...]
        $name = preg_replace('/\([^\(\)]*\)/', ' ', $name); // remove (...)

        // remove all file meta data
        $reg = sprintf('/[ .,](?:%s)[ .,]/i', implode('|', $this->meta));
        while (preg_match($reg, $name.' ')) {
            $name = preg_replace($reg, ' ', $name.' ');
        }

        $name = str_replace('  ', ' ', $name); // remove double spaces
        $name = trim($name, ' .,-');

        return $name;
    }
991334
public static function proccessFile(\SplFileInfo $file, ContainerBuilder $container, array $configs, bool $resolveClassMap = false): array
    {
        self::$doctrineMapping = $configs['doctrine']['types_mapping'];

        $rootQueryType = $configs['definitions']['schema']['default']['query'] ?? false;
        $rootMutationType = $configs['definitions']['schema']['default']['mutation'] ?? false;

        $container->addResource(new FileResource($file->getRealPath()));

        if (!$resolveClassMap) {
            $container->setParameter(self::CLASSESMAP_CONTAINER_PARAMETER, self::$classesMap);
        }

        try {
            $fileContent = \file_get_contents($file->getRealPath());

            $shortClassName = \substr($file->getFilename(), 0, -4);
            if (\preg_match('#namespace (.+);#', $fileContent, $namespace)) {
                $className = $namespace[1].'\\'.$shortClassName;
                $namespace = $namespace[1];
            } else {
                $className = $shortClassName;
            }

            $reflexionEntity = new \ReflectionClass($className);

            $classAnnotations = self::getAnnotationReader()->getClassAnnotations($reflexionEntity);

            $properties = [];
            foreach ($reflexionEntity->getProperties() as $property) {
                $properties[$property->getName()] = ['property' => $property, 'annotations' => self::getAnnotationReader()->getPropertyAnnotations($property)];
            }

            $methods = [];
            foreach ($reflexionEntity->getMethods() as $method) {
                $methods[$method->getName()] = ['method' => $method, 'annotations' => self::getAnnotationReader()->getMethodAnnotations($method)];
            }

            $gqlTypes = [];

            foreach ($classAnnotations as $classAnnotation) {
                $gqlConfiguration = $gqlType = $gqlName = false;

                switch (true) {
                    case $classAnnotation instanceof GQL\Type:
                        $gqlType = self::GQL_TYPE;
                        $gqlName = $classAnnotation->name ?: $shortClassName;

                        if (!$resolveClassMap) {
                            $isRootQuery = ($rootQueryType && $gqlName === $rootQueryType);
                            $isRootMutation = ($rootMutationType && $gqlName === $rootMutationType);
                            $currentValue = ($isRootQuery || $isRootMutation) ? \sprintf("service('%s')", self::formatNamespaceForExpression($className)) : 'value';

                            $gqlConfiguration = self::getGraphqlType($classAnnotation, $classAnnotations, $properties, $methods, $namespace, $currentValue);
                            $providerFields = self::getGraphqlFieldsFromProviders($namespace, $className, $isRootMutation ? 'Mutation' : 'Query', $gqlName, ($isRootQuery || $isRootMutation));
                            $gqlConfiguration['config']['fields'] = $providerFields + $gqlConfiguration['config']['fields'];

                            if ($classAnnotation instanceof GQL\Relay\Edge) {
                                if (!$reflexionEntity->implementsInterface(EdgeInterface::class)) {
                                    throw new InvalidArgumentException(\sprintf('The annotation @Edge on class "%s" can only be used on class implementing the EdgeInterface.', $className));
                                }
                                if (!isset($gqlConfiguration['config']['builders'])) {
                                    $gqlConfiguration['config']['builders'] = [];
                                }
                                \array_unshift($gqlConfiguration['config']['builders'], ['builder' => 'relay-edge', 'builderConfig' => ['nodeType' => $classAnnotation->node]]);
                            }

                            if ($classAnnotation instanceof GQL\Relay\Connection) {
                                if (!$reflexionEntity->implementsInterface(ConnectionInterface::class)) {
                                    throw new InvalidArgumentException(\sprintf('The annotation @Connection on class "%s" can only be used on class implementing the ConnectionInterface.', $className));
                                }

                                if (!($classAnnotation->edge xor $classAnnotation->node)) {
                                    throw new InvalidArgumentException(\sprintf('The annotation @Connection on class "%s" is invalid. You must define the "edge" OR the "node" attribute.', $className));
                                }

                                $edgeType = $classAnnotation->edge;
                                if (!$edgeType) {
                                    $edgeType = \sprintf('%sEdge', $gqlName);
                                    $gqlTypes[$edgeType] = [
                                        'type' => 'object',
                                        'config' => [
                                            'builders' => [
                                                ['builder' => 'relay-edge', 'builderConfig' => ['nodeType' => $classAnnotation->node]],
                                            ],
                                        ],
                                    ];
                                }
                                if (!isset($gqlConfiguration['config']['builders'])) {
                                    $gqlConfiguration['config']['builders'] = [];
                                }
                                \array_unshift($gqlConfiguration['config']['builders'], ['builder' => 'relay-connection', 'builderConfig' => ['edgeType' => $edgeType]]);
                            }
                        }
                        break;
                    case $classAnnotation instanceof GQL\Input:
                        $gqlType = self::GQL_INPUT;
                        $gqlName = $classAnnotation->name ?: self::suffixName($shortClassName, 'Input');
                        if (!$resolveClassMap) {
                            $gqlConfiguration = self::getGraphqlInput($classAnnotation, $classAnnotations, $properties, $namespace);
                        }
                        break;
                    case $classAnnotation instanceof GQL\Scalar:
                        $gqlType = self::GQL_SCALAR;
                        if (!$resolveClassMap) {
                            $gqlConfiguration = self::getGraphqlScalar($className, $classAnnotation, $classAnnotations);
                        }
                        break;
                    case $classAnnotation instanceof GQL\Enum:
                        $gqlType = self::GQL_ENUM;
                        if (!$resolveClassMap) {
                            $gqlConfiguration = self::getGraphqlEnum($classAnnotation, $classAnnotations, $reflexionEntity->getConstants());
                        }
                        break;
                    case $classAnnotation instanceof GQL\Union:
                        $gqlType = self::GQL_UNION;
                        if (!$resolveClassMap) {
                            $gqlConfiguration = self::getGraphqlUnion($className, $classAnnotation, $classAnnotations, $methods);
                        }
                        break;
                    case $classAnnotation instanceof GQL\TypeInterface:
                        $gqlType = self::GQL_INTERFACE;
                        if (!$resolveClassMap) {
                            $gqlConfiguration = self::getGraphqlInterface($classAnnotation, $classAnnotations, $properties, $methods, $namespace);
                        }
                        break;
                    case $classAnnotation instanceof GQL\Provider:
                        if ($resolveClassMap) {
                            self::$providers[$className] = ['annotation' => $classAnnotation, 'methods' => $methods];
                        }
                        break;
                    default:
                        continue 2;
                }

                if ($gqlType) {
                    if (!$gqlName) {
                        $gqlName = $classAnnotation->name ?: $shortClassName;
                    }

                    if ($resolveClassMap) {
                        if (isset(self::$classesMap[$gqlName])) {
                            throw new InvalidArgumentException(\sprintf('The GraphQL type "%s" has already been registered in class "%s"', $gqlName, self::$classesMap[$gqlName]['class']));
                        }
                        self::$classesMap[$gqlName] = ['type' => $gqlType, 'class' => $className];
                    } else {
                        $gqlTypes = [$gqlName => $gqlConfiguration] + $gqlTypes;
                    }
                }
            }

            return $resolveClassMap ? self::$classesMap : $gqlTypes;
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(\sprintf('Failed to parse GraphQL annotations from file "%s".', $file), $e->getCode(), $e);
        }
    }
441852
protected function runUp($path, $file, Extension $extension = null)
    {
        $migration = $this->resolve($path, $file);

        $this->runClosureMigration($migration);

        // Once we have run a migrations class, we will log that it was run in this
        // repository so that we don't try to run it next time we do a migration
        // in the application. A migration repository keeps the migrate order.
        $this->repository->log($file, $extension ? $extension->getId() : null);

        $this->note("<info>Migrated:</info> $file");
    }
197779
public function filter(SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (Exception $e){
            return false;
        }

        $usedtraits = class_uses($class, $this->useautoload);

        foreach ($this->instances as $instance) {
            if (in_array($instance, $usedtraits)) {
                return true;
            }
        }

        return false;
    }
1055469
public static function removeFile(string $file): void
    {
        if (\is_file($file)) {
            if (!@\unlink($file)) {
                throw new \RuntimeException(\sprintf('Unable to delete file "%s"%s', $file, self::getErrorInfo()));
            }
        }
        
        \clearstatcache(true, $file);
    }
241010
private function validateExecutable($file)
    {
        if (!file_exists($file) || !is_executable($file)) {
            throw new InvalidExecutableException(sprintf('File does not exist or is not executable: %s', $file));
        }

        return true;
    }
874592
private function supports(SplFileInfo $file): bool
    {
        return '.js' === substr($file->getRealPath(), -3) && '.min.js' !== substr($file->getRealPath(), -7);
    }
1232242
private void addFileToList(final CmsFileInfo file, boolean invalid, boolean existingDeleted, boolean isTooLarge) {

        CmsListInfoBean infoBean = createInfoBean(file);
        CmsListItemWidget listItemWidget = new CmsListItemWidget(infoBean);
        listItemWidget.setIcon(CmsCoreProvider.get().getResourceTypeIcon(file));
        CmsCheckBox check = new CmsCheckBox();
        check.setChecked(false);
        if (!invalid && !isTooLarge && !existingDeleted) {
            if (file.getFileSize() == 0) {
                check.setChecked(false);
            }
            check.setChecked(m_filesToUpload.containsKey(file.getFileName()));
            check.setTitle(file.getFileName());
            if (!m_selectionDone && file.getFileName().toLowerCase().endsWith(".zip")) {
                final Widget unzip = createUnzipCheckBox(file);
                addClickHandlerToCheckBox(check, unzip, file);
                listItemWidget.addButton(unzip);
            } else {
                addClickHandlerToCheckBox(check, null, file);
            }
        } else if (existingDeleted) {
            // is invalid
            String message = Messages.get().key(Messages.GUI_UPLOAD_FILE_EXISTING_DELETED_1, file.getFileName());
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        } else if (isTooLarge) {
            String message = getFileSizeTooLargeMessage(file);
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        } else {
            // is invalid
            String message = Messages.get().key(
                Messages.GUI_UPLOAD_FILE_INVALID_NAME_2,
                file.getFileName(),
                CmsUploadButton.formatBytes(file.getFileSize()));
            check.disable(message);
            listItemWidget.setBackground(Background.RED);
            listItemWidget.setSubtitleLabel(message);
        }

        CmsListItem listItem = new CmsListItem(check, listItemWidget);
        m_fileList.addItem(listItem);
        m_listItems.put(file.getFileName(), listItem);
        doResize();
    }
957777
public static function process($file = NULL){

        $exists = isset( self::$data[ self::$level ] );

        if( $exists ){
            $variables = self::$data[ self::$level ];

            foreach( $variables as $key => $value ){
                global $$key;
                $$key = $value;
            }
        }

        if( $file ){
            require $file;
        }

    }
1076466
static function AddExtension($path, $extension, $replaceExisting = false)
    {
        $result = $path;
        if ($replaceExisting)
        {
            $result = self::RemoveExtension($path);
        }
        if (!$extension) {
            return $result;
        }
        return join('.', array($result, System\Str::TrimLeft($extension, '.')));
    }
824436
public function init(\SplFileInfo $file, $extension = null)
    {
        $config = Grav::instance()['config'];

        // some extension logic
        if (empty($extension)) {
            $this->extension('.' . $file->getExtension());
        } else {
            $this->extension($extension);
        }

        // extract page language from page extension
        $language = trim(basename($this->extension(), 'md'), '.') ?: null;
        $this->language($language);

        $this->hide_home_route = $config->get('system.home.hide_in_urls', false);
        $this->home_route = $this->adjustRouteCase($config->get('system.home.alias'));
        $this->filePath($file->getPathname());
        $this->modified($file->getMTime());
        $this->id($this->modified() . md5($this->filePath()));
        $this->routable(true);
        $this->header();
        $this->date();
        $this->metadata();
        $this->url();
        $this->visible();
        $this->modularTwig(strpos($this->slug(), '_') === 0);
        $this->setPublishState();
        $this->published();
        $this->urlExtension();


        return $this;
    }
429010
function replace(file, options) {
  var contents = file.contents;
  var copied = 0;

  var processed = translate(options, contents, copied, file.path);

  var files = [];
  for (var lang in processed) {
    var params = {};
    params.ext = path.extname(file.path).substr(1);
    params.name = path.basename(file.path, path.extname(file.path));
    params.path = file.path.substring(file.base.length, file.path.lastIndexOf(path.sep));
    params.lang = lang;

    var filePath = options.filename;
    for (var param in params) {
      filePath = filePath.replace('${' + param + '}', params[param]);
    }
    filePath = path.join(file.base,filePath);

    var newFile = new gutil.File({
      base: file.base,
      cwd: file.cwd,
      path: filePath,
      contents: new Buffer(processed[lang], 'utf8')
    });
    files.push(newFile);
  }

	return files;
}
406167
public function make($file, $content, $recursive = false)
    {
        if ($this->exists($this->getPath($file))) {
            throw new FileAlreadyExists;
        }
        $this->put($file, $content, 0, $recursive);
    }