logger = $logger; $this->enabled = (Boolean) $enabled; $this->type = strtolower($type); $this->mapping = $mapping; } /** * Creates a new instance of XSendFile Factory according to the application * configuration. * * @param Application $app * @return XSendFileFactory */ public static function create(Application $app) { $conf = $app['conf']->get('xsendfile'); $mapping = []; if (isset($conf['mapping'])) { $mapping = $conf['mapping']; } return new self($app['monolog'], $conf['enabled'], $conf['type'], $mapping); } /** * Returns a new instance of XSendFileModeInterface. * * @return null|ModeInterface * * @throws InvalidArgumentException if mode type is unknown */ public function getMode($throwException = false, $forceMode = false) { if (false === $this->enabled && true !== $forceMode) { return new NullMode(); } switch ($this->type) { case 'nginx': case 'sendfile': case 'xaccel': case 'xaccelredirect': case 'x-accel': case 'x-accel-redirect': if (2 >= count($this->mapping)) { $this->logger->error('Invalid xsendfile mapping configuration.'); if ($throwException) { throw new RuntimeException('Mapping is not set up.'); } } return new NginxMode($this->mapping); case 'apache': case 'apache2': case 'xsendfile': return new ApacheMode($this->mapping); default: $this->logger->error('Invalid xsendfile type configuration.'); if ($throwException) { throw new InvalidArgumentException(sprintf( 'Invalid xsendfile type value "%s"', $this->type )); } return new NullMode(); } } /** * @return Boolean */ public function isXSendFileModeEnabled() { return $this->enabled; } }