Skip to content
Merged
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
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: './docker/php'
args:
SYSTEM_TIMEZONE: ${SYSTEM_TIMEZONE:-Europe/Belgrade}
SYSTEM_TIMEZONE: ${SYSTEM_TIMEZONE:-UTC}
environment:
PHP_XDEBUG_MODE: ${PHP_XDEBUG_MODE:-debug}
PHP_XDEBUG_REMOTE_PORT: ${PHP_XDEBUG_REMOTE_PORT:-9000}
Expand Down
2 changes: 2 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ RUN composer global config --no-plugins allow-plugins.infection/extension-instal
# #
#####################################################################################

RUN git config --global --add safe.directory /var/www/html

WORKDIR /var/www/html
5 changes: 5 additions & 0 deletions phpunit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
bootstrap="phpunit.php"
failOnDeprecation="true"
failOnRisky="true"
failOnWarning="true"
Expand Down
5 changes: 5 additions & 0 deletions src/RunOpenCode/Bundle/QueryBundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ Bundle integrates [Query Component](https://github.com/RunOpenCode/query) into S
- [Send pull requests](https://github.com/RunOpenCode/phplib/pulls)
- [Changelog](https://github.com/RunOpenCode/phplib/blob/master/CHANGELOG)
- [License](https://github.com/RunOpenCode/phplib/blob/master/LICENSE)

## TODO

- [ ] Add compile time check for replica, verify that replica connection exists. If replica is disabled, verification
should emit only warning.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
'cache',
'parser',
'convert',
'retry',
'slow'
])
->scalarPrototype()->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
->addDefaultsIfNotSet()
->children()
->arrayNode('pattern')
->defaultValue(['*.sql', '*.dql'])
->defaultValue(['/^.+\.(sql|dql)$/i'])
->beforeNormalization()
->ifString()
->then(static fn($value): array => [$value])
Expand Down Expand Up @@ -49,13 +49,13 @@
->min(-1)
->end()
->arrayNode('pattern')
->example('*.twig')
->example('**/*.twig')
->info('Pattern of file names to parse with Twig parser.')
->beforeNormalization()
->ifString()
->then(static fn($value): array => [$value])
->end()
->defaultValue(['*.twig'])
->defaultValue(['/^.+\.(sql\.twig|dql\.twig)$/i'])
->prototype('scalar')->end()
->end()
->arrayNode('globals')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
->tag('runopencode.query.middleware', [
'alias' => 'slow',
]);

$configurator
->set(ConvertMiddleware::class)
->arg('$registry', AdapterRegistry::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
/**
* Create frozen, context aware variable bag.
*
* @param \RunOpenCode\Component\Query\Contract\Context\ContextInterface $context Execution context.
* @param VariablesInterface|null $variables Variables to use for query/statement parsing.
* @param ParametersInterface|null $parameters Parameters to use for query/statement parsing.
* @param \RunOpenCode\Component\Query\Contract\Context\ContextInterface $context Execution context.
* @param VariablesInterface|null $variables Variables to use for query/statement parsing.
* @param ParametersInterface|null $parameters Parameters to use for query/statement parsing.
*/
public function __construct(
public ContextInterface $context,
Expand All @@ -60,7 +60,7 @@ public function __construct(
$this->parser = $variables?->parser;
$this->bag = \array_merge(
$params,
$variables instanceof \RunOpenCode\Component\Query\Contract\Parser\VariablesInterface ? \iterator_to_array($variables) : [],
$variables instanceof VariablesInterface ? \iterator_to_array($variables) : [],
[
'variables' => $variables,
'parameters' => $parameters,
Expand Down
8 changes: 8 additions & 0 deletions src/RunOpenCode/Component/Query/src/Parser/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public static function void(): self
return new self(VoidParser::NAME);
}

/**
* Create new variable bag for file parser.
*/
public static function file(): self
{
return new self(FileParser::NAME);
}

/**
* Create new variables bag for twig parser.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
final class MySqlFactory
{
private const int MAX_ATTEMPTS = 15;

private static self $instance;

public static function instance(): self
Expand All @@ -37,14 +39,32 @@ public function create(MySqlDatabase $database): array

$configuration->setMiddlewares([new DbalLoggingMiddleware($logger)]);

$connection = DriverManager::getConnection([
'driver' => 'mysqli',
'dbname' => $database->value,
'user' => 'roc',
'password' => 'roc',
'host' => 'mysql.local',
], $configuration);
for ($i = 0; $i < self::MAX_ATTEMPTS; ++$i) {
$connection = DriverManager::getConnection([
'driver' => 'mysqli',
'dbname' => $database->value,
'user' => 'roc',
'password' => 'roc',
'host' => 'mysql.local',
], $configuration);

if (!$connection->isConnected()) {
return [$connection, $logger];
}

try {
$connection->getServerVersion();

return [$connection, $logger];
} catch (\Exception) {
\sleep(1);
}
}

return [$connection, $logger];
throw new \RuntimeException(\sprintf(
'Unable to connect to database "%s" after %d attempts.',
$database->value,
self::MAX_ATTEMPTS,
));
}
}
43 changes: 43 additions & 0 deletions src/RunOpenCode/Component/Query/tests/Functions/ToRegexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace RunOpenCode\Component\Query\Tests\Functions;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

use function RunOpenCode\Component\Query\to_regex;

final class ToRegexTest extends TestCase
{
/**
* @param non-empty-string $glob
*/
#[Test]
#[DataProvider('get_data_for_glob_matches')]
public function glob_matches(string $glob, string $path, bool $expected): void
{
$this->assertSame($expected ? 1 : 0, \preg_match(to_regex($glob), $path));
}

/**
* @return iterable<non-empty-string, array{non-empty-string, string, bool}>
*/
public static function get_data_for_glob_matches(): iterable
{
yield '*.twig, @foo/bar.sql.twig' => ['*.twig', '@foo/bar.sql.twig', false];
yield '*.twig, foo.sql.twig' => ['*.twig', 'foo.sql.twig', true];
yield '**/*.twig, @foo/bar.sql.twig' => ['**/*.twig', '@foo/bar.sql.twig', true];
}

/**
* @see https://github.com/symfony/symfony/issues/62737
*/
#[Test]
public function monitor_fix(): void
{
$this->assertDoesNotMatchRegularExpression(to_regex('**/*.twig'), 'foo.sql.twig');
}
}
Loading