Skip to content

Commit

Permalink
Replace many " with '
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-schindler committed Jul 8, 2022
1 parent d692a83 commit 5a96418
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Backend/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class HomeController extends Controller

protected function execute(): void {
$layout = new LayoutView();
$layout->addChild(new HeadingView("Home"));
$layout->addChild(new HeadingView('Home'));
$layout->render();
}
}
10 changes: 5 additions & 5 deletions Backend/Controllers/NotCalledController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class NotCalledController extends Controller

protected function execute(): void {
$layout = new LayoutView();
$layout->addChild(new HeadingView("Doesn't get called when only using links from the LayoutView"));
$layout->addChild(new TextView("Go and work on the Router!"));
$layout->addChild(new TextView($this->param("type")));
if (($id = $this->param("id")) !== null)
$layout->addChild(new TextView("ID: " . $id));
$layout->addChild(new HeadingView('Doesn\'t get called when only using links from the LayoutView'));
$layout->addChild(new TextView('Go and work on the Router!'));
$layout->addChild(new TextView($this->param('type')));
if (($id = $this->param('id')) !== null)
$layout->addChild(new TextView("ID: $id"));

$layout->render();
}
Expand Down
6 changes: 3 additions & 3 deletions Backend/Controllers/SecondHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class SecondHome extends Controller

