Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • Symfony\Component\Yaml\Tests\A
  • Symfony\Component\Yaml\Tests\B
  • Symfony\Component\Yaml\Tests\DumperTest
  • Symfony\Component\Yaml\Tests\InlineTest
  • Symfony\Component\Yaml\Tests\ParseExceptionTest
  • Symfony\Component\Yaml\Tests\ParserTest
  • Symfony\Component\Yaml\Tests\YamlTest
  • Overview
  • Namespace
  • Function
  • Tree
  1: <?php
  2: 
  3: /*
  4:  * This file is part of the Symfony package.
  5:  *
  6:  * (c) Fabien Potencier <fabien@symfony.com>
  7:  *
  8:  * For the full copyright and license information, please view the LICENSE
  9:  * file that was distributed with this source code.
 10:  */
 11: 
 12: namespace Symfony\Component\HttpFoundation\Session\Attribute;
 13: 
 14: /**
 15:  * This class provides structured storage of session attributes using
 16:  * a name spacing character in the key.
 17:  *
 18:  * @author Drak <drak@zikula.org>
 19:  */
 20: class NamespacedAttributeBag extends AttributeBag
 21: {
 22:     /**
 23:      * Namespace character.
 24:      *
 25:      * @var string
 26:      */
 27:     private $namespaceCharacter;
 28: 
 29:     /**
 30:      * Constructor.
 31:      *
 32:      * @param string $storageKey         Session storage key.
 33:      * @param string $namespaceCharacter Namespace character to use in keys.
 34:      */
 35:     public function __construct($storageKey = '_sf2_attributes', $namespaceCharacter = '/')
 36:     {
 37:         $this->namespaceCharacter = $namespaceCharacter;
 38:         parent::__construct($storageKey);
 39:     }
 40: 
 41:     /**
 42:      * {@inheritdoc}
 43:      */
 44:     public function has($name)
 45:     {
 46:         $attributes = $this->resolveAttributePath($name);
 47:         $name = $this->resolveKey($name);
 48: 
 49:         if (null === $attributes) {
 50:             return false;
 51:         }
 52: 
 53:         return array_key_exists($name, $attributes);
 54:     }
 55: 
 56:     /**
 57:      * {@inheritdoc}
 58:      */
 59:     public function get($name, $default = null)
 60:     {
 61:         $attributes = $this->resolveAttributePath($name);
 62:         $name = $this->resolveKey($name);
 63: 
 64:         if (null === $attributes) {
 65:             return $default;
 66:         }
 67: 
 68:         return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
 69:     }
 70: 
 71:     /**
 72:      * {@inheritdoc}
 73:      */
 74:     public function set($name, $value)
 75:     {
 76:         $attributes = & $this->resolveAttributePath($name, true);
 77:         $name = $this->resolveKey($name);
 78:         $attributes[$name] = $value;
 79:     }
 80: 
 81:     /**
 82:      * {@inheritdoc}
 83:      */
 84:     public function remove($name)
 85:     {
 86:         $retval = null;
 87:         $attributes = & $this->resolveAttributePath($name);
 88:         $name = $this->resolveKey($name);
 89:         if (null !== $attributes && array_key_exists($name, $attributes)) {
 90:             $retval = $attributes[$name];
 91:             unset($attributes[$name]);
 92:         }
 93: 
 94:         return $retval;
 95:     }
 96: 
 97:     /**
 98:      * Resolves a path in attributes property and returns it as a reference.
 99:      *
100:      * This method allows structured namespacing of session attributes.
101:      *
102:      * @param string $name         Key name
103:      * @param bool   $writeContext Write context, default false
104:      *
105:      * @return array
106:      */
107:     protected function &resolveAttributePath($name, $writeContext = false)
108:     {
109:         $array = & $this->attributes;
110:         $name = (strpos($name, $this->namespaceCharacter) === 0) ? substr($name, 1) : $name;
111: 
112:         // Check if there is anything to do, else return
113:         if (!$name) {
114:             return $array;
115:         }
116: 
117:         $parts = explode($this->namespaceCharacter, $name);
118:         if (count($parts) < 2) {
119:             if (!$writeContext) {
120:                 return $array;
121:             }
122: 
123:             $array[$parts[0]] = array();
124: 
125:             return $array;
126:         }
127: 
128:         unset($parts[count($parts)-1]);
129: 
130:         foreach ($parts as $part) {
131:             if (null !== $array && !array_key_exists($part, $array)) {
132:                 $array[$part] = $writeContext ? array() : null;
133:             }
134: 
135:             $array = & $array[$part];
136:         }
137: 
138:         return $array;
139:     }
140: 
141:     /**
142:      * Resolves the key from the name.
143:      *
144:      * This is the last part in a dot separated string.
145:      *
146:      * @param string $name
147:      *
148:      * @return string
149:      */
150:     protected function resolveKey($name)
151:     {
152:         if (false !== $pos = strrpos($name, $this->namespaceCharacter)) {
153:             $name = substr($name, $pos+1);
154:         }
155: 
156:         return $name;
157:     }
158: }
159: 
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen