ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ILIAS\StaticURL\Shortlinks\Handler Class Reference
+ Inheritance diagram for ILIAS\StaticURL\Shortlinks\Handler:
+ Collaboration diagram for ILIAS\StaticURL\Shortlinks\Handler:

Public Member Functions

 __construct ()
 
 getNamespace ()
 
 getNamespaceAliasses ()
 
 canHandle (Request $request)
 
 handle (Request $request, Context $context, Factory $response_factory)
 
 getNamespaceAliasses ()
 
 __construct ()
 
 getNamespace ()
 
 canHandle (Request $request)
 
 handle (Request $request, Context $context, Factory $response_factory)
 

Data Fields

const string SHORTLINK_NAMESPACE = self::NAMESPACE_ALTERNATIVE
 

Protected Member Functions

 mustShift (ServerRequestInterface $request)
 

Private Attributes

const string NAMESPACE_SHORT = 's'
 
const string NAMESPACE_LONG = 'shortlink'
 
const string NAMESPACE_ALTERNATIVE = 'to'
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 37 of file Handler.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\StaticURL\Shortlinks\Handler::__construct ( )

Implements ILIAS\StaticURL\Handler\Handler.

Definition at line 44 of file Handler.php.

45 {
46 }

Member Function Documentation

◆ canHandle()

ILIAS\StaticURL\Shortlinks\Handler::canHandle ( Request  $request)

Implements ILIAS\StaticURL\Handler\Handler.

Definition at line 61 of file Handler.php.

61 : bool
62 {
63 if ($request->getNamespace() === $this->getNamespace()) {
64 return true;
65 }
66 return in_array(
67 $request->getNamespace(),
68 $this->getNamespaceAliasses()
69 );
70 }

References ILIAS\StaticURL\Request\Request\getNamespace().

+ Here is the call graph for this function:

◆ getNamespace()

ILIAS\StaticURL\Shortlinks\Handler::getNamespace ( )

Implements ILIAS\StaticURL\Handler\Handler.

Definition at line 48 of file Handler.php.

48 : string
49 {
51 }

References ILIAS\StaticURL\Shortlinks\Handler\SHORTLINK_NAMESPACE.

Referenced by ILIAS\StaticURL\Shortlinks\Handler\getNamespaceAliasses().

+ Here is the caller graph for this function:

◆ getNamespaceAliasses()

ILIAS\StaticURL\Shortlinks\Handler::getNamespaceAliasses ( )

Implements ILIAS\StaticURL\Handler\AliasedHandler.

Definition at line 53 of file Handler.php.

53 : array
54 {
55 return array_diff(
56 [self::NAMESPACE_LONG, self::NAMESPACE_ALTERNATIVE, self::NAMESPACE_SHORT],
57 [$this->getNamespace()]
58 );
59 }

References ILIAS\StaticURL\Shortlinks\Handler\getNamespace().

+ Here is the call graph for this function:

◆ handle()

ILIAS\StaticURL\Shortlinks\Handler::handle ( Request  $request,
Context  $context,
Factory  $response_factory 
)

Implements ILIAS\StaticURL\Handler\Handler.

Definition at line 72 of file Handler.php.

72 : Response
73 {
74 global $DIC;
75 $repository = new RepositoryDB(
76 $DIC->database(),
77 new ILIASTypeDataResolver(
78 $DIC->repositoryTree()
79 )
80 );
81 $alias = $request->getAdditionalParameters()[0] ?? '';
82 if (!$repository->has($alias)) {
83 return $response_factory->cannot();
84 }
85
86 if (($shortlink = $repository->getByAlias($alias)) === null) {
87 return $response_factory->cannot();
88 };
89
90 if (!$shortlink->isActive()) {
91 return $response_factory->cannot();
92 }
93
94 $target_resolver = new TargetLinkResolver(
95 $DIC['static_url']->builder(),
96 $DIC[\ILIAS\Data\Factory::class]
97 );
98
99 $target = $target_resolver->resolve(
100 $shortlink
101 );
102 if ($target instanceof URI) {
103 $target = $target->getPath();
104 }
105
106 if (empty($target)) {
107 return $response_factory->cannot();
108 }
109
110 $repository->increaseUsage(
111 $shortlink
112 );
113
114 return $response_factory->can(
115 $target,
116 $this->mustShift($context->http()->request())
117 );
118 }
can(string $uri_path, bool $shift=false)
Definition: Factory.php:50
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\StaticURL\Response\Factory\can(), ILIAS\StaticURL\Response\Factory\cannot(), ILIAS\StaticURL\Request\Request\getAdditionalParameters(), ILIAS\StaticURL\Context\http(), and ILIAS\StaticURL\Shortlinks\Handler\mustShift().

+ Here is the call graph for this function:

◆ mustShift()

ILIAS\StaticURL\Shortlinks\Handler::mustShift ( ServerRequestInterface  $request)
protected

Definition at line 120 of file Handler.php.

120 : bool
121 {
122 $requested_uri = $request->getUri()->getPath();
123
124 return !str_contains($requested_uri, StandardURIBuilder::SHORT)
125 && !str_contains($requested_uri, StandardURIBuilder::LONG);
126 }

References ILIAS\StaticURL\Builder\StandardURIBuilder\LONG, and ILIAS\StaticURL\Builder\StandardURIBuilder\SHORT.

Referenced by ILIAS\StaticURL\Shortlinks\Handler\handle().

+ Here is the caller graph for this function:

Field Documentation

◆ NAMESPACE_ALTERNATIVE

const string ILIAS\StaticURL\Shortlinks\Handler::NAMESPACE_ALTERNATIVE = 'to'
private

Definition at line 42 of file Handler.php.

◆ NAMESPACE_LONG

const string ILIAS\StaticURL\Shortlinks\Handler::NAMESPACE_LONG = 'shortlink'
private

Definition at line 41 of file Handler.php.

◆ NAMESPACE_SHORT

const string ILIAS\StaticURL\Shortlinks\Handler::NAMESPACE_SHORT = 's'
private

Definition at line 40 of file Handler.php.

◆ SHORTLINK_NAMESPACE

const string ILIAS\StaticURL\Shortlinks\Handler::SHORTLINK_NAMESPACE = self::NAMESPACE_ALTERNATIVE

The documentation for this class was generated from the following file: