Esempio n. 1
0
 /**
  * Identify API method name without version suffix by its reflection.
  *
  * @param ReflectionMethod|string $method Method name or method reflection.
  * @return string Method name without version suffix on success.
  * @throws InvalidArgumentException When method name is invalid API resource method.
  */
 public function getMethodNameWithoutVersionSuffix($method)
 {
     if ($method instanceof ReflectionMethod) {
         $methodNameWithSuffix = $method->getName();
     } else {
         $methodNameWithSuffix = $method;
     }
     $regularExpression = $this->getMethodNameRegularExpression();
     if (preg_match($regularExpression, $methodNameWithSuffix, $methodMatches)) {
         $methodName = $methodMatches[1];
         return $methodName;
     }
     throw new InvalidArgumentException(sprintf('"%s" is an invalid API resource method.', $methodNameWithSuffix));
 }
Esempio n. 2
0
 /**
  * Extract method deprecation policy "use method" data.
  *
  * @param ReflectionMethod $methodReflection
  * @param string $useMethod
  * @param array $deprecationPolicy
  * @throws LogicException
  */
 protected function _extractDeprecationPolicyUseMethod(ReflectionMethod $methodReflection, $useMethod, &$deprecationPolicy)
 {
     $invalidFormatMessage = sprintf('The "%s" method has invalid format of Deprecation policy. ' . 'Accepted formats are createV1, catalogProduct::createV1 ' . 'and Mage_Catalog_Webapi_ProductController::createV1.', $methodReflection->getDeclaringClass()->getName() . '::' . $methodReflection->getName());
     /** Add information about what method should be used instead of deprecated/removed one. */
     /**
      * Description is expected in one of the following formats:
      * - Mage_Catalog_Webapi_ProductController::createV1
      * - catalogProduct::createV1
      * - createV1
      */
     $useMethodParts = explode('::', $useMethod);
     switch (count($useMethodParts)) {
         case 2:
             try {
                 /** Support of: Mage_Catalog_Webapi_ProductController::createV1 */
                 $resourceName = $this->_helper->translateResourceName($useMethodParts[0]);
             } catch (InvalidArgumentException $e) {
                 /** Support of: catalogProduct::createV1 */
                 $resourceName = $useMethodParts[0];
             }
             $deprecationPolicy['use_resource'] = $resourceName;
             $methodName = $useMethodParts[1];
             break;
         case 1:
             $methodName = $useMethodParts[0];
             /** If resource was not specified, current one should be used. */
             $deprecationPolicy['use_resource'] = $this->_helper->translateResourceName($methodReflection->getDeclaringClass()->getName());
             break;
         default:
             throw new LogicException($invalidFormatMessage);
             break;
     }
     try {
         $methodWithoutVersion = $this->getMethodNameWithoutVersionSuffix($methodName);
     } catch (Exception $e) {
         throw new LogicException($invalidFormatMessage);
     }
     $deprecationPolicy['use_method'] = $methodWithoutVersion;
     $methodVersion = str_replace($methodWithoutVersion, '', $methodName);
     $deprecationPolicy['use_version'] = ucfirst($methodVersion);
 }
Esempio n. 3
0
 /**
  * Identify API method version by its reflection.
  *
  * @param ReflectionMethod $methodReflection
  * @return string|bool Method version with prefix on success.
  *      false is returned in case when method should not be exposed via API.
  */
 protected function _getMethodVersion(ReflectionMethod $methodReflection)
 {
     $methodVersion = false;
     $methodNameWithSuffix = $methodReflection->getName();
     $regularExpression = $this->_helper->getMethodNameRegularExpression();
     if (preg_match($regularExpression, $methodNameWithSuffix, $methodMatches)) {
         $resourceNamePosition = 2;
         $methodVersion = ucfirst($methodMatches[$resourceNamePosition]);
     }
     return $methodVersion;
 }
Esempio n. 4
0
 /**
  * Retrieve method full documentation description.
  *
  * @param ReflectionMethod $method
  * @return string
  */
 protected function extractMethodDescription(ReflectionMethod $method)
 {
     $methodReflection = new MethodReflection($method->getDeclaringClass()->getName(), $method->getName());
     $docBlock = $methodReflection->getDocBlock();
     return $this->_typeProcessor->getDescription($docBlock);
 }
 /**
  * Retrieve method full documentation description.
  *
  * @param ReflectionMethod $method
  * @return string
  */
 protected function extractMethodDescription(ReflectionMethod $method)
 {
     $methodReflection = new MethodReflection($method->getDeclaringClass()->getName(), $method->getName());
     $docBlock = $methodReflection->getDocBlock();
     if (!$docBlock) {
         throw new \LogicException('The docBlock of the method ' . $method->getDeclaringClass()->getName() . '::' . $method->getName() . ' is empty.');
     }
     return $this->_typeProcessor->getDescription($docBlock);
 }