PageRenderTime 332ms CodeModel.GetById 180ms app.highlight 80ms RepoModel.GetById 33ms app.codeStats 4ms

/app/cache/dev/classes.php

https://bitbucket.org/duncanheron/symfony-tutorial
PHP | 8822 lines | 6229 code | 1521 blank | 1072 comment | 595 complexity | 0d2bb55f7db890eff0eb137afe702290 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php  
   2
   3
   4
   5namespace Symfony\Bundle\FrameworkBundle\EventListener
   6{
   7
   8use Symfony\Component\DependencyInjection\ContainerInterface;
   9
  10use Symfony\Component\HttpKernel\HttpKernelInterface;
  11use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  12
  13
  14class SessionListener
  15{
  16    private $container;
  17    private $autoStart;
  18
  19    public function __construct(ContainerInterface $container, $autoStart = false)
  20    {
  21        $this->container = $container;
  22        $this->autoStart = $autoStart;
  23    }
  24
  25    public function onKernelRequest(GetResponseEvent $event)
  26    {
  27        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
  28            return;
  29        }
  30
  31        if (!$this->container->has('session')) {
  32            return;
  33        }
  34
  35        $request = $event->getRequest();
  36        if ($request->hasSession()) {
  37            return;
  38        }
  39
  40        $request->setSession($session = $this->container->get('session'));
  41
  42        if ($this->autoStart || $request->hasPreviousSession()) {
  43            $session->start();
  44        }
  45    }
  46}
  47}
  48 
  49
  50
  51
  52namespace Symfony\Component\HttpFoundation\SessionStorage
  53{
  54
  55
  56interface SessionStorageInterface
  57{
  58    
  59    function start();
  60
  61    
  62    function getId();
  63
  64    
  65    function read($key);
  66
  67    
  68    function remove($key);
  69
  70    
  71    function write($key, $data);
  72
  73    
  74    function regenerate($destroy = false);
  75}
  76}
  77 
  78
  79
  80
  81namespace Symfony\Component\HttpFoundation
  82{
  83
  84use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface;
  85
  86
  87class Session implements \Serializable
  88{
  89    protected $storage;
  90    protected $started;
  91    protected $attributes;
  92    protected $flashes;
  93    protected $oldFlashes;
  94    protected $locale;
  95    protected $defaultLocale;
  96    protected $closed;
  97
  98    
  99    public function __construct(SessionStorageInterface $storage, $defaultLocale = 'en')
 100    {
 101        $this->storage = $storage;
 102        $this->defaultLocale = $defaultLocale;
 103        $this->locale = $defaultLocale;
 104        $this->flashes = array();
 105        $this->oldFlashes = array();
 106        $this->attributes = array();
 107        $this->setPhpDefaultLocale($this->defaultLocale);
 108        $this->started = false;
 109        $this->closed = false;
 110    }
 111
 112    
 113    public function start()
 114    {
 115        if (true === $this->started) {
 116            return;
 117        }
 118
 119        $this->storage->start();
 120
 121        $attributes = $this->storage->read('_symfony2');
 122
 123        if (isset($attributes['attributes'])) {
 124            $this->attributes = $attributes['attributes'];
 125            $this->flashes = $attributes['flashes'];
 126            $this->locale = $attributes['locale'];
 127            $this->setPhpDefaultLocale($this->locale);
 128
 129                        $this->oldFlashes = $this->flashes;
 130        }
 131
 132        $this->started = true;
 133    }
 134
 135    
 136    public function has($name)
 137    {
 138        return array_key_exists($name, $this->attributes);
 139    }
 140
 141    
 142    public function get($name, $default = null)
 143    {
 144        return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
 145    }
 146
 147    
 148    public function set($name, $value)
 149    {
 150        if (false === $this->started) {
 151            $this->start();
 152        }
 153
 154        $this->attributes[$name] = $value;
 155    }
 156
 157    
 158    public function all()
 159    {
 160        return $this->attributes;
 161    }
 162
 163    
 164    public function replace(array $attributes)
 165    {
 166        if (false === $this->started) {
 167            $this->start();
 168        }
 169
 170        $this->attributes = $attributes;
 171    }
 172
 173    
 174    public function remove($name)
 175    {
 176        if (false === $this->started) {
 177            $this->start();
 178        }
 179
 180        if (array_key_exists($name, $this->attributes)) {
 181            unset($this->attributes[$name]);
 182        }
 183    }
 184
 185    
 186    public function clear()
 187    {
 188        if (false === $this->started) {
 189            $this->start();
 190        }
 191
 192        $this->attributes = array();
 193        $this->flashes = array();
 194        $this->setPhpDefaultLocale($this->locale = $this->defaultLocale);
 195    }
 196
 197    
 198    public function invalidate()
 199    {
 200        $this->clear();
 201        $this->storage->regenerate(true);
 202    }
 203
 204    
 205    public function migrate()
 206    {
 207        $this->storage->regenerate();
 208    }
 209
 210    
 211    public function getId()
 212    {
 213        if (false === $this->started) {
 214            $this->start();
 215        }
 216
 217        return $this->storage->getId();
 218    }
 219
 220    
 221    public function getLocale()
 222    {
 223        return $this->locale;
 224    }
 225
 226    
 227    public function setLocale($locale)
 228    {
 229        if (false === $this->started) {
 230            $this->start();
 231        }
 232
 233        $this->setPhpDefaultLocale($this->locale = $locale);
 234    }
 235
 236    
 237    public function getFlashes()
 238    {
 239        return $this->flashes;
 240    }
 241
 242    
 243    public function setFlashes($values)
 244    {
 245        if (false === $this->started) {
 246            $this->start();
 247        }
 248
 249        $this->flashes = $values;
 250        $this->oldFlashes = array();
 251    }
 252
 253    
 254    public function getFlash($name, $default = null)
 255    {
 256        return array_key_exists($name, $this->flashes) ? $this->flashes[$name] : $default;
 257    }
 258
 259    
 260    public function setFlash($name, $value)
 261    {
 262        if (false === $this->started) {
 263            $this->start();
 264        }
 265
 266        $this->flashes[$name] = $value;
 267        unset($this->oldFlashes[$name]);
 268    }
 269
 270    
 271    public function hasFlash($name)
 272    {
 273        if (false === $this->started) {
 274            $this->start();
 275        }
 276
 277        return array_key_exists($name, $this->flashes);
 278    }
 279
 280    
 281    public function removeFlash($name)
 282    {
 283        if (false === $this->started) {
 284            $this->start();
 285        }
 286
 287        unset($this->flashes[$name]);
 288    }
 289
 290    
 291    public function clearFlashes()
 292    {
 293        if (false === $this->started) {
 294            $this->start();
 295        }
 296
 297        $this->flashes = array();
 298        $this->oldFlashes = array();
 299    }
 300
 301    public function save()
 302    {
 303        if (false === $this->started) {
 304            $this->start();
 305        }
 306
 307        $this->flashes = array_diff_key($this->flashes, $this->oldFlashes);
 308
 309        $this->storage->write('_symfony2', array(
 310            'attributes' => $this->attributes,
 311            'flashes'    => $this->flashes,
 312            'locale'     => $this->locale,
 313        ));
 314    }
 315
 316    
 317    public function close()
 318    {
 319        $this->closed = true;
 320    }
 321
 322    public function __destruct()
 323    {
 324        if (true === $this->started && !$this->closed) {
 325            $this->save();
 326        }
 327    }
 328
 329    public function serialize()
 330    {
 331        return serialize(array($this->storage, $this->defaultLocale));
 332    }
 333
 334    public function unserialize($serialized)
 335    {
 336        list($this->storage, $this->defaultLocale) = unserialize($serialized);
 337        $this->attributes = array();
 338        $this->started = false;
 339    }
 340
 341    private function setPhpDefaultLocale($locale)
 342    {
 343                                try {
 344            if (class_exists('Locale', false)) {
 345                \Locale::setDefault($locale);
 346            }
 347        } catch (\Exception $e) {
 348        }
 349    }
 350}
 351}
 352 
 353
 354
 355
 356namespace Symfony\Component\HttpFoundation\SessionStorage
 357{
 358
 359
 360class NativeSessionStorage implements SessionStorageInterface
 361{
 362    static protected $sessionIdRegenerated = false;
 363    static protected $sessionStarted       = false;
 364
 365    protected $options;
 366
 367    
 368    public function __construct(array $options = array())
 369    {
 370        $cookieDefaults = session_get_cookie_params();
 371
 372        $this->options = array_merge(array(
 373            'lifetime' => $cookieDefaults['lifetime'],
 374            'path'     => $cookieDefaults['path'],
 375            'domain'   => $cookieDefaults['domain'],
 376            'secure'   => $cookieDefaults['secure'],
 377            'httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
 378        ), $options);
 379
 380                if (isset($this->options['name'])) {
 381            session_name($this->options['name']);
 382        }
 383    }
 384
 385    
 386    public function start()
 387    {
 388        if (self::$sessionStarted) {
 389            return;
 390        }
 391
 392        session_set_cookie_params(
 393            $this->options['lifetime'],
 394            $this->options['path'],
 395            $this->options['domain'],
 396            $this->options['secure'],
 397            $this->options['httponly']
 398        );
 399
 400                session_cache_limiter(false);
 401
 402        if (!ini_get('session.use_cookies') && isset($this->options['id']) && $this->options['id'] && $this->options['id'] != session_id()) {
 403            session_id($this->options['id']);
 404        }
 405
 406        session_start();
 407
 408        self::$sessionStarted = true;
 409    }
 410
 411    
 412    public function getId()
 413    {
 414        if (!self::$sessionStarted) {
 415            throw new \RuntimeException('The session must be started before reading its ID');
 416        }
 417
 418        return session_id();
 419    }
 420
 421    
 422    public function read($key, $default = null)
 423    {
 424        return array_key_exists($key, $_SESSION) ? $_SESSION[$key] : $default;
 425    }
 426
 427    
 428    public function remove($key)
 429    {
 430        $retval = null;
 431
 432        if (isset($_SESSION[$key])) {
 433            $retval = $_SESSION[$key];
 434            unset($_SESSION[$key]);
 435        }
 436
 437        return $retval;
 438    }
 439
 440    
 441    public function write($key, $data)
 442    {
 443        $_SESSION[$key] = $data;
 444    }
 445
 446    
 447    public function regenerate($destroy = false)
 448    {
 449        if (self::$sessionIdRegenerated) {
 450            return;
 451        }
 452
 453        session_regenerate_id($destroy);
 454
 455        self::$sessionIdRegenerated = true;
 456    }
 457}
 458}
 459 
 460
 461
 462
 463namespace Symfony\Component\Routing\Matcher
 464{
 465
 466use Symfony\Component\Routing\RequestContextAwareInterface;
 467
 468
 469interface UrlMatcherInterface extends RequestContextAwareInterface
 470{
 471    
 472    function match($pathinfo);
 473}
 474}
 475 
 476
 477
 478
 479namespace Symfony\Component\Routing\Generator
 480{
 481
 482use Symfony\Component\Routing\RequestContextAwareInterface;
 483
 484
 485interface UrlGeneratorInterface extends RequestContextAwareInterface
 486{
 487    
 488    function generate($name, $parameters = array(), $absolute = false);
 489}
 490}
 491 
 492
 493
 494
 495namespace Symfony\Component\Routing
 496{
 497
 498use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 499use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
 500
 501
 502interface RouterInterface extends UrlMatcherInterface, UrlGeneratorInterface
 503{
 504}
 505}
 506 
 507
 508
 509
 510namespace Symfony\Component\Routing\Matcher
 511{
 512
 513use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 514use Symfony\Component\Routing\Exception\ResourceNotFoundException;
 515use Symfony\Component\Routing\Route;
 516use Symfony\Component\Routing\RouteCollection;
 517use Symfony\Component\Routing\RequestContext;
 518
 519
 520class UrlMatcher implements UrlMatcherInterface
 521{
 522    protected $context;
 523
 524    private $routes;
 525
 526    
 527    public function __construct(RouteCollection $routes, RequestContext $context)
 528    {
 529        $this->routes = $routes;
 530        $this->context = $context;
 531    }
 532
 533    
 534    public function setContext(RequestContext $context)
 535    {
 536        $this->context = $context;
 537    }
 538
 539    
 540    public function getContext()
 541    {
 542        return $this->context;
 543    }
 544
 545    
 546    public function match($pathinfo)
 547    {
 548        $this->allow = array();
 549
 550        if ($ret = $this->matchCollection($pathinfo, $this->routes)) {
 551            return $ret;
 552        }
 553
 554        throw 0 < count($this->allow)
 555            ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow)))
 556            : new ResourceNotFoundException();
 557    }
 558
 559    protected function matchCollection($pathinfo, RouteCollection $routes)
 560    {
 561        $pathinfo = urldecode($pathinfo);
 562
 563        foreach ($routes as $name => $route) {
 564            if ($route instanceof RouteCollection) {
 565                if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
 566                    continue;
 567                }
 568
 569                if (!$ret = $this->matchCollection($pathinfo, $route)) {
 570                    continue;
 571                }
 572
 573                return $ret;
 574            }
 575
 576            $compiledRoute = $route->compile();
 577
 578                        if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
 579                continue;
 580            }
 581
 582            if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
 583                continue;
 584            }
 585
 586                        if ($req = $route->getRequirement('_method')) {
 587                                if ('HEAD' === $method = $this->context->getMethod()) {
 588                    $method = 'GET';
 589                }
 590
 591                if (!in_array($method, $req = explode('|', strtoupper($req)))) {
 592                    $this->allow = array_merge($this->allow, $req);
 593
 594                    continue;
 595                }
 596            }
 597
 598            return array_merge($this->mergeDefaults($matches, $route->getDefaults()), array('_route' => $name));
 599        }
 600    }
 601
 602    protected function mergeDefaults($params, $defaults)
 603    {
 604        $parameters = $defaults;
 605        foreach ($params as $key => $value) {
 606            if (!is_int($key)) {
 607                $parameters[$key] = rawurldecode($value);
 608            }
 609        }
 610
 611        return $parameters;
 612    }
 613}
 614}
 615 
 616
 617
 618
 619namespace Symfony\Component\Routing\Generator
 620{
 621
 622use Symfony\Component\Routing\Route;
 623use Symfony\Component\Routing\RouteCollection;
 624use Symfony\Component\Routing\RequestContext;
 625use Symfony\Component\Routing\Exception\InvalidParameterException;
 626use Symfony\Component\Routing\Exception\RouteNotFoundException;
 627use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
 628
 629
 630class UrlGenerator implements UrlGeneratorInterface
 631{
 632    protected $context;
 633    protected $decodedChars = array(
 634                '%2F' => '/',
 635    );
 636
 637    protected $routes;
 638    protected $cache;
 639
 640    
 641    public function __construct(RouteCollection $routes, RequestContext $context)
 642    {
 643        $this->routes = $routes;
 644        $this->context = $context;
 645        $this->cache = array();
 646    }
 647
 648    
 649    public function setContext(RequestContext $context)
 650    {
 651        $this->context = $context;
 652    }
 653
 654    
 655    public function getContext()
 656    {
 657        return $this->context;
 658    }
 659
 660    
 661    public function generate($name, $parameters = array(), $absolute = false)
 662    {
 663        if (null === $route = $this->routes->get($name)) {
 664            throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
 665        }
 666
 667        if (!isset($this->cache[$name])) {
 668            $this->cache[$name] = $route->compile();
 669        }
 670
 671        return $this->doGenerate($this->cache[$name]->getVariables(), $route->getDefaults(), $route->getRequirements(), $this->cache[$name]->getTokens(), $parameters, $name, $absolute);
 672    }
 673
 674    
 675    protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute)
 676    {
 677        $variables = array_flip($variables);
 678
 679        $originParameters = $parameters;
 680        $parameters = array_replace($this->context->getParameters(), $parameters);
 681        $tparams = array_replace($defaults, $parameters);
 682
 683                if ($diff = array_diff_key($variables, $tparams)) {
 684            throw new MissingMandatoryParametersException(sprintf('The "%s" route has some missing mandatory parameters ("%s").', $name, implode('", "', array_keys($diff))));
 685        }
 686
 687        $url = '';
 688        $optional = true;
 689        foreach ($tokens as $token) {
 690            if ('variable' === $token[0]) {
 691                if (false === $optional || !array_key_exists($token[3], $defaults) || (isset($parameters[$token[3]]) && (string) $parameters[$token[3]] != (string) $defaults[$token[3]])) {
 692                    if (!$isEmpty = in_array($tparams[$token[3]], array(null, '', false), true)) {
 693                                                if ($tparams[$token[3]] && !preg_match('#^'.$token[2].'$#', $tparams[$token[3]])) {
 694                            throw new InvalidParameterException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $tparams[$token[3]]));
 695                        }
 696                    }
 697
 698                    if (!$isEmpty || !$optional) {
 699                        $url = $token[1].strtr(rawurlencode($tparams[$token[3]]), $this->decodedChars).$url;
 700                    }
 701
 702                    $optional = false;
 703                }
 704            } elseif ('text' === $token[0]) {
 705                $url = $token[1].$url;
 706                $optional = false;
 707            }
 708        }
 709
 710        if (!$url) {
 711            $url = '/';
 712        }
 713
 714                $extra = array_diff_key($originParameters, $variables, $defaults);
 715        if ($extra && $query = http_build_query($extra)) {
 716            $url .= '?'.$query;
 717        }
 718
 719        $url = $this->context->getBaseUrl().$url;
 720
 721        if ($this->context->getHost()) {
 722            $scheme = $this->context->getScheme();
 723            if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme != $req) {
 724                $absolute = true;
 725                $scheme = $req;
 726            }
 727
 728            if ($absolute) {
 729                $port = '';
 730                if ('http' === $scheme && 80 != $this->context->getHttpPort()) {
 731                    $port = ':'.$this->context->getHttpPort();
 732                } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) {
 733                    $port = ':'.$this->context->getHttpsPort();
 734                }
 735
 736                $url = $scheme.'://'.$this->context->getHost().$port.$url;
 737            }
 738        }
 739
 740        return $url;
 741    }
 742}
 743}
 744 
 745
 746
 747
 748namespace Symfony\Component\Routing\Matcher
 749{
 750
 751
 752interface RedirectableUrlMatcherInterface
 753{
 754    
 755    function redirect($path, $route, $scheme = null);
 756}
 757}
 758 
 759
 760
 761
 762namespace Symfony\Component\Routing
 763{
 764
 765
 766interface RequestContextAwareInterface
 767{
 768    
 769    function setContext(RequestContext $context);
 770}
 771}
 772 
 773
 774
 775
 776namespace Symfony\Component\Routing
 777{
 778
 779
 780class RequestContext
 781{
 782    private $baseUrl;
 783    private $method;
 784    private $host;
 785    private $scheme;
 786    private $httpPort;
 787    private $httpsPort;
 788    private $parameters;
 789
 790    
 791    public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443)
 792    {
 793        $this->baseUrl = $baseUrl;
 794        $this->method = strtoupper($method);
 795        $this->host = $host;
 796        $this->scheme = strtolower($scheme);
 797        $this->httpPort = $httpPort;
 798        $this->httpsPort = $httpsPort;
 799        $this->parameters = array();
 800    }
 801
 802    
 803    public function getBaseUrl()
 804    {
 805        return $this->baseUrl;
 806    }
 807
 808    
 809    public function setBaseUrl($baseUrl)
 810    {
 811        $this->baseUrl = $baseUrl;
 812    }
 813
 814    
 815    public function getMethod()
 816    {
 817        return $this->method;
 818    }
 819
 820    
 821    public function setMethod($method)
 822    {
 823        $this->method = strtoupper($method);
 824    }
 825
 826    
 827    public function getHost()
 828    {
 829        return $this->host;
 830    }
 831
 832    
 833    public function setHost($host)
 834    {
 835        $this->host = $host;
 836    }
 837
 838    
 839    public function getScheme()
 840    {
 841        return $this->scheme;
 842    }
 843
 844    
 845    public function setScheme($scheme)
 846    {
 847        $this->scheme = strtolower($scheme);
 848    }
 849
 850    
 851    public function getHttpPort()
 852    {
 853        return $this->httpPort;
 854    }
 855
 856    
 857    public function setHttpPort($httpPort)
 858    {
 859        $this->httpPort = $httpPort;
 860    }
 861
 862    
 863    public function getHttpsPort()
 864    {
 865        return $this->httpsPort;
 866    }
 867
 868    
 869    public function setHttpsPort($httpsPort)
 870    {
 871        $this->httpsPort = $httpsPort;
 872    }
 873
 874    
 875    public function getParameters()
 876    {
 877        return $this->parameters;
 878    }
 879
 880    
 881    public function setParameters(array $parameters)
 882    {
 883        $this->parameters = $parameters;
 884
 885        return $this;
 886    }
 887
 888    
 889    public function getParameter($name)
 890    {
 891        return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
 892    }
 893
 894    
 895    public function hasParameter($name)
 896    {
 897        return array_key_exists($name, $this->parameters);
 898    }
 899
 900    
 901    public function setParameter($name, $parameter)
 902    {
 903        $this->parameters[$name] = $parameter;
 904    }
 905}
 906}
 907 
 908
 909
 910
 911namespace Symfony\Component\Routing
 912{
 913
 914use Symfony\Component\Config\Loader\LoaderInterface;
 915use Symfony\Component\Config\ConfigCache;
 916
 917
 918class Router implements RouterInterface
 919{
 920    protected $matcher;
 921    protected $generator;
 922    protected $defaults;
 923    protected $context;
 924    protected $loader;
 925    protected $collection;
 926    protected $resource;
 927    protected $options;
 928
 929    
 930    public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array())
 931    {
 932        $this->loader = $loader;
 933        $this->resource = $resource;
 934        $this->context = null === $context ? new RequestContext() : $context;
 935        $this->defaults = $defaults;
 936        $this->setOptions($options);
 937    }
 938
 939    
 940    public function setOptions(array $options)
 941    {
 942        $this->options = array(
 943            'cache_dir'              => null,
 944            'debug'                  => false,
 945            'generator_class'        => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
 946            'generator_base_class'   => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
 947            'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper',
 948            'generator_cache_class'  => 'ProjectUrlGenerator',
 949            'matcher_class'          => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
 950            'matcher_base_class'     => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
 951            'matcher_dumper_class'   => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper',
 952            'matcher_cache_class'    => 'ProjectUrlMatcher',
 953            'resource_type'          => null,
 954        );
 955
 956                $invalid = array();
 957        $isInvalid = false;
 958        foreach ($options as $key => $value) {
 959            if (array_key_exists($key, $this->options)) {
 960                $this->options[$key] = $value;
 961            } else {
 962                $isInvalid = true;
 963                $invalid[] = $key;
 964            }
 965        }
 966
 967        if ($isInvalid) {
 968            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('\', \'', $invalid)));
 969        }
 970    }
 971
 972    
 973    public function setOption($key, $value)
 974    {
 975        if (!array_key_exists($key, $this->options)) {
 976            throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
 977        }
 978
 979        $this->options[$key] = $value;
 980    }
 981
 982    
 983    public function getOption($key)
 984    {
 985        if (!array_key_exists($key, $this->options)) {
 986            throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
 987        }
 988
 989        return $this->options[$key];
 990    }
 991
 992    
 993    public function getRouteCollection()
 994    {
 995        if (null === $this->collection) {
 996            $this->collection = $this->loader->load($this->resource, $this->options['resource_type']);
 997        }
 998
 999        return $this->collection;
1000    }
1001
1002    
1003    public function setContext(RequestContext $context)
1004    {
1005        $this->context = $context;
1006
1007        $this->getMatcher()->setContext($context);
1008        $this->getGenerator()->setContext($context);
1009    }
1010
1011    
1012    public function getContext()
1013    {
1014        return $this->context;
1015    }
1016
1017    
1018    public function generate($name, $parameters = array(), $absolute = false)
1019    {
1020        return $this->getGenerator()->generate($name, $parameters, $absolute);
1021    }
1022
1023    
1024    public function match($url)
1025    {
1026        return $this->getMatcher()->match($url);
1027    }
1028
1029    
1030    public function getMatcher()
1031    {
1032        if (null !== $this->matcher) {
1033            return $this->matcher;
1034        }
1035
1036        if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) {
1037            return $this->matcher = new $this->options['matcher_class']($this->getRouteCollection(), $this->context, $this->defaults);
1038        }
1039
1040        $class = $this->options['matcher_cache_class'];
1041        $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
1042        if (!$cache->isFresh($class)) {
1043            $dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
1044
1045            $options = array(
1046                'class'      => $class,
1047                'base_class' => $this->options['matcher_base_class'],
1048            );
1049
1050            $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
1051        }
1052
1053        require_once $cache;
1054
1055        return $this->matcher = new $class($this->context, $this->defaults);
1056    }
1057
1058    
1059    public function getGenerator()
1060    {
1061        if (null !== $this->generator) {
1062            return $this->generator;
1063        }
1064
1065        if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) {
1066            return $this->generator = new $this->options['generator_class']($this->getRouteCollection(), $this->context, $this->defaults);
1067        }
1068
1069        $class = $this->options['generator_cache_class'];
1070        $cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
1071        if (!$cache->isFresh($class)) {
1072            $dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
1073
1074            $options = array(
1075                'class'      => $class,
1076                'base_class' => $this->options['generator_base_class'],
1077            );
1078
1079            $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources());
1080        }
1081
1082        require_once $cache;
1083
1084        return $this->generator = new $class($this->context, $this->defaults);
1085    }
1086}
1087}
1088 
1089
1090
1091
1092namespace Symfony\Bundle\FrameworkBundle\Routing
1093{
1094
1095use Symfony\Component\Routing\Matcher\UrlMatcher;
1096use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
1097
1098
1099class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
1100{
1101    
1102    public function redirect($path, $route, $scheme = null)
1103    {
1104        return array(
1105            '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction',
1106            'path'        => $path,
1107            'permanent'   => true,
1108            'scheme'      => $scheme,
1109            'httpPort'    => $this->context->getHttpPort(),
1110            'httpsPort'   => $this->context->getHttpsPort(),
1111            '_route'      => $route,
1112        );
1113    }
1114}
1115}
1116 
1117
1118
1119
1120namespace Symfony\Bundle\FrameworkBundle\Routing
1121{
1122
1123use Symfony\Component\Routing\Router as BaseRouter;
1124use Symfony\Component\Routing\RequestContext;
1125use Symfony\Component\DependencyInjection\ContainerInterface;
1126
1127
1128class Router extends BaseRouter
1129{
1130    private $container;
1131
1132    
1133    public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, array $defaults = array())
1134    {
1135        $this->container = $container;
1136
1137        $this->resource = $resource;
1138        $this->context = null === $context ? new RequestContext() : $context;
1139        $this->defaults = $defaults;
1140        $this->setOptions($options);
1141    }
1142
1143    
1144    public function getRouteCollection()
1145    {
1146        if (null === $this->collection) {
1147            $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
1148        }
1149
1150        return $this->collection;
1151    }
1152}
1153}
1154 
1155
1156
1157
1158namespace Symfony\Bundle\FrameworkBundle\Templating
1159{
1160
1161use Symfony\Component\DependencyInjection\ContainerInterface;
1162
1163
1164class GlobalVariables
1165{
1166    protected $container;
1167
1168    public function __construct(ContainerInterface $container)
1169    {
1170        $this->container = $container;
1171    }
1172
1173    
1174    public function getSecurity()
1175    {
1176        if ($this->container->has('security.context')) {
1177            return $this->container->get('security.context');
1178        }
1179    }
1180
1181    
1182    public function getUser()
1183    {
1184        if (!$security = $this->getSecurity()) {
1185            return;
1186        }
1187
1188        if (!$token = $security->getToken()) {
1189            return;
1190        }
1191
1192        $user = $token->getUser();
1193        if (!is_object($user)) {
1194            return;
1195        }
1196
1197        return $user;
1198    }
1199
1200    
1201    public function getRequest()
1202    {
1203        if ($this->container->has('request') && $request = $this->container->get('request')) {
1204            return $request;
1205        }
1206    }
1207
1208    
1209    public function getSession()
1210    {
1211        if ($request = $this->getRequest()) {
1212            return $request->getSession();
1213        }
1214    }
1215
1216    
1217    public function getEnvironment()
1218    {
1219        return $this->container->getParameter('kernel.environment');
1220    }
1221
1222    
1223    public function getDebug()
1224    {
1225        return (Boolean) $this->container->getParameter('kernel.debug');
1226    }
1227}
1228}
1229 
1230
1231
1232
1233namespace Symfony\Bundle\FrameworkBundle\Templating
1234{
1235
1236use Symfony\Component\Templating\EngineInterface as BaseEngineInterface;
1237use Symfony\Component\HttpFoundation\Response;
1238
1239
1240interface EngineInterface extends BaseEngineInterface
1241{
1242    
1243    function renderResponse($view, array $parameters = array(), Response $response = null);
1244}
1245}
1246 
1247
1248
1249
1250namespace Symfony\Component\Templating
1251{
1252
1253
1254interface TemplateNameParserInterface
1255{
1256    
1257    function parse($name);
1258}
1259}
1260 
1261
1262
1263
1264namespace Symfony\Component\Templating
1265{
1266
1267use Symfony\Component\Templating\TemplateReferenceInterface;
1268use Symfony\Component\Templating\TemplateReference;
1269
1270
1271class TemplateNameParser implements TemplateNameParserInterface
1272{
1273    
1274    public function parse($name)
1275    {
1276        if ($name instanceof TemplateReferenceInterface) {
1277            return $name;
1278        }
1279
1280        $engine = null;
1281        if (false !== $pos = strrpos($name, '.')) {
1282            $engine = substr($name, $pos + 1);
1283        }
1284
1285        return new TemplateReference($name, $engine);
1286    }
1287}
1288}
1289 
1290
1291
1292
1293namespace Symfony\Component\Templating
1294{
1295
1296
1297interface EngineInterface
1298{
1299    
1300    function render($name, array $parameters = array());
1301
1302    
1303    function exists($name);
1304
1305    
1306    function supports($name);
1307}
1308}
1309 
1310
1311
1312
1313namespace Symfony\Component\Config
1314{
1315
1316
1317interface FileLocatorInterface
1318{
1319    
1320    function locate($name, $currentPath = null, $first = true);
1321}
1322}
1323 
1324
1325
1326
1327namespace Symfony\Component\Templating
1328{
1329
1330
1331interface TemplateReferenceInterface
1332{
1333    
1334    function all();
1335
1336    
1337    function set($name, $value);
1338
1339    
1340    function get($name);
1341
1342    
1343    function getPath();
1344
1345    
1346    function getLogicalName();
1347}
1348}
1349 
1350
1351
1352
1353namespace Symfony\Component\Templating
1354{
1355
1356
1357class TemplateReference implements TemplateReferenceInterface
1358{
1359    protected $parameters;
1360
1361    public function __construct($name = null, $engine = null)
1362    {
1363        $this->parameters = array(
1364            'name'   => $name,
1365            'engine' => $engine,
1366        );
1367    }
1368
1369    public function __toString()
1370    {
1371        return $this->getLogicalName();
1372    }
1373
1374    
1375    public function set($name, $value)
1376    {
1377        if (array_key_exists($name, $this->parameters)) {
1378            $this->parameters[$name] = $value;
1379        } else {
1380            throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
1381        }
1382
1383        return $this;
1384    }
1385
1386    
1387    public function get($name)
1388    {
1389        if (array_key_exists($name, $this->parameters)) {
1390            return $this->parameters[$name];
1391        }
1392
1393        throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
1394    }
1395
1396    
1397    public function all()
1398    {
1399        return $this->parameters;
1400    }
1401
1402    
1403    public function getPath()
1404    {
1405        return $this->parameters['name'];
1406    }
1407
1408    
1409    public function getLogicalName()
1410    {
1411        return $this->parameters['name'];
1412    }
1413}
1414}
1415 
1416
1417
1418
1419namespace Symfony\Bundle\FrameworkBundle\Templating
1420{
1421
1422use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
1423
1424
1425class TemplateReference extends BaseTemplateReference
1426{
1427    public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
1428    {
1429        $this->parameters = array(
1430            'bundle'     => $bundle,
1431            'controller' => $controller,
1432            'name'       => $name,
1433            'format'     => $format,
1434            'engine'     => $engine,
1435        );
1436    }
1437
1438    
1439    public function getPath()
1440    {
1441        $controller = str_replace('\\', '/', $this->get('controller'));
1442
1443        $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
1444
1445        return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
1446    }
1447
1448    
1449    public function getLogicalName()
1450    {
1451        return sprintf('%s:%s:%s.%s.%s', $this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
1452    }
1453}
1454}
1455 
1456
1457
1458
1459namespace Symfony\Bundle\FrameworkBundle\Templating
1460{
1461
1462use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;
1463use Symfony\Component\Templating\TemplateReferenceInterface;
1464use Symfony\Component\HttpKernel\KernelInterface;
1465
1466
1467class TemplateNameParser extends BaseTemplateNameParser
1468{
1469    protected $kernel;
1470    protected $cache;
1471
1472    
1473    public function __construct(KernelInterface $kernel)
1474    {
1475        $this->kernel = $kernel;
1476        $this->cache = array();
1477    }
1478
1479    
1480    public function parse($name)
1481    {
1482        if ($name instanceof TemplateReferenceInterface) {
1483            return $name;
1484        } else if (isset($this->cache[$name])) {
1485            return $this->cache[$name];
1486        }
1487
1488                $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')));
1489
1490        if (false !== strpos($name, '..')) {
1491            throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
1492        }
1493
1494        $parts = explode(':', $name);
1495        if (3 !== count($parts)) {
1496            throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
1497        }
1498
1499        $elements = explode('.', $parts[2]);
1500        if (3 > count($elements)) {
1501            throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name));
1502        }
1503        $engine = array_pop($elements);
1504        $format = array_pop($elements);
1505
1506        $template = new TemplateReference($parts[0], $parts[1], implode('.', $elements), $format, $engine);
1507
1508        if ($template->get('bundle')) {
1509            try {
1510                $this->kernel->getBundle($template->get('bundle'));
1511            } catch (\Exception $e) {
1512                throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e);
1513            }
1514        }
1515
1516        return $this->cache[$name] = $template;
1517    }
1518
1519    
1520    public function parseFromFilename($file)
1521    {
1522        $parts = explode('/', strtr($file, '\\', '/'));
1523
1524        $elements = explode('.', array_pop($parts));
1525        if (3 > count($elements)) {
1526            return false;
1527        }
1528        $engine = array_pop($elements);
1529        $format = array_pop($elements);
1530
1531        return new TemplateReference('', implode('/', $parts), implode('.', $elements), $format, $engine);
1532    }
1533
1534}
1535}
1536 
1537
1538
1539
1540namespace Symfony\Bundle\FrameworkBundle\Templating\Loader
1541{
1542
1543use Symfony\Component\Config\FileLocatorInterface;
1544use Symfony\Component\Templating\TemplateReferenceInterface;
1545
1546
1547class TemplateLocator implements FileLocatorInterface
1548{
1549    protected $locator;
1550    protected $path;
1551    protected $cache;
1552
1553    
1554    public function __construct(FileLocatorInterface $locator, $cacheDir = null)
1555    {
1556        if (null !== $cacheDir && file_exists($cache = $cacheDir.'/templates.php')) {
1557            $this->cache = require $cache;
1558        }
1559
1560        $this->locator = $locator;
1561    }
1562
1563    
1564    public function locate($template, $currentPath = null, $first = true)
1565    {
1566        if (!$template instanceof TemplateReferenceInterface) {
1567            throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
1568        }
1569
1570        $key = $template->getLogicalName();
1571
1572        if (isset($this->cache[$key])) {
1573            return $this->cache[$key];
1574        }
1575
1576        try {
1577            return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
1578        } catch (\InvalidArgumentException $e) {
1579            throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e);
1580        }
1581    }
1582}
1583}
1584 
1585
1586
1587
1588namespace Symfony\Component\HttpFoundation
1589{
1590
1591
1592class ParameterBag
1593{
1594    protected $parameters;
1595
1596    
1597    public function __construct(array $parameters = array())
1598    {
1599        $this->parameters = $parameters;
1600    }
1601
1602    
1603    public function all()
1604    {
1605        return $this->parameters;
1606    }
1607
1608    
1609    public function keys()
1610    {
1611        return array_keys($this->parameters);
1612    }
1613
1614    
1615    public function replace(array $parameters = array())
1616    {
1617        $this->parameters = $parameters;
1618    }
1619
1620    
1621    public function add(array $parameters = array())
1622    {
1623        $this->parameters = array_replace($this->parameters, $parameters);
1624    }
1625
1626    
1627    public function get($path, $default = null, $deep = false)
1628    {
1629        if (!$deep || false === $pos = strpos($path, '[')) {
1630            return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
1631        }
1632
1633        $root = substr($path, 0, $pos);
1634        if (!array_key_exists($root, $this->parameters)) {
1635            return $default;
1636        }
1637
1638        $value = $this->parameters[$root];
1639        $currentKey = null;
1640        for ($i=$pos,$c=strlen($path); $i<$c; $i++) {
1641            $char = $path[$i];
1642
1643            if ('[' === $char) {
1644                if (null !== $currentKey) {
1645                    throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
1646                }
1647
1648                $currentKey = '';
1649            } else if (']' === $char) {
1650                if (null === $currentKey) {
1651                    throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
1652                }
1653
1654                if (!is_array($value) || !array_key_exists($currentKey, $value)) {
1655                    return $default;
1656                }
1657
1658                $value = $value[$currentKey];
1659                $currentKey = null;
1660            } else {
1661                if (null === $currentKey) {
1662                    throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
1663                }
1664
1665                $currentKey .= $char;
1666            }
1667        }
1668
1669        if (null !== $currentKey) {
1670            throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
1671        }
1672
1673        return $value;
1674    }
1675
1676    
1677    public function set($key, $value)
1678    {
1679        $this->parameters[$key] = $value;
1680    }
1681
1682    
1683    public function has($key)
1684    {
1685        return array_key_exists($key, $this->parameters);
1686    }
1687
1688    
1689    public function remove($key)
1690    {
1691        unset($this->parameters[$key]);
1692    }
1693
1694    
1695    public function getAlpha($key, $default = '', $deep = false)
1696    {
1697        return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
1698    }
1699
1700    
1701    public function getAlnum($key, $default = '', $deep = false)
1702    {
1703        return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
1704    }
1705
1706    
1707    public function getDigits($key, $default = '', $deep = false)
1708    {
1709        return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default, $deep));
1710    }
1711
1712    
1713    public function getInt($key, $default = 0, $deep = false)
1714    {
1715        return (int) $this->get($key, $default, $deep);
1716    }
1717}
1718}
1719 
1720
1721
1722
1723namespace Symfony\Component\HttpFoundation
1724{
1725
1726
1727class HeaderBag
1728{
1729    protected $headers;
1730    protected $cacheControl;
1731
1732    
1733    public function __construct(array $headers = array())
1734    {
1735        $this->cacheControl = array();
1736        $this->headers = array();
1737        foreach ($headers as $key => $values) {
1738            $this->set($key, $values);
1739        }
1740    }
1741
1742    
1743    public function __toString()
1744    {
1745        if (!$this->headers) {
1746            return '';
1747        }
1748
1749        $beautifier = function ($name) {
1750            return preg_replace_callback('/\-(.)/', function ($match) { return '-'.strtoupper($match[1]); }, ucfirst($name));
1751        };
1752
1753        $max = max(array_map('strlen', array_keys($this->headers))) + 1;
1754        $content = '';
1755        ksort($this->headers);
1756        foreach ($this->headers as $name => $values) {
1757            foreach ($values as $value) {
1758                $content .= sprintf("%-{$max}s %s\r\n", $beautifier($name).':', $value);
1759            }
1760        }
1761
1762        return $content;
1763    }
1764
1765    
1766    public function all()
1767    {
1768        return $this->headers;
1769    }
1770
1771    
1772    public function keys()
1773    {
1774        return array_keys($this->headers);
1775    }
1776
1777    
1778    public function replace(array $headers = array())
1779    {
1780        $this->headers = array();
1781        $this->add($headers);
1782    }
1783
1784    
1785    public function add(array $headers)
1786    {
1787        foreach ($headers as $key => $values) {
1788            $this->set($key, $values);
1789        }
1790    }
1791
1792    
1793    public function get($key, $default = null, $first = true)
1794    {
1795        $key = strtr(strtolower($key), '_', '-');
1796
1797        if (!array_key_exists($key, $this->headers)) {
1798            if (null === $default) {
1799                return $first ? null : array();
1800            }
1801
1802            return $first ? $default : array($default);
1803        }
1804
1805        if ($first) {
1806            return count($this->headers[$key]) ? $this->headers[$key][0] : $default;
1807        }
1808
1809        return $this->headers[$key];
1810    }
1811
1812    
1813    public function set($key, $values, $replace = true)
1814    {
1815        $key = strtr(strtolower($key), '_', '-');
1816
1817        $values = (array) $values;
1818
1819        if (true === $replace || !isset($this->headers[$key])) {
1820            $this->headers[$key] = $values;
1821        } else {
1822            $this->headers[$key] = array_merge($this->headers[$key], $values);
1823        }
1824
1825        if ('cache-control' === $key) {
1826            $this->cacheControl = $this->parseCacheControl($values[0]);
1827        }
1828    }
1829
1830    
1831    public function has($key)
1832    {
1833        return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
1834    }
1835
1836    
1837    public function contains($key, $value)
1838    {
1839        return in_array($value, $this->get($key, null, false));
1840    }
1841
1842    
1843    public function remove($key)
1844    {
1845        $key = strtr(strtolower($key), '_', '-');
1846
1847        unset($this->headers[$key]);
1848
1849        if ('cache-control' === $key) {
1850            $this->cacheControl = array();
1851        }
1852    }
1853
1854    
1855    public function getDate($key, \DateTime $default = null)
1856    {
1857        if (null === $value = $this->get($key)) {
1858            return $default;
1859        }
1860
1861        if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
1862            throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
1863        }
1864
1865        return $date;
1866    }
1867
1868    public function addCacheControlDirective($key, $value = true)
1869    {
1870        $this->cacheControl[$key] = $value;
1871
1872        $this->set('Cache-Control', $this->getCacheControlHeader());
1873    }
1874
1875    public function hasCacheControlDirective($key)
1876    {
1877        return array_key_exists($key, $this->cacheControl);
1878    }
1879
1880    public function getCacheControlDirective($key)
1881    {
1882        return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
1883    }
1884
1885    public function removeCacheControlDirective($key)
1886    {
1887        unset($this->cacheControl[$key]);
1888
1889        $this->set('Cache-Control', $this->getCacheControlHeader());
1890    }
1891
1892    protected function getCacheControlHeader()
1893    {
1894        $parts = array();
1895        ksort($this->cacheControl);
1896        foreach ($this->cacheControl as $key => $value) {
1897            if (true === $value) {
1898                $parts[] = $key;
1899            } else {
1900                if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
1901                    $value = '"'.$value.'"';
1902                }
1903
1904                $parts[] = "$key=$value";
1905            }
1906        }
1907
1908        return implode(', ', $parts);
1909    }
1910
1911    
1912    protected function parseCacheControl($header)
1913    {
1914        $cacheControl = array();
1915        preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
1916        foreach ($matches as $match) {
1917            $cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true);
1918        }
1919
1920        return $cacheControl;
1921    }
1922}
1923}
1924 
1925
1926
1927
1928namespace Symfony\Component\HttpFoundation
1929{
1930
1931use Symfony\Component\HttpFoundation\File\UploadedFile;
1932
1933
1934class FileBag extends ParameterBag
1935{
1936    static private $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
1937
1938    
1939    public function __construct(array $parameters = array())
1940    {
1941        $this->replace($parameters);
1942    }
1943
1944    
1945    public function replace(array $files = array())
1946    {
1947        $this->parameters = array();
1948        $this->add($files);
1949    }
1950
1951    
1952    public function set($key, $value)
1953    {
1954        if (is_array($value) || $value instanceof UploadedFile) {
1955            parent::set($key, $this->convertFileInformation($value));
1956        } else {
1957            throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
1958        }
1959    }
1960
1961    
1962    public function add(array $files = array())
1963    {
1964        foreach ($files as $key => $file) {
1965            $this->set($key, $file);
1966        }
1967    }
1968
1969    
1970    protected function convertFileInformation($file)
1971    {
1972        if ($file instanceof UploadedFile) {
1973            return $file;
1974        }
1975
1976        $file = $this->fixPhpFilesArray($file);
1977        if (is_array($file)) {
1978            $keys = array_keys($file);
1979            sort($keys);
1980
1981            if ($keys == self::$fileKeys) {
1982                if (UPLOAD_ERR_NO_FILE == $file['error']) {
1983                    $file = null;
1984                } else {
1985                    $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
1986                }
1987            } else {
1988                $file = array_map(array($this, 'convertFileInformation'), $file);
1989            }
1990        }
1991
1992        return $file;
1993    }
1994
1995    
1996    protected function fixPhpFilesArray($data)
1997    {
1998        if (!is_array($data)) {
1999            return $data;
2000        }
2001
2002        $keys = array_keys($data);
2003        sort($keys);
2004
2005        if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
2006            return $data;
2007        }
2008
2009        $files = $data;
2010        foreach (self::$fileKeys as $k) {
2011            unset($files[$k]);
2012        }
2013
2014        foreach (array_keys($data['name']) as $key) {
2015            $files[$key] = $this->fixPhpFilesArray(array(
2016                'error'    => $data['error'][$key],
2017                'name'     => $data['name'][$key],
2018                'type'     => $data['type'][$key],
2019                'tmp_name' => $data['tmp_name'][$key],
2020                'size'     => $data['size'][$key]
2021            ));
2022        }
2023
2024        return $files;
2025    }
2026}
2027}
2028 
2029
2030
2031
2032namespace Symfony\Component\HttpFoundation
2033{
2034
2035
2036class ServerBag extends ParameterBag
2037{
2038    public function getHeaders()
2039    {
2040        $headers = array();
2041        foreach ($this->parameters as $key => $value) {
2042            if ('HTTP_' === substr($key, 0, 5)) {
2043                $headers[substr($key, 5)] = $value;
2044            }
2045                        elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
2046                $headers[$key] = $this->parameters[$key];
2047            }
2048        }
2049
2050                if (isset($this->parameters['PHP_AUTH_USER'])) {
2051            $pass = isset($this->parameters['PHP_AUTH_PW']) ? $this->parameters['PHP_AUTH_PW'] : '';
2052            $headers['AUTHORIZATION'] = 'Basic '.base64_encode($this->parameters['PHP_AUTH_USER'].':'.$pass);
2053        }
2054
2055        return $headers;
2056    }
2057}
2058}
2059 
2060
2061
2062
2063namespace Symfony\Component\HttpFoundation
2064{
2065
2066
2067class Request
2068{
2069    static protected $trustProxy = false;
2070
2071    
2072    public $attributes;
2073
2074    
2075    public $request;
2076
2077    
2078    public $query;
2079
2080    
2081    public $server;
2082
2083    
2084    public $files;
2085
2086    
2087    public $cookies;
2088
2089    
2090    public $headers;
2091
2092    protected $content;
2093    protected $languages;
2094    protected $charsets;
2095    protected $acceptableContentTypes;
2096    protected $pathInfo;
2097    protected $requestUri;
2098    protected $baseUrl;
2099    protected $basePath;
2100    protected $method;
2101    protected $format;
2102    protected $session;
2103
2104    static protected $formats;
2105
2106    
2107    public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
2108    {
2109        $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
2110    }
2111
2112    
2113    public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
2114    {
2115        $this->request = new ParameterBag($request);
2116        $this->query = new ParameterBag($query);
2117        $this->attributes = new ParameterBag($attributes);
2118        $this->cookies = new ParameterBag($cookies);
2119        $this->

Large files files are truncated, but you can click here to view the full file