Imports one or multiple sites from the XML file at $pathAndFilename

@param string $pathAndFilename
@return Site The imported site
@throws UnknownPackageException|InvalidPackageStateException|NeosException
771347
public function importFromFile($pathAndFilename)
    {
        if (!file_exists($pathAndFilename)) {
            throw new NeosException(sprintf('Error: File "%s" does not exist.', $pathAndFilename), 1540934412);
        }

        /** @var Site $importedSite */
        $site = null;
        $xmlReader = new \XMLReader();
        if ($xmlReader->open($pathAndFilename, null, LIBXML_PARSEHUGE) === false) {
            throw new NeosException(sprintf('Error: XMLReader could not open "%s".', $pathAndFilename), 1540934199);
        }

        if ($this->workspaceRepository->findOneByName('live') === null) {
            $this->workspaceRepository->add(new Workspace('live'));
            $this->persistenceManager->persistAll();
        }

        while ($xmlReader->read()) {
            if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') {
                continue;
            }

            $site = $this->getSiteByNodeName($xmlReader->getAttribute('siteNodeName'));
            $site->setName($xmlReader->getAttribute('name'));
            $site->setState((integer)$xmlReader->getAttribute('state'));

            $siteResourcesPackageKey = $xmlReader->getAttribute('siteResourcesPackageKey');
            if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) {
                throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443);
            }
            if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) {
                throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135);
            }
            $site->setSiteResourcesPackageKey($siteResourcesPackageKey);

            $rootNode = $this->contextFactory->create()->getRootNode();
            // We fetch the workspace to be sure it's known to the persistence manager and persist all
            // so the workspace and site node are persisted before we import any nodes to it.
            $rootNode->getContext()->getWorkspace();
            $this->persistenceManager->persistAll();

            $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH);
            if ($sitesNode === null) {
                $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH));
            }

            $this->nodeImportService->import($xmlReader, $sitesNode->getPath(), dirname($pathAndFilename) . '/Resources');
        }

        if ($site === null) {
            throw new NeosException(sprintf('The XML file did not contain a valid site node.'), 1418999522);
        }
        $this->emitSiteImported($site);
        return $site;
    }
348882
public function addLoadedFile(string $name, string $pathFile)
    {
        $properties                     = $this->getProperties();
        $loadedFiles                    = $properties['loadedFiles'];
        $names                          = array_column($loadedFiles, 'name');
        if (!in_array($name, $names)) {
            $key                        = '1ld';
            if (!empty($loadedFiles)) {
                $loadedFiles                = ksort($loadedFiles);
                /** @var array $loadedFiles */
                $key                        = ((int) array_key_last($loadedFiles) + 1).'ld';
            }
            $item                       = [];
            $item['name']               = $name;
            $item['pathFile']           = $pathFile;
            $item['mime']               = mime_content_type($pathFile);
//            $loadedFiles[$name]         = $pathFile;
            $loadedFiles[$key]          = $item;
            $properties['loadedFiles']  = $loadedFiles;
            $this->setProperties($properties);
            return $this;
        }
        return false;
    }
1135929
public static function writeComposerManifest(array $manifest, $pathAndFilename)
    {
        file_put_contents($pathAndFilename, json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
    }
126452
public function copyTemplateAndGetPath(
        string $pathToProjectRoot,
        string $templatePath,
        string $destinationFileName,
        array $subDirectories
    ): string {
        try {
            $path = $this->createSubDirectoriesAndGetPath($pathToProjectRoot, $subDirectories);
            if (false === \ts\stringContains($destinationFileName, '.php')) {
                $destinationFileName = "$destinationFileName.php";
            }
            $filePath = "$path/$destinationFileName";
            $this->filesystem->copy($templatePath, $filePath, true);
            $this->fileCreationTransaction::setPathCreated($filePath);

            return $filePath;
        } catch (\Exception $e) {
            throw new DoctrineStaticMetaException(
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
                $e->getCode(),
                $e
            );
        }
    }
1204870
public function listWorksheetNames($pFilename)
	{
		// Check if file exists
		if (!file_exists($pFilename)) {
			throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
		}

        $zipClass = PHPExcel_Settings::getZipClass();

		$zip = new $zipClass;
		if (!$zip->open($pFilename)) {
			throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
		}

		$worksheetNames = array();

		$xml = new XMLReader();
		$res = $xml->open('zip://'.realpath($pFilename).'#content.xml', null, PHPExcel_Settings::getLibXmlLoaderOptions());
		$xml->setParserProperty(2,true);

		//	Step into the first level of content of the XML
		$xml->read();
		while ($xml->read()) {
			//	Quickly jump through to the office:body node
			while ($xml->name !== 'office:body') {
				if ($xml->isEmptyElement)
					$xml->read();
				else
					$xml->next();
			}
			//	Now read each node until we find our first table:table node
			while ($xml->read()) {
				if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
					//	Loop through each table:table node reading the table:name attribute for each worksheet name
					do {
						$worksheetNames[] = $xml->getAttribute('table:name');
						$xml->next();
					} while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT);
				}
			}
		}

		return $worksheetNames;
	}
