Skip to content

Commit 685e9eb

Browse files
committed
[fw-bundle] Add support for validator auto-mapping
1 parent c33b011 commit 685e9eb

File tree

10 files changed

+191
-0
lines changed

10 files changed

+191
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Symfony\Component\Dotenv\Dotenv;
4+
5+
require dirname(__DIR__).'/vendor/autoload.php';
6+
7+
// Load cached env vars if the .env.local.php file exists
8+
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
9+
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
10+
$_SERVER += $env;
11+
$_ENV += $env;
12+
} elseif (!class_exists(Dotenv::class)) {
13+
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
14+
} else {
15+
// load all the .env files
16+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
17+
}
18+
19+
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
20+
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
21+
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../3.3/config/packages/cache.yaml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
framework:
2+
secret: '%env(APP_SECRET)%'
3+
#default_locale: en
4+
#csrf_protection: true
5+
#http_method_override: true
6+
7+
# Enables session support. Note that the session will ONLY be started if you read or write from it.
8+
# Remove or comment this section to explicitly disable session support.
9+
session:
10+
handler_id: ~
11+
cookie_secure: auto
12+
cookie_samesite: lax
13+
14+
#esi: true
15+
#fragments: true
16+
php_errors:
17+
log: true
18+
19+
validation:
20+
# Enables validator auto-mapping support.
21+
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
22+
auto_mapping:
23+
App\Entity\: []
24+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
test: true
3+
session:
4+
storage_id: session.storage.mock_file
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is the entry point to configure your own services.
2+
# Files in the packages/ subdirectory configure your dependencies.
3+
4+
# Put parameters here that don't need to change on each machine where the app is deployed
5+
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
6+
parameters:
7+
8+
services:
9+
# default configuration for services in *this* file
10+
_defaults:
11+
autowire: true # Automatically injects dependencies in your services.
12+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13+
14+
# makes classes in src/ available to be used as services
15+
# this creates a service per class whose id is the fully-qualified class name
16+
App\:
17+
resource: '../src/*'
18+
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
19+
20+
# controllers are imported separately to make sure services can be injected
21+
# as action arguments even if you don't extend any base controller class
22+
App\Controller\:
23+
resource: '../src/Controller'
24+
tags: ['controller.service_arguments']
25+
26+
# add more service definitions when explicit configuration is needed
27+
# please note that last definitions always *replace* previous ones
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"bundles": {
3+
"Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle": ["all"]
4+
},
5+
"copy-from-recipe": {
6+
"config/": "%CONFIG_DIR%/",
7+
"public/": "%PUBLIC_DIR%/",
8+
"src/": "%SRC_DIR%/"
9+
},
10+
"composer-scripts": {
11+
"cache:clear": "symfony-cmd",
12+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
13+
},
14+
"env": {
15+
"APP_ENV": "dev",
16+
"APP_SECRET": "%generate(secret)%",
17+
"#TRUSTED_PROXIES": "127.0.0.1,127.0.0.2",
18+
"#TRUSTED_HOSTS": "'^localhost|example\\.com$'"
19+
},
20+
"gitignore": [
21+
"/.env.local",
22+
"/.env.local.php",
23+
"/.env.*.local",
24+
"/%PUBLIC_DIR%/bundles/",
25+
"/%VAR_DIR%/",
26+
"/vendor/"
27+
]
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<bg=blue;fg=white> </>
2+
<bg=blue;fg=white> What's next? </>
3+
<bg=blue;fg=white> </>
4+
5+
* <fg=blue>Run</> your application:
6+
1. Change to the project directory
7+
2. Create your code repository with the <comment>git init</comment> command
8+
3. Run <comment>composer require server --dev</> to install the development web server,
9+
or configure another supported web server <comment>https://symfony.com/doc/current/setup/web_server_configuration.html</>
10+
11+
* <fg=blue>Read</> the documentation at <comment>https://symfony.com/doc</>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use App\Kernel;
4+
use Symfony\Component\Debug\Debug;
5+
use Symfony\Component\HttpFoundation\Request;
6+
7+
require dirname(__DIR__).'/config/bootstrap.php';
8+
9+
if ($_SERVER['APP_DEBUG']) {
10+
umask(0000);
11+
12+
Debug::enable();
13+
}
14+
15+
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
16+
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
17+
}
18+
19+
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
20+
Request::setTrustedHosts([$trustedHosts]);
21+
}
22+
23+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
24+
$request = Request::createFromGlobals();
25+
$response = $kernel->handle($request);
26+
$response->send();
27+
$kernel->terminate($request, $response);

symfony/framework-bundle/4.3/src/Controller/.gitignore

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6+
use Symfony\Component\Config\Loader\LoaderInterface;
7+
use Symfony\Component\Config\Resource\FileResource;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10+
use Symfony\Component\Routing\RouteCollectionBuilder;
11+
12+
class Kernel extends BaseKernel
13+
{
14+
use MicroKernelTrait;
15+
16+
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
17+
18+
public function registerBundles(): iterable
19+
{
20+
$contents = require $this->getProjectDir().'/config/bundles.php';
21+
foreach ($contents as $class => $envs) {
22+
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
23+
yield new $class();
24+
}
25+
}
26+
}
27+
28+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
29+
{
30+
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
31+
$container->setParameter('container.dumper.inline_class_loader', true);
32+
$confDir = $this->getProjectDir().'/config';
33+
34+
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
35+
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
36+
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
37+
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
38+
}
39+
40+
protected function configureRoutes(RouteCollectionBuilder $routes): void
41+
{
42+
$confDir = $this->getProjectDir().'/config';
43+
44+
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
45+
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
46+
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
47+
}
48+
}

0 commit comments

Comments
 (0)