Skip to content

Commit f3b8a58

Browse files
wouterjfabpot
authored andcommitted
[DotEnv][WebLink][Templating][ErrorHandler] Updated README with minimal example
1 parent 6a8b22d commit f3b8a58

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

src/Symfony/Component/Dotenv/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,32 @@ Dotenv Component
44
Symfony Dotenv parses `.env` files to make environment variables stored in them
55
accessible via `$_SERVER` or `$_ENV`.
66

7+
Getting Started
8+
---------------
9+
10+
```
11+
$ composer require symfony/dotenv
12+
```
13+
14+
```php
15+
use Symfony\Component\Dotenv\Dotenv;
16+
17+
$dotenv = new Dotenv();
18+
$dotenv->load(__DIR__.'/.env');
19+
20+
// you can also load several files
21+
$dotenv->load(__DIR__.'/.env', __DIR__.'/.env.dev');
22+
23+
// overwrites existing env variables
24+
$dotenv->overload(__DIR__.'/.env');
25+
26+
// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV
27+
$dotenv->loadEnv(__DIR__.'/.env');
28+
```
29+
730
Resources
831
---------
932

10-
* [Documentation](https://symfony.com/doc/current/components/dotenv.html)
1133
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1234
* [Report issues](https://github.com/symfony/symfony/issues) and
1335
[send Pull Requests](https://github.com/symfony/symfony/pulls)

src/Symfony/Component/ErrorHandler/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ ErrorHandler Component
33

44
The ErrorHandler component provides tools to manage errors and ease debugging PHP code.
55

6+
Getting Started
7+
---------------
8+
9+
```
10+
$ composer require symfony/error-handler
11+
```
12+
13+
```php
14+
use Symfony\Component\ErrorHandler\Debug;
15+
use Symfony\Component\ErrorHandler\ErrorHandler;
16+
use Symfony\Component\ErrorHandler\DebugClassLoader;
17+
18+
Debug::enable();
19+
20+
// or enable only one feature
21+
//ErrorHandler::register();
22+
//DebugClassLoader::enable();
23+
24+
$data = ErrorHandler::call(static function () use ($filename, $datetimeFormat) {
25+
// if any code executed inside this anonymous function fails, a PHP exception
26+
// will be thrown, even if the code uses the '@' PHP silence operator
27+
$data = json_decode(file_get_contents($filename), true);
28+
$data['read_at'] = date($datetimeFormat);
29+
file_put_contents($filename, json_encode($data));
30+
31+
return $data;
32+
});
33+
```
34+
635
Resources
736
---------
837

src/Symfony/Component/Templating/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,33 @@ for changes. It also provides a concrete template engine implementation using
99
PHP with additional tools for escaping and separating templates into blocks and
1010
layouts.
1111

12+
Getting Started
13+
---------------
14+
15+
```
16+
$ composer require symfony/templating
17+
```
18+
19+
```php
20+
use Symfony\Component\Templating\Loader\FilesystemLoader;
21+
use Symfony\Component\Templating\PhpEngine;
22+
use Symfony\Component\Templating\Helper\SlotsHelper;
23+
use Symfony\Component\Templating\TemplateNameParser;
24+
25+
$filesystemLoader = new FilesystemLoader(__DIR__.'/views/%name%');
26+
27+
$templating = new PhpEngine(new TemplateNameParser(), $filesystemLoader);
28+
$templating->set(new SlotsHelper());
29+
30+
echo $templating->render('hello.php', ['firstname' => 'Fabien']);
31+
32+
// hello.php
33+
Hello, <?= $view->escape($firstname) ?>!
34+
```
35+
1236
Resources
1337
---------
1438

15-
* [Documentation](https://symfony.com/doc/current/components/templating.html)
1639
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1740
* [Report issues](https://github.com/symfony/symfony/issues) and
1841
[send Pull Requests](https://github.com/symfony/symfony/pulls)

src/Symfony/Component/WebLink/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,30 @@ This component implements the [HTML5's Links](https://www.w3.org/TR/html5/links.
88
and [Resource Hints](https://www.w3.org/TR/resource-hints/) W3C's specifications.
99
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).
1010

11+
Getting Started
12+
---------------
13+
14+
```
15+
$ composer require symfony/web-link
16+
```
17+
18+
```php
19+
use Symfony\Component\WebLink\GenericLinkProvider;
20+
use Symfony\Component\WebLink\HttpHeaderSerializer;
21+
use Symfony\Component\WebLink\Link;
22+
23+
$linkProvider = (new GenericLinkProvider())
24+
->withLink(new Link('preload', '/bootstrap.min.css'));
25+
26+
header('Link: '.(new HttpHeaderSerializer())->serialize($linkProvider->getLinks()));
27+
28+
echo 'Hello';
29+
```
30+
1131
Resources
1232
---------
1333

14-
* [Documentation](https://symfony.com/doc/current/components/web_link.html)
34+
* [Documentation](https://symfony.com/doc/current/web_link.html)
1535
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
1636
* [Report issues](https://github.com/symfony/symfony/issues) and
1737
[send Pull Requests](https://github.com/symfony/symfony/pulls)

0 commit comments

Comments
 (0)