public function register(Application $app)
 {
     $app['fabricius.excerpt_delimiter'] = '<!-- more -->';
     $app['fabricius'] = $app->share(function ($app) {
         AnnotationRegistry::registerLoader('class_exists');
         return LibraryBuilder::create()->setCacheDir($app['fabricius.cache_dir'])->setExcerptDelimiter($app['fabricius.excerpt_delimiter'])->build();
     });
     $app['fabricius.formatter'] = $app->share(function ($app) {
         return new Formatter($app['fabricius']->getMetadataFactory());
     });
     $app['fabricius.validator'] = $app->share(function ($app) {
         $constraintValidatorFactory = new ConstraintValidatorFactory();
         $translator = new DefaultTranslator();
         return new Validator($app['fabricius']->getMetadataFactory(), $constraintValidatorFactory, $translator);
     });
 }
Exemplo n.º 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/article.php';
use Doctrine\Common\Annotations\AnnotationRegistry;
use Fabricius\Events;
use Fabricius\Formatter\Formatter;
use Fabricius\Formatter\Handler\MarkdownPhpHandler;
use Fabricius\Formatter\Handler\TextileHandler;
use Fabricius\LibraryBuilder;
use Fabricius\Validator\Validator;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\DefaultTranslator;
AnnotationRegistry::registerLoader('class_exists');
$library = LibraryBuilder::create()->setCacheDir(__DIR__ . '/cache')->setExcerptDelimiter('<!-- more -->')->build();
$constraintValidatorFactory = new ConstraintValidatorFactory();
$translator = new DefaultTranslator();
$validator = new Validator($library->getMetadataFactory(), $constraintValidatorFactory, $translator);
$formatter = new Formatter($library->getMetadataFactory());
if (class_exists('dflydev\\markdown\\MarkdownExtraParser')) {
    $markdownHandler = new MarkdownPhpHandler();
    $formatter->addFormatHandler($markdownHandler);
}
if (class_exists('Netcarver\\Textile\\Parser')) {
    $textileHandler = new TextileHandler();
    $formatter->addFormatHandler($textileHandler);
}
$library->getEventDispatcher()->addListener(Events::CONTENT_PARSED, array($validator, 'onContentItemParsed'), -100);
$library->getEventDispatcher()->addListener(Events::CONTENT_PARSED, array($formatter, 'onContentItemParsed'));