[DotEnv][WebLink][Templating][ErrorHandler] Updated README with minimal example
This commit is contained in:
parent
6a8b22d3b1
commit
f3b8a58513
@ -4,10 +4,32 @@ Dotenv Component
|
|||||||
Symfony Dotenv parses `.env` files to make environment variables stored in them
|
Symfony Dotenv parses `.env` files to make environment variables stored in them
|
||||||
accessible via `$_SERVER` or `$_ENV`.
|
accessible via `$_SERVER` or `$_ENV`.
|
||||||
|
|
||||||
|
Getting Started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require symfony/dotenv
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\Dotenv\Dotenv;
|
||||||
|
|
||||||
|
$dotenv = new Dotenv();
|
||||||
|
$dotenv->load(__DIR__.'/.env');
|
||||||
|
|
||||||
|
// you can also load several files
|
||||||
|
$dotenv->load(__DIR__.'/.env', __DIR__.'/.env.dev');
|
||||||
|
|
||||||
|
// overwrites existing env variables
|
||||||
|
$dotenv->overload(__DIR__.'/.env');
|
||||||
|
|
||||||
|
// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV
|
||||||
|
$dotenv->loadEnv(__DIR__.'/.env');
|
||||||
|
```
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* [Documentation](https://symfony.com/doc/current/components/dotenv.html)
|
|
||||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||||
|
@ -3,6 +3,35 @@ ErrorHandler Component
|
|||||||
|
|
||||||
The ErrorHandler component provides tools to manage errors and ease debugging PHP code.
|
The ErrorHandler component provides tools to manage errors and ease debugging PHP code.
|
||||||
|
|
||||||
|
Getting Started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require symfony/error-handler
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\ErrorHandler\Debug;
|
||||||
|
use Symfony\Component\ErrorHandler\ErrorHandler;
|
||||||
|
use Symfony\Component\ErrorHandler\DebugClassLoader;
|
||||||
|
|
||||||
|
Debug::enable();
|
||||||
|
|
||||||
|
// or enable only one feature
|
||||||
|
//ErrorHandler::register();
|
||||||
|
//DebugClassLoader::enable();
|
||||||
|
|
||||||
|
$data = ErrorHandler::call(static function () use ($filename, $datetimeFormat) {
|
||||||
|
// if any code executed inside this anonymous function fails, a PHP exception
|
||||||
|
// will be thrown, even if the code uses the '@' PHP silence operator
|
||||||
|
$data = json_decode(file_get_contents($filename), true);
|
||||||
|
$data['read_at'] = date($datetimeFormat);
|
||||||
|
file_put_contents($filename, json_encode($data));
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
@ -9,10 +9,33 @@ for changes. It also provides a concrete template engine implementation using
|
|||||||
PHP with additional tools for escaping and separating templates into blocks and
|
PHP with additional tools for escaping and separating templates into blocks and
|
||||||
layouts.
|
layouts.
|
||||||
|
|
||||||
|
Getting Started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require symfony/templating
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\Templating\Loader\FilesystemLoader;
|
||||||
|
use Symfony\Component\Templating\PhpEngine;
|
||||||
|
use Symfony\Component\Templating\Helper\SlotsHelper;
|
||||||
|
use Symfony\Component\Templating\TemplateNameParser;
|
||||||
|
|
||||||
|
$filesystemLoader = new FilesystemLoader(__DIR__.'/views/%name%');
|
||||||
|
|
||||||
|
$templating = new PhpEngine(new TemplateNameParser(), $filesystemLoader);
|
||||||
|
$templating->set(new SlotsHelper());
|
||||||
|
|
||||||
|
echo $templating->render('hello.php', ['firstname' => 'Fabien']);
|
||||||
|
|
||||||
|
// hello.php
|
||||||
|
Hello, <?= $view->escape($firstname) ?>!
|
||||||
|
```
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* [Documentation](https://symfony.com/doc/current/components/templating.html)
|
|
||||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||||
|
@ -8,10 +8,30 @@ This component implements the [HTML5's Links](https://www.w3.org/TR/html5/links.
|
|||||||
and [Resource Hints](https://www.w3.org/TR/resource-hints/) W3C's specifications.
|
and [Resource Hints](https://www.w3.org/TR/resource-hints/) W3C's specifications.
|
||||||
It can also be used with extensions defined in the [HTML5 link type extensions wiki](http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions).
|
It can also be used with extensions defined in the [HTML5 link type extensions wiki](http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions).
|
||||||
|
|
||||||
|
Getting Started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require symfony/web-link
|
||||||
|
```
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\WebLink\GenericLinkProvider;
|
||||||
|
use Symfony\Component\WebLink\HttpHeaderSerializer;
|
||||||
|
use Symfony\Component\WebLink\Link;
|
||||||
|
|
||||||
|
$linkProvider = (new GenericLinkProvider())
|
||||||
|
->withLink(new Link('preload', '/bootstrap.min.css'));
|
||||||
|
|
||||||
|
header('Link: '.(new HttpHeaderSerializer())->serialize($linkProvider->getLinks()));
|
||||||
|
|
||||||
|
echo 'Hello';
|
||||||
|
```
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
* [Documentation](https://symfony.com/doc/current/components/web_link.html)
|
* [Documentation](https://symfony.com/doc/current/web_link.html)
|
||||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||||
|
Reference in New Issue
Block a user