687951
private File getFile(String xmlFilename) {

        File file = new File(m_basePath + xmlFilename);
        if (!file.exists() || !file.canRead()) {
            file = new File(xmlFilename);
        }
        return file;
    }
341237
public function nodeAt($path)
    {
        $pathParts = array_filter(explode('/', str_replace('\\', '/', $path)), 'strlen');

        $node = $this->root();

        foreach ($pathParts as $level) {
            if ($node instanceof File) {
                throw new NotFoundException();
            }
            $node = $node->childAt($level);
        }

        return $node;
    }
1146980
public function addDir($pathname, $localname = null)
    {
        return $this->pclZip->add(
            $pathname,
            PCLZIP_OPT_REMOVE_PATH,
            $pathname,
            PCLZIP_OPT_ADD_PATH,
            $localname
        );
    }
101434
public function unify($name, $paths, $recursively = false)
    {
        $content = $this->unifySingle($paths['corePath'], $name, $recursively);

        if (!empty($paths['modulePath'])) {
            $customDir = strstr($paths['modulePath'], '{*}', true);

            $moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($customDir, false, '', false);

            foreach ($moduleList as $moduleName) {
                $curPath = str_replace('{*}', $moduleName, $paths['modulePath']);

                if ($this->useObjects) {
                    $content = Utils\DataUtil::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
                } else {
                    $content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $moduleName));
                }
            }
        }

        if (!empty($paths['customPath'])) {
            if ($this->useObjects) {
                $content = Utils\DataUtil::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
            } else {
                $content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
            }
        }

        return $content;
    }
539411
public final function compose(string $fileName): LoaderInterface
    {
       if (is_file($fileName)){
           $config = json_decode(file_get_contents($fileName));
           if (is_object($config)
            && isset($config->{"autoload"})
            && isset($config->{"autoload"}->{"psr-4"})) {
               $includePath = dirname($fileName) . DIRECTORY_SEPARATOR;
               foreach ($config->{"autoload"}->{"psr-4"} as $key => $value) {
                   $this->addPrefix($key, $includePath . $value);
               }
           }
       }
       return $this;
    }
686231
public function copy($pathFrom, $pathTo)
    {
        $pathFrom = $this->getRealPath($pathFrom);
        $pathTo = $this->getRealPath($pathTo);
        
        if (!is_dir(dirname($pathTo))) {
            @mkdir(dirname($pathTo), 0755, true);
        }
    
        return copy($pathFrom, $pathTo);
    }
672484
public function getFileStatus($pathAndFilename)
    {
        $actualModificationTime = @filemtime($pathAndFilename);
        if (isset($this->filesAndModificationTimes[$pathAndFilename])) {
            if ($actualModificationTime !== false) {
                if ($this->filesAndModificationTimes[$pathAndFilename] === $actualModificationTime) {
                    return self::STATUS_UNCHANGED;
                } else {
                    $this->filesAndModificationTimes[$pathAndFilename] = $actualModificationTime;
                    $this->modificationTimesChanged = true;
                    return self::STATUS_CHANGED;
                }
            } else {
                unset($this->filesAndModificationTimes[$pathAndFilename]);
                $this->modificationTimesChanged = true;
                return self::STATUS_DELETED;
            }
        } else {
            if ($actualModificationTime !== false) {
                $this->filesAndModificationTimes[$pathAndFilename] = $actualModificationTime;
                $this->modificationTimesChanged = true;
                return self::STATUS_CREATED;
            } else {
                return self::STATUS_UNCHANGED;
            }
        }
    }
