getRoute() public method

Returns a route and replaces tokenized parts of the string with the passed params
public getRoute ( $name, array $params = [] ) : mixed
$name
$params array
return mixed
 /**
  * Returns a route and replaces tokenized parts of the string with
  * the passed params
  *
  * @param       $name
  * @param array $params
  *
  * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
  * based on the parent chain
  * GET /api/v2/groups.json
  * GET /api/v2/users/{user_id}/groups.json
  *
  * @throws \Exception
  */
 public function getRoute($name, array $params = [])
 {
     $lastChained = $this->getLatestChainedParameter([self::class]);
     $chainableRoutes = ['findAll', 'find', 'create', 'delete', 'assignable'];
     if (empty($lastChained) || !in_array($name, $chainableRoutes)) {
         return parent::getRoute($name, $params);
     }
     $chainedResourceId = reset($lastChained);
     $chainedResourceNames = array_keys($lastChained);
     $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
     if ($name === 'assignable' && $chainedResourceName === 'groups') {
         return "{$chainedResourceName}/{$chainedResourceId}/memberships/assignable.json";
     }
     if ($name === 'create' && $chainedResourceName === 'users') {
         return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
     }
     if (in_array($name, ['find', 'delete']) && $chainedResourceName === 'users') {
         return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}/{$params['id']}.json";
     }
     if ($name === 'findAll') {
         if ($chainedResourceName === 'groups') {
             return "{$chainedResourceName}/{$chainedResourceId}/memberships.json";
         } elseif ($chainedResourceName === 'users') {
             return "{$chainedResourceName}/{$chainedResourceId}/group_memberships.json";
         }
     }
     throw new RouteException('Route not found.');
 }
 /**
  * Returns a route and replaces tokenized parts of the string with
  * the passed params
  *
  * @param       $name
  * @param array $params
  *
  * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
  * based on the parent chain
  * GET /api/v2/groups.json
  * GET /api/v2/users/{user_id}/groups.json
  *
  * @throws \Exception
  */
 public function getRoute($name, array $params = [])
 {
     $lastChained = $this->getLatestChainedParameter([self::class]);
     if (empty($lastChained) || !in_array($name, ['findAll', 'find', 'create', 'delete'])) {
         return parent::getRoute($name, $params);
     }
     $chainedResourceId = reset($lastChained);
     $chainedResourceNames = array_keys($lastChained);
     $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
     if ($name === 'findAll') {
         if (in_array($chainedResourceName, ['users', 'organizations'])) {
             return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
         }
         return "{$this->resourceName}.json";
     } elseif (in_array($name, ['find', 'delete'])) {
         if ($chainedResourceName === 'users') {
             return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}/{$params['id']}.json";
         }
         return "{$this->resourceName}/{$params['id']}.json";
     } elseif ($name === 'create') {
         if ($chainedResourceName === 'users') {
             return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
         }
         return "{$this->resourceName}.json";
     }
 }
 /**
  * Returns a route and replaces tokenized parts of the string with
  * the passed params
  *
  * @param       $name
  * @param array $params
  *
  * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
  * based on the parent chain
  * /api/v2/sessions.json
  * /api/v2/users/{userId}/sessions.json
  *
  * @throws \Exception
  */
 public function getRoute($name, array $params = [])
 {
     $userId = $this->getChainedParameter(Users::class);
     if (in_array($name, ['delete', 'deleteUserSessionss', 'find', 'findAll']) && !is_null($userId)) {
         if ($name === 'findAll') {
             return "users/{$userId}/sessions.json";
         }
         $params = $this->addChainedParametersToParams($params, ['userId' => Users::class]);
     }
     return parent::getRoute($name, $params);
 }
示例#4
0
 /**
  * Returns a route and replaces tokenized parts of the string with
  * the passed params
  *
  * @param       $name
  * @param array $params
  *
  * @return mixed Any of the following formats based on the parent chain
  *              tickets/{id}/tags.json
  *              topics/{id}/tags.json
  *              organizations/{id}/tags.json
  *              users/{id}/tags.json
  *
  * @throws \Exception
  */
 public function getRoute($name, array $params = [])
 {
     $allowedRoutes = ['update', 'find', 'create', 'delete'];
     if (!in_array($name, $allowedRoutes)) {
         return parent::getRoute($name, $params);
     }
     $lastChained = $this->getLatestChainedParameter();
     if (empty($lastChained)) {
         throw new CustomException('The ' . $name . '() method needs to be called while chaining.');
     }
     $id = reset($lastChained);
     $chainedResourceNames = array_keys($lastChained);
     $resource = (new $chainedResourceNames[0]($this->client))->resourceName;
     return "{$resource}/{$id}/tags.json";
 }
 /**
  * Returns a route and replaces tokenized parts of the string with
  * the passed params
  *
  * @param       $name
  * @param array $params
  *
  * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
  * based on the parent chain
  * GET /api/v2/organizations.json
  * GET /api/v2/users/{user_id}/organizations.json
  *
  * @throws \Exception
  */
 public function getRoute($name, array $params = [])
 {
     $lastChained = $this->getLatestChainedParameter();
     $chainedResourceNames = array_keys($lastChained);
     if (empty($lastChained) || $name !== 'findAll') {
         return parent::getRoute($name, $params);
     } else {
         $id = reset($lastChained);
         $resource = (new $chainedResourceNames[0]($this->client))->resourceName;
         if ('users' === $resource) {
             return "users/{$id}/organizations.json";
         } else {
             return 'organizations.json';
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getRoute($name, array $params = [])
 {
     $params = $this->addChainedParametersToParams($params, ['item_id' => DynamicContentItems::class]);
     return parent::getRoute($name, $params);
 }