Exemple #1
0
 /**
  * Add api classes through this method.
  *
  * All the public methods that do not start with _ (underscore)
  * will be will be exposed as the public api by default.
  *
  * All the protected methods that do not start with _ (underscore)
  * will exposed as protected api which will require authentication
  *
  * @param string $className       name of the service class
  * @param string $resourcePath    optional url prefix for mapping, uses
  *                                lowercase version of the class name when
  *                                not specified
  *
  * @return null
  *
  * @throws Exception when supplied with invalid class name
  */
 public function addAPIClass($className, $resourcePath = null)
 {
     try {
         if ($this->productionMode && is_null($this->cached)) {
             $routes = $this->cache->get('routes');
             if (isset($routes) && is_array($routes)) {
                 $this->apiVersionMap = $routes['apiVersionMap'];
                 unset($routes['apiVersionMap']);
                 Routes::fromArray($routes);
                 $this->cached = true;
             } else {
                 $this->cached = false;
             }
         }
         if (isset(Scope::$classAliases[$className])) {
             $className = Scope::$classAliases[$className];
         }
         if (!$this->cached) {
             $maxVersionMethod = '__getMaximumSupportedVersion';
             if (class_exists($className)) {
                 if (method_exists($className, $maxVersionMethod)) {
                     $max = $className::$maxVersionMethod();
                     for ($i = 1; $i <= $max; $i++) {
                         $this->apiVersionMap[$className][$i] = $className;
                     }
                 } else {
                     $this->apiVersionMap[$className][1] = $className;
                 }
             }
             //versioned api
             if (false !== ($index = strrpos($className, '\\'))) {
                 $name = substr($className, 0, $index) . '\\v{$version}' . substr($className, $index);
             } else {
                 if (false !== ($index = strrpos($className, '_'))) {
                     $name = substr($className, 0, $index) . '_v{$version}' . substr($className, $index);
                 } else {
                     $name = 'v{$version}\\' . $className;
                 }
             }
             for ($version = $this->apiMinimumVersion; $version <= $this->apiVersion; $version++) {
                 $versionedClassName = str_replace('{$version}', $version, $name);
                 if (class_exists($versionedClassName)) {
                     Routes::addAPIClass($versionedClassName, Util::getResourcePath($className, $resourcePath), $version);
                     if (method_exists($versionedClassName, $maxVersionMethod)) {
                         $max = $versionedClassName::$maxVersionMethod();
                         for ($i = $version; $i <= $max; $i++) {
                             $this->apiVersionMap[$className][$i] = $versionedClassName;
                         }
                     } else {
                         $this->apiVersionMap[$className][$version] = $versionedClassName;
                     }
                 } elseif (isset($this->apiVersionMap[$className][$version])) {
                     Routes::addAPIClass($this->apiVersionMap[$className][$version], Util::getResourcePath($className, $resourcePath), $version);
                 }
             }
         }
     } catch (Exception $e) {
         $e = new Exception("addAPIClass('{$className}') failed. " . $e->getMessage(), $e->getCode(), $e);
         $this->setSupportedFormats('JsonFormat');
         $this->message($e);
     }
 }
 /**
  * Add api classes through this method.
  *
  * All the public methods that do not start with _ (underscore)
  * will be will be exposed as the public api by default.
  *
  * All the protected methods that do not start with _ (underscore)
  * will exposed as protected api which will require authentication
  *
  * @param string $className
  *            name of the service class
  * @param string $resourcePath
  *            optional url prefix for mapping, uses
  *            lowercase version of the class name when not specified
  *
  * @throws Exception when supplied with invalid class name
  */
 public function addAPIClass($className, $resourcePath = null)
 {
     $this->loadCache();
     if (!$this->cached) {
         $foundClass = array();
         if (class_exists($className)) {
             $foundClass[$className] = $className;
         }
         //versioned api
         if (false !== ($index = strrpos($className, '\\'))) {
             $name = substr($className, 0, $index) . '\\v{$version}' . substr($className, $index);
         } else {
             if (false !== ($index = strrpos($className, '_'))) {
                 $name = substr($className, 0, $index) . '_v{$version}' . substr($className, $index);
             } else {
                 $name = 'v{$version}\\' . $className;
             }
         }
         for ($version = $this->apiMinimumVersion; $version <= $this->apiVersion; $version++) {
             $versionedClassName = str_replace('{$version}', $version, $name);
             if (class_exists($versionedClassName)) {
                 $this->generateMap($versionedClassName, Util::getResourcePath($className, $resourcePath, "v{$version}/"));
                 $foundClass[$className] = $versionedClassName;
             } elseif (isset($foundClass[$className])) {
                 $this->generateMap($foundClass[$className], Util::getResourcePath($className, $resourcePath, "v{$version}/"));
             }
         }
     }
 }
Exemple #3
0
 /**
  * Add api classes through this method.
  *
  * All the public methods that do not start with _ (underscore)
  * will be will be exposed as the public api by default.
  *
  * All the protected methods that do not start with _ (underscore)
  * will exposed as protected api which will require authentication
  *
  * @param string $className       name of the service class
  * @param string $resourcePath    optional url prefix for mapping, uses
  *                                lowercase version of the class name when
  *                                not specified
  *
  * @return null
  *
  * @throws Exception when supplied with invalid class name
  */
 public function addAPIClass($className, $resourcePath = null)
 {
     try {
         if ($this->productionMode && is_null($this->cached)) {
             $routes = $this->cache->get('routes');
             if (isset($routes) && is_array($routes)) {
                 Routes::fromArray($routes);
                 $this->cached = true;
             } else {
                 $this->cached = false;
             }
         }
         if (isset(Util::$classAliases[$className])) {
             $className = Util::$classAliases[$className];
         }
         if (!$this->cached) {
             $foundClass = array();
             if (class_exists($className)) {
                 $foundClass[$className] = $className;
             }
             //versioned api
             if (false !== ($index = strrpos($className, '\\'))) {
                 $name = substr($className, 0, $index) . '\\v{$version}' . substr($className, $index);
             } else {
                 if (false !== ($index = strrpos($className, '_'))) {
                     $name = substr($className, 0, $index) . '_v{$version}' . substr($className, $index);
                 } else {
                     $name = 'v{$version}\\' . $className;
                 }
             }
             for ($version = $this->apiMinimumVersion; $version <= $this->apiVersion; $version++) {
                 $versionedClassName = str_replace('{$version}', $version, $name);
                 if (class_exists($versionedClassName)) {
                     Routes::addAPIClass($versionedClassName, Util::getResourcePath($className, $resourcePath, "v{$version}/"));
                     $foundClass[$className] = $versionedClassName;
                 } elseif (isset($foundClass[$className])) {
                     Routes::addAPIClass($foundClass[$className], Util::getResourcePath($className, $resourcePath, "v{$version}/"));
                 }
             }
         }
     } catch (Exception $e) {
         $e = new Exception("addAPIClass('{$className}') failed. " . $e->getMessage(), $e->getCode(), $e);
         $this->setSupportedFormats('JsonFormat');
         $this->message($e);
     }
 }