172068
@FFDCIgnore(IllegalStateException.class)
    public URL getBundleEntry(Bundle bundleToTest, String pathAndName) {
        try {
            URL bundleEntry = bundleToTest.getEntry(pathAndName);

            /*
             * Defect 54588 discovered that if a directory does not have a zip entry then calling getEntry will return null unless the path has a "/" on the end so if we have null
             * still then add a "/" on the end of the path and retest
             */
            if (bundleEntry == null) {
                bundleEntry = bundleToTest.getEntry(pathAndName + "/");
            }
            return bundleEntry;
        } catch (IllegalStateException ise) {
            //bundle context was no longer valid, so we cannot use getEntry any more.
            return null;
        }
    }
121823
public function getChild($name)
    {
        $path = $this->path.'/'.$name;

        if (!file_exists($path)) {
            throw new NotFound('File could not be located');
        }
        if ('.' == $name || '..' == $name) {
            throw new Forbidden('Permission denied to . and ..');
        }
        if (is_dir($path)) {
            return new self($path, $this->acl, $this->owner);
        } else {
            return new File($path, $this->acl, $this->owner);
        }
    }
755583
public static function realpath($pFilename) {
		// Returnvalue
		$returnValue = '';

		// Try using realpath()
		if (file_exists($pFilename)) {
			$returnValue = realpath($pFilename);
		}

		// Found something?
		if ($returnValue == '' || ($returnValue === NULL)) {
			$pathArray = explode('/' , $pFilename);
			while(in_array('..', $pathArray) && $pathArray[0] != '..') {
				for ($i = 0; $i < count($pathArray); ++$i) {
					if ($pathArray[$i] == '..' && $i > 0) {
						unset($pathArray[$i]);
						unset($pathArray[$i - 1]);
						break;
					}
				}
			}
			$returnValue = implode('/', $pathArray);
		}

		// Return
		return $returnValue;
	}
409079
protected function _constructPathname($pathname)
    {
        // obtain ref to the filesystem layer
        $fs = FileSystem::getFileSystem();

        if ($pathname === null) {
            throw new NullPointerException("Argument to function must not be null");
        }

        $this->path = (string) $fs->normalize($pathname);
        $this->prefixLength = (int) $fs->prefixLength($this->path);
    }
704981
protected function importFile($filePath, $fileName = null)
    {
        // Filename parsing
        if ($fileName == null) {
            $fileName = basename($filePath);
        }
        if (!preg_match('/\w+\.\w+\.\w+/', $fileName)) {
            throw new ImportException("Invalid filename [$fileName], all translation files must be named: domain.locale.format (ex: messages.en.yml)");
        }
        list($domain, $locale, $format) = explode('.', $fileName, 3);
        $catalogue = $this->translator->loadResource(array(
            'format' => $format,
            'locale' => $locale,
            'domain' => $domain,
            'path' => $filePath,
        ));

        // Merge with existing entries
        $translations = $this->getTranslationsFromSession();
        $counters = array('new' => 0, 'updated' => 0);
        if (!array_key_exists($locale, $translations)) {
            $translations[$locale] = array('new' => array(), 'updated' => array());
        }
        foreach ($catalogue->all() as $domain => $messages) {
            foreach ($messages as $key => $value) {
                if ($trans = $this->repository->findTranslation($domain, $key, $locale, true)) {
                    if ($trans->getValue() !== $value) {
                        $translations[$locale]['updated'][$domain][$key] = array('old' => $trans->getValue(), 'new' => $value);
                        $counters['updated'] += 1;
                    }
                } else {
                    $translations[$locale]['new'][$domain][$key] = $value;
                    $counters['new'] += 1;
                }
            }
        }

        $this->updateSession($translations);

        return $counters;
    }