Skip to content

Commit

Permalink
Add service markdown chanelle
Browse files Browse the repository at this point in the history
  • Loading branch information
tesshsu committed Apr 4, 2018
1 parent 233e639 commit 0aa3926
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 251 deletions.
2 changes: 2 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/the_spacebar.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

505 changes: 257 additions & 248 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -12,6 +12,7 @@
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/maker-bundle": "^1.3",
"symfony/monolog-bundle": "^3.2",
"symfony/orm-pack": "^1.0",
"symfony/security-bundle": "^4.0",
Expand Down
118 changes: 117 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Expand Up @@ -12,4 +12,5 @@
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
];
2 changes: 2 additions & 0 deletions config/packages/monolog.yaml
@@ -0,0 +1,2 @@
monolog:
channels: ['markdown']
4 changes: 3 additions & 1 deletion config/services.yaml
Expand Up @@ -11,7 +11,9 @@ services:
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.

# setup special, global autowiring rules
bind:
$markdownLogger: '@monolog.logger.markdown'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
Expand Down
9 changes: 8 additions & 1 deletion src/Service/MarkdownHelper.php
Expand Up @@ -2,20 +2,27 @@
namespace App\Service;

use Michelf\MarkdownInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;

class MarkdownHelper
{
private $cache;
private $markdown;
public function __construct(AdapterInterface $cache, MarkdownInterface $markdown)
private $logger;

public function __construct(AdapterInterface $cache, MarkdownInterface $markdown, LoggerInterface $markdownLogger)
{
$this->cache = $cache;
$this->markdown = $markdown;
$this->logger = $markdownLogger;
}

public function parse(string $source): string
{
if (stripos($source, 'Spicy') !== false) {
$this->logger->info('They are talking about spicy again!');
}
$item = $this->cache->getItem('markdown_'.md5($source));
if (!$item->isHit()) {
$item->set($this->markdown->transform($source));
Expand Down
12 changes: 12 additions & 0 deletions symfony.lock
Expand Up @@ -68,6 +68,9 @@
"monolog/monolog": {
"version": "1.23.0"
},
"nikic/php-parser": {
"version": "v4.0.1"
},
"ocramius/package-versions": {
"version": "1.3.0"
},
Expand Down Expand Up @@ -170,6 +173,15 @@
"symfony/lts": {
"version": "4-dev"
},
"symfony/maker-bundle": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
}
},
"symfony/monolog-bridge": {
"version": "v4.0.6"
},
Expand Down

0 comments on commit 0aa3926

Please sign in to comment.