Skip to content

Commit

Permalink
Refactoring ideas
Browse files Browse the repository at this point in the history
Fix: #80
  • Loading branch information
Spomky committed Mar 5, 2024
1 parent 8536bf7 commit d7a6f8b
Show file tree
Hide file tree
Showing 21 changed files with 916 additions and 885 deletions.
6 changes: 3 additions & 3 deletions src/Command/CreateServiceWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SpomkyLabs\PwaBundle\Command;

use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -14,7 +15,6 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\Yaml\Yaml;
use function count;

Expand All @@ -24,7 +24,6 @@ final class CreateServiceWorkerCommand extends Command
public function __construct(
private readonly AssetMapperInterface $assetMapper,
private readonly Filesystem $filesystem,
private readonly FileLocator $fileLocator,
#[Autowire('%kernel.project_dir%')]
private readonly string $projectDir,
) {
Expand Down Expand Up @@ -55,7 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return self::SUCCESS;
}

$resourcePath = $this->fileLocator->locate('@SpomkyLabsPwaBundle/Resources/sw-skeleton.js', null, false);
$fileLocator = new FileLocator(__DIR__ . '/../Resources');
$resourcePath = $fileLocator->locate('sw-skeleton.js', null, false);
if (count($resourcePath) !== 1) {
$io->error('Unable to find the Workbox resource.');
return Command::FAILURE;
Expand Down
803 changes: 0 additions & 803 deletions src/DependencyInjection/Configuration.php

This file was deleted.

65 changes: 0 additions & 65 deletions src/DependencyInjection/SpomkyLabsPwaExtension.php

This file was deleted.

17 changes: 17 additions & 0 deletions src/Resources/config/definition/image_processor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use SpomkyLabs\PwaBundle\ImageProcessor\GDImageProcessor;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function (DefinitionConfigurator $definition): void {
$definition->rootNode()

Check failure on line 9 in src/Resources/config/definition/image_processor.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children().
->children()
->scalarNode('image_processor')
->defaultNull()
->info('The image processor to use to generate the icons of different sizes.')
->example(GDImageProcessor::class)
->end()
->end();
};
138 changes: 138 additions & 0 deletions src/Resources/config/definition/manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

declare(strict_types=1);

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

require_once __DIR__ . '/utils/file_handlers.php';
require_once __DIR__ . '/utils/icons.php';
require_once __DIR__ . '/utils/launch_handler.php';
require_once __DIR__ . '/utils/protocol_handlers.php';
require_once __DIR__ . '/utils/related_applications.php';
require_once __DIR__ . '/utils/screenshots.php';
require_once __DIR__ . '/utils/shared_target.php';
require_once __DIR__ . '/utils/shortcuts.php';
require_once __DIR__ . '/utils/url_node.php';
require_once __DIR__ . '/utils/widgets.php';

return static function (DefinitionConfigurator $definition): void {
$definition->rootNode()

Check failure on line 19 in src/Resources/config/definition/manifest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children().
->children()
->arrayNode('manifest')
->canBeEnabled()
->children()
->scalarNode('public_url')
->defaultValue('/site.webmanifest')
->cannotBeEmpty()
->info('The public URL of the manifest file.')
->example('/site.manifest')
->end()
->scalarNode('background_color')
->info(
'The background color of the application. It should match the background-color CSS property in the sites stylesheet for a smooth transition between launching the web application and loading the site\'s content.'
)
->example('red')
->end()
->arrayNode('categories')
->info('The categories of the application.')
->example([['news', 'sports', 'lifestyle']])
->scalarPrototype()
->end()
->end()
->scalarNode('description')
->info('The description of the application.')
->example('My awesome application')
->end()
->scalarNode('display')
->info('The display mode of the application.')
->example('standalone')
->end()
->arrayNode('display_override')
->info('A sequence of display modes that the browser will consider before using the display member.')
->example([['fullscreen', 'minimal-ui']])
->scalarPrototype()
->end()
->end()
->scalarNode('id')
->info('A string that represents the identity of the web application.')
->example('?homescreen=1')
->end()
->scalarNode('orientation')
->info('The orientation of the application.')
->example('portrait-primary')
->end()
->scalarNode('dir')
->info('The direction of the application.')
->example('rtl')
->end()
->scalarNode('lang')
->info('The language of the application.')
->example('ar')
->end()
->scalarNode('name')
->info('The name of the application.')
->example('My awesome application')
->end()
->scalarNode('short_name')
->info('The short name of the application.')
->example('awesome_app')
->end()
->scalarNode('scope')
->info('The scope of the application.')
->example('/app/')
->end()
->scalarNode('start_url')
->info('The start URL of the application.')
->example('https://example.com')
->end()
->scalarNode('theme_color')
->info('The theme color of the application.')
->example('red')
->end()
->arrayNode('edge_side_panel')
->info('Specifies whether or not your app supports the side panel view in Microsoft Edge.')
->children()
->integerNode('preferred_width')
->info('Specifies the preferred width of the side panel view in Microsoft Edge.')
->end()
->end()
->end()
->scalarNode('iarc_rating_id')
->info(
'Specifies the International Age Rating Coalition (IARC) rating ID for the app. See https://www.globalratings.com/how-iarc-works.aspx for more information.'
)
->end()
->arrayNode('scope_extensions')
->info(
'Specifies a list of origin patterns to associate with. This allows for your app to control multiple subdomains and top-level domains as a single entity.'
)
->arrayPrototype()
->children()
->scalarNode('origin')
->isRequired()
->info('Specifies the origin pattern to associate with.')
->example('*.foo.com')
->end()
->end()
->end()
->end()
->scalarNode('handle_links')
->info('Specifies the default link handling for the web app.')
->example(['auto', 'preferred', 'not-preferred'])
->end()
->append(getIconsNode('The icons of the application.'))
->append(getScreenshotsNode('The screenshots of the application.'))
->append(getFileHandlersNode())
->append(getLaunchHandlerNode())
->append(getProtocolHandlersNode())
->booleanNode('prefer_related_applications')
->info('The prefer related native applications of the application.')
->end()
->append(setupRelatedApplications())
->append(setupShortcuts())
->append(setupSharedTarget())
->append(setupWidgets())
->end()
->end()
->end();
};
32 changes: 32 additions & 0 deletions src/Resources/config/definition/path_type_reference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

return static function (DefinitionConfigurator $definition): void {
$definition->rootNode()

Check failure on line 9 in src/Resources/config/definition/path_type_reference.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children().
->children()
->integerNode('path_type_reference')
->defaultValue(UrlGeneratorInterface::ABSOLUTE_PATH)
->info(
'The path type reference to generate paths/URLs. See https://symfony.com/doc/current/routing.html#generating-urls-in-controllers for more information.'
)
->example([
UrlGeneratorInterface::ABSOLUTE_PATH,
UrlGeneratorInterface::ABSOLUTE_URL,
UrlGeneratorInterface::NETWORK_PATH,
UrlGeneratorInterface::RELATIVE_PATH,
])
->validate()
->ifNotInArray([
UrlGeneratorInterface::ABSOLUTE_PATH,
UrlGeneratorInterface::ABSOLUTE_URL,
UrlGeneratorInterface::NETWORK_PATH,
UrlGeneratorInterface::RELATIVE_PATH,
])
->thenInvalid('Invalid path type reference "%s".')
->end()
->end();
};
Loading

0 comments on commit d7a6f8b

Please sign in to comment.