/**
  * @param ContainerBuilder $container
  * @return array    method => direction => service_id
  * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  */
 protected function findAllMethods(ContainerBuilder $container)
 {
     $arrTaggedMethods = $container->findTaggedServiceIds('bwc_component_jwt_api.method');
     $arrMethods = array();
     foreach ($arrTaggedMethods as $id => $attributes) {
         if (count($attributes) > 1) {
             throw new InvalidConfigurationException(sprintf("Service '%s' has more then one bwc_component_jwt_api.method tag", $id));
         }
         $attr = array_shift($attributes);
         if (!isset($attr['method'])) {
             throw new InvalidConfigurationException(sprintf("Service '%s' missing method attribute in bwc_component_jwt_api.method tag", $id));
         }
         if (!isset($attr['direction'])) {
             throw new InvalidConfigurationException(sprintf("Service '%s' missing direction attribute in bwc_component_jwt_api.method tag", $id));
         }
         if (!Directions::isValid($attr['direction'])) {
             throw new InvalidConfigurationException(sprintf("Service '%s' has invalid direction attribute value in bwc_component_jwt_api.method tag", $id));
         }
         if (isset($arrMethods[$attr['method']][$attr['direction']])) {
             throw new InvalidConfigurationException(sprintf("Service '%s' declared as method '%s' direction '%s' but service '%s' already registered for same method and direction", $id, $attr['method'], $attr['direction'], $arrMethods[$attr['method']][$attr['direction']]));
         }
         $arrMethods[$attr['method']][$attr['direction']] = $id;
     }
     // foreach tagged method
     return $arrMethods;
 }
示例#2
0
 /**
  * @param string $direction
  * @param string $issuer
  * @param string $method
  * @param string|null $instance
  * @param mixed $data
  * @param string|null $inResponseTo
  * @throws \InvalidArgumentException
  * @return MethodJwt
  */
 public static function create($direction, $issuer, $method, $instance = null, $data = null, $inResponseTo = null)
 {
     if (!Directions::isValid($direction)) {
         throw new \InvalidArgumentException(sprintf("Invalid direction value '%s'", $direction));
     }
     $payload = array(JwtClaim::ISSUER => $issuer, JwtClaim::ISSUED_AT => DateTime::now(), JwtClaim::TYPE => self::PAYLOAD_TYPE, MethodClaims::DIRECTION => $direction, MethodClaims::METHOD => $method);
     if ($instance) {
         $payload[MethodClaims::INSTANCE] = $instance;
     }
     if ($data) {
         $payload[MethodClaims::DATA] = $data;
     }
     if ($inResponseTo) {
         $payload[MethodClaims::IN_RESPONSE_TO] = $inResponseTo;
     }
     $result = new MethodJwt(array(), $payload);
     return $result;
 }