Skip to content

Commit

Permalink
Merge pull request #5 from fatkulnurk/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
fatkulnurk authored Nov 13, 2019
2 parents 7511121 + 73cabc9 commit e946577
Show file tree
Hide file tree
Showing 58 changed files with 3,007 additions and 50 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# MICROFRAMEWORK
[![StyleCI](https://github.styleci.io/repos/210505965/shield?branch=master)](https://github.styleci.io/repos/210505965)
[![Build Status](https://travis-ci.org/fatkulnurk/microframework.svg?branch=master)](https://travis-ci.org/fatkulnurk/microframework)
[![CodeFactor](https://www.codefactor.io/repository/github/fatkulnurk/microframework/badge)](https://www.codefactor.io/repository/github/fatkulnurk/microframework)
[![Latest Stable Version](https://poser.pugx.org/fatkulnurk/microframework/v/stable)](https://packagist.org/packages/fatkulnurk/microframework)
[![Total Downloads](https://poser.pugx.org/fatkulnurk/microframework/downloads)](https://packagist.org/packages/fatkulnurk/microframework)
[![Latest Unstable Version](https://poser.pugx.org/fatkulnurk/microframework/v/unstable)](https://packagist.org/packages/fatkulnurk/microframework)
Expand All @@ -18,6 +19,11 @@ Standard yang digunakan adalah PSR2, untuk menjalankan ketikan command berikut.
phpcs ./system --standard=psr2
``

---
**DocBlock**
Jalankan
`u`

---
**Tool**
- PHP_CodeSniffer (phpcs & phpcbf),
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
"require": {
"php": "^7.2",
"twig/twig":"2.*",
"pyrocms/lex": "2.2.*"
"pyrocms/lex": "2.2.*",
"ext-json": "*",
"monolog/monolog": "^2.0",
"psr/http-message": "^1.0",
"myclabs/php-enum": "^1.7"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"phpunit/phpunit": "8"
}
}
9 changes: 9 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="My Project - TestSuite">
<directory>./tests</directory>
</testsuite>
</testsuites>

</phpunit>
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
require_once 'vendor/autoload.php';

use Mifa\App;
use Fatkulnurk\Microframework\App;

// membuat instance app
$app = App::getInstance();
Expand Down
9 changes: 9 additions & 0 deletions src/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
include 'vendor\autoload.php';

use Mifa\Http\Message\Uri;

$uri = new Uri('https://user:[email protected]:8080/path/123?q=abc#test');
//echo $uri->getPath();
//echo $uri->getQuery();
echo $uri->getQuery();
34 changes: 31 additions & 3 deletions src/route.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
<?php
use Mifa\Routing\RouteCollector;

use Fatkulnurk\Microframework\Routing\RouteCollector;

return function (RouteCollector $r) {
$r->addRoute('GET', '/', function (){

/**
* Example GET route
*
* @param array $args Route parameters
*
* @return \Psr\Http\Message\ResponseInterface
*/
$r->addRoute('GET', '/', function ($args) {
// echo "hello";
// echo "aaaaaaa";
echo json_encode([
'a' => 'b'
]);
header('Content-Type: application/json');
});

$r->addRoute('GET', '/home', function ($args, $request, $response) {
echo "aa";
});
};

$r->addRoute('GET', '/test/{name}', 'Coba::index');
};

// testing handler
class Coba {
public function index() {
echo "Aaaa";
}
}
47 changes: 47 additions & 0 deletions src/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
//ini_set('memory_limit', '-1');
require_once "../vendor/autoload.php";

use FastRoute\RouteCollector;
use Mifa\App;

$app = App::getInstance();

$dispatcher = $app->routing(function (RouteCollector $r){
$r->addRoute('GET', '/', function (){

});
});
// Fetch method and URI from somewhere
$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = $_SERVER['REQUEST_URI'];

// Strip query string (?foo=bar) and decode URI
if (false !== $pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
$uri = rawurldecode($uri);

$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
case FastRoute\Dispatcher::NOT_FOUND:
// ... 404 Not Found
break;
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
$allowedMethods = $routeInfo[1];
// ... 405 Method Not Allowed
break;
case FastRoute\Dispatcher::FOUND:
$handler = $routeInfo[1];
$vars = $routeInfo[2];
// ... call $handler with $vars
die("yeah");
break;
}

//App::getInstance()
// ->routing(function (RouteCollector $r){
// $r->addRoute('GET', '/', function (){
//
// });
// })->dispatch();
49 changes: 29 additions & 20 deletions system/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

declare(strict_types=1);

namespace Mifa;
namespace Fatkulnurk\Microframework;

use Mifa\Routing\Dispatcher;
use Mifa\Routing\RouteParser;
use Mifa\Routing\DataGenerator;
use Mifa\Routing\RouteCollector;
use Fatkulnurk\Microframework\Core\Singleton;
use Fatkulnurk\Microframework\Routing\Dispatcher;
use Fatkulnurk\Microframework\Routing\RouteParser;
use Fatkulnurk\Microframework\Routing\DataGenerator;
use Fatkulnurk\Microframework\Routing\RouteCollector;

class App
{
use Singleton;

/** @var App|null Untuk menyimpan instance dari class ini */
private static $instance = null;
// private static $instance = null;
//
// private function __construct()
// {
// }
//
// /** @return App */
// public static function getInstance() : App
// {
// if (self::$instance == null) {
// self::$instance = new static();
// }
//
// return self::$instance;
// }


/** @var Dispatcher|null Untuk menyimpan informasi dari routing, setelah di deklarasikan */
private $dispatcher;
Expand All @@ -23,19 +41,6 @@ class App
/** @var ResponseInterface|null Untuk menyimpan informasi dari response secara globals */
private $response = null;

private function __construct()
{
}

/** @return App */
public static function getInstance() : App
{
if (self::$instance == null) {
self::$instance = new static();
}

return self::$instance;
}

/**
* Method ini untuk interaksi dengan routing
Expand Down Expand Up @@ -89,8 +94,9 @@ public function routing(callable $routeDefinitionCallback, array $options = []):
*/
public function dispatch() : void
{
// Fetch method and URI from somewhere
// mendapatkan method
$httpMethod = $_SERVER['REQUEST_METHOD'];
// mendapatkan uri
$uri = $_SERVER['REQUEST_URI'];

// Strip query string (?foo=bar) and decode URI
Expand Down Expand Up @@ -130,6 +136,9 @@ public function dispatch() : void
}

break;

default:
new \ErrorException('Handler Error');
}
}
}
9 changes: 9 additions & 0 deletions system/Core/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

namespace Mifa\Core;

class Config
{

}
25 changes: 25 additions & 0 deletions system/Core/Singleton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Fatkulnurk\Microframework\Core;

trait Singleton
{
/**
* Berisi Object dari class yang menggunakan trait ini.
* @var self $instance
*/
private static $instance = null;

/**
* Pembuatan object singleton
* @return self
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new static();
}

return self::$instance;
}
}
13 changes: 13 additions & 0 deletions system/Enum/DispatchEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php


namespace Fatkulnurk\Microframework\Enum;

use MyCLabs\Enum\Enum;

class DispatchEnum extends Enum
{
private const NOT_FOUND = 0;
private const FOUND = 1;
private const METHOD_NOT_ALLOWED = 2;
}
Loading

0 comments on commit e946577

Please sign in to comment.