/app/cache/dev/classes.php
PHP | 6458 lines | 6458 code | 0 blank | 0 comment | 781 complexity | 460ab38af96583ae9f2c44d2ac335ce0 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- namespace Monolog\Formatter
- {
- interface FormatterInterface
- {
- public function format(array $record);
- public function formatBatch(array $records);
- }
- }
- namespace Monolog\Formatter
- {
- use Exception;
- class NormalizerFormatter implements FormatterInterface
- {
- const SIMPLE_DATE ="Y-m-d H:i:s";
- protected $dateFormat;
- public function __construct($dateFormat = null)
- {
- $this->dateFormat = $dateFormat ?: static::SIMPLE_DATE;
- }
- public function format(array $record)
- {
- return $this->normalize($record);
- }
- public function formatBatch(array $records)
- {
- foreach ($records as $key => $record) {
- $records[$key] = $this->format($record);
- }
- return $records;
- }
- protected function normalize($data)
- {
- if (null === $data || is_scalar($data)) {
- return $data;
- }
- if (is_array($data) || $data instanceof \Traversable) {
- $normalized = array();
- $count = 1;
- foreach ($data as $key => $value) {
- if ($count++ >= 1000) {
- $normalized['...'] ='Over 1000 items, aborting normalization';
- break;
- }
- $normalized[$key] = $this->normalize($value);
- }
- return $normalized;
- }
- if ($data instanceof \DateTime) {
- return $data->format($this->dateFormat);
- }
- if (is_object($data)) {
- if ($data instanceof Exception) {
- return $this->normalizeException($data);
- }
- return sprintf("[object] (%s: %s)", get_class($data), $this->toJson($data, true));
- }
- if (is_resource($data)) {
- return'[resource]';
- }
- return'[unknown('.gettype($data).')]';
- }
- protected function normalizeException(Exception $e)
- {
- $data = array('class'=> get_class($e),'message'=> $e->getMessage(),'file'=> $e->getFile().':'.$e->getLine(),
- );
- $trace = $e->getTrace();
- foreach ($trace as $frame) {
- if (isset($frame['file'])) {
- $data['trace'][] = $frame['file'].':'.$frame['line'];
- } else {
- $data['trace'][] = json_encode($frame);
- }
- }
- if ($previous = $e->getPrevious()) {
- $data['previous'] = $this->normalizeException($previous);
- }
- return $data;
- }
- protected function toJson($data, $ignoreErrors = false)
- {
- if ($ignoreErrors) {
- if (version_compare(PHP_VERSION,'5.4.0','>=')) {
- return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
- }
- return @json_encode($data);
- }
- if (version_compare(PHP_VERSION,'5.4.0','>=')) {
- return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
- }
- return json_encode($data);
- }
- }
- }
- namespace Monolog\Formatter
- {
- use Exception;
- class LineFormatter extends NormalizerFormatter
- {
- const SIMPLE_FORMAT ="[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
- protected $format;
- protected $allowInlineLineBreaks;
- public function __construct($format = null, $dateFormat = null, $allowInlineLineBreaks = false)
- {
- $this->format = $format ?: static::SIMPLE_FORMAT;
- $this->allowInlineLineBreaks = $allowInlineLineBreaks;
- parent::__construct($dateFormat);
- }
- public function format(array $record)
- {
- $vars = parent::format($record);
- $output = $this->format;
- foreach ($vars['extra'] as $var => $val) {
- if (false !== strpos($output,'%extra.'.$var.'%')) {
- $output = str_replace('%extra.'.$var.'%', $this->replaceNewlines($this->convertToString($val)), $output);
- unset($vars['extra'][$var]);
- }
- }
- foreach ($vars as $var => $val) {
- if (false !== strpos($output,'%'.$var.'%')) {
- $output = str_replace('%'.$var.'%', $this->replaceNewlines($this->convertToString($val)), $output);
- }
- }
- return $output;
- }
- public function formatBatch(array $records)
- {
- $message ='';
- foreach ($records as $record) {
- $message .= $this->format($record);
- }
- return $message;
- }
- protected function normalizeException(Exception $e)
- {
- $previousText ='';
- if ($previous = $e->getPrevious()) {
- do {
- $previousText .=', '.get_class($previous).': '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
- } while ($previous = $previous->getPrevious());
- }
- return'[object] ('.get_class($e).': '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
- }
- protected function convertToString($data)
- {
- if (null === $data || is_bool($data)) {
- return var_export($data, true);
- }
- if (is_scalar($data)) {
- return (string) $data;
- }
- if (version_compare(PHP_VERSION,'5.4.0','>=')) {
- return $this->toJson($data, true);
- }
- return str_replace('\\/','/', @json_encode($data));
- }
- protected function replaceNewlines($str)
- {
- if ($this->allowInlineLineBreaks) {
- return $str;
- }
- return preg_replace('{[\r\n]+}',' ', $str);
- }
- }
- }
- namespace Monolog\Handler
- {
- use Monolog\Formatter\FormatterInterface;
- interface HandlerInterface
- {
- public function isHandling(array $record);
- public function handle(array $record);
- public function handleBatch(array $records);
- public function pushProcessor($callback);
- public function popProcessor();
- public function setFormatter(FormatterInterface $formatter);
- public function getFormatter();
- }
- }
- namespace Monolog\Handler
- {
- use Monolog\Logger;
- use Monolog\Formatter\FormatterInterface;
- use Monolog\Formatter\LineFormatter;
- abstract class AbstractHandler implements HandlerInterface
- {
- protected $level = Logger::DEBUG;
- protected $bubble = true;
- protected $formatter;
- protected $processors = array();
- public function __construct($level = Logger::DEBUG, $bubble = true)
- {
- $this->level = $level;
- $this->bubble = $bubble;
- }
- public function isHandling(array $record)
- {
- return $record['level'] >= $this->level;
- }
- public function handleBatch(array $records)
- {
- foreach ($records as $record) {
- $this->handle($record);
- }
- }
- public function close()
- {
- }
- public function pushProcessor($callback)
- {
- if (!is_callable($callback)) {
- throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
- }
- array_unshift($this->processors, $callback);
- return $this;
- }
- public function popProcessor()
- {
- if (!$this->processors) {
- throw new \LogicException('You tried to pop from an empty processor stack.');
- }
- return array_shift($this->processors);
- }
- public function setFormatter(FormatterInterface $formatter)
- {
- $this->formatter = $formatter;
- return $this;
- }
- public function getFormatter()
- {
- if (!$this->formatter) {
- $this->formatter = $this->getDefaultFormatter();
- }
- return $this->formatter;
- }
- public function setLevel($level)
- {
- $this->level = $level;
- return $this;
- }
- public function getLevel()
- {
- return $this->level;
- }
- public function setBubble($bubble)
- {
- $this->bubble = $bubble;
- return $this;
- }
- public function getBubble()
- {
- return $this->bubble;
- }
- public function __destruct()
- {
- try {
- $this->close();
- } catch (\Exception $e) {
- }
- }
- protected function getDefaultFormatter()
- {
- return new LineFormatter();
- }
- }
- }
- namespace Monolog\Handler
- {
- abstract class AbstractProcessingHandler extends AbstractHandler
- {
- public function handle(array $record)
- {
- if (!$this->isHandling($record)) {
- return false;
- }
- $record = $this->processRecord($record);
- $record['formatted'] = $this->getFormatter()->format($record);
- $this->write($record);
- return false === $this->bubble;
- }
- abstract protected function write(array $record);
- protected function processRecord(array $record)
- {
- if ($this->processors) {
- foreach ($this->processors as $processor) {
- $record = call_user_func($processor, $record);
- }
- }
- return $record;
- }
- }
- }
- namespace Monolog\Handler
- {
- use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
- use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
- use Monolog\Logger;
- class FingersCrossedHandler extends AbstractHandler
- {
- protected $handler;
- protected $activationStrategy;
- protected $buffering = true;
- protected $bufferSize;
- protected $buffer = array();
- protected $stopBuffering;
- public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true)
- {
- if (null === $activationStrategy) {
- $activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
- }
- if (!$activationStrategy instanceof ActivationStrategyInterface) {
- $activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
- }
- $this->handler = $handler;
- $this->activationStrategy = $activationStrategy;
- $this->bufferSize = $bufferSize;
- $this->bubble = $bubble;
- $this->stopBuffering = $stopBuffering;
- }
- public function isHandling(array $record)
- {
- return true;
- }
- public function handle(array $record)
- {
- if ($this->processors) {
- foreach ($this->processors as $processor) {
- $record = call_user_func($processor, $record);
- }
- }
- if ($this->buffering) {
- $this->buffer[] = $record;
- if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
- array_shift($this->buffer);
- }
- if ($this->activationStrategy->isHandlerActivated($record)) {
- if ($this->stopBuffering) {
- $this->buffering = false;
- }
- if (!$this->handler instanceof HandlerInterface) {
- if (!is_callable($this->handler)) {
- throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
- }
- $this->handler = call_user_func($this->handler, $record, $this);
- if (!$this->handler instanceof HandlerInterface) {
- throw new \RuntimeException("The factory callable should return a HandlerInterface");
- }
- }
- $this->handler->handleBatch($this->buffer);
- $this->buffer = array();
- }
- } else {
- $this->handler->handle($record);
- }
- return false === $this->bubble;
- }
- public function reset()
- {
- $this->buffering = true;
- }
- }
- }
- namespace Monolog\Handler\FingersCrossed
- {
- interface ActivationStrategyInterface
- {
- public function isHandlerActivated(array $record);
- }
- }
- namespace Monolog\Handler\FingersCrossed
- {
- class ErrorLevelActivationStrategy implements ActivationStrategyInterface
- {
- private $actionLevel;
- public function __construct($actionLevel)
- {
- $this->actionLevel = $actionLevel;
- }
- public function isHandlerActivated(array $record)
- {
- return $record['level'] >= $this->actionLevel;
- }
- }
- }
- namespace Monolog\Handler
- {
- use Monolog\Logger;
- class StreamHandler extends AbstractProcessingHandler
- {
- protected $stream;
- protected $url;
- private $errorMessage;
- protected $filePermission;
- public function __construct($stream, $level = Logger::DEBUG, $bubble = true, $filePermission = null)
- {
- parent::__construct($level, $bubble);
- if (is_resource($stream)) {
- $this->stream = $stream;
- } else {
- $this->url = $stream;
- }
- $this->filePermission = $filePermission;
- }
- public function close()
- {
- if (is_resource($this->stream)) {
- fclose($this->stream);
- }
- $this->stream = null;
- }
- protected function write(array $record)
- {
- if (!is_resource($this->stream)) {
- if (!$this->url) {
- throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
- }
- $this->errorMessage = null;
- set_error_handler(array($this,'customErrorHandler'));
- $this->stream = fopen($this->url,'a');
- if ($this->filePermission !== null) {
- @chmod($this->url, $this->filePermission);
- }
- restore_error_handler();
- if (!is_resource($this->stream)) {
- $this->stream = null;
- throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
- }
- }
- fwrite($this->stream, (string) $record['formatted']);
- }
- private function customErrorHandler($code, $msg)
- {
- $this->errorMessage = preg_replace('{^fopen\(.*?\): }','', $msg);
- }
- }
- }
- namespace Monolog\Handler
- {
- use Monolog\Logger;
- class TestHandler extends AbstractProcessingHandler
- {
- protected $records = array();
- protected $recordsByLevel = array();
- public function getRecords()
- {
- return $this->records;
- }
- public function hasEmergency($record)
- {
- return $this->hasRecord($record, Logger::EMERGENCY);
- }
- public function hasAlert($record)
- {
- return $this->hasRecord($record, Logger::ALERT);
- }
- public function hasCritical($record)
- {
- return $this->hasRecord($record, Logger::CRITICAL);
- }
- public function hasError($record)
- {
- return $this->hasRecord($record, Logger::ERROR);
- }
- public function hasWarning($record)
- {
- return $this->hasRecord($record, Logger::WARNING);
- }
- public function hasNotice($record)
- {
- return $this->hasRecord($record, Logger::NOTICE);
- }
- public function hasInfo($record)
- {
- return $this->hasRecord($record, Logger::INFO);
- }
- public function hasDebug($record)
- {
- return $this->hasRecord($record, Logger::DEBUG);
- }
- public function hasEmergencyRecords()
- {
- return isset($this->recordsByLevel[Logger::EMERGENCY]);
- }
- public function hasAlertRecords()
- {
- return isset($this->recordsByLevel[Logger::ALERT]);
- }
- public function hasCriticalRecords()
- {
- return isset($this->recordsByLevel[Logger::CRITICAL]);
- }
- public function hasErrorRecords()
- {
- return isset($this->recordsByLevel[Logger::ERROR]);
- }
- public function hasWarningRecords()
- {
- return isset($this->recordsByLevel[Logger::WARNING]);
- }
- public function hasNoticeRecords()
- {
- return isset($this->recordsByLevel[Logger::NOTICE]);
- }
- public function hasInfoRecords()
- {
- return isset($this->recordsByLevel[Logger::INFO]);
- }
- public function hasDebugRecords()
- {
- return isset($this->recordsByLevel[Logger::DEBUG]);
- }
- protected function hasRecord($record, $level)
- {
- if (!isset($this->recordsByLevel[$level])) {
- return false;
- }
- if (is_array($record)) {
- $record = $record['message'];
- }
- foreach ($this->recordsByLevel[$level] as $rec) {
- if ($rec['message'] === $record) {
- return true;
- }
- }
- return false;
- }
- protected function write(array $record)
- {
- $this->recordsByLevel[$record['level']][] = $record;
- $this->records[] = $record;
- }
- }
- }
- namespace Psr\Log
- {
- interface LoggerInterface
- {
- public function emergency($message, array $context = array());
- public function alert($message, array $context = array());
- public function critical($message, array $context = array());
- public function error($message, array $context = array());
- public function warning($message, array $context = array());
- public function notice($message, array $context = array());
- public function info($message, array $context = array());
- public function debug($message, array $context = array());
- public function log($level, $message, array $context = array());
- }
- }
- namespace Monolog
- {
- use Monolog\Handler\HandlerInterface;
- use Monolog\Handler\StreamHandler;
- use Psr\Log\LoggerInterface;
- use Psr\Log\InvalidArgumentException;
- class Logger implements LoggerInterface
- {
- const DEBUG = 100;
- const INFO = 200;
- const NOTICE = 250;
- const WARNING = 300;
- const ERROR = 400;
- const CRITICAL = 500;
- const ALERT = 550;
- const EMERGENCY = 600;
- const API = 1;
- protected static $levels = array(
- 100 =>'DEBUG',
- 200 =>'INFO',
- 250 =>'NOTICE',
- 300 =>'WARNING',
- 400 =>'ERROR',
- 500 =>'CRITICAL',
- 550 =>'ALERT',
- 600 =>'EMERGENCY',
- );
- protected static $timezone;
- protected $name;
- protected $handlers;
- protected $processors;
- public function __construct($name, array $handlers = array(), array $processors = array())
- {
- $this->name = $name;
- $this->handlers = $handlers;
- $this->processors = $processors;
- }
- public function getName()
- {
- return $this->name;
- }
- public function pushHandler(HandlerInterface $handler)
- {
- array_unshift($this->handlers, $handler);
- }
- public function popHandler()
- {
- if (!$this->handlers) {
- throw new \LogicException('You tried to pop from an empty handler stack.');
- }
- return array_shift($this->handlers);
- }
- public function pushProcessor($callback)
- {
- if (!is_callable($callback)) {
- throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
- }
- array_unshift($this->processors, $callback);
- }
- public function popProcessor()
- {
- if (!$this->processors) {
- throw new \LogicException('You tried to pop from an empty processor stack.');
- }
- return array_shift($this->processors);
- }
- public function addRecord($level, $message, array $context = array())
- {
- if (!$this->handlers) {
- $this->pushHandler(new StreamHandler('php://stderr', static::DEBUG));
- }
- if (!static::$timezone) {
- static::$timezone = new \DateTimeZone(date_default_timezone_get() ?:'UTC');
- }
- $record = array('message'=> (string) $message,'context'=> $context,'level'=> $level,'level_name'=> static::getLevelName($level),'channel'=> $this->name,'datetime'=> \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone),'extra'=> array(),
- );
- $handlerKey = null;
- foreach ($this->handlers as $key => $handler) {
- if ($handler->isHandling($record)) {
- $handlerKey = $key;
- break;
- }
- }
- if (null === $handlerKey) {
- return false;
- }
- foreach ($this->processors as $processor) {
- $record = call_user_func($processor, $record);
- }
- while (isset($this->handlers[$handlerKey]) &&
- false === $this->handlers[$handlerKey]->handle($record)) {
- $handlerKey++;
- }
- return true;
- }
- public function addDebug($message, array $context = array())
- {
- return $this->addRecord(static::DEBUG, $message, $context);
- }
- public function addInfo($message, array $context = array())
- {
- return $this->addRecord(static::INFO, $message, $context);
- }
- public function addNotice($message, array $context = array())
- {
- return $this->addRecord(static::NOTICE, $message, $context);
- }
- public function addWarning($message, array $context = array())
- {
- return $this->addRecord(static::WARNING, $message, $context);
- }
- public function addError($message, array $context = array())
- {
- return $this->addRecord(static::ERROR, $message, $context);
- }
- public function addCritical($message, array $context = array())
- {
- return $this->addRecord(static::CRITICAL, $message, $context);
- }
- public function addAlert($message, array $context = array())
- {
- return $this->addRecord(static::ALERT, $message, $context);
- }
- public function addEmergency($message, array $context = array())
- {
- return $this->addRecord(static::EMERGENCY, $message, $context);
- }
- public static function getLevels()
- {
- return array_flip(static::$levels);
- }
- public static function getLevelName($level)
- {
- if (!isset(static::$levels[$level])) {
- throw new InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', array_keys(static::$levels)));
- }
- return static::$levels[$level];
- }
- public function isHandling($level)
- {
- $record = array('level'=> $level,
- );
- foreach ($this->handlers as $handler) {
- if ($handler->isHandling($record)) {
- return true;
- }
- }
- return false;
- }
- public function log($level, $message, array $context = array())
- {
- if (is_string($level) && defined(__CLASS__.'::'.strtoupper($level))) {
- $level = constant(__CLASS__.'::'.strtoupper($level));
- }
- return $this->addRecord($level, $message, $context);
- }
- public function debug($message, array $context = array())
- {
- return $this->addRecord(static::DEBUG, $message, $context);
- }
- public function info($message, array $context = array())
- {
- return $this->addRecord(static::INFO, $message, $context);
- }
- public function notice($message, array $context = array())
- {
- return $this->addRecord(static::NOTICE, $message, $context);
- }
- public function warn($message, array $context = array())
- {
- return $this->addRecord(static::WARNING, $message, $context);
- }
- public function warning($message, array $context = array())
- {
- return $this->addRecord(static::WARNING, $message, $context);
- }
- public function err($message, array $context = array())
- {
- return $this->addRecord(static::ERROR, $message, $context);
- }
- public function error($message, array $context = array())
- {
- return $this->addRecord(static::ERROR, $message, $context);
- }
- public function crit($message, array $context = array())
- {
- return $this->addRecord(static::CRITICAL, $message, $context);
- }
- public function critical($message, array $context = array())
- {
- return $this->addRecord(static::CRITICAL, $message, $context);
- }
- public function alert($message, array $context = array())
- {
- return $this->addRecord(static::ALERT, $message, $context);
- }
- public function emerg($message, array $context = array())
- {
- return $this->addRecord(static::EMERGENCY, $message, $context);
- }
- public function emergency($message, array $context = array())
- {
- return $this->addRecord(static::EMERGENCY, $message, $context);
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Configuration
- {
- interface ConfigurationInterface
- {
- public function getAliasName();
- public function allowArray();
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Configuration
- {
- abstract class ConfigurationAnnotation implements ConfigurationInterface
- {
- public function __construct(array $values)
- {
- foreach ($values as $k => $v) {
- if (!method_exists($this, $name ='set'.$k)) {
- throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this)));
- }
- $this->$name($v);
- }
- }
- }
- }
- namespace Symfony\Component\EventDispatcher
- {
- interface EventSubscriberInterface
- {
- public static function getSubscribedEvents();
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
- {
- use Doctrine\Common\Annotations\Reader;
- use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
- use Doctrine\Common\Util\ClassUtils;
- class ControllerListener implements EventSubscriberInterface
- {
- protected $reader;
- public function __construct(Reader $reader)
- {
- $this->reader = $reader;
- }
- public function onKernelController(FilterControllerEvent $event)
- {
- if (!is_array($controller = $event->getController())) {
- return;
- }
- $className = class_exists('Doctrine\Common\Util\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
- $object = new \ReflectionClass($className);
- $method = $object->getMethod($controller[1]);
- $classConfigurations = $this->getConfigurations($this->reader->getClassAnnotations($object));
- $methodConfigurations = $this->getConfigurations($this->reader->getMethodAnnotations($method));
- $configurations = array();
- foreach (array_merge(array_keys($classConfigurations), array_keys($methodConfigurations)) as $key) {
- if (!array_key_exists($key, $classConfigurations)) {
- $configurations[$key] = $methodConfigurations[$key];
- } elseif (!array_key_exists($key, $methodConfigurations)) {
- $configurations[$key] = $classConfigurations[$key];
- } else {
- if (is_array($classConfigurations[$key])) {
- if (!is_array($methodConfigurations[$key])) {
- throw new \UnexpectedValueException('Configurations should both be an array or both not be an array');
- }
- $configurations[$key] = array_merge($classConfigurations[$key], $methodConfigurations[$key]);
- } else {
- $configurations[$key] = $methodConfigurations[$key];
- }
- }
- }
- $request = $event->getRequest();
- foreach ($configurations as $key => $attributes) {
- $request->attributes->set($key, $attributes);
- }
- }
- protected function getConfigurations(array $annotations)
- {
- $configurations = array();
- foreach ($annotations as $configuration) {
- if ($configuration instanceof ConfigurationInterface) {
- if ($configuration->allowArray()) {
- $configurations['_'.$configuration->getAliasName()][] = $configuration;
- } else {
- $configurations['_'.$configuration->getAliasName()] = $configuration;
- }
- }
- }
- return $configurations;
- }
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::CONTROLLER =>'onKernelController',
- );
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
- {
- use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
- use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
- class HttpCacheListener implements EventSubscriberInterface
- {
- private $lastModifiedDates;
- private $etags;
- private $expressionLanguage;
- public function __construct()
- {
- $this->lastModifiedDates = new \SplObjectStorage();
- $this->etags = new \SplObjectStorage();
- }
- public function onKernelController(FilterControllerEvent $event)
- {
- $request = $event->getRequest();
- if (!$configuration = $request->attributes->get('_cache')) {
- return;
- }
- $response = new Response();
- $lastModifiedDate ='';
- if ($configuration->getLastModified()) {
- $lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
- $response->setLastModified($lastModifiedDate);
- }
- $etag ='';
- if ($configuration->getETag()) {
- $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
- $response->setETag($etag);
- }
- if ($response->isNotModified($request)) {
- $event->setController(function () use ($response) {
- return $response;
- });
- } else {
- if ($etag) {
- $this->etags[$request] = $etag;
- }
- if ($lastModifiedDate) {
- $this->lastModifiedDates[$request] = $lastModifiedDate;
- }
- }
- }
- public function onKernelResponse(FilterResponseEvent $event)
- {
- $request = $event->getRequest();
- if (!$configuration = $request->attributes->get('_cache')) {
- return;
- }
- $response = $event->getResponse();
- if (!$response->isSuccessful()) {
- return;
- }
- if (null !== $configuration->getSMaxAge()) {
- $response->setSharedMaxAge($configuration->getSMaxAge());
- }
- if (null !== $configuration->getMaxAge()) {
- $response->setMaxAge($configuration->getMaxAge());
- }
- if (null !== $configuration->getExpires()) {
- $date = \DateTime::createFromFormat('U', strtotime($configuration->getExpires()), new \DateTimeZone('UTC'));
- $response->setExpires($date);
- }
- if (null !== $configuration->getVary()) {
- $response->setVary($configuration->getVary());
- }
- if ($configuration->isPublic()) {
- $response->setPublic();
- }
- if (isset($this->lastModifiedDates[$request])) {
- $response->setLastModified($this->lastModifiedDates[$request]);
- unset($this->lastModifiedDates[$request]);
- }
- if (isset($this->etags[$request])) {
- $response->setETag($this->etags[$request]);
- unset($this->etags[$request]);
- }
- $event->setResponse($response);
- }
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::CONTROLLER =>'onKernelController',
- KernelEvents::RESPONSE =>'onKernelResponse',
- );
- }
- private function getExpressionLanguage()
- {
- if (null === $this->expressionLanguage) {
- if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
- throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
- }
- $this->expressionLanguage = new ExpressionLanguage();
- }
- return $this->expressionLanguage;
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
- {
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
- use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager;
- use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- class ParamConverterListener implements EventSubscriberInterface
- {
- protected $manager;
- public function __construct(ParamConverterManager $manager)
- {
- $this->manager = $manager;
- }
- public function onKernelController(FilterControllerEvent $event)
- {
- $controller = $event->getController();
- $request = $event->getRequest();
- $configurations = array();
- if ($configuration = $request->attributes->get('_converters')) {
- foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
- $configurations[$configuration->getName()] = $configuration;
- }
- }
- if (is_array($controller)) {
- $r = new \ReflectionMethod($controller[0], $controller[1]);
- } else {
- $r = new \ReflectionFunction($controller);
- }
- foreach ($r->getParameters() as $param) {
- if (!$param->getClass() || $param->getClass()->isInstance($request)) {
- continue;
- }
- $name = $param->getName();
- if (!isset($configurations[$name])) {
- $configuration = new ParamConverter(array());
- $configuration->setName($name);
- $configuration->setClass($param->getClass()->getName());
- $configurations[$name] = $configuration;
- } elseif (null === $configurations[$name]->getClass()) {
- $configurations[$name]->setClass($param->getClass()->getName());
- }
- $configurations[$name]->setIsOptional($param->isOptional());
- }
- $this->manager->apply($request, $configurations);
- }
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::CONTROLLER =>'onKernelController',
- );
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
- {
- use Sensio\Bundle\FrameworkExtraBundle\Security\ExpressionLanguage;
- use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Symfony\Component\ExpressionLanguage\Expression;
- use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
- use Symfony\Component\Security\Core\SecurityContextInterface;
- use Symfony\Component\Security\Core\Exception\AccessDeniedException;
- use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
- class SecurityListener implements EventSubscriberInterface
- {
- private $securityContext;
- private $language;
- private $trustResolver;
- private $roleHierarchy;
- public function __construct(SecurityContextInterface $securityContext = null, ExpressionLanguage $language = null, AuthenticationTrustResolverInterface $trustResolver = null, RoleHierarchyInterface $roleHierarchy = null)
- {
- $this->securityContext = $securityContext;
- $this->language = $language;
- $this->trustResolver = $trustResolver;
- $this->roleHierarchy = $roleHierarchy;
- }
- public function onKernelController(FilterControllerEvent $event)
- {
- $request = $event->getRequest();
- if (!$configuration = $request->attributes->get('_security')) {
- return;
- }
- if (null === $this->securityContext || null === $this->trustResolver) {
- throw new \LogicException('To use the @Security tag, you need to install the Symfony Security bundle.');
- }
- if (!$this->language->evaluate($configuration->getExpression(), $this->getVariables($request))) {
- throw new AccessDeniedException(sprintf('Expression "%s" denied access.', $configuration->getExpression()));
- }
- }
- private function getVariables(Request $request)
- {
- $token = $this->securityContext->getToken();
- if (null !== $this->roleHierarchy) {
- $roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
- } else {
- $roles = $token->getRoles();
- }
- $variables = array('token'=> $token,'user'=> $token->getUser(),'object'=> $request,'request'=> $request,'roles'=> array_map(function ($role) { return $role->getRole(); }, $roles),'trust_resolver'=> $this->trustResolver,'security_context'=> $this->securityContext,
- );
- return array_merge($request->attributes->all(), $variables);
- }
- public static function getSubscribedEvents()
- {
- return array(KernelEvents::CONTROLLER =>'onKernelController');
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\EventListener
- {
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
- use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
- use Symfony\Component\HttpKernel\KernelEvents;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Symfony\Component\HttpFoundation\StreamedResponse;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- class TemplateListener implements EventSubscriberInterface
- {
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- }
- public function onKernelController(FilterControllerEvent $event)
- {
- if (!is_array($controller = $event->getController())) {
- return;
- }
- $request = $event->getRequest();
- if (!$configuration = $request->attributes->get('_template')) {
- return;
- }
- if (!$configuration->getTemplate()) {
- $guesser = $this->container->get('sensio_framework_extra.view.guesser');
- $configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
- }
- $request->attributes->set('_template', $configuration->getTemplate());
- $request->attributes->set('_template_vars', $configuration->getVars());
- $request->attributes->set('_template_streamable', $configuration->isStreamable());
- if (!$configuration->getVars()) {
- $r = new \ReflectionObject($controller[0]);
- $vars = array();
- foreach ($r->getMethod($controller[1])->getParameters() as $param) {
- $vars[] = $param->getName();
- }
- $request->attributes->set('_template_default_vars', $vars);
- }
- }
- public function onKernelView(GetResponseForControllerResultEvent $event)
- {
- $request = $event->getRequest();
- $parameters = $event->getControllerResult();
- $templating = $this->container->get('templating');
- if (null === $parameters) {
- if (!$vars = $request->attributes->get('_template_vars')) {
- if (!$vars = $request->attributes->get('_template_default_vars')) {
- return;
- }
- }
- $parameters = array();
- foreach ($vars as $var) {
- $parameters[$var] = $request->attributes->get($var);
- }
- }
- if (!is_array($parameters)) {
- return $parameters;
- }
- if (!$template = $request->attributes->get('_template')) {
- return $parameters;
- }
- if (!$request->attributes->get('_template_streamable')) {
- $event->setResponse($templating->renderResponse($template, $parameters));
- } else {
- $callback = function () use ($templating, $template, $parameters) {
- return $templating->stream($template, $parameters);
- };
- $event->setResponse(new StreamedResponse($callback));
- }
- }
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::CONTROLLER => array('onKernelController', -128),
- KernelEvents::VIEW =>'onKernelView',
- );
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
- {
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
- use Symfony\Component\HttpFoundation\Request;
- interface ParamConverterInterface
- {
- public function apply(Request $request, ParamConverter $configuration);
- public function supports(ParamConverter $configuration);
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
- {
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use DateTime;
- class DateTimeParamConverter implements ParamConverterInterface
- {
- public function apply(Request $request, ParamConverter $configuration)
- {
- $param = $configuration->getName();
- if (!$request->attributes->has($param)) {
- return false;
- }
- $options = $configuration->getOptions();
- $value = $request->attributes->get($param);
- if (!$value && $configuration->isOptional()) {
- return false;
- }
- $date = isset($options['format'])
- ? DateTime::createFromFormat($options['format'], $value)
- : new DateTime($value);
- if (!$date) {
- throw new NotFoundHttpException('Invalid date given.');
- }
- $request->attributes->set($param, $date);
- return true;
- }
- public function supports(ParamConverter $configuration)
- {
- if (null === $configuration->getClass()) {
- return false;
- }
- return"DateTime"=== $configuration->getClass();
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
- {
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\HttpFoundation\Request;
- use Doctrine\Common\Persistence\ManagerRegistry;
- use Doctrine\ORM\NoResultException;
- class DoctrineParamConverter implements ParamConverterInterface
- {
- protected $registry;
- public function __construct(ManagerRegistry $registry = null)
- {
- $this->registry = $registry;
- }
- public function apply(Request $request, ParamConverter $configuration)
- {
- $name = $configuration->getName();
- $class = $configuration->getClass();
- $options = $this->getOptions($configuration);
- if (null === $request->attributes->get($name, false)) {
- $configuration->setIsOptional(true);
- }
- if (false === $object = $this->find($class, $request, $options, $name)) {
- if (false === $object = $this->findOneBy($class, $request, $options)) {
- if ($configuration->isOptional()) {
- $object = null;
- } else {
- throw new \LogicException('Unable to guess how to get a Doctrine instance from the request information.');
- }
- }
- }
- if (null === $object && false === $configuration->isOptional()) {
- throw new NotFoundHttpException(sprintf('%s object not found.', $class));
- }
- $request->attributes->set($name, $object);
- return true;
- }
- protected function find($class, Request $request, $options, $name)
- {
- if ($options['mapping'] || $options['exclude']) {
- return false;
- }
- $id = $this->getIdentifier($request, $options, $name);
- if (false === $id || null === $id) {
- return false;
- }
- if (isset($options['repository_method'])) {
- $method = $options['repository_method'];
- } else {
- $method ='find';
- }
- try {
- return $this->getManager($options['entity_manager'], $class)->getRepository($class)->$method($id);
- } catch (NoResultException $e) {
- return null;
- }
- }
- protected function getIdentifier(Request $request, $options, $name)
- {
- if (isset($options['id'])) {
- if (!is_array($options['id'])) {
- $name = $options['id'];
- } elseif (is_array($options['id'])) {
- $id = array();
- foreach ($options['id'] as $field) {
- $id[$field] = $request->attributes->get($field);
- }
- return $id;
- }
- }
- if ($request->attributes->has($name)) {
- return $request->attributes->get($name);
- }
- if ($request->attributes->has('id')) {
- return $request->attributes->get('id');
- }
- return false;
- }
- protected function findOneBy($class, Request $request, $options)
- {
- if (!$options['mapping']) {
- $keys = $request->attributes->keys();
- $options['mapping'] = $keys ? array_combine($keys, $keys) : array();
- }
- foreach ($options['exclude'] as $exclude) {
- unset($options['mapping'][$exclude]);
- }
- if (!$options['mapping']) {
- return false;
- }
- $criteria = array();
- $em = $this->getManager($options['entity_manager'], $class);
- $metadata = $em->getClassMetadata($class);
- foreach ($options['mapping'] as $attribute => $field) {
- if ($metadata->hasField($field) || ($metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field))) {
- $criteria[$field] = $request->attributes->get($attribute);
- }
- }
- if ($options['strip_null']) {
- $criteria = array_filter($criteria, function ($value) { return !is_null($value); });
- }
- if (!$criteria) {
- return false;
- }
- if (isset($options['repository_method'])) {
- $method = $options['repository_method'];
- } else {
- $method ='findOneBy';
- }
- try {
- return $em->getRepository($class)->$method($criteria);
- } catch (NoResultException $e) {
- return null;
- }
- }
- public function supports(ParamConverter $configuration)
- {
- if (null === $this->registry || !count($this->registry->getManagers())) {
- return false;
- }
- if (null === $configuration->getClass()) {
- return false;
- }
- $options = $this->getOptions($configuration);
- $em = $this->getManager($options['entity_manager'], $configuration->getClass());
- if (null === $em) {
- return false;
- }
- return ! $em->getMetadataFactory()->isTransient($configuration->getClass());
- }
- protected function getOptions(ParamConverter $configuration)
- {
- return array_replace(array('entity_manager'=> null,'exclude'=> array(),'mapping'=> array(),'strip_null'=> false,
- ), $configuration->getOptions());
- }
- private function getManager($name, $class)
- {
- if (null === $name) {
- return $this->registry->getManagerForClass($class);
- }
- return $this->registry->getManager($name);
- }
- }
- }
- namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter
- {
- use Symfony\Component\HttpFoundation\Request;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
- class ParamConverterManager
- {
- protected $converters = array();
- protected $namedConverters = array();
- public function apply(Request $request, $configurations)
- {
- if (is_object($configurations)) {
- $configurations = array($configurations);
- }
- foreach ($configurations as $configuration) {
- $this->applyConverter($request, $configuration);
- }
- }
- protected function applyConverter(Request $request, ConfigurationInterface $configuration)
- {
- $value = $request->attributes->get($configuration->getName());
- $className = $configuration->getClass();
- if (is_object($value) && $value instanceof $className) {
- return;
- }
- if ($converterName = $configuration->getConverter()) {
- if (!isset($this->namedConverters[$converterName])) {
- throw new \RuntimeException(sprintf("No converter named '%s' found for conversion of parameter '%s'.",
- $converterName, $configuration->getName()
- ));
- }
- $converter = $this->namedConverters[$converterName];
- if (!$converter->supports($configuration)) {
- throw new \RuntimeException(sprintf("Converter '%s' does not support conversion of parameter '%s'.",
- $converterName, $configuration->getName()
- ));
- }
- $converter->apply($request, $configuration);
- return;
- }
- foreach ($this->all() as $converter) {
- if ($converter->supports($configuration)) {
- if ($converter->apply($request, $configuration)) {
- return;
- }
- }
- }
- }
- public function add(ParamConverterInterface $converter, $priority = 0, $name = null)
- {
- if ($priority !== null) {
- if (!isset($this->converters[$priority])) {
- $this->converters[$priority] = array();
- }
- $this->converters[$priority][] = $converter;
- }
- if (null !== $name) {
- $this->namedConverters[$name] = $converter;
- }
- }
- public function all()
- {
- krsort($this->converters);
- $converters = array();
- foreach ($this->converters as $all) {
- $converters = array_merge($converters, $all);
- }
- return $converters;
- }
- }
- }
- namespace Symfony\Component\HttpKernel\Log
- {
- interface DebugLoggerInterface
- {
- public function getLogs();
- public function countErrors();
- }
- }
- namespace Symfony\Bridge\Monolog\Handler
- {
- use Monolog\Logger;
- use Monolog\Handler\TestHandler;
- use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
- class DebugHandler extends TestHandler implements DebugLoggerInterface
- {
- public function getLogs()
- {
- $records = array();
- foreach ($this->records as $record) {
- $records[] = array('timestamp'=> $record['datetime']->getTimestamp(),'message'=> $record['message'],'priority'=> $record['level'],'priorityName'=> $record['level_name'],'context'=> $record['context'],
- );
- }
- return $records;
- }
- public function countErrors()
- {
- $cnt = 0;
- $levels = array(Logger::ERROR, Logger::CRITICAL, Logger::ALERT, Logger::EMERGENCY);
- foreach ($levels as $level) {
- if (isset($this->recordsByLevel[$level])) {
- $cnt += count($this->recordsByLevel[$level]);
- }
- }
- return $cnt;
- }
- }
- }
- namespace Symfony\Component\HttpKernel\Log
- {
- use Psr\Log\LoggerInterface as PsrLogger;
- interface LoggerInterface extends PsrLogger
- {
- public function emerg($message, array $context = array());
- public function crit($message, array $context = array());
- public function err($message, array $context = array());
- public function warn($message, array $context = array());
- }
- }
- namespace Symfony\Bridge\Monolog
- {
- use Monolog\Logger as BaseLogger;
- use Symfony\Component\HttpKernel\Log\LoggerInterface;
- use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
- class Logger extends BaseLogger implements LoggerInterface, DebugLoggerInterface
- {
- public function emerg($message, array $context = array())
- {
- return parent::addRecord(BaseLogger::EMERGENCY, $message, $context);
- }
- public function crit($message, array $context = array())
- {
- return parent::addRecord(BaseLogger::CRITICAL, $message, $context);
- }
- public function err($message, array $context = array())
- {
- return parent::addRecord(BaseLogger::ERROR, $message, $context);
- }
- public function warn($message, array $context = array())
- {
- return parent::addRecord(BaseLogger::WARNING, $message, $context);
- }
- public function getLogs()
- {
- if ($logger = $this->getDebugLogger()) {
- return $logger->getLogs();
- }
- return array();
- }
- public function countErrors()
- {
- if ($logger = $this->getDebugLogger()) {
- return $logger->countErrors();
- }
- return 0;
- }
- private function getDebugLogger()
- {
- foreach ($this->handlers as $handler) {
- if ($handler instanceof DebugLoggerInterface) {
- return $handler;
- }
- }
- }
- }
- }
- namespace Assetic
- {
- interface ValueSupplierInterface
- {
- public function getValues();
- }
- }
- namespace Symfony\Bundle\AsseticBundle
- {
- use Assetic\ValueSupplierInterface;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class DefaultValueSupplier implements ValueSupplierInterface
- {
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- }
- public function getValues()
- {
- if (!$this->container->isScopeActive('request')) {
- return array();
- }
- $request = $this->container->get('request');
- return array('locale'=> $request->getLocale(),'env'=> $this->container->getParameter('kernel.environment'),
- );
- }
- }
- }
- namespace Assetic\Factory
- {
- use Assetic\Asset\AssetCollection;
- use Assetic\Asset\AssetCollectionInterface;
- use Assetic\Asset\AssetInterface;
- use Assetic\Asset\AssetReference;
- use Assetic\Asset\FileAsset;
- use Assetic\Asset\GlobAsset;
- use Assetic\Asset\HttpAsset;
- use Assetic\AssetManager;
- use Assetic\Factory\Worker\WorkerInterface;
- use Assetic\FilterManager;
- class AssetFactory
- {
- private $root;
- private $debug;
- private $output;
- private $workers;
- private $am;
- private $fm;
- public function __construct($root, $debug = false)
- {
- $this->root = rtrim($root,'/');
- $this->debug = $debug;
- $this->output ='assetic/*';
- $this->workers = array();
- }
- public function setDebug($debug)
- {
- $this->debug = $debug;
- }
- public function isDebug()
- {
- return $this->debug;
- }
- public function setDefaultOutput($output)
- {
- $this->output = $output;
- }
- public function addWorker(WorkerInterface $worker)
- {
- $this->workers[] = $worker;
- }
- public function getAssetManager()
- {
- return $this->am;
- }
- public function setAssetManager(AssetManager $am)
- {
- $this->am = $am;
- }
- public function getFilterManager()
- {
- return $this->fm;
- }
- public function setFilterManager(FilterManager $fm)
- {
- $this->fm = $fm;
- }
- public function createAsset($inputs = array(), $filters = array(), array $options = array())
- {
- if (!is_array($inputs)) {
- $inputs = array($inputs);
- }
- if (!is_array($filters)) {
- $filters = array($filters);
- }
- if (!isset($options['output'])) {
- $options['output'] = $this->output;
- }
- if (!isset($options['vars'])) {
- $options['vars'] = array();
- }
- if (!isset($options['debug'])) {
- $options['debug'] = $this->debug;
- }
- if (!isset($options['root'])) {
- $options['root'] = array($this->root);
- } else {
- if (!is_array($options['root'])) {
- $options['root'] = array($options['root']);
- }
- $options['root'][] = $this->root;
- }
- if (!isset($options['name'])) {
- $options['name'] = $this->generateAssetName($inputs, $filters, $options);
- }
- $asset = $this->createAssetCollection(array(), $options);
- $extensions = array();
- foreach ($inputs as $input) {
- if (is_array($input)) {
- $asset->add(call_user_func_array(array($this,'createAsset'), $input));
- } else {
- $asset->add($this->parseInput($input, $options));
- $extensions[pathinfo($input, PATHINFO_EXTENSION)] = true;
- }
- }
- foreach ($filters as $filter) {
- if ('?'!= $filter[0]) {
- $asset->ensureFilter($this->getFilter($filter));
- } elseif (!$options['debug']) {
- $asset->ensureFilter($this->getFilter(substr($filter, 1)));
- }
- }
- if (!empty($options['vars'])) {
- $toAdd = array();
- foreach ($options['vars'] as $var) {
- if (false !== strpos($options['output'],'{'.$var.'}')) {
- continue;
- }
- $toAdd[] ='{'.$var.'}';
- }
- if ($toAdd) {
- $options['output'] = str_replace('*','*.'.implode('.', $toAdd), $options['output']);
- }
- }
- if (1 == count($extensions) && !pathinfo($options['output'], PATHINFO_EXTENSION) && $extension = key($extensions)) {
- $options['output'] .='.'.$extension;
- }
- $asset->setTargetPath(str_replace('*', $options['name'], $options['output']));
- return $this->applyWorkers($asset);
- }
- public function generateAssetName($inputs, $filters, $options = array())
- {
- foreach (array_diff(array_keys($options), array('output','debug','root')) as $key) {
- unset($options[$key]);
- }
- ksort($options);
- return substr(sha1(serialize($inputs).serialize($filters).serialize($options)), 0, 7);
- }
- protected function parseInput($input, array $options = array())
- {
- if ('@'== $input[0]) {
- return $this->createAssetReference(substr($input, 1));
- }
- if (false !== strpos($input,'://') || 0 === strpos($input,'//')) {
- return $this->createHttpAsset($input, $options['vars']);
- }
- if (self::isAbsolutePath($input)) {
- if ($root = self::findRootDir($input, $options['root'])) {
- $path = ltrim(substr($input, strlen($root)),'/');
- } else {
- $path = null;
- }
- } else {
- $root = $this->root;
- $path = $input;
- $input = $this->root.'/'.$path;
- }
- if (false !== strpos($input,'*')) {
- return $this->createGlobAsset($input, $root, $options['vars']);
- }
- return $this->createFileAsset($input, $root, $path, $options['vars']);
- }
- protected function createAssetCollection(array $assets = array(), array $options = array())
- {
- return new AssetCollection($assets, array(), null, isset($options['vars']) ? $options['vars'] : array());
- }
- protected function createAssetReference($name)
- {
- if (!$this->am) {
- throw new \LogicException('There is no asset manager.');
- }
- return new AssetReference($this->am, $name);
- }
- protected function createHttpAsset($sourceUrl, $vars)
- {
- return new HttpAsset($sourceUrl, array(), false, $vars);
- }
- protected function createGlobAsset($glob, $root = null, $vars)
- {
- return new GlobAsset($glob, array(), $root, $vars);
- }
- protected function createFileAsset($source, $root = null, $path = null, $vars)
- {
- return new FileAsset($source, array(), $root, $path, $vars);
- }
- protected function getFilter($name)
- {
- if (!$this->fm) {
- throw new \LogicException('There is no filter manager.');
- }
- return $this->fm->get($name);
- }
- private function applyWorkers(AssetCollectionInterface $asset)
- {
- foreach ($asset as $leaf) {
- foreach ($this->workers as $worker) {
- $retval = $worker->process($leaf);
- if ($retval instanceof AssetInterface && $leaf !== $retval) {
- $asset->replaceLeaf($leaf, $retval);
- }
- }
- }
- foreach ($this->workers as $worker) {
- $retval = $worker->process($asset);
- if ($retval instanceof AssetInterface) {
- $asset = $retval;
- }
- }
- return $asset instanceof AssetCollectionInterface ? $asset : $this->createAssetCollection(array($asset));
- }
- private static function isAbsolutePath($path)
- {
- return'/'== $path[0] ||'\\'== $path[0] || (3 < strlen($path) && ctype_alpha($path[0]) && $path[1] ==':'&& ('\\'== $path[2] ||'/'== $path[2]));
- }
- private static function findRootDir($path, array $roots)
- {
- foreach ($roots as $root) {
- if (0 === strpos($path, $root)) {
- return $root;
- }
- }
- }
- }
- }
- namespace Symfony\Bundle\AsseticBundle\Factory
- {
- use Assetic\Factory\AssetFactory as BaseAssetFactory;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\HttpKernel\KernelInterface;
- class AssetFactory extends BaseAssetFactory
- {
- private $kernel;
- private $container;
- private $parameterBag;
- public function __construct(KernelInterface $kernel, ContainerInterface $container, ParameterBagInterface $parameterBag, $baseDir, $debug = false)
- {
- $this->kernel = $kernel;
- $this->container = $container;
- $this->parameterBag = $para…
Large files files are truncated, but you can click here to view the full file