Skip to content

Commit 5c8d9b6

Browse files
committed
readme - add docs link
1 parent 7b112a3 commit 5c8d9b6

File tree

1 file changed

+2
-169
lines changed

1 file changed

+2
-169
lines changed

README.md

Lines changed: 2 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -26,173 +26,6 @@ echo signedurl()->setExpiration(DAY * 2)->urlTo('namedRoute', 12);
2626
// https://example.com/route/name/12?expiration=1671980371&signature=signature-goes-here
2727
```
2828

29-
## Configuration
29+
## Docs
3030

31-
To make changes to the config file, we have to have our copy in the `app/Config/SignedUrl.php`. Luckily, this package comes with handy command that will make this easy.
32-
33-
When we run:
34-
35-
php spark signedurl:publish
36-
37-
We will get our copy ready for modifications.
38-
39-
**Warning**
40-
41-
Be aware that changing CodeIgniter's `encryption key` will instantly invalidate all the generated URLs.
42-
43-
#### $expirationTime
44-
45-
This setting allows us to set a fixed time after which the signed URL will expire.
46-
It's number of seconds in unix timestamp that will be added to the current date.
47-
48-
By default, this is set to `null`.
49-
50-
#### $algorithm
51-
52-
This setting allows us to set algorithm that will be used during signing the URLs.
53-
54-
You can see the list of all available options when running command:
55-
56-
php spark signedurl:algorithms
57-
58-
**Warning**
59-
60-
Changing this value without including the used algorithm key to the query string will invalidate all the generated URLs instantly.
61-
62-
#### $expirationKey
63-
64-
This is the name of the query string key, which will be responsible for storing the time after which the URL will expire.
65-
66-
Whatever the name you will choose, treat it as a restricted name and don't use it as a part Query String in your code.
67-
68-
By default, this is set to `expires`.
69-
70-
#### $signatureKey
71-
72-
This is the name of the query string key, which will be responsible for storing the signature by which the validity of the entire URL will be checked.
73-
74-
Whatever the name you will choose, treat it as a restricted name and don't use it as a part of the Query String in your code.
75-
76-
By default, this is set to `signature`.
77-
78-
#### $algorithmKey
79-
80-
This is the name of the query string key, which will be responsible for storing the algorithm by which the validity of the entire URL will be checked.
81-
82-
Whatever the name you will choose, treat it as a restricted name and don't use it as a part of the Query String in your code.
83-
84-
By default, this is set to `algorithm`.
85-
86-
#### $includeAlgorithmKey
87-
88-
This setting determines if the algorithm will be included to the query string of the generated URL.
89-
90-
By default, this is set to `false`.
91-
92-
#### $redirect
93-
94-
This setting is used in the Filter to determine whether we will redirect user to the previous page with the `error`, when URL will not be valid or expired.
95-
96-
By default, this is set to `false`.
97-
98-
#### $show404
99-
100-
This setting is used in the Filter to determine whether we will show a 404 page, when URL will not be valid or expired.
101-
102-
By default, this is set to `false`.
103-
104-
## Methods
105-
106-
#### siteUrl()
107-
108-
This method is similar to the standard `site_url`, but it produces signed URL.
109-
110-
```php
111-
service('signedurl')->siteUrl('controller/method');
112-
```
113-
114-
#### urlTo()
115-
116-
This method is similar to the standard `url_to`, but it produces signed URL.
117-
118-
```php
119-
service('signedurl')->urlTo('namedRoute', 'param');
120-
```
121-
122-
#### sign()
123-
124-
With this method we can sign URI. Usually you won't be using this method directly, since it is used by other methods.
125-
126-
```php
127-
service('signedurl')->sign($uri);
128-
```
129-
130-
By default `$expirationTime` is set to `null`. If you want the URLs to always be valid for a certain period of time, you can set time in the `$expirationTime` variable in the configuration file.
131-
132-
#### verify()
133-
134-
With this method we can verify if given URL is properly signed and not expired if expiration timestamp was set during URL creation.
135-
136-
```php
137-
service('signedurl')->verify($request);
138-
```
139-
140-
The URL verification may take place automatically via Filter class, but you can also make it happen in your Controller instead. The choice is up to you.
141-
142-
#### setExpiration()
143-
144-
With this method we can set temporary value for expiration. Value set here will be resetted after calling method: `siteUrl()`, `urlTo()` or `sign()`.
145-
146-
```php
147-
service('signedurl')->setExpiration(DAY)->siteUrl('url');
148-
```
149-
150-
## Helpers
151-
152-
#### signedurl()
153-
154-
This function returns the `SignedUrl` class instance.
155-
156-
```php
157-
signedurl()->setExpiration(DAY)->siteUrl('controller/method');
158-
```
159-
160-
## Filters
161-
162-
To validate signed URLs we can use build in filter. We can enable it in two simple steps.
163-
164-
1. We have to add our filter to the `$aliases` array.
165-
2. And then define when filter should be fired up. In the example below we will assume it will be used when the first segment of the url will contain `signed-urls` string.
166-
167-
```php
168-
// app/Config/Filters.php
169-
<?php
170-
171-
...
172-
173-
use Michalsn\CodeIgniterSignedUrl\Filters\SignedUrl;
174-
175-
class Filters extends BaseConfig
176-
{
177-
...
178-
179-
public $aliases = [
180-
...
181-
'signedurl' => SignedUrl::class
182-
];
183-
184-
...
185-
186-
public $filters = [
187-
'signedurl' => ['before' => ['signed-urls/*']],
188-
];
189-
```
190-
191-
By default, this filter will throw `SignedUrlException` when the URL won't be signed or will be expired. But there are other options, and we can enable them by editing the config file:
192-
193-
* We can redirect to the previous page
194-
* Or show 404 page
195-
196-
More info you can find in the Config section.
197-
198-
Remember, that if the filter implementation doesn't suit you, you can always create your own, which will behave differently upon an error. You can also not use the filter at all and make the check in the controller.
31+
https://michalsn.github.io/codeigniter-signed-url

0 commit comments

Comments
 (0)