Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update composer.json to support symfony 6.4 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Command/GraphQLConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class GraphQLConfigureCommand extends Command
{
const PROJECT_NAMESPACE = 'App';
public const PROJECT_NAMESPACE = 'App';

/** @var Container */
protected $container;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$originalConfigData = file_get_contents($configFile);
if (strpos($originalConfigData, 'graphql') === false) {
if (!str_contains($originalConfigData, 'graphql')) {
$projectNameSpace = self::PROJECT_NAMESPACE;
$configData = <<<CONFIG
graphql:
Expand Down Expand Up @@ -119,7 +119,7 @@ protected function getMainRouteConfig()
$routerResources = $this->container->get('router')->getRouteCollection()->getResources();
foreach ($routerResources as $resource) {
/** @var FileResource|DirectoryResource $resource */
if (method_exists($resource, 'getResource') && substr($resource->getResource(), -11) == 'routes.yaml') {
if (method_exists($resource, 'getResource') && str_ends_with($resource->getResource(), 'routes.yaml')) {
return $resource->getResource();
}
}
Expand All @@ -136,7 +136,7 @@ protected function graphQLRouteExists()
$routerResources = $this->container->get('router')->getRouteCollection()->getResources();
foreach ($routerResources as $resource) {
/** @var FileResource|DirectoryResource $resource */
if (method_exists($resource, 'getResource') && strpos($resource->getResource(), 'GraphQLController.php') !== false) {
if (method_exists($resource, 'getResource') && str_contains($resource->getResource(), 'GraphQLController.php')) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Config/Rule/TypeValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function validate($data, $ruleInfo)

if (($ruleInfo == TypeService::TYPE_CALLABLE) && (
is_callable($data) ||
(is_array($data) && count($data) == 2 && substr($data[0], 0, 1) == '@'))
(is_array($data) && count($data) == 2 && str_starts_with((string) $data[0], '@')))
) {
return true;
}
Expand Down
28 changes: 12 additions & 16 deletions Controller/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
class GraphQLController extends AbstractController
{
protected $container;
protected $params;

public function __construct(ContainerInterface $container, ParameterBagInterface $params)
public function __construct(ContainerInterface $container, protected ParameterBagInterface $params)
{
$this->container = $container;
$this->params = $params;
}

/**
Expand All @@ -35,27 +33,25 @@ public function __construct(ContainerInterface $container, ParameterBagInterface
*
* @return JsonResponse
*/
public function defaultAction()
public function defaultAction(): JsonResponse
{
try {
$this->initializeSchemaService();
} catch (UnableToInitializeSchemaServiceException $e) {
} catch (UnableToInitializeSchemaServiceException) {
return new JsonResponse(
[['message' => 'Schema class ' . $this->getSchemaClass() . ' does not exist']],
200,
$this->getResponseHeaders()
);
}

if ($this->container->get('request_stack')->getCurrentRequest()->getMethod() == 'OPTIONS') {
if ($this->container->get('request_stack')->getCurrentRequest()->getMethod() === 'OPTIONS') {
return $this->createEmptyResponse();
}

list($queries, $isMultiQueryRequest) = $this->getPayload();
[$queries, $isMultiQueryRequest] = $this->getPayload();

$queryResponses = array_map(function ($queryData) {
return $this->executeQuery($queryData['query'], $queryData['variables']);
}, $queries);
$queryResponses = array_map(fn($queryData) => $this->executeQuery($queryData['query'], $queryData['variables']), $queries);

$response = new JsonResponse($isMultiQueryRequest ? $queryResponses : $queryResponses[0], 200, $this->getParam('graphql.response.headers'));

Expand All @@ -66,12 +62,12 @@ public function defaultAction()
return $response;
}

protected function createEmptyResponse()
protected function createEmptyResponse(): JsonResponse
{
return new JsonResponse([], 200, $this->getResponseHeaders());
}

protected function executeQuery($query, $variables)
protected function executeQuery($query, $variables): array
{
/** @var Processor $processor */
$processor = $this->container->get('graphql.processor');
Expand All @@ -85,7 +81,7 @@ protected function executeQuery($query, $variables)
*
* @throws \Exception
*/
protected function getPayload()
protected function getPayload(): array
{
$request = $this->container->get('request_stack')->getCurrentRequest();
$query = $request->get('query', null);
Expand All @@ -103,7 +99,7 @@ protected function getPayload()
'variables' => [],
];
} else {
$params = json_decode($content, true);
$params = json_decode((string) $content, true);

if ($params) {
// check for a list of queries
Expand All @@ -114,7 +110,7 @@ protected function getPayload()
}

foreach ($params as $queryParams) {
$query = isset($queryParams['query']) ? $queryParams['query'] : $query;
$query = $queryParams['query'] ?? $query;

if (isset($queryParams['variables'])) {
if (is_string($queryParams['variables'])) {
Expand Down Expand Up @@ -198,7 +194,7 @@ protected function getSchemaService()
{
$serviceName = $this->getParam('graphql.schema_service');

if (substr($serviceName ?: '', 0, 1) === '@') {
if (str_starts_with($serviceName ?: '', '@')) {
return substr($serviceName, 1, strlen($serviceName) - 1);
}

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/GraphQlCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GraphQlCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if ($loggerAlias = $container->getParameter('graphql.logger')) {
if (strpos($loggerAlias, '@') === 0) {
if (str_starts_with($loggerAlias, '@')) {
$loggerAlias = substr($loggerAlias, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('graphql');
$rootNode = $treeBuilder->getRootNode();
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/GraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->config = $this->processConfiguration($configuration, $configs);

$preparedHeaders = [];
$headers = $this->config['response']['headers'] ? $this->config['response']['headers'] : $this->getDefaultHeaders();
$headers = $this->config['response']['headers'] ?: $this->getDefaultHeaders();
foreach ($headers as $header) {
$preparedHeaders[$header['name']] = $header['value'];
}
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM php:8.3
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN apt update
RUN apt install git -y
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
RUN pecl install xdebug && docker-php-ext-enable xdebug
WORKDIR /var/www/html
ENTRYPOINT ["tail", "-f", "/dev/null"]
17 changes: 2 additions & 15 deletions Event/ResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@

class ResolveEvent extends GenericEvent
{
/**
* @var Field */
private $field;

/** @var array */
private $astFields;

/** @var mixed|null */
private $resolvedValue;

/**
* Constructor.
*
* @param FieldInterface $field
* @param array $astFields
* @param mixed|null $resolvedValue
*/
public function __construct(FieldInterface $field, array $astFields, $resolvedValue = null)
public function __construct(private readonly FieldInterface $field, private readonly array $astFields, private $resolvedValue = null)
{
$this->field = $field;
$this->astFields = $astFields;
$this->resolvedValue = $resolvedValue;
parent::__construct('ResolveEvent', [$field, $astFields, $resolvedValue]);
parent::__construct('ResolveEvent', [$this->field, $this->astFields, $this->resolvedValue]);
}

/**
Expand Down
10 changes: 3 additions & 7 deletions Execution/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ class Processor extends BaseProcessor
/** @var SecurityManagerInterface */
private $securityManager;

/** @var EventDispatcherInterface */
private $eventDispatcher;

/**
* Constructor.
*
* @param ExecutionContextInterface $executionContext
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(ExecutionContextInterface $executionContext, EventDispatcherInterface $eventDispatcher)
public function __construct(ExecutionContextInterface $executionContext, private readonly EventDispatcherInterface $eventDispatcher)
{
$this->executionContext = $executionContext;
$this->eventDispatcher = $eventDispatcher;

parent::__construct($executionContext->getSchema());
}
Expand Down Expand Up @@ -105,7 +101,7 @@ protected function doResolve(FieldInterface $field, AstFieldInterface $ast, $par

if (($field instanceof AbstractField) && ($resolveFunc = $field->getConfig()->getResolveFunction())) {
if ($this->isServiceReference($resolveFunc)) {
$service = substr($resolveFunc[0], 1);
$service = substr((string) $resolveFunc[0], 1);
$method = $resolveFunc[1];
if (!$this->executionContext->getContainer()->has($service)) {
throw new ResolveException(sprintf('Resolve service "%s" not found for field "%s"', $service, $field->getName()));
Expand Down Expand Up @@ -153,7 +149,7 @@ private function assertClientHasFieldAccess(ResolveInfo $resolveInfo)

private function isServiceReference($resolveFunc)
{
return is_array($resolveFunc) && count($resolveFunc) == 2 && strpos($resolveFunc[0], '@') === 0;
return is_array($resolveFunc) && count($resolveFunc) == 2 && str_starts_with((string) $resolveFunc[0], '@');
}

public function setLogger($logger = null)
Expand Down
10 changes: 3 additions & 7 deletions Security/Manager/DefaultSecurityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ class DefaultSecurityManager implements SecurityManagerInterface
/** @var bool */
private $rootOperationSecurityEnabled = false;

/** @var AuthorizationCheckerInterface */
private $authorizationChecker;

public function __construct(AuthorizationCheckerInterface $authorizationChecker, array $guardConfig = [])
public function __construct(private readonly AuthorizationCheckerInterface $authorizationChecker, array $guardConfig = [])
{
$this->authorizationChecker = $authorizationChecker;
$this->fieldSecurityEnabled = isset($guardConfig['field']) ? $guardConfig['field'] : false;
$this->rootOperationSecurityEnabled = isset($guardConfig['operation']) ? $guardConfig['operation'] : false;
$this->fieldSecurityEnabled = $guardConfig['field'] ?? false;
$this->rootOperationSecurityEnabled = $guardConfig['operation'] ?? false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Security/Manager/SecurityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
interface SecurityManagerInterface
{

const RESOLVE_ROOT_OPERATION_ATTRIBUTE = 'RESOLVE_ROOT_OPERATION';
const RESOLVE_FIELD_ATTRIBUTE = 'RESOLVE_FIELD';
public const RESOLVE_ROOT_OPERATION_ATTRIBUTE = 'RESOLVE_ROOT_OPERATION';
public const RESOLVE_FIELD_ATTRIBUTE = 'RESOLVE_FIELD';

/**
* @param $attribute string
Expand Down
2 changes: 1 addition & 1 deletion Security/Voter/AbstractListVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class AbstractListVoter extends Voter
/** @var bool */
private $enabled = false;

protected function supports($attribute, $subject)
protected function supports($attribute, $subject): bool
{
return $this->enabled && $attribute == SecurityManagerInterface::RESOLVE_ROOT_OPERATION_ATTRIBUTE;
}
Expand Down
2 changes: 1 addition & 1 deletion Security/Voter/BlacklistVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BlacklistVoter extends AbstractListVoter
*
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
/** @var $subject Query */
return $this->isLoggedInUser($token) || !$this->inList($subject->getName());
Expand Down
27 changes: 9 additions & 18 deletions Tests/DependencyInjection/GraphQLExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testDefaultCanBeOverridden()
);
}

private function loadContainerFromFile($file, $type, array $services = array(), $skipEnvVars = false)
private function loadContainerFromFile($file, $type, array $services = [], $skipEnvVars = false)
{
$container = new ContainerBuilder();
if ($skipEnvVars && !method_exists($container, 'resolveEnvPlaceholders')) {
Expand All @@ -80,25 +80,16 @@ private function loadContainerFromFile($file, $type, array $services = array(),
$container->registerExtension(new GraphQLExtension());
$locator = new FileLocator(__DIR__ . '/Fixtures/config/' . $type);

switch ($type) {
case 'xml':
$loader = new XmlFileLoader($container, $locator);
break;
case 'yml':
$loader = new YamlFileLoader($container, $locator);
break;
case 'php':
$loader = new PhpFileLoader($container, $locator);
break;
default:
throw new \InvalidArgumentException('Invalid file type');
}
$loader = match ($type) {
'xml' => new XmlFileLoader($container, $locator),
'yml' => new YamlFileLoader($container, $locator),
'php' => new PhpFileLoader($container, $locator),
default => throw new \InvalidArgumentException('Invalid file type'),
};

$loader->load($file . '.' . $type);
$container->getCompilerPassConfig()->setOptimizationPasses(array(
new ResolveChildDefinitionsPass(),
));
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]);
$container->getCompilerPassConfig()->setRemovingPasses([]);
$container->compile();
return $container;
}
Expand Down
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@
"Youshido\\GraphQLBundle\\": ""
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/msklenica/GraphQL-php.git"
}
],
"require": {
"99designs/graphql": "~1",
"symfony/security-core": "~4.4 || ~5.4",
"symfony/framework-bundle": "~4.4 || ~5.4",
"php": ">=5.6"
"php": "^8.3",
"99designs/graphql": "v1.0.2",
"symfony/security-core": "~6.4",
"symfony/framework-bundle": "~6.4",
"symfony/console": "~6.4"
},
"require-dev": {
"phpunit/phpunit": "~9.6",
"composer/composer": "~1.2",
"symfony/yaml": "~4.4 || ~5.4"
"rector/rector": "*",
"symfony/yaml": "~6.4"
}
}
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
app:
hostname: app
container_name: app
build: .
volumes:
- .:/var/www/html:rw
Loading