一つのお題を表す配列をクイズ形式で直列化します。
@param (string|string[]|float)[][] $word
@param string $directoryName
@param string[] $filenames
@return string 末尾に改行 (CRLF) を含みます。直列化できないお題だった場合は空文字列を返します。
324258
protected function serializeWordAsQuiz(array $word, string $directoryName, array $filenames): string
    {
        if (isset($word['question'][0])
            || isset($word['image'][0]) || isset($word['audio'][0]) || isset($word['option'][0])) {
            $answerLine = $this->serializeAnswerLine($word);
            if ($answerLine !== '') {
                $output = $this->serializeQuestionLine($word, $directoryName, $filenames) . $answerLine;
            }
        }
        return $output ?? '';
    }
1327583
public function directories($directoryName)
    {
        if (!$this->isDir($directoryName)) {
            throw new FileNotFoundException('Directory not found in the path [ ' . $directoryName . ' ].');
        }

        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($directoryName,
                RecursiveDirectoryIterator::CURRENT_AS_FILEINFO)
        );

        $directories = [];

        foreach($iterator as $file) {
            if($file->isDir()) {
                if( !(substr($file,-2) === '..')) {
                    $directories[] = trim($file,'.');
                }
            }
        }

        array_shift($directories);

        return $directories;
    }
453569
public function setFilename($filename , $directory = null)
    {
        $this->filename  = $filename;
        $this->directory = $directory;
    }
1062148
protected function loadWddxFile( $fileName )
	{
		$array	= XML_WDDX_FileReader::load( $fileName );
		foreach( $array as $sectionName => $sectionData )
			foreach( $sectionData as $key => $value )
				$this->pairs[$sectionName.".".$key]	= $value;
	}
906102
protected function _loadTemplate($directory, $filename)
	{
		$contents = '';

		// Check to see if we have a valid template file
		if (file_exists($directory . DS . $filename))
		{
			// Store the file path
			$this->_file = $directory . DS . $filename;

			// Get the file content
			ob_start();
			require $directory . DS . $filename;
			$contents = ob_get_contents();
			ob_end_clean();
		}

		return $contents;
	}
201162
private function buildFilePath (array $directories, string $fileName) : string
    {
        $dir = !empty($directories)
            ? "/" . implode("/", $directories)
            : "";

        $file = "" !== $fileName
            ? "/{$fileName}"
            : "";

        return $dir . $file;
    }
602139
public static function load($directoryName = 'filters'): array
    {
        $files = static::getFilePattern($directoryName);

        return collect(glob($files))
            ->map(function ($filename) {
                return include $filename;
            })
            ->flatten(1)
            ->toArray();
    }
1144455
protected function parseFiles(array $dirs, $fileMatch, $cacheDir = null)
    {
        $files   = $this->filesystem->getFilesOfDirs($dirs, $fileMatch);
        $results = [];

        $tmpFile  = $cacheDir !== null ? $cacheDir . '/' . $this->getCacheFile() : null;
        $oldCache = [];

        if ($tmpFile !== null && file_exists($tmpFile)) {
            $oldCache = unserialize(file_get_contents($tmpFile));
        }

        foreach ($files as $file) {
            $realPath = $file->getRealPath();
            if (!$realPath) {
                return [];
            }

            $hash = $this->filesystem->getFileHash($realPath);

            if (isset($oldCache[$hash])) {
                $fileResult = $this->fromCache($oldCache[$hash], $file);
                unset($oldCache[$hash]);
            } else {
                $fileResult = $this->parseFile($realPath);
            }

            $results[$hash] = $fileResult;
        }

        if ($tmpFile !== null) {
            $this->filesystem->writeFile(
                $tmpFile,
                serialize($results)
            );
        }

        return $results;
    }
277814
public function getMailMergeFieldNames($fileName)
    {
        //check whether file is set or not
        if ($fileName == '')
            throw new Exception('No file name specified');

        $strURI = Product::$baseProductUri . '/words/' . $fileName . '/mailMergeFieldNames';

        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');

        $json = json_decode($responseStream);

        return $json->FieldNames->Names;
    }
1102483
public function zip($directory, $fileName)
    {
        $path = sprintf('%s/%s/%s.zip', $this->localDirectory, $this->name, $fileName);
        $this->filesystem->mkdir(dirname($path));

        // FIXME find better place for this message
        $this->output->writeln(PHP_EOL . 'Creating zip file (it may take a few minutes) ...');

        $zip = $this->openZip($path);

        $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
        foreach ($files as $filePath => $file) {
            $relative = Path::makeRelative($filePath, $directory);
            if (is_dir($filePath)) {
                $zip->addEmptyDir($relative);

                continue;
            }

            $zip->addFile($filePath, $relative);
        }

        $zip->close();

        return $path;
    }
