Skip to content

Commit

Permalink
[Router] Initialize the component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Oct 27, 2023
1 parent 52dc225 commit 9cfb19b
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Router/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.symfony.bundle.yaml export-ignore
/phpunit.xml.dist export-ignore
/assets/src export-ignore
/assets/test export-ignore
/tests export-ignore
4 changes: 4 additions & 0 deletions src/Router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor
composer.lock
.php_cs.cache
.phpunit.result.cache
3 changes: 3 additions & 0 deletions src/Router/.symfony.bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
branches: ["2.x"]
maintained_branches: ["2.x"]
doc_dir: "doc"
5 changes: 5 additions & 0 deletions src/Router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## [Unreleased]

- Create the component.
19 changes: 19 additions & 0 deletions src/Router/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023-present Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
16 changes: 16 additions & 0 deletions src/Router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Symfony UX Router

**EXPERIMENTAL** This component is currently experimental and is
likely to change, or even change drastically.

Symfony UX Router integrates [Symfony Router](https://symfony.com/doc/current/routing.html) for JavaScript.

**This repository is a READ-ONLY sub-tree split**. See
https://github.com/symfony/ux to create issues or submit pull requests.

## Resources

- [Documentation](https://symfony.com/bundles/ux-router/current/index.html)
- [Report issues](https://github.com/symfony/ux/issues) and
[send Pull Requests](https://github.com/symfony/ux/pulls)
in the [main Symfony UX repository](https://github.com/symfony/ux)
16 changes: 16 additions & 0 deletions src/Router/assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@symfony/ux-router",
"description": "Symfony Router for JavaScript",
"license": "MIT",
"version": "1.0.0",
"main": "dist/router_controller.js",
"types": "dist/router_controller.d.ts",
"symfony": {
"importmap": {
"intl-messageformat": "^10.2.5",
"@symfony/ux-router": "path:%PACKAGE%/dist/router_controller.js",
"@app/routes": "path:var/routes/index.js",
"@app/routes/configuration": "path:var/routes/configuration.js"
}
}
}
12 changes: 12 additions & 0 deletions src/Router/assets/src/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

'use strict';

// TODO
12 changes: 12 additions & 0 deletions src/Router/assets/src/router_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

'use strict';

export * from './router';
48 changes: 48 additions & 0 deletions src/Router/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "symfony/ux-router",
"type": "symfony-bundle",
"description": "Exposes Symfony Routes directly to JavaScript.",
"keywords": [
"symfony-ux"
],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Hugo Alliaume",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"autoload": {
"psr-4": {
"Symfony\\UX\\Router\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Symfony\\UX\\Router\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.1",
"symfony/console": "^5.4|^6.0|^7.0",
"symfony/filesystem": "^5.4|^6.0|^7.0",
"symfony/string": "^5.4|^6.0|^7.0",
},
"require-dev": {
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"extra": {
"thanks": {
"name": "symfony/ux",
"url": "https://github.com/symfony/ux"
}
},
"minimum-stability": "dev"
}
35 changes: 35 additions & 0 deletions src/Router/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\UX\Router\CacheWarmer\RoutesCacheWarmer;
use Symfony\UX\Router\RoutesDumper;

/*
* @author Hugo Alliaume <[email protected]>
*/
return static function (ContainerConfigurator $container): void {
$container->services()
->set('ux.router.cache_warmer.routes_cache_warmer', RoutesCacheWarmer::class)
->args([
service('router'),
service('ux.router.routes_dumper'),
])
->tag('kernel.cache_warmer')

->set('ux.router.routes_dumper', RoutesDumper::class)
->args([
null, // Dump directory
service('filesystem'),
])
;
};
39 changes: 39 additions & 0 deletions src/Router/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Symfony UX Router
=================

**EXPERIMENTAL** This component is currently experimental and is likely
to change, or even change drastically.

// ...

Installation
------------

Usage
-----

Configuring the default locale
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ...

Importing and using routes
~~~~~~~~~~~~~~~~~~~~~~~~~~

// ...

.. _using-with-asset-mapper:

Using with AssetMapper
----------------------

// ...

Backward Compatibility promise
------------------------------

This bundle aims at following the same Backward Compatibility promise as
the Symfony framework:
https://symfony.com/doc/current/contributing/code/bc.html

// ...
31 changes: 31 additions & 0 deletions src/Router/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true">
<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
<env name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0"/>
</php>

<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
43 changes: 43 additions & 0 deletions src/Router/src/CacheWarmer/TranslationsCacheWarmer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\Router\CacheWarmer;

use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\UX\Router\RoutesDumper;

/**
* @author Hugo Alliaume <[email protected]>
*
* @experimental
*/
class RoutesCacheWarmer implements CacheWarmerInterface
{
public function __construct(
private RoutesDumper $routesDumper,
) {
}

public function isOptional(): bool
{
return true;
}

public function warmUp(string $cacheDir, string $buildDir = null): array
{
$this->routesDumper->dump(
// TODO: pass routes collection
);

// No need to preload anything
return [];
}
}
36 changes: 36 additions & 0 deletions src/Router/src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\Router\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* @author Hugo Alliaume <[email protected]>
*
* @experimental
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('ux_router');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->scalarNode('dump_directory')->defaultValue('%kernel.project_dir%/var/routes')->end()
->end()
;

return $treeBuilder;
}
}
Loading

0 comments on commit 9cfb19b

Please sign in to comment.