for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Digia\GraphQL\Language;
use Digia\GraphQL\Error\InvariantException;
/**
* Class DirectorySourceBuilder
* @package Digia\GraphQL\Language
*/
class DirectorySourceBuilder implements SourceBuilderInterface
{
* @var string
private $directoryPath;
* DirectorySourceBuilder constructor.
* @param string $directoryPath
public function __construct(string $directoryPath)
$this->directoryPath = $directoryPath;
}
* @inheritdoc
*
* @throws InvariantException
public function buildSource(): Source
$iterator = new \DirectoryIterator($this->directoryPath);
$combinedSource = '';
foreach ($iterator as $item) {
// Skip directories and dot files
if ($item->isDot() || !$item->isFile()) {
continue;
$itemPath = $item->getPathname();
if (!$item->isReadable()) {
throw new InvariantException(sprintf('The file %s is not readable', $itemPath));
$combinedSource .= \file_get_contents($itemPath);
return new Source($combinedSource);