616258
public static function rotateLogs( $dir, $filename, $maxSize=0, $maxFiles=0 )
    {
        $filepath = "$dir/$filename";
        if ( is_file( $filepath ) && filesize( $filepath ) > $maxSize )
        {
            if ( !rename( $filepath, $filepath . "." . strftime( '%Y%m%d_%H%M%S' ) ) )
            {
                eZPerfLoggerDebug::writeWarning( "Could not rotate log file $filepath", __METHOD__ );
            }
        }
        if ( $maxFiles )
        {
            $files = array();
            foreach( scandir( $dir ) as $afile )
            {
                if ( is_file( "$dir/$afile" ) && strpos( $afile, $filename ) === 0 )
                {
                    $ext = substr( strrchr( $afile, "." ), 1 );
                    $files[$ext] = $afile;
                }
            }
            if ( count( $files ) > $maxFiles )
            {
                ksort( $files );
                $oldest = "$dir/" . reset( $files );
                if ( !unlink( $oldest ) )
                {
                    eZPerfLoggerDebug::writeWarning( "Could not remove log file $oldest", __METHOD__ );
                }
            }
        }
    }
983716
public static function find($filename, $dirs = array())
    {
        if (empty($dirs)) {
            if ($filename = realpath($filename)) {
                return $filename;
            }
        } else {
            foreach ((array) $dirs as $dir) {
                $pathname = self::join($dir, $filename);
                if ($pathname = realpath($pathname)) {
                    return $pathname;
                }
            }
        }
        return false;
    }
1092847
static function recursiveList( $dir, $path, &$fileList )
    {
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $file = readdir( $handle ) ) !== false )
            {
                if ( ( $file == "." ) || ( $file == ".." ) )
                {
                    continue;
                }
                if ( is_dir( $dir . '/' . $file ) )
                {
                    $fileList[] = array( 'path' => $path, 'name' => $file, 'type' => 'dir' );
                    eZDir::recursiveList( $dir . '/' . $file, $path . '/' . $file, $fileList );
                }
                else
                {
                    $fileList[] = array( 'path' => $path, 'name' => $file, 'type' => 'file'  );
                }
            }
            @closedir( $handle );
        }
    }
863709
protected function convertWordToRecord(array $word, array $fieldNames, array $metadata, array $filenames): array
    {
        $numberValidator = new NumberValidator();
        $output = [];
        foreach ($fieldNames as $fieldName) {
            $field = isset($word[$fieldName][0])
                ? array_shift($word[$fieldName])
                : (isset($metadata[$fieldName]) ? $metadata[$fieldName] : '');
            if (is_array($field)) {
                $includedFilename = false;
                if (is_string($this->csvOnly)) {
                    $html = (new \esperecyan\html_filter\Filter(
                        null,
                        ['before' => function (\DOMElement $body) use ($filenames, &$includedFilename) {
                            foreach (['img', 'audio', 'video'] as $elementName) {
                                foreach ($body->getElementsByTagName($elementName) as $element) {
                                    $src = $element->getAttribute('src');
                                    if (in_array($src, $filenames)) {
                                        $includedFilename = true;
                                        $element->setAttribute('src', sprintf($this->csvOnly, $src));
                                    }
                                }
                            }
                        }]
                    ))->filter($field['html']);
                }
                $field
                    = $includedFilename ? (new \League\HTMLToMarkdown\HtmlConverter())->convert($html) : $field['lml'];
            } elseif (is_float($field)) {
                $field = $numberValidator->serializeFloat($field);
            } elseif (is_string($this->csvOnly)
                && in_array($fieldName, ['image', 'audio', 'video']) && in_array($field, $filenames)) {
                $field = sprintf($this->csvOnly, $field);
            }
            $output[] = $field;
        }
        return $output;
    }
121728
public function resolveDirectoriesWithFnmatch(array $directories): array
    {
        $absoluteDirectories = [];
        foreach ($directories as $directory) {
            if (Strings::contains($directory, '*')) { // is fnmatch for directories
                $absoluteDirectories = array_merge($absoluteDirectories, glob($directory, GLOB_ONLYDIR));
            } else { // is classic directory
                $this->ensureDirectoryExists($directory);
                $absoluteDirectories[] = $directory;
            }
        }

        return $absoluteDirectories;
    }
235768
protected function preparePaths(string $folder, array $paths, string $fileNames = ''): string
    {
        foreach ($paths as $path) {
            if (dirname($path) != $folder) {
                return ''; // all source paths must be the same
            }
            if ($fileNames != '') {
                $fileNames .= ':';
            }
            $fileNames .= basename($path);
        }

        return $fileNames;
    }
1314495
public function locateInFolders(array $folders, $filename = null)
    {
        $list = [];
        foreach ($folders as $folder) {
            $path = trim(Folder::getRelativePath($folder), '/');
            $list[$path] = $this->detectInFolder($folder, $filename);
        }
        return $list;
    }