Skip to content

Commit 3bf3180

Browse files
committed
[Composer] create the project based on bear/skeleton by composer create-project
1 parent e7ced56 commit 3bf3180

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4288
-0
lines changed

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
nbproject
2+
._*
3+
.~lock.*
4+
.buildpath
5+
.DS_Store
6+
.idea
7+
.project
8+
.settings
9+
vendor
10+
cache.properties
11+
build
12+
tmp
13+
*.log
14+
*.tpl.php
15+
composer.phar
16+
resource.db

bin/clear.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Application clear script
4+
*
5+
*/
6+
7+
use BEAR\Package\Bootstrap\Bootstrap;
8+
9+
require dirname(__DIR__) . '/bootstrap/autoload.php';
10+
11+
$clearDirs = [
12+
dirname(__DIR__) . '/var/tmp'
13+
];
14+
15+
Bootstrap::clearApp($clearDirs);
16+

bootstrap/autoload.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace PHPMentors\DomainCoder;
4+
5+
use BEAR\Package\Bootstrap\Bootstrap;
6+
7+
$appDir = dirname(__DIR__);
8+
$packageDir = dirname(dirname(dirname(__DIR__)));
9+
$baseDir = file_exists($appDir . '/vendor/autoload.php') ? $appDir : $packageDir;
10+
$loader = require $baseDir . '/vendor/autoload.php';
11+
12+
Bootstrap::registerLoader(
13+
$loader,
14+
__NAMESPACE__,
15+
dirname(__DIR__)
16+
);

bootstrap/contexts/api.php

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* CLI Built-in web server for API
5+
*
6+
* This is an entry point for an API response based application build.
7+
*
8+
* Examples:
9+
*
10+
* CLI:
11+
* $ php api.pgp get page://self/
12+
* $ php api.pgp get 'page://first/greeting?name=koriym'
13+
*
14+
* Built-in web server:
15+
*
16+
* $ php -S localhost:8089 api.php
17+
*
18+
* @global $context
19+
*/
20+
use BEAR\Resource\Exception\Parameter as BadRequest;
21+
use BEAR\Resource\Exception\ResourceNotFound as NotFound;
22+
23+
//
24+
// The cache is cleared on each request via the following script. We understand that you may want to debug
25+
// your application with caching turned on. When doing so just comment out the following.
26+
//
27+
require dirname(dirname(__DIR__)) . '/bin/clear.php';
28+
29+
//
30+
// Here we get an application instance by setting a $context variable such as (prod, dev, api, stub, test)
31+
// the dev instance provides debugging tools and defaults to help you the development of your application.
32+
//
33+
$context = 'api';
34+
$app = require dirname(dirname(__DIR__)) . '/bootstrap/instance.php';
35+
/* @var $app \BEAR\Package\Provide\Application\AbstractApp */
36+
37+
//
38+
// When using the CLI we set the router arguments needed for CLI use.
39+
// Otherwise just get the path directly from the globals.
40+
//
41+
if (PHP_SAPI === 'cli') {
42+
$app->router->setArgv($argv);
43+
$uri = $argv[2];
44+
parse_str((isset(parse_url($uri)['query']) ? parse_url($uri)['query'] : ''), $get);
45+
} else {
46+
$pathInfo = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : '/index';
47+
$uri = 'app://self' . $pathInfo;
48+
$get = $_GET;
49+
}
50+
51+
//
52+
// Get the method from the router and attempt to request the resource and render.
53+
// On failure trigger the error handler.
54+
//
55+
try {
56+
list($method,) = $app->router->match();
57+
$app->page = $app->resource->$method->uri($uri)->withQuery($get)->eager->request();
58+
} catch (NotFound $e) {
59+
$code = 404;
60+
$body = 'Not Found';
61+
goto ERROR;
62+
} catch (BadRequest $e) {
63+
$code = 400;
64+
$body = 'Bad Request';
65+
goto ERROR;
66+
} catch (Exception $e) {
67+
$code = 503;
68+
$body = 'Service Unavailable';
69+
error_log((string)$e);
70+
goto ERROR;
71+
}
72+
73+
//
74+
// OK: Sets the response resources and renders
75+
// ERROR: sets the response code and loads error page.
76+
//
77+
OK: {
78+
$app->response->setResource($app->page)->render()->send();
79+
exit(0);
80+
}
81+
82+
ERROR: {
83+
if (PHP_SAPI === 'cli') {
84+
$app->exceptionHandler->handle($e);
85+
exit;
86+
}
87+
http_response_code($code);
88+
echo $body;
89+
exit(1);
90+
}

