Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
- Fixed .htaccess
- Removed noslash pattern
- editorconfig
  • Loading branch information
brcontainer committed May 31, 2024
1 parent 87ec320 commit 63c8380
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 28 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2

[*.{htm,html}]
insert_final_newline = false

[{*.bat,web.config}]
end_of_line = crlf
23 changes: 22 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
* -text
* text=auto eol=lf

*.bash text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
*.coffee text
*.css text diff=css
*.htm text diff=html
*.html text diff=html
*.md text diff=markdown
*.php text diff=php

server text eol=lf

package-lock.json text eol=lf -diff
pnpm-lock.yaml text eol=lf -diff
yarn.lock text -diff

.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
9 changes: 7 additions & 2 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ ErrorDocument 501 /index.php/RESERVED.TEENY-501.html

RewriteEngine On

# Handle Authorization Header
# RewriteCond %{HTTP:Authorization} .
# RewriteRule . - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Ignore hidden files
RewriteRule ^\.|/\. index.php [L]

# Redirect to public folder
RewriteCond %{REQUEST_URI} !(^$|public/|index\.php(/|$))
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_URI} !(^$|/$|public/|index\.php(/|$))
RewriteRule ^(.*)$ public/$1 [L]

# Redirect all urls to index.php if no exits files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
9 changes: 2 additions & 7 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -1371,14 +1371,9 @@ <h2 id="supported-types-for-named-parameters-in-routes">Supported types for name
<td>Only accepts parameters with integer format and <code>$params</code> returns <code>array( id =&gt; ...)</code></td>
</tr>
<tr>
<td><code>noslash</code></td>
<td><code>$app-&gt;action('GET', '/foo/&lt;noslash:noslash&gt;', ...);</code></td>
<td>Accpets any characters expcet slashs (<code>/</code>)</td>
</tr>
<tr>
<td><code>nospace</code></td>
<td><code>$app-&gt;action('GET', '/foo/&lt;nospace:nospace&gt;', ...);</code></td>
<td>Accpets any characters expcet spaces, like white-spaces (<code>%20</code>), tabs (<code>%0A</code>) and others (see about <code>\S</code> in regex)</td>
<td>Accepts any characters expcet spaces, like white-spaces (<code>%20</code>), tabs (<code>%0A</code>) and others (see about <code>\S</code> in regex)</td>
</tr>
<tr>
<td><code>uuid</code></td>
Expand Down Expand Up @@ -1512,4 +1507,4 @@ <h2 id="serving-public-files-and-scripts">Serving public files (and scripts)<a c
<li><code>https://&lt;domain&gt;/blog/2023/04/17/researchers-discover-small-galaxy/</code></li>
</ul>
<hr />
<p>If you need more features you can experience the <strong>Inphinit PHP framework</strong>: <a href="https://inphinit.github.io">https://inphinit.github.io</a></p></article></body></html>
<p>If you need more features you can experience the <strong>Inphinit PHP framework</strong>: <a href="https://inphinit.github.io">https://inphinit.github.io</a></p></article></body></html>
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ Type | Example | Description
`alpha` | `$app->action('GET', '/foo/bar/<name:alpha>', ...);` | Only accepts parameters with alpha format and `$params` returns `array( name => ...)`
`decimal` | `$app->action('GET', '/baz/<price:decimal>', ...);` | Only accepts parameters with decimal format and `$params` returns `array( price => ...)`
`num` | `$app->action('GET', '/foo/<id:num>', ...);` | Only accepts parameters with integer format and `$params` returns `array( id => ...)`
`noslash` | `$app->action('GET', '/foo/<noslash:noslash>', ...);` | Accpets any characters expcet slashs (`/`)
`nospace` | `$app->action('GET', '/foo/<nospace:nospace>', ...);` | Accpets any characters expcet spaces, like white-spaces (`%20`), tabs (`%0A`) and others (see about `\S` in regex)
`nospace` | `$app->action('GET', '/foo/<nospace:nospace>', ...);` | Accepts any characters expcet spaces, like white-spaces (`%20`), tabs (`%0A`) and others (see about `\S` in regex)
`uuid` | `$app->action('GET', '/bar/<barcode:alnum>', ...);` | Only accepts parameters with uuid format and `$params` returns `array( barcode => ...)`
`version` | `$app->action('GET', '/baz/<api:version>', ...);` | Only accepts parameters with [semversion (v2)](https://semver.org/spec/v2.0.0.html) format and `$params` returns `array( api => ...)`

Expand Down
9 changes: 3 additions & 6 deletions examples/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
<li><a href="./version/2.3.1-rc5.a4.z0%2Bb100"><code>/version/&lt;value:version></code></a></li>
<li><a href="./version/2.3.1-rc5.a4.z0%2Bb1.b2"><code>/version/&lt;value:version></code></a></li>
<li><a href="./noslash/abc"><code>/noslash/&lt;name:noslash></code></a></li>
<li><a href="./noslash/a/b/c"><code>/noslash/&lt;name:noslash> (invalid example)</code></a></li>
<li><a href="./nospace/a-b-c-ção"><code>/noslash/&lt;name:nospace></code></a></li>
<li><a href="./nospace/a%20b-c-ção"><code>/noslash/&lt;name:nospace> (invalid example)</code></a></li>
<li><a href="./nospace/a+b-c-ção"><code>/noslash/&lt;name:nospace> (invalid example)</code></a></li>
<li><a href="./nospace/a-b-c-ção"><code>/nospace/&lt;name:nospace></code></a></li>
<li><a href="./nospace/a%20b-c-ção"><code>/nospace/&lt;name:nospace> (invalid example)</code></a></li>
<li><a href="./nospace/a+b-c-ção"><code>/nospace/&lt;name:nospace> (invalid example)</code></a></li>
<li><a href="./custom/A00001"><code>/custom/&lt;myexample:example></code></a></li>
Expand Down
7 changes: 0 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ function testCallback($params) {
echo '</pre>';
}

$app->action('GET', '/noslash/<value:noslash>', function ($params) {
echo '<h1>noslash</h1>';
echo '<pre>';
print_r($params);
echo '</pre>';
});

$app->action('GET', '/nospace/<value:nospace>', function ($params) {
echo '<h1>nospace</h1>';
echo '<pre>';
Expand Down
5 changes: 2 additions & 3 deletions vendor/Teeny.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class Teeny
'alpha' => '[a-zA-Z]+',
'decimal' => '\d+\.\d+',
'num' => '\d+',
'noslash' => '[^/]+',
'nospace' => '[^/\s]+',
'uuid' => '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}',
'uuid' => '[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}',
'version' => '\d+\.\d+(\.\d+(-[\da-zA-Z]+(\.[\da-zA-Z]+)*(\+[\da-zA-Z]+(\.[\da-zA-Z]+)*)?)?)?'
);

Expand All @@ -38,7 +37,7 @@ public function __construct()

$uri = urldecode(strtok($_SERVER['REQUEST_URI'], '?'));

if (!$this->builtIn) {
if ($this->builtIn === false) {
$uri = substr($uri, stripos($_SERVER['SCRIPT_NAME'], '/index.php'));
}

Expand Down

0 comments on commit 63c8380

Please sign in to comment.