protected function execute(): void {
$layout = new LayoutView();
$layout->addChild(new TextView("Welcome to another route"));
if (($id = $this->param("id")) !== null) {
$layout->addChild(new TextView("ID: " . $id));
$layout->addChild(new TextView('Welcome to another route'));
if (($id = $this->param('id')) !== null) {
$layout->addChild(new TextView("ID: $id"));
}

$layout->render();
Expand Down
32 changes: 19 additions & 13 deletions Backend/Controllers/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ class TestController extends Controller
protected function execute(): void
{
// Query
echo "PARAM<br>";
echo $this->param("id") . "<br>";
echo $this->param("not_defined") ?? "not set" . "<br>";
echo 'PARAM<br>';
echo $this->param('id');
echo '<br>';
echo $this->param('not_defined') ?? 'not set';
echo '<br>';

echo "<br>QUERY<br>";
echo IO::query("str") . "<br>"; // String
print_r(IO::query("arr")); // Array
echo "<br>";
echo IO::query("not_defined") ?? "not set" . "<br>"; // Not set
echo '<br>QUERY<br>';
echo IO::query('str'); // String
echo '<br>';
print_r(IO::query('arr')); // Array
echo '<br>';
echo IO::query('not_defined') ?? 'not set'; // Not set
echo '<br>';

// Body
echo "<br>BODY<br>";
echo IO::body("str") . "<br>";
print_r(IO::body("arr"));
echo "<br>";
echo IO::body("not_defined") ?? "not set" . "<br>";
echo '<br>BODY<br>';
echo IO::body('str');
echo '<br>';
print_r(IO::body('arr'));
echo '<br>';
echo IO::body('not_defined') ?? 'not set';
echo '<br>';
}
}
6 changes: 3 additions & 3 deletions Backend/Core/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ClassLoader
public static function 파람(): void {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Backend'), RecursiveIteratorIterator::SELF_FIRST);
foreach($files as $file)
if (pathinfo($file->getFileName(), PATHINFO_EXTENSION) == "php" && !str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'Libraries' . DIRECTORY_SEPARATOR . 'vendor'))
self::$classes[str_replace(".php", "", $file->getFileName())] = $file->getPathname();
if (pathinfo($file->getFileName(), PATHINFO_EXTENSION) == 'php' && !str_contains($file->getPathname(), DIRECTORY_SEPARATOR . 'Libraries' . DIRECTORY_SEPARATOR . 'vendor'))
self::$classes[str_replace('.php', '', $file->getFileName())] = $file->getPathname();

spl_autoload_register(function($className): void {
if (isset(self::$classes[$className]) && file_exists(self::$classes[$className]))
Expand All @@ -35,7 +35,7 @@ public static function 파람(): void {
*/
private static function initControllers(): void {
foreach (self::$classes as $name => $path) {
if (str_contains(str_replace('\\', '/', $path), "/Controllers/")) { // Replace \ with / for windows users
if (str_contains(str_replace('\\', '/', $path), '/Controllers/')) { // Replace \ with / for windows users
$controller = new $name();
if ($controller instanceof Controller)
$controller->initRoutes();
Expand Down
4 changes: 2 additions & 2 deletions Backend/Core/Data/InsertQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function __construct(string $tableName) {
*/
public function add(string $columnName, string $value): void {
if ($this->values != null)
$this->queryStr .= ",";
$this->queryStr .= ',';
else
$this->values = [];
$placeholder = ":" . strtolower($columnName);
$placeholder = ":{strtolower($columnName)}";
$this->queryStr .= " `$columnName`=";
$this->queryStr .= $placeholder;

Expand Down
2 changes: 1 addition & 1 deletion Backend/Core/Data/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Query
* @param string $queryStr Query as a string
* @param array<string|int,string|float>|null $values Values for placeholders
*/
public function __construct($queryStr = "", ?array $values = null) {
public function __construct($queryStr = '', ?array $values = null) {
$this->queryStr = $queryStr;
$this->values = $values;
$this->con = new PDO('mysql:host='.DB_HOST.'; dbname='.DB_NAME, DB_USER, DB_PASS);
Expand Down
28 changes: 14 additions & 14 deletions Backend/Core/System/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function body(string $var): string | array | null {
if ($inputData != null) {
$arr = [];
foreach (explode('&', $inputData) as $chunk) {
$param = explode("=", $chunk);
$param = explode('=', $chunk);
$key = urldecode($param[0]);
if (isset($param[1])) {
if (!isset($arr[$key]))
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function body(string $var): string | array | null {
*/
public static function SESSION(string $var, string $value = null, bool $exact = false): ?string {
if (session_status() !== PHP_SESSION_ACTIVE)
throw new Error("You have to start the session first");
throw new Error('You have to start the session first');

// Set variable
if ($value !== null) {
Expand All @@ -108,7 +108,7 @@ public static function SESSION(string $var, string $value = null, bool $exact =
*/
public static function COOKIE(string $var, ?string $value = null, int $lifetime = 2592000, bool $exact = false): ?string {
if ($value !== null) {
setcookie($var, $value, time()+$lifetime, "/", self::domain(), true);
setcookie($var, $value, time()+$lifetime, '/', self::domain(), true);
return null;
}

Expand All @@ -135,9 +135,9 @@ public static function authHeader(): ?string {
* @return string The domain (URL without HTTP(S)://)
*/
public static function domain(): string {
if (isset($_SERVER["SERVER_NAME"]) && $_SERVER["SERVER_NAME"] != null)
return $_SERVER["SERVER_NAME"];
throw new Exception("Not running on a server");
if (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] != null)
return $_SERVER['SERVER_NAME'];
throw new Exception('Not running on a server');
}

/**
Expand All @@ -147,9 +147,9 @@ public static function domain(): string {
* @throws Exception When no request is set
*/
public static function path(): string {
if (isset($_SERVER["REQUEST_URI"]) && $_SERVER["REQUEST_URI"] != null)
return explode("?", $_SERVER["REQUEST_URI"], 2)[0];
throw new Exception("No request");
if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != null)
return explode('?', $_SERVER['REQUEST_URI'], 2)[0];
throw new Exception('No request');
}

/**
Expand All @@ -165,9 +165,9 @@ public static function fullURL(): string {
* @return string HTTP request method
*/
public static function method(): string {
if (isset($_SERVER["REQUEST_METHOD"]))
return $_SERVER["REQUEST_METHOD"];
throw new Exception("No request method set");
if (isset($_SERVER['REQUEST_METHOD']))
return $_SERVER['REQUEST_METHOD'];
throw new Exception('No request method set');
}

/**
Expand All @@ -176,7 +176,7 @@ public static function method(): string {
*/
public static function accept(): string {
if (isset($_SERVER['HTTP_ACCEPT']))
return explode(",", $_SERVER['HTTP_ACCEPT'])[0];
throw new Exception("No accept header set");
return explode(',', $_SERVER['HTTP_ACCEPT'])[0];
throw new Exception('No accept header set');
}
}
4 changes: 2 additions & 2 deletions Backend/Core/System/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function renderChildren(?string $element = null): void {
if ($element === null)
$child->render();
else
echo "<".$element.">" . $child->__toString() . "</".$element.">";
echo "<$element>{$child->__toString()}</$element>";
}
}

Expand All @@ -46,6 +46,6 @@ public function __toString(): string {
$this->render();
if (($content = ob_get_clean()) !== false)
return $content;
return "";
return '';
}
}
12 changes: 6 additions & 6 deletions Backend/Libraries/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Backend/Views/Base/APIView.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public function __construct(
){}

public function render(): void {
header("Content-Type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: " . DOMAIN);
// header("Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept");
// header("Access-Control-Max-Age: 86400");
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: ' . DOMAIN);
// header('Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept');
// header('Access-Control-Max-Age: 86400');

echo json_encode($this->data);
}
Expand Down
2 changes: 1 addition & 1 deletion Backend/Views/Base/ErrorView.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function render(): void {
(new APIView([$this->code => $this->message]))->render(); // Render error as JSON
} else {
(new LayoutView())
->addChild(new HeadingView($this->code . " &middot; " . $this->message))
->addChild(new HeadingView("{$this->code} &middot; {$this->message}"))
->render(); // Render error as HTML
$this->renderChildren();
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

- Dependency-free
- MVC
- No Models included, use PDO with the [Query class](/Backend/Core/Data/Query.php)
- Use readable urls like "/u/:user" instead of things like "user.php?name="
- No Models included, but you use PDO with the [Query class](/Backend/Core/Data/Query.php)
- Easy to use readable URLs like "/u/:name" instead of things like "user.php?name="

## Getting started

Expand Down Expand Up @@ -34,6 +34,6 @@ Make sure your web server:

- Supports PHP
- Serves files
- Then routes through index.php
- Routes through index.php (if the path doesn't match a file)

Works on: Apache, Nginx, [Caddy](https://caddyserver.com)

0 comments on commit 5a96418

Please sign in to comment.