Skip to content

Commit

Permalink
Version 0.2.11 👾
Browse files Browse the repository at this point in the history
- Improved ./server and server.bat
- Fixed document root in ./server
- Removed unnecessary `trim()`
  • Loading branch information
brcontainer committed Apr 28, 2024
1 parent ab54f01 commit f6973aa
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 42 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Guilherme Nascimento (brcontainer@yahoo.com.br)
Copyright (c) 2024 Guilherme Nascimento (brcontainer@yahoo.com.br)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
60 changes: 51 additions & 9 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,13 @@
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0,0,0,0.04);
border-radius: 3px;
}

.markdown-body code:not(.highlight):not(.codehilite), .markdown-body samp {
background-color: rgba(0,0,0,0.04);
}

.markdown-body code:before,
.markdown-body code:after {
letter-spacing: -0.2em;
Expand Down Expand Up @@ -532,10 +535,18 @@
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
}

.markdown-body .codehilite,
.markdown-body .highlight,
.markdown-body pre {
border-radius: 3px;
}

.markdown-body :not(.highlight) > pre {
background-color: #f7f7f7;
}

.markdown-body .codehilite pre,
.markdown-body .highlight pre {
margin-bottom: 0;
Expand Down Expand Up @@ -1003,7 +1014,7 @@
}
}
</style><style>/*GitHub*/
.highlight {background-color:#fff;color:#333333;}
.highlight {background-color:#f7f7f7;color:#333333;}
.highlight .hll {background-color:#ffffcc;}
.highlight .c{color:#999988;font-style:italic}
.highlight .err{color:#a61717;background-color:#e3d2d2}
Expand Down Expand Up @@ -1067,16 +1078,16 @@
.highlight .gc{color:#999;background-color:#EAF2F5}
</style><title>README</title></head><body><article class="markdown-body"><div align="center">
<a href="https://github.com/inphinit/teeny/">
<img src="./badges/php.png" width="160" alt="Teeny route system for PHP">
<img src="/C:/DATA/projects/teeny/badges/php.png" width="160" alt="Teeny route system for PHP">
</a>
<a href="https://github.com/inphinit/teeny.js/">
<img src="./badges/javascript.png" width="160" alt="Teeny route system for JavaScript (Node.js)">
<img src="/C:/DATA/projects/teeny/badges/javascript.png" width="160" alt="Teeny route system for JavaScript (Node.js)">
</a>
<a href="https://github.com/inphinit/teeny.go/">
<img src="./badges/golang.png" width="160" alt="Teeny route system for Golang">
<img src="/C:/DATA/projects/teeny/badges/golang.png" width="160" alt="Teeny route system for Golang">
</a>
<a href="https://github.com/inphinit/teeny.py/">
<img src="./badges/python.png" width="160" alt="Teeny route system for Python">
<img src="/C:/DATA/projects/teeny/badges/python.png" width="160" alt="Teeny route system for Python">
</a>
</div>

Expand All @@ -1094,7 +1105,38 @@ <h2 id="install-using-composer">Install using composer<a class="headerlink" href
<h2 id="download-without-composer">Download without composer<a class="headerlink" href="#download-without-composer" title="Permanent link">î…—</a></h2>
<p>If is not using <code>composer</code> try direct download from <a href="https://github.com/inphinit/teeny/releases">https://github.com/inphinit/teeny/releases</a></p>
<h2 id="execute">Execute<a class="headerlink" href="#execute" title="Permanent link">î…—</a></h2>
<p>Copy for Apache or Nginx folder and configure Vhost in Apache or configure [`try_files`](https://nginx.org/en/docs/http/ngx_http_core_module.html#try_files) in Nginx</p>
<p>Copy for Apache or Nginx folder and configure Vhost in Apache or configure <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#try_files"><code>try_files</code></a> in Nginx.</p>
<p>You can use <a href="https://www.php.net/manual/en/features.commandline.webserver.php">built-in server</a> to facilitate the development, Teeny provides the relative static files, which will facilitate the use, example of use (navigate to project folder using <code>cd</code> command):</p>
<div class="highlight"><pre>php -S localhost:8080 index.php
</pre></div>

<p>You can edit the server.bat (Windows) or server (Linux or macOS) files to make it easier to start the project with a simple command</p>
<h3 id="windows-serverbat-file">Windows (server.bat file)<a class="headerlink" href="#windows-serverbat-file" title="Permanent link">î…—</a></h3>
<p>Configure the <code>server.bat</code> variables according to your environment:</p>
<div class="highlight"><pre>set PHP_BIN=&quot;C:\php\php.exe&quot;
set PHP_INI=&quot;C:\php\php.ini&quot;
set HOST_HOST=localhost
set HOST_PORT=9000
</pre></div>

<p>Once configured, you can navigate to the project folder and run the command that will start built-in server, see an example:</p>
<div class="highlight"><pre>cd c:\projets\blog
server
</pre></div>

<h3 id="linux-and-macos-server-file">Linux and macOS (server file)<a class="headerlink" href="#linux-and-macos-server-file" title="Permanent link">î…—</a></h3>
<p>Configure the <code>./server</code> variables according to your environment:</p>
<div class="highlight"><pre>PHP_BIN=&quot;/usr/bin/php&quot;
PHP_INI=&quot;/etc/php5/cli/php.ini&quot;
HOST_HOST=localhost
HOST_PORT=9000
</pre></div>

<p>Once configured, you can navigate to the project folder and run the command that will start built-in server, see an example:</p>
<div class="highlight"><pre>cd ~/projets/blog
./server
</pre></div>

<h2 id="api">API<a class="headerlink" href="#api" title="Permanent link">î…—</a></h2>
<p>Methods from <code>Teeny</code> class</p>
<table>
Expand Down Expand Up @@ -1294,4 +1336,4 @@ <h2 id="types-of-params-named-in-routes">Types of params named in routes<a class

<p>And for access this route exemple use <code>http://mysite/test/A00001</code> or <code>http://mysite/test/C02</code>, start with upper-case letter and after width a integer number</p>
<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>
1 change: 1 addition & 0 deletions examples/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<ul>
<li><a href="./include"><code>/include</code></a></li>
<li><a href="./info"><code>/info</code></a></li>
<li><a href="./about"><code>/about</code></a></li>
<li><a href="./memory"><code>/memory</code></a></li>
<li><a href="./foo/bar"><code>/foo/bar</code> ("405 Method Not Allowed" example)</a></li>
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

$app->action('GET', '/include', 'examples/foo.php');

$app->action('GET', '/info', 'phpinfo');

$app->action('GET', '/about', function () {
echo 'Teeny is very small and easy route system';
});
Expand Down
22 changes: 14 additions & 8 deletions server
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/bin/bash
#!/usr/bin/env bash

# Setup PHP and PORT
PHP_BIN="/usr/bin/php"
PHP_INI="/etc/php5/cli/php.ini"
PHP_BIN=/usr/bin/php
PHP_INI=/etc/php.ini
HOST_HOST=localhost
HOST_PORT=9000

# Used to restore current dir if using command line
BASEDIR=$(dirname "${0}")
# Sets the project path so you can call the "./server" command from any location
DOCUMENT_ROOT=$(cd -- $(dirname ${BASH_SOURCE:-$0}) && pwd -P)

# Router path
ROUTER="$BASEDIR/index.php"
ROUTER=$DOCUMENT_ROOT/index.php

# Start built in server
$PHP_BIN -S "$HOST_HOST:$HOST_PORT" -c $PHP_INI -t "$BASEDIR" $ROUTER
if [ ! -f "$PHP_BIN" ]; then
echo ERROR: $PHP_BIN not found
elif [ ! -f "$PHP_INI" ]; then
echo ERROR: $PHP_INI not found
else
# Start built in server
"$PHP_BIN" -S $HOST_HOST:$HOST_PORT -c "$PHP_INI" -t "$DOCUMENT_ROOT" "$ROUTER"
fi
26 changes: 12 additions & 14 deletions server.bat
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
@echo off

:: Setup PHP and PORT
set PHP_BIN="C:\php\php.exe"
set PHP_INI="C:\php\php.ini"
rem Setup PHP and PORT
set PHP_BIN=C:\php\php.exe
set PHP_INI=C:\php\php.ini
set HOST_HOST=localhost
set HOST_PORT=9000

:: Current path
set CURRENT_PATH=%~dp0
set CURRENT_PATH=%CURRENT_PATH:~0,-1%
rem Sets the project path so you can call the "server" command from any location
set DOCUMENT_ROOT=%~dp0
set DOCUMENT_ROOT=%DOCUMENT_ROOT:~0,-1%

:: Router path
set ROUTER="%CURRENT_PATH%\index.php"
rem Router path
set ROUTER=%DOCUMENT_ROOT%\index.php

if not exist %PHP_BIN% (
echo ERROR: %PHP_BIN% not found
pause
echo ERROR: %PHP_BIN% not found & pause
) else if not exist %PHP_INI% (
echo ERROR: %PHP_INI% not found
pause
echo ERROR: %PHP_INI% not found & pause
) else (
:: Start built in server
%PHP_BIN% -S "%HOST_HOST%:%HOST_PORT%" -c %PHP_INI% -t "%CURRENT_PATH%" %ROUTER% || pause
rem Start built in server
"%PHP_BIN%" -S %HOST_HOST%:%HOST_PORT% -c "%PHP_INI%" -t "%DOCUMENT_ROOT%" "%ROUTER%" || pause
)
20 changes: 10 additions & 10 deletions vendor/Teeny.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function status($code = null)
/**
* Register a callback or script for a route
*
* @param string|array $methods
* @param string $path
* @param string|\Closure $callback
* @param string|array $methods
* @param string $path
* @param string|\Closure $callback
* @return void
*/
public function action($methods, $path, $callback)
Expand All @@ -113,18 +113,18 @@ public function action($methods, $path, $callback)

if (is_array($methods)) {
foreach ($methods as $method) {
$routes[$path][strtoupper(trim($method))] = $callback;
$routes[$path][strtoupper($method)] = $callback;
}
} else {
$routes[$path][strtoupper(trim($methods))] = $callback;
$routes[$path][strtoupper($methods)] = $callback;
}
}

/**
* Handler HTTP status code
*
* @param array $codes
* @param callable $callback
* @param array $codes
* @param callable $callback
* @return void
*/
public function handlerCodes(array $codes, $callback)
Expand Down Expand Up @@ -288,9 +288,9 @@ private function builtinFile()
/**
* Require file
*
* @param Teeny $app Teeny (or custom) context
* @param string $callback File required
* @param array $params Params from route pattern
* @param Teeny $app Teeny (or custom) context
* @param string $callback File required
* @param array $params Params from route pattern
* @return mixed
*/
function TeenyLoader(Teeny $app, $callback, $params)
Expand Down

0 comments on commit f6973aa

Please sign in to comment.