bootstrap/contexts/dev.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
use BEAR\Package\Dev\Dev;
4+
5+
/**
6+
* CLI / Built-in web server script for development
7+
*
8+
* This script is the entry point for CLI an application whilst in development. When in production look
9+
* at index.php. This script is a base guideline and this procedural boot strap is gives you some defaults
10+
* as a guide. You are free to change and configure this script at will.
11+
*
12+
* CLI:
13+
* $ php web.php get /
14+
*
15+
* Built-in web server:
16+
* $ php -S localhost:8080 web.php
17+
*
18+
* @global $context string
19+
*/
20+
21+
ob_start();
22+
23+
// Serve file as is in built in wev-server.
24+
if (php_sapi_name() === 'cli-server' && preg_match('/\.(?:png|jpg|jpeg|gif|js|txt|css)$/', $_SERVER["REQUEST_URI"])) {
25+
return false;
26+
}
27+
28+
$appDir = dirname(dirname(__DIR__));
29+
30+
//
31+
// The cache is cleared on each request via the following script. We understand that you may want to debug
32+
// your application with caching turned on. When doing so just comment out the following.
33+
//
34+
//require $appDir . '/bin/clear.php';
35+
36+
// Here we get an application instance by setting a $context variable such as (prod, dev, api)
37+
// the dev instance provides debugging tools and defaults to help you the development of your application.
38+
$context = 'dev';
39+
$app = require $appDir . '/bootstrap/instance.php';
40+
/* @var $app \BEAR\Package\Provide\Application\AbstractApp */
41+
42+
$devHtml = (new Dev)
43+
->iniSet()
44+
->registerErrorHandler()
45+
->registerFatalErrorHandler()
46+
->registerExceptionHandler("{$appDir}/var/log")
47+
->registerSyntaxErrorEdit()
48+
->setApp($app, $appDir)
49+
->getDevHtml();
50+
if ($devHtml) {
51+
http_response_code(200);
52+
echo $devHtml;
53+
exit(0);
54+
}
55+
56+
//
57+
// Calling the match of a BEAR.Sunday compatible router will give us the $method, $pagePath, $query to be used
58+
// in the page request.
59+
//
60+
list($method, $pagePath, $query) = $app->router->match();
61+
62+
//
63+
// An attempt to request the page resource is made along with setting the response with the resource itself.
64+
// Upon failure the exception handler will be triggered.
65+
//
66+
try {
67+
$app->page = $app->resource->$method->uri('page://self' . $pagePath)->withQuery($query)->eager->request();
68+
$app->response->setResource($app->page)->render()->send();
69+
exit(0);
70+
} catch (Exception $e) {
71+
$app->exceptionHandler->handle($e);
72+
exit(1);
73+
}

bootstrap/contexts/prod.php

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* A Web server script for use in production.
4+
*
5+
* This script is the entry point for an application whilst in production. This script is a base
6+
* guideline and this procedural boot strap is gives you some defaults as a guide.
7+
* You are free to change and configure this script at will.
8+
*
9+
* @global $context
10+
*/
11+
use BEAR\Resource\Exception\MethodNotAllowed;
12+
use BEAR\Resource\Exception\Parameter as BadRequest;
13+
use BEAR\Resource\Exception\ResourceNotFound as NotFound;
14+
15+
//
16+
// Compiled preloader
17+
//
18+
// require dirname(dirname(__DIR__)) . '/var/tmp/preloader/preload.php';
19+
20+
//
21+
// Here we get the production application instance. No $context variable is needed as it defaults to prod.
22+
//
23+
/* @var $app \BEAR\Package\Provide\Application\AbstractApp */
24+
$context = 'prod';
25+
$app = require dirname(dirname(__DIR__)) . '/bootstrap/instance.php';
26+
27+
//
28+
// Calling the match of a BEAR.Sunday compatible router will give us the $method, $pagePath, $query to be used
29+
// in the page request.
30+
//
31+
list($method, $pagePath, $query) = $app->router->match();
32+
33+
//
34+
// An attempt to request the page resource is made.
35+
// Upon failure the appropriate error code is assigned and forwarded to ERROR.
36+
//
37+
try {
38+
$app->page = $app->resource->$method->uri('page://self' . $pagePath)->withQuery($query)->eager->request();
39+
} catch (NotFound $e) {
40+
$code = 404;
41+
goto ERROR;
42+
} catch (MethodNotAllowed $e) {
43+
$code = 405;
44+
goto ERROR;
45+
} catch (BadRequest $e) {
46+
$code = 400;
47+
goto ERROR;
48+
} catch (Exception $e) {
49+
$code = 503;
50+
error_log((string)$e);
51+
goto ERROR;
52+
}
53+
54+
//
55+
// OK: Sets the response resources and renders
56+
// ERROR: sets the response code and loads error page.
57+
//
58+
OK: {
59+
$app->response->setResource($app->page)->render()->send();
60+
exit(0);
61+
}
62+
63+
ERROR: {
64+
http_response_code($code);
65+
require dirname(dirname(__DIR__)) . "/var/lib/http_response/{$code}.php";
66+
exit(1);
67+
}

bootstrap/instance.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Application instance script
4+
*
5+
* @return $app \BEAR\Sunday\Extension\Application\AppInterface
6+
*
7+
* @global $context string configuration context
8+
*/
9+
namespace PHPMentors\DomainCoder;
10+
11+
use BEAR\Package\Bootstrap\Bootstrap;
12+
13+
require_once __DIR__ . '/autoload.php';
14+
15+
$app = Bootstrap::getApp(
16+
__NAMESPACE__,
17+
isset($context) ? $context : 'prod',
18+
dirname(__DIR__) . '/var/tmp'
19+
);
20+
21+
return $app;

0 commit comments

Comments
 (0)