Skip to content

Commit

Permalink
Updated Packages & More
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Jul 27, 2022
1 parent 662d61f commit 9feb6b6
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 55 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class App extends WebApplication {

public function init() : void {
$this->getConfig()
->loadENVFile(".enva");
->loadENVFile(".env");

// A ulole-framework helper for UloleORM::database("main", new Database(...))
$this->initDatabase(/*Config prefix*/ "database", "main");
Expand All @@ -48,7 +48,7 @@ class App extends WebApplication {

public function run() : void {
$this->getRouter()
->get("/user/(\d+)", function($req, $res, int $userId){
->get("/user/{i+:userId}", function($req, $res, int $userId){
$res->json([
"user" => User::table()->where("id", $userId)->get()
]);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "interaapps/ulole-framework",
"version": "3.3.2",
"version": "3.3.3",
"require": {
"interaapps/ulole": "=3.1.4"
"interaapps/ulole": "=3.1.6"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 11 additions & 9 deletions src/main/com/example/myproject/App.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace com\example\myproject;

use com\example\myproject\controller\SecondTestController;
Expand All @@ -23,7 +24,7 @@ public function __construct() {
* Global init. It'll be used for the web, cli and other places.
* Handle databases (and other connections), configurations and more here.
*/
public function init() : void{
public function init(): void {
$this->getConfig()
->loadENV() // Loads environment variables
// If the file doesn't exists it'll just ignore it without any exception!
Expand All @@ -41,21 +42,22 @@ public function init() : void{
}

/**
* This'll be called before running the app for the web.
* This will be called before running the app for the web.
* Handle routes, views and other stuff needed for running for the web here.
*/
public function run() : void {
public function run(): void {
$router = $this->getRouter();

$router
->get("/a/(.*)", function(Request $req, Response $res, string $test = null){
$res->json([
->get("/a/{test}", function (Request $req, Response $res, string $test = null): array {
// Automatically turns this into JSON
return [
"Yep" => $test
]);
];
});

$router->notFound(function(){
view("error", ["error" => "Page not found"]);
$router->notFound(function () {
return view("error", ["error" => "Page not found"]);
});

// Register controllers
Expand All @@ -65,7 +67,7 @@ public function run() : void {
);
}

public static function main(Environment $environment){
public static function main(Environment $environment) {
(new self())->start($environment);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace com\example\myproject\controller;


Expand All @@ -12,14 +13,14 @@
#[Controller("/jobs")]
class SecondTestController {

#[Route("/(.*)", method: "GET")]
public function useJob(Request $req, Response $res, $val) {
#[Route("/{*:val}", method: "GET")]
public function useJob(Request $req, Response $res, string $val): string {

// Job Example
$example = new ExampleJob($val);
App::getInstance()->getJobHandler()->push($example);

return "HI";
return "Hi, Job created!";
}

}
14 changes: 8 additions & 6 deletions src/main/com/example/myproject/controller/TestController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace com\example\myproject\controller;

use com\example\myproject\model\User;
use de\interaapps\ulole\orm\Query;
use de\interaapps\ulole\router\attributes\Controller;
use de\interaapps\ulole\router\attributes\Route;
use de\interaapps\ulole\router\Request;
Expand All @@ -10,21 +12,21 @@
#[Controller]
class TestController {
#[Route("/", method: "GET")]
public static function test(Request $req, Response $res){
public static function index(Request $req, Response $res): string {
return view("homepage", [
'name' => "Me",
]);
}

#[Route("/user/(\d+)", method: "GET")]
public static function getUser(Request $req, Response $res, $userId){
#[Route("/user/{i+:userId}", method: "GET")]
public static function getUser(Request $req, Response $res, int $userId): string {
$user = User::table()
->where("id", $userId)
->or( fn ($q) => $q->where("name", "test") )
->or(fn(Query $q) => $q->where("name", "test"))
->first();

return view("homepage", [
'name' => ($user === null) ? "Not found" : $user->name,
'name' => ($user === null) ? "Not found" : $user->name ?? "World",
]);
}
}
7 changes: 4 additions & 3 deletions src/main/com/example/myproject/helper/cli/CustomCLI.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

namespace com\example\myproject\helper\cli;

use de\interaapps\ulole\core\cli\CLI;
use de\interaapps\ulole\core\cli\CLIHandler;
use de\interaapps\ulole\core\cli\Colors;

class CustomCLI extends CLIHandler {
public function registerCommands(CLI $cli){
$cli->register("test", function($args){
Colors::info("This is an example :) ".(isset($args[2]) ? $args[2] : "Arg not set") /* STARTING POINT (first argument) */);
public function registerCommands(CLI $cli) {
$cli->register("test", function ($args) {
Colors::info("This is an example :) " . ($args[2] ?? "Arg not set") /* STARTING POINT (first argument) */);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace com\example\myproject\helper\factories;


Expand All @@ -9,13 +10,11 @@

// app\factories\UserFactory::run(5)

class UserFactory extends Factory
{
class UserFactory extends Factory {
public string $model = User::class;

protected function production(AssemblyLine $assemblyLine) : void
{
$assemblyLine->insert(function(User $user, Faker $faker){
protected function production(AssemblyLine $assemblyLine): void {
$assemblyLine->insert(function (User $user, Faker $faker) {
$user->name = $faker->fullName();
$user->gender = "FEMALE";
$user->password = password_hash($faker->password(), PASSWORD_BCRYPT);
Expand Down
10 changes: 7 additions & 3 deletions src/main/com/example/myproject/helper/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// include_once "app/helper/". "NAME" .".php";

// Change this, if you wan't to use an other view-renderer
function view($view, $vars=[]) {
foreach ($vars as $var=>$val) {
function view($view, $vars = []): string {
ob_start();
foreach ($vars as $var => $val) {
global ${$var};
${$var} = $val;
}
include "resources/views/".$view.".php";
include "resources/views/" . $view . ".php";
$v = ob_get_contents();
ob_end_clean();
return $v;
}
6 changes: 3 additions & 3 deletions src/main/com/example/myproject/jobs/ExampleJob.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace com\example\myproject\jobs;


Expand All @@ -9,8 +10,7 @@ class ExampleJob implements Job {

public function __construct(
private string $message
)
{
) {
}

function run(JobHandler $jobHandler = null) {
Expand All @@ -22,7 +22,7 @@ function run(JobHandler $jobHandler = null) {
if ($this->message == "pleaseThrowAnException")
throw new \Exception("Oh no!");

file_put_contents("example_file.txt", file_get_contents("example_file.txt").$this->message);
file_put_contents("example_file.txt", file_get_contents("example_file.txt") . $this->message);

}
}
18 changes: 13 additions & 5 deletions src/main/com/example/myproject/model/User.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace com\example\myproject\model;

use de\interaapps\jsonplus\JSONModel;
use de\interaapps\ulole\orm\attributes\Column;
use de\interaapps\ulole\orm\attributes\CreatedAt;
use de\interaapps\ulole\orm\attributes\Table;
use de\interaapps\ulole\orm\ORMHelper;
use de\interaapps\ulole\orm\ORMModel;
Expand All @@ -11,20 +13,26 @@
class User {
use ORMModel;
use ORMHelper; // Adds more ORM-Helper like User::all() and User::get(id)

use JSONModel; // Adds $user->json() and User::fromJson("{...}")

#[Column]
public int $id;

#[Column]
public string $name;
#[Column]
public string $password;
public ?string $name;

#[Column]
public string $gender;
public ?string $password;

#[Column]
public ?string $gender;

#[Column(sqlType: "TIMESTAMP")]
#[CreatedAt]
public string $createdAt;

public function setPassword($password){
public function setPassword($password) {
$this->password = password_hash($password, PASSWORD_BCRYPT);
}
}
31 changes: 17 additions & 14 deletions uppm.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{
"name": "ulole-framework",
"version": "3.3.2",
"description": "",
"author": "",
"keywords": [],
"modules": {
"ulole-core": "3.1.4"
},
"version": "3.3.3",
"repositories": [],
"run": {
"cli": "cli"
},
"serve": {
"port": 8000,
"directory": "public",
"routerFile": "index.php"
},
"build": {
"type": "phar",
"run": "cli",
"ignored": [
".git", ".idea", "README.md", ".env"
".git",
".idea",
"README.md",
".env"
]
}
},
"serve": {
"port": 8000,
"directory": "public",
"routerFile": "index.php"
},
"modules": {
"ulole-core": "3.1.6"
},
"namespaceBindings": {},
"initScripts": []
}

0 comments on commit 9feb6b6

Please sign in to comment.