22 |
23 |

24 |
25 |
{{ $app->name() }}
26 |
A lightweight PHP framework with Laravel look like
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "octopyid/octopyframework",
3 | "type": "project",
4 | "description": "A lightweight PHP framework with Laravel look like.",
5 | "license": "MIT",
6 | "keywords": [
7 | "php",
8 | "framework",
9 | "octopy",
10 | "laravel"
11 | ],
12 | "support": {
13 | "issues": "https://github.com/OctopyID/OctopyFramework/issues",
14 | "source": "https://github.com/OctopyID/OctopyFramework"
15 | },
16 | "authors": [
17 | {
18 | "name": "Supian M",
19 | "email": "supianidz@gmail.com"
20 | }
21 | ],
22 | "require": {
23 | "php": "^7.3",
24 | "ext-curl": "*",
25 | "ext-json": "*",
26 | "ext-mbstring": "*"
27 | },
28 | "require-dev": {
29 | "phpunit/phpunit": "^8.0"
30 | },
31 | "config": {
32 | "optimize-autoloader": true,
33 | "preferred-install": "dist",
34 | "sort-packages": true
35 | },
36 | "autoload-dev": {
37 | "psr-4": {
38 | "Octopy\\Testing\\": "testing/"
39 | }
40 | },
41 | "minimum-stability": "dev",
42 | "prefer-stable": true,
43 | "scripts": {
44 | "post-root-package-install": [
45 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
46 | ],
47 | "post-create-project-cmd": [
48 | "@php octopy key:generate"
49 | ]
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/octopy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 |
12 | * @link : framework.octopy.id
13 | * @license : MIT
14 | */
15 |
16 | /*
17 | |--------------------------------------------------------------------------
18 | | Turn On The Lights
19 | |--------------------------------------------------------------------------
20 | |
21 | | We need to Octopy PHP development, so let us turn on the lights.
22 | | This bootstraps the framework and gets it ready for use, then it
23 | | will load up this application so that we can run it and send
24 | | the responses back to the terminal and delight our users.
25 | |
26 | */
27 | $app = require 'system/Octopy.php';
28 |
29 | /*
30 | |--------------------------------------------------------------------------
31 | | Run The Octopy Application
32 | |--------------------------------------------------------------------------
33 | |
34 | | When we run the console application, the current CLI command will be
35 | | executed in this console and the response sent back to a terminal
36 | | or another output device for the developers. Here goes nothing!
37 | |
38 | */
39 | $kernel = $app->make(App\Console\Kernel::class);
40 |
41 | $status = $kernel->handle(
42 | $input = $app->make(Octopy\Console\Argv::class, [
43 | 'argv' => $argv,
44 | ]),
45 |
46 | $app->make(Octopy\Console\Output::class)
47 | );
48 |
49 | $kernel->terminate($input);
50 |
51 | die($status);
52 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | testing
20 |
21 |
22 |
23 |
24 | system
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/public/.htaccess:
--------------------------------------------------------------------------------
1 | # Front of Controller
2 | DirectoryIndex index.php
3 |
4 | # ----------------------------------------------------------------------
5 | # UTF-8 Encoding
6 | # ----------------------------------------------------------------------
7 | AddDefaultCharset utf-8
8 |
9 | # Force UTF-8
10 |
11 | AddCharset utf-8 .atom .css .js .json .rss .vtt .xml
12 |
13 |
14 | # ----------------------------------------------------------------------
15 | # Rewrite Engine
16 | # ----------------------------------------------------------------------
17 |
18 | Options -MultiViews -Indexes
19 |
20 |
21 |
22 | RewriteEngine On
23 |
24 | # Handle Authorization Header
25 | RewriteCond %{HTTP:Authorization} .
26 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
27 |
28 | # Redirect Trailing Slashes If Not A Folder...
29 | RewriteCond %{REQUEST_FILENAME} !-d
30 | RewriteCond %{REQUEST_URI} (.+)/$
31 | RewriteRule ^ %1 [L,R=301]
32 |
33 | # Handle Front Controller...
34 | RewriteCond %{REQUEST_FILENAME} !-d
35 | RewriteCond %{REQUEST_FILENAME} !-f
36 | RewriteRule ^ index.php [L]
37 |
38 |
39 |
40 | # If we don't have mod_rewrite installed, all 404's
41 | # can be sent to index.php, and everything works as normal.
42 | ErrorDocument 404 /index.php
43 |
44 |
45 | # ----------------------------------------------------------------------
46 | # Gzip Compression
47 | # ----------------------------------------------------------------------
48 |
49 |
50 |
51 | SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
52 | RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OctopyID/OctopyFramework/d4720f4c4621942fbf83f275868d72d9dad090e2/public/favicon.ico
--------------------------------------------------------------------------------
/public/img/octopy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OctopyID/OctopyFramework/d4720f4c4621942fbf83f275868d72d9dad090e2/public/img/octopy.png
--------------------------------------------------------------------------------
/public/index.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | /*
16 | |--------------------------------------------------------------------------
17 | | Turn On The Lights
18 | |--------------------------------------------------------------------------
19 | |
20 | | We need to Octopy PHP development, so let us turn on the lights.
21 | | This bootstraps the framework and gets it ready for use, then it
22 | | will load up this application so that we can run it and send
23 | | the responses back to the browser and delight our users.
24 | |
25 | */
26 | $app = require __DIR__ . '/../system/Octopy.php';
27 |
28 | /*
29 | |--------------------------------------------------------------------------
30 | | Run The Application
31 | |--------------------------------------------------------------------------
32 | |
33 | | Once we have the application, we can handle the incoming request
34 | | through the kernel, and send the associated response back to
35 | | the client's browser allowing them to enjoy the creative
36 | | and wonderful application we have prepared for them.
37 | |
38 | */
39 | $kernel = $app->make(App\HTTP\Kernel::class);
40 |
41 | $response = $kernel->handle(
42 | $request = $app->make(Octopy\HTTP\Request::class)
43 | );
44 |
45 | $response->send();
46 |
47 | $kernel->terminate($request, $response);
48 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
3 |
--------------------------------------------------------------------------------
/public/web.config:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/server.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | $uri = urldecode(
16 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
17 | );
18 |
19 | /*
20 | * This file allows us to emulate Apache's "mod_rewrite" functionality from the
21 | * built-in PHP web server. This provides a convenient way to test a Octopy
22 | * application without having installed a "real" web server software here.
23 | */
24 | if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) {
25 | return false;
26 | }
27 |
28 | require __DIR__ . '/public/index.php';
29 |
--------------------------------------------------------------------------------
/storage/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
--------------------------------------------------------------------------------
/system/.htaccess:
--------------------------------------------------------------------------------
1 | # Security is KING
2 |
3 | Require all denied
4 |
5 |
6 |
7 | Deny from all
8 |
9 |
--------------------------------------------------------------------------------
/system/Bootstrap/BootUpServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Bootstrap;
16 |
17 | use Throwable;
18 | use Octopy\Application;
19 |
20 | class BootUpServiceProvider
21 | {
22 | /**
23 | * @param Application $app
24 | */
25 | public function bootstrap(Application $app)
26 | {
27 | try {
28 | $app->booting();
29 | } catch (Throwable $exception) {
30 | throw $exception;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/system/Bootstrap/RegisterEnvironmentVariable.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Bootstrap;
16 |
17 | use Throwable;
18 | use Octopy\Application;
19 | use Octopy\Config\DotEnv;
20 |
21 | class RegisterEnvironmentVariable
22 | {
23 | /**
24 | * @param Application $app
25 | */
26 | public function bootstrap(Application $app)
27 | {
28 | try {
29 | $app->instance('env', new DotEnv($app->basepath()))->load();
30 | } catch (Throwable $exception) {
31 | throw $exception;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/system/Bootstrap/RegisterMiddlewareProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Bootstrap;
16 |
17 | use Octopy\Application;
18 | use Octopy\HTTP\Middleware;
19 |
20 | class RegisterMiddlewareProvider
21 | {
22 | /**
23 | * @var Octopy\HTTP\Middleware
24 | */
25 | protected $middleware;
26 |
27 | /**
28 | * @param Middleware $middleware
29 | */
30 | public function __construct(Middleware $middleware)
31 | {
32 | $this->middleware = $middleware;
33 | }
34 |
35 | /**
36 | * @param Application $app
37 | */
38 | public function bootstrap(Application $app)
39 | {
40 | $this->middleware->set(\Octopy\HTTP\Middleware\ValidatePostSize::class);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/system/Bootstrap/RegisterServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Bootstrap;
16 |
17 | use Octopy\Application;
18 |
19 | class RegisterServiceProvider
20 | {
21 | /**
22 | * @param Application $app
23 | */
24 | public function bootstrap(Application $app)
25 | {
26 | $array = $app->config->get('app', []);
27 |
28 | // register class aliases
29 | $app['autoload']->aliases($array['aliases'] ?? []);
30 |
31 | // register service provider
32 | usort($array['provider'], static function ($provider) {
33 | return mb_substr($provider, 0, 3) === 'App';
34 | });
35 |
36 | $array['provider'] = array_merge(['Octopy\Provider\EncryptionServiceProvider'], $array['provider']);
37 |
38 | foreach ($array['provider'] as $provider) {
39 | $app->register($provider, true);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/system/Bootstrap/RegisterSystemConfiguration.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Bootstrap;
16 |
17 | use Octopy\FileSystem;
18 | use Octopy\Application;
19 | use Octopy\Config\Repository;
20 |
21 | class RegisterSystemConfiguration
22 | {
23 | /**
24 | * @var Octopy\FileSystem\PathLocator
25 | */
26 | protected $path;
27 |
28 | /**
29 | * @var Octopy\FileSystem
30 | */
31 | protected $filesystem;
32 |
33 | /**
34 | * @param FileSystem $filesystem
35 | */
36 | public function __construct(FileSystem $filesystem)
37 | {
38 | $this->filesystem = $filesystem;
39 | }
40 |
41 | /**
42 | * @param Application $app
43 | */
44 | public function bootstrap(Application $app)
45 | {
46 | // set path locator
47 | $this->path = $app->path;
48 |
49 | // set item to config repository
50 | $app->instance('config', $config = new Repository(
51 | $this->search($this->path->app->config())
52 | ));
53 |
54 | // setting up default config
55 | mb_internal_encoding('UTF-8');
56 | date_default_timezone_set($config->get('app.timezone', 'UTC'));
57 | }
58 |
59 | /**
60 | * @param string $path
61 | * @return array
62 | */
63 | protected function search(string $path) : array
64 | {
65 | $config = [];
66 |
67 | $iterator = $this->filesystem->iterator($path);
68 | foreach ($iterator as $row) {
69 | if ($row->isDir()) {
70 | continue;
71 | }
72 |
73 | $key = mb_strtolower(mb_substr($row->getFilename(), 0, -4));
74 |
75 | $config[$key] = require $row->getRealpath();
76 | }
77 |
78 | if (array_key_exists('constant', $config)) {
79 | unset($config['constant']);
80 | }
81 |
82 | return $config;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/system/Config/Container.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | return [
16 | 'app' => Octopy\Application::class,
17 | 'auth' => Octopy\Foundation\Auth::class,
18 | 'argv' => Octopy\Console\Argv::class,
19 | 'autoload' => Octopy\Autoload::class,
20 | 'config' => Octopy\Config::class,
21 | 'console' => Octopy\Console::class,
22 | 'database' => Octopy\Database::class,
23 | 'datetime' => Octopy\Support\DateTime::class,
24 | 'toolbar' => Octopy\Debug\Toolbar::class,
25 | 'encrypter' => Octopy\Encryption\Encrypter::class,
26 | 'env' => Octopy\Config\DotEnv::class,
27 | 'filesystem' => Octopy\FileSystem::class,
28 | 'hash' => Octopy\Hashing\HashManager::class,
29 | 'lang' => Octopy\Language::class,
30 | 'logger' => Octopy\Logger::class,
31 | 'middleware' => Octopy\HTTP\Middleware::class,
32 | 'path' => Octopy\FileSystem\PathLocator::class,
33 | 'request' => Octopy\HTTP\Request::class,
34 | 'response' => Octopy\HTTP\Response::class,
35 | 'route' => Octopy\HTTP\Routing\Router::class,
36 | 'router' => Octopy\HTTP\Routing\Router::class,
37 | 'schema' => Octopy\Database\Migration\Schema::class,
38 | 'session' => Octopy\Session::class,
39 | 'syntax' => Octopy\Support\Syntax::class,
40 | 'url' => Octopy\HTTP\Routing\URLGenerator::class,
41 | 'validator' => Octopy\Validation\Validator::class,
42 | 'vardump' => Octopy\Support\VarDump::class,
43 | 'view' => Octopy\View\Engine::class,
44 | ];
45 |
--------------------------------------------------------------------------------
/system/Config/Exception/DotEnvException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Config\Exception;
16 |
17 | use InvalidArgumentException;
18 |
19 | class DotEnvException extends InvalidArgumentException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Console/Collection.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console;
16 |
17 | use Countable;
18 | use ArrayAccess;
19 | use ArrayIterator;
20 | use IteratorAggregate;
21 |
22 | class Collection implements ArrayAccess, Countable, IteratorAggregate
23 | {
24 | /**
25 | * @var array
26 | */
27 | protected $command = [];
28 |
29 | /**
30 | * @param Route $command
31 | */
32 | public function set(Route $command)
33 | {
34 | $this->command = array_merge($this->command, [
35 | $command->command() => $command,
36 | ]);
37 |
38 | return $command;
39 | }
40 |
41 | /**
42 | * @return array
43 | */
44 | public function all() : array
45 | {
46 | asort($this->command);
47 |
48 | return $this->command;
49 | }
50 |
51 | /**
52 | * @return ArrayIterator
53 | */
54 | public function getIterator()
55 | {
56 | return new ArrayIterator($this->command);
57 | }
58 |
59 | /**
60 | * @return int
61 | */
62 | public function count()
63 | {
64 | return count($this->command);
65 | }
66 |
67 | /**
68 | * @param string $key
69 | * @return bool
70 | */
71 | public function offsetExists($key)
72 | {
73 | return isset($this->command[$key]);
74 | }
75 |
76 | /**
77 | * @param string $key
78 | * @return object
79 | */
80 | public function offsetGet($key)
81 | {
82 | return $this->command[$key] ?? null;
83 | }
84 |
85 | /**
86 | * @param string $key
87 | * @param mixed $value
88 | * @return null
89 | */
90 | public function offsetSet($key, $value)
91 | {
92 | }
93 |
94 | /**
95 | * @param string $key
96 | */
97 | public function offsetUnset($key)
98 | {
99 | unset($this->command[$key]);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/system/Console/Command/AutoloadClearCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class AutoloadClearCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'autoload:clear';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Clear autoload cache';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | if (file_exists($autoload = $this->app['path']->storage('autoload.php'))) {
51 | unlink($autoload);
52 | }
53 |
54 | return $output->success('Autoload cache cleared.');
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/system/Console/Command/DatabaseRefreshCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class DatabaseRefreshCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'database:refresh';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Drop all tables and re-run all migration and seeder';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | echo $this->call('database:migrate', [
51 | '--seed' => true,
52 | '--refresh' => true,
53 | ]);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/system/Console/Command/MaintenanceDownCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MaintenanceDownCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'maintenance:down';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [
33 | '--message[=MESSAGE]' => 'The message for the maintenance mode',
34 | '--allow[=ALLOW]' => 'IP or networks allowed to access the application while in maintenance mode',
35 | ];
36 |
37 | /**
38 | * @var array
39 | */
40 | protected $argument = [];
41 |
42 | /**
43 | * @var string
44 | */
45 | protected $description = 'Put the application into maintenance mode';
46 |
47 | /**
48 | * @param Argv $argv
49 | * @param Output $output
50 | * @return string
51 | */
52 | public function handle(Argv $argv, Output $output)
53 | {
54 | $message = 'Sorry, we are doing some maintenance. Please check back soon.';
55 | if ($argv->get('--message')) {
56 | $message = $argv->get('--message');
57 | }
58 |
59 | $allowed = [];
60 | if ($argv->get('--allow')) {
61 | $allowed = array_map('trim', explode(',', $argv->get('--allow')));
62 | }
63 |
64 | try {
65 | $location = $this->app['path']->storage('maintenance.json');
66 |
67 | $this->app['filesystem']->put($location, json_encode([
68 | 'time' => time(),
69 | 'message' => $message,
70 | 'allowed' => $allowed,
71 | ], JSON_PRETTY_PRINT));
72 |
73 | return $output->warning('Application is now in maintenance mode.');
74 | } catch (Exception $exception) {
75 | throw $exception;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/system/Console/Command/MaintenanceUpCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class MaintenanceUpCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'maintenance:up';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Bring the application out of maintenance mode';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | $down = $this->app['path']->storage('maintenance.json');
51 |
52 | if (file_exists($down)) {
53 | unlink($down);
54 | }
55 |
56 | return $output->success('Application is now live.');
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/system/Console/Command/MakeConsoleCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MakeConsoleCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'make:command';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [
33 | '--command[=COMMAND]' => 'The terminal command that should be assigned [default: "command:name"]',
34 | ];
35 |
36 | /**
37 | * @var array
38 | */
39 | protected $argument = [
40 | 'name' => 'The name of the class',
41 | ];
42 |
43 | /**
44 | * @var string
45 | */
46 | protected $description = 'Create a new console command';
47 |
48 | /**
49 | * @param Argv $argv
50 | * @param Output $output
51 | * @return string
52 | */
53 | public function handle(Argv $argv, Output $output)
54 | {
55 | try {
56 | $parsed = $this->parse($argv);
57 | } catch (Exception $exception) {
58 | return $output->error('Not enough arguments (missing : "name").');
59 | }
60 |
61 | if (file_exists($location = $this->app['path']->app->console->command($parsed['location']))) {
62 | return $output->warning('Command already exists.');
63 | }
64 |
65 | if (! ($command = $argv->get('--command'))) {
66 | $command = 'command:name';
67 | }
68 |
69 | $data = [
70 | 'DummyClassName' => $parsed['classname'],
71 | 'DummyCommandName' => $command,
72 | ];
73 |
74 | if ($this->generate($location, 'Command', $data)) {
75 | return $output->success('Command created successfully.');
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/system/Console/Command/MakeMiddlewareCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MakeMiddlewareCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'make:middleware';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [];
33 |
34 | /**
35 | * @var array
36 | */
37 | protected $argument = [
38 | 'name' => 'The name of the class',
39 | ];
40 |
41 | /**
42 | * @var string
43 | */
44 | protected $description = 'Create a new middleware class';
45 |
46 | /**
47 | * @param Argv $argv
48 | * @param Output $output
49 | * @return string
50 | */
51 | public function handle(Argv $argv, Output $output)
52 | {
53 | try {
54 | $parsed = $this->parse($argv);
55 | } catch (Exception $exception) {
56 | return $output->error('Not enough arguments (missing : "name").');
57 | }
58 |
59 | if (file_exists($location = $this->app['path']->app->HTTP->middleware($parsed['location']))) {
60 | return $output->warning('Middleware already exists.');
61 | }
62 |
63 | $data = [
64 | 'DummyNameSpace' => $parsed['namespace'],
65 | 'DummyClassName' => $parsed['classname'],
66 | ];
67 |
68 | if ($this->generate($location, 'Middleware', $data)) {
69 | return $output->success('Middleware created successfully.');
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/system/Console/Command/MakeMigrationCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MakeMigrationCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'make:migration';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [];
33 |
34 | /**
35 | * @var array
36 | */
37 | protected $argument = [
38 | 'name' => 'The name of the class',
39 | ];
40 |
41 | /**
42 | * @var string
43 | */
44 | protected $description = 'Create a new migration class';
45 |
46 | /**
47 | * @param Argv $argv
48 | * @param Output $output
49 | * @return string
50 | */
51 | public function handle(Argv $argv, Output $output)
52 | {
53 | try {
54 | $parsed = $this->parse($argv);
55 | } catch (Exception $exception) {
56 | return $output->error('Not enough arguments (missing : "name").');
57 | }
58 |
59 | if (file_exists($location = $this->app['path']->app->DB->migration($parsed['location']))) {
60 | return $output->warning('Migration already exists.');
61 | }
62 |
63 | if (($table = $argv->get('-t')) === false && ($table = $argv->get('--table')) === false) {
64 | $table = str_ireplace('Migration', '', mb_strtolower($parsed['classname']));
65 | }
66 |
67 | $data = [
68 | 'DummyTimeStamp' => time(),
69 | 'DummyTableName' => $table,
70 | 'DummyNameSpace' => $parsed['namespace'],
71 | 'DummyClassName' => $parsed['classname'],
72 | ];
73 |
74 | if ($this->generate($location, 'Migration', $data)) {
75 | return $output->success('Migration created successfully.');
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/system/Console/Command/MakeModelCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MakeModelCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'make:model';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [];
33 |
34 | /**
35 | * @var array
36 | */
37 | protected $argument = [
38 | 'name' => 'The name of the class',
39 | ];
40 |
41 | /**
42 | * @var string
43 | */
44 | protected $description = 'Create a new database model class';
45 |
46 | /**
47 | * @param Argv $argv
48 | * @param Output $output
49 | * @return string
50 | */
51 | public function handle(Argv $argv, Output $output)
52 | {
53 | try {
54 | $parsed = $this->parse($argv);
55 | } catch (Exception $exception) {
56 | return $output->error('Not enough arguments (missing : "name").');
57 | }
58 |
59 | if (file_exists($location = $this->app['path']->app->DB($parsed['location']))) {
60 | return $output->warning('Model already exists.');
61 | }
62 |
63 | if (($table = $argv->get('-t')) === false && ($table = $argv->get('--table')) === false) {
64 | $table = mb_strtolower($parsed['classname']);
65 | }
66 |
67 | $data = [
68 | 'DummyTableName' => $table,
69 | 'DummyNameSpace' => $parsed['namespace'],
70 | 'DummyClassName' => $parsed['classname'],
71 | ];
72 |
73 | if ($this->generate($location, 'Model', $data)) {
74 | return $output->success('Model created successfully.');
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/system/Console/Command/MakeSeederCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class MakeSeederCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'make:seeder';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [];
33 |
34 | /**
35 | * @var array
36 | */
37 | protected $argument = [
38 | 'name' => 'The name of the class',
39 | ];
40 |
41 | /**
42 | * @var string
43 | */
44 | protected $description = 'Create a new seeder class';
45 |
46 | /**
47 | * @param Argv $argv
48 | * @param Output $output
49 | * @return string
50 | */
51 | public function handle(Argv $argv, Output $output)
52 | {
53 | try {
54 | $parsed = $this->parse($argv);
55 | } catch (Exception $exception) {
56 | return $output->error('Not enough arguments (missing : "name").');
57 | }
58 |
59 | if (file_exists($location = $this->app['path']->app->DB->seeder($parsed['location']))) {
60 | return $output->warning('Seeder already exists.');
61 | }
62 |
63 | $data = [
64 | 'DummyClassName' => $parsed['classname'],
65 | ];
66 |
67 | if ($this->generate($location, 'Seeder', $data)) {
68 | return $output->success('Seeder created successfully.');
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/system/Console/Command/OctopyServeCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class OctopyServeCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'serve';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [
32 | '--port[=PORT]' => 'The port to serve the application on [default: 1337]',
33 | ];
34 |
35 | /**
36 | * @var array
37 | */
38 | protected $argument = [];
39 |
40 | /**
41 | * @var string
42 | */
43 | protected $description = 'Serve the application on the PHP development server';
44 |
45 | /**
46 | * @param Argv $argv
47 | * @param Output $output
48 | * @return string
49 | */
50 | public function handle(Argv $argv, Output $output)
51 | {
52 | if (($port = $argv->get('-p')) === false && ($port = $argv->get('--port')) === false) {
53 | $port = 1337;
54 | }
55 |
56 | $info = $output->format(
57 | '
Octopy CLI Tool - Version ' . $this->app->version() . ' - Server Time : ' . date('Y-m-d H:i:s')
58 | );
59 | $info .= "\n";
60 | $info .= $output->format('Octopy development server started : http://localhost:' . $port, true);
61 | $info .= $output->format('Press Control-C to stop development server.');
62 |
63 | echo $info;
64 |
65 | foreach (['system', 'shell', 'shell_exec', 'exec'] as $shell) {
66 | if (function_exists($shell)) {
67 | $shell('php -S localhost:' . $port . ' -t ' . $this->app['path']->public());
68 | break;
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/system/Console/Command/OptimizeCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Exception;
18 | use Octopy\Console\Argv;
19 | use Octopy\Console\Output;
20 | use Octopy\Console\Command;
21 |
22 | class OptimizeCommand extends Command
23 | {
24 | /**
25 | * @var string
26 | */
27 | protected $command = 'optimize';
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $options = [];
33 |
34 | /**
35 | * @var array
36 | */
37 | protected $argument = [];
38 |
39 | /**
40 | * @var string
41 | */
42 | protected $description = 'Cache the framework for better performance';
43 |
44 | /**
45 | * @param Argv $argv
46 | * @param Output $output
47 | * @return string
48 | */
49 | public function handle(Argv $argv, Output $output)
50 | {
51 | echo $this->call('autoload:cache');
52 |
53 | echo $this->call('view:clear');
54 | echo $this->call('view:cache');
55 |
56 | try {
57 | echo $this->call('route:cache');
58 | } catch (Exception $exception) {
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/system/Console/Command/RouteClearCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class RouteClearCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'route:clear';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Remove the route cache file';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | $cache = $this->app->storage();
51 | $cache .= '9C46408A3BC655C68505C57A11D6C4EE';
52 |
53 | if (file_exists($cache)) {
54 | unlink($cache);
55 | }
56 |
57 | return $output->success('Route cache cleared.');
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/system/Console/Command/ViewCacheCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class ViewCacheCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'view:cache';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Compile all of the application\'s Octopy templates';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | $iterator = $this->app['filesystem']->iterator($this->app['config']['view.resource']);
51 |
52 | foreach ($iterator as $row) {
53 | $filename = str_replace(['.octopy.php', '.php'], '', $row->getFilename());
54 | $this->app['view']->render($filename, [], false);
55 | }
56 |
57 | return $output->success('Template cached successfully.');
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/system/Console/Command/ViewClearCommand.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class ViewClearCommand extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'view:clear';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = 'Clear all compiled view files';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | $iterator = $this->app['filesystem']->iterator(
51 | $this->app['config']['view.compiled']
52 | );
53 |
54 | foreach ($iterator as $row) {
55 | try {
56 | unlink($row);
57 | } catch (Throwable $exception) {
58 | continue;
59 | }
60 | }
61 |
62 | return $output->success('Compiled views cleared.');
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Cache.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | return 'SerializedContent';
16 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Command.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\Console\Command;
16 |
17 | use Octopy\Console\Argv;
18 | use Octopy\Console\Output;
19 | use Octopy\Console\Command;
20 |
21 | class DummyClassName extends Command
22 | {
23 | /**
24 | * @var string
25 | */
26 | protected $command = 'DummyCommandName';
27 |
28 | /**
29 | * @var array
30 | */
31 | protected $options = [];
32 |
33 | /**
34 | * @var array
35 | */
36 | protected $argument = [];
37 |
38 | /**
39 | * @var string
40 | */
41 | protected $description = '';
42 |
43 | /**
44 | * @param Argv $argv
45 | * @param Output $output
46 | * @return string
47 | */
48 | public function handle(Argv $argv, Output $output)
49 | {
50 | //
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Controller.api.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\HTTP\Controller\DummyNameSpace;
16 |
17 | use App\HTTP\Controller;
18 | use Octopy\HTTP\Request;
19 | use Octopy\HTTP\Response;
20 |
21 | class DummyClassName extends Controller
22 | {
23 | /**
24 | * @return Response
25 | */
26 | public function index()
27 | {
28 | //
29 | }
30 |
31 | /**
32 | * @param Request $request
33 | * @return Response
34 | */
35 | public function store(Request $request)
36 | {
37 | //
38 | }
39 |
40 | /**
41 | * @param int $id
42 | * @return Response
43 | */
44 | public function show($id)
45 | {
46 | //
47 | }
48 |
49 | /**
50 | * @param Request $request
51 | * @param int $id
52 | * @return Response
53 | */
54 | public function update(Request $request, $id)
55 | {
56 | //
57 | }
58 |
59 | /**
60 | * @param int $id
61 | * @return Response
62 | */
63 | public function destroy($id)
64 | {
65 | //
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Controller.plain.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\HTTP\Controller\DummyNameSpace;
16 |
17 | use App\HTTP\Controller;
18 |
19 | class DummyClassName extends Controller
20 | {
21 | //
22 | }
23 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Controller.resource.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\HTTP\Controller\DummyNameSpace;
16 |
17 | use App\HTTP\Controller;
18 | use Octopy\HTTP\Request;
19 | use Octopy\HTTP\Response;
20 |
21 | class DummyClassName extends Controller
22 | {
23 | /**
24 | * @return Response
25 | */
26 | public function index()
27 | {
28 | //
29 | }
30 |
31 | /**
32 | * @return Response
33 | */
34 | public function create()
35 | {
36 | //
37 | }
38 |
39 | /**
40 | * @param Request $request
41 | * @return Response
42 | */
43 | public function store(Request $request)
44 | {
45 | //
46 | }
47 |
48 | /**
49 | * @param int $id
50 | * @return Response
51 | */
52 | public function show($id)
53 | {
54 | //
55 | }
56 |
57 | /**
58 | * @param int $id
59 | * @return Response
60 | */
61 | public function edit($id)
62 | {
63 | //
64 | }
65 |
66 | /**
67 | * @param Request $request
68 | * @param int $id
69 | * @return Response
70 | */
71 | public function update(Request $request, $id)
72 | {
73 | //
74 | }
75 |
76 | /**
77 | * @param int $id
78 | * @return Response
79 | */
80 | public function destroy($id)
81 | {
82 | //
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Middleware.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\HTTP\Middleware\DummyNameSpace;
16 |
17 | use Closure;
18 | use Octopy\HTTP\Request;
19 |
20 | class DummyClassName
21 | {
22 | /**
23 | * @param Request $request
24 | * @param Closure $next
25 | * @return Request
26 | */
27 | public function handle(Request $request, Closure $next)
28 | {
29 | return $next($request);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Migration.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\DB\Migration;
16 |
17 | use Octopy\Database\Migration;
18 | use Octopy\Support\Facade\Schema;
19 | use Octopy\Database\Migration\BluePrint;
20 |
21 | class DummyClassName extends Migration
22 | {
23 | /**
24 | * @var int
25 | */
26 | public static $timestamp = DummyTimeStamp;
27 |
28 | /**
29 | * @return void
30 | */
31 | public function create()
32 | {
33 | Schema::create('DummyTableName', static function (BluePrint $table) {
34 | $table->increment('id');
35 | });
36 | }
37 |
38 | /**
39 | * @return void
40 | */
41 | public function drop()
42 | {
43 | Schema::drop('DummyTableName');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Model.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\DB\DummyNameSpace;
16 |
17 | use Octopy\Database\Model;
18 |
19 | class DummyClassName extends Model
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected $table = 'DummyTableName';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Console/Command/stub/Seeder.stub:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace App\DB\Seeder;
16 |
17 | use Octopy\Database\Seeder;
18 |
19 | class DummyClassName extends Seeder
20 | {
21 | /**
22 | * @return void
23 | */
24 | public function seed()
25 | {
26 | //
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/system/Console/Exception/InvalidStyleException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Exception;
16 |
17 | use Exception;
18 |
19 | class InvalidStyleException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Console/Exception/NotEnoughArgumentException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console\Exception;
16 |
17 | use InvalidArgumentException;
18 |
19 | class NotEnoughArgumentException extends InvalidArgumentException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Console/Kernel.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Console;
16 |
17 | use Octopy\Application;
18 |
19 | class Kernel
20 | {
21 | /**
22 | * @var Octopy\Application
23 | */
24 | protected $app;
25 |
26 | /**
27 | * @var array
28 | */
29 | protected $bootstrap = [
30 | \Octopy\Bootstrap\RegisterEnvironmentVariable::class,
31 | \Octopy\Bootstrap\RegisterSystemConfiguration::class,
32 | \Octopy\Bootstrap\RegisterExceptionHandler::class,
33 | \Octopy\Bootstrap\RegisterServiceProvider::class,
34 | \Octopy\Bootstrap\BootUpServiceProvider::class,
35 | ];
36 |
37 | /**
38 | * @param Application $app
39 | */
40 | public function __construct(Application $app)
41 | {
42 | $this->app = $app;
43 |
44 | try {
45 | foreach ($this->bootstrap as $bootstrap) {
46 | $app->make($bootstrap)->bootstrap($app);
47 | }
48 | } catch (Exception $exception) {
49 | throw $exception;
50 | }
51 | }
52 |
53 | /**
54 | * @param Argv $argv
55 | * @param Output $output
56 | * @return string
57 | */
58 | public function handle(Argv $argv, Output $output)
59 | {
60 | try {
61 | return $this->ansi(
62 | $this->app['console']->dispatch($argv, $output)
63 | );
64 | } catch (Exception $exception) {
65 | throw $exception;
66 | }
67 | }
68 |
69 | /**
70 | * @param Argv $argv
71 | */
72 | public function terminate(Argv $argv)
73 | {
74 | $this->app->terminate();
75 | }
76 |
77 | /**
78 | * @param string $string
79 | * @return string
80 | */
81 | private function ansi(?string $string) : ?string
82 | {
83 | if (strcasecmp(mb_substr(PHP_OS, 0, 3), 'WIN') === 0) {
84 | $string = preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $string);
85 | }
86 |
87 | return $string;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/system/Container/Exception/BindingResolutionException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Container\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class BindingResolutionException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Database/Connection.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database;
16 |
17 | class Connection
18 | {
19 | /**
20 | * @var string
21 | */
22 | protected $driver;
23 |
24 | /**
25 | * @var array
26 | */
27 | protected $config;
28 |
29 | /**
30 | * @param string $driver
31 | * @param array $config
32 | */
33 | public function __construct(string $driver, array $config)
34 | {
35 | $this->driver = $driver;
36 | $this->config = $config;
37 | }
38 |
39 | /**
40 | * @param string $driver
41 | * @param array $config
42 | * @return PDO
43 | */
44 | public function connect()
45 | {
46 | switch (mb_strtolower($this->driver)) {
47 | case 'mysql':
48 | return new \Octopy\Database\Driver\MySQL(
49 | $this->config['hostname'],
50 | $this->config['database'],
51 | $this->config['username'],
52 | $this->config['password']
53 | );
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/system/Database/Driver/MySQL.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database\Driver;
16 |
17 | use PDO;
18 | use PDOException;
19 |
20 | class MySQL extends PDO
21 | {
22 | /**
23 | * @param string $hostname
24 | * @param string $database
25 | * @param string $username
26 | * @param string $password
27 | */
28 | public function __construct(string $hostname, string $database, string $username, string $password)
29 | {
30 | try {
31 | parent::__construct("mysql:host=$hostname;dbname=$database;charset=utf8", $username, $password, [
32 | MySQL::ATTR_PERSISTENT => true,
33 | MySQL::ATTR_CASE => MySQL::CASE_LOWER,
34 | MySQL::ATTR_ERRMODE => MySQL::ERRMODE_WARNING,
35 | MySQL::ATTR_ERRMODE => MySQL::ERRMODE_EXCEPTION,
36 | MySQL::ATTR_DEFAULT_FETCH_MODE => MySQL::FETCH_OBJ,
37 | ]);
38 | } catch (PDOException $exception) {
39 | throw $exception;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/system/Database/Exception/DBException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database\Exception;
16 |
17 | use PDOException;
18 |
19 | class DBException extends PDOException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Database/Migration/BluePrint/BluePrint.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database\Migration;
16 |
17 | use Octopy\Application;
18 |
19 | abstract class BluePrint
20 | {
21 | /**
22 | * @var Octopy\Application;
23 | */
24 | protected $app;
25 |
26 | /**
27 | * @var array
28 | */
29 | protected $query = [];
30 |
31 | /**
32 | * @var array
33 | */
34 | protected $index = [];
35 |
36 | /**
37 | * @var array
38 | */
39 | protected $primary = [];
40 |
41 | /**
42 | * @var array
43 | */
44 | protected $unique = [];
45 |
46 | /**
47 | * @param Application $app
48 | */
49 | public function __construct(Application $app)
50 | {
51 | $this->app = $app;
52 | }
53 |
54 | /**
55 | * @param string $query
56 | * @return bool
57 | */
58 | protected function query(string $query)
59 | {
60 | return $this->app['database']->query($query);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/system/Database/Migration/Migration.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database;
16 |
17 | use Octopy\Application;
18 |
19 | abstract class Migration
20 | {
21 | /**
22 | * @var Octopy\Application
23 | */
24 | protected $app;
25 |
26 | /**
27 | * @param Application $app
28 | */
29 | public function __construct(Application $app)
30 | {
31 | $this->app = $app;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/system/Database/Migration/Schema.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database\Migration;
16 |
17 | use Closure;
18 | use Octopy\Application;
19 | use Octopy\Database\Exception\DBException;
20 |
21 | class Schema
22 | {
23 | /**
24 | * @var Octopy\Database\Migration\BluePrint
25 | */
26 | protected $blueprint;
27 |
28 | /**
29 | * @param Application $app
30 | */
31 | public function __construct(Application $app)
32 | {
33 | try {
34 | $this->blueprint = $app->make(
35 | \Octopy\Database\Migration\BluePrint\MySQL::class
36 | );
37 | } catch (DBException $exception) {
38 | throw $exception;
39 | }
40 | }
41 |
42 | /**
43 | * @param string $table
44 | * @param Closure $callback
45 | * @return BluePrint
46 | */
47 | public function create(string $table, Closure $callback)
48 | {
49 | if ($callback instanceof Closure) {
50 | $callback($this->blueprint);
51 | }
52 |
53 | return $this->blueprint->create($table);
54 | }
55 |
56 | /**
57 | * @param string $table
58 | */
59 | public function drop(string $table)
60 | {
61 | return $this->blueprint->drop($table);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/system/Database/Queries.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database;
16 |
17 | class Queries
18 | {
19 | /**
20 | * @var array
21 | */
22 | protected static $queries = [];
23 |
24 | /**
25 | * @param string $query
26 | */
27 | public static function collect(string $query)
28 | {
29 | static::$queries[] = $query;
30 | }
31 |
32 | /**
33 | * @return array
34 | */
35 | public static function all() : array
36 | {
37 | return static::$queries;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/system/Database/Seeder.php:
--------------------------------------------------------------------------------
1 |
11 | * @version : v1.0
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Database;
16 |
17 | abstract class Seeder
18 | {
19 | /**
20 | * @var array
21 | */
22 | protected $seeder = [];
23 |
24 | /**
25 | * @param array $seeder
26 | * @return void
27 | */
28 | public function call(...$seeder)
29 | {
30 | if (empty($seeder)) {
31 | return $this->seeder;
32 | }
33 |
34 | $this->seeder = array_merge($this->seeder, $seeder);
35 | }
36 |
37 | /**
38 | * @return void
39 | */
40 | abstract public function seed();
41 | }
42 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/Controller/AssetController.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\Controller;
16 |
17 | use Octopy\HTTP\Response;
18 |
19 | class AssetController
20 | {
21 | /**
22 | * @param Response $response
23 | * @return Response
24 | */
25 | public function stylesheet(Response $response)
26 | {
27 | return $response->make($this->content('toolbar.css'), 200, [
28 | 'Content-Type' => 'text/css',
29 | ]);
30 | }
31 |
32 | /**
33 | * @param string $filename
34 | * @param Response $response
35 | * @return Response
36 | */
37 | public function javascript($filename, Response $response)
38 | {
39 | $content = $this->content($filename);
40 | if ($filename === 'octopy.js') {
41 | $content = str_replace('{{ ROUTE }}', route('toolbar.detail', ''), $content);
42 | }
43 |
44 | return $response->make($content, 200, [
45 | 'Content-Type' => 'text/javascript',
46 | ]);
47 | }
48 |
49 | /**
50 | * @param string $filename
51 | * @return string
52 | */
53 | protected function content(string $filename) : string
54 | {
55 | $filename = __DIR__ . '/../Asset/' . $filename;
56 |
57 | if (! file_exists($filename)) {
58 | return '';
59 | }
60 |
61 | return file_get_contents($filename);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/Controller/DetailController.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\Controller;
16 |
17 | use Octopy\Application;
18 | use Octopy\HTTP\Response;
19 | use Octopy\HTTP\Controller;
20 |
21 | class DetailController extends Controller
22 | {
23 | /**
24 | * @param Application $app
25 | */
26 | public function __construct(Application $app)
27 | {
28 | parent::__construct($app);
29 |
30 | $app->view->resource(
31 | $app->path->system->debug->toolbar('View')
32 | );
33 |
34 | $this->app->toolbar->boot($this->app);
35 | }
36 |
37 | /**
38 | * @param string $id
39 | * @param Response $response
40 | * @return Response
41 | */
42 | public function index(string $id, Response $response)
43 | {
44 | return $response->view('content', [
45 | 'tool' => $this->app->toolbar,
46 | 'time' => $this->app->toolbar->time(),
47 | 'data' => json_decode(file_get_contents(
48 | $this->app->config->get('toolbar.storage', 'storage') . $id . '.json'
49 | )),
50 | ]);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/Collector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | use Octopy\Application;
18 |
19 | class Collector
20 | {
21 | /**
22 | * @var boolean
23 | */
24 | public $show = true;
25 |
26 | /**
27 | * @var boolean
28 | */
29 | public $badge = true;
30 |
31 | /**
32 | * @var Octopy\Application
33 | */
34 | protected $app;
35 |
36 | /**
37 | * @param Application $app
38 | */
39 | public function __construct(Application $app)
40 | {
41 | $this->app = $app;
42 | }
43 |
44 | /**
45 | * @return string
46 | */
47 | public function __toString()
48 | {
49 | return $this->name();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/FileCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | class FileCollector extends Collector
18 | {
19 | /**
20 | * @var string
21 | */
22 | public $name = 'Files';
23 |
24 | /**
25 | * @var boolean
26 | */
27 | public $badge = true;
28 |
29 | /**
30 | * @return array
31 | */
32 | public function collect()
33 | {
34 | return get_included_files();
35 | }
36 |
37 | /**
38 | * @return int
39 | */
40 | public function badge() : int
41 | {
42 | return count(get_included_files());
43 | }
44 |
45 | /**
46 | * @return string
47 | */
48 | public function icon() : string
49 | {
50 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAflBMVEUAAAA0SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV7SQDzzAAAAKXRSTlMAAQQFBgcKDg8QFxofJSgrLS8xPUBGUHd7foWRnq2vwcPH2uLr7e/19wBvAYgAAACuSURBVCiRjdHJEoIwEATQFhcIiAoZo4KKiAv9/z/oAZQEcrBPqbyqZGoaCOmkVuijCStkm/ZHccEUzLwgODD1A4pWeaAUMayncOtm20xgeHAMSR54wZBN4EC8BQA0JHMHqrcCgAvJxAYh7wGA1aUx9h/zF8nrbDrViSR57K6XA8T9zvcAFmcZoPq2scbuwQGyX03PkrRA3BL/ACVOVAfat10NIKInIQBEWkbRIfABDgEkhSklNigAAAAASUVORK5CYII=';
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/MainCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | class MainCollector extends Collector
18 | {
19 | /**
20 | * @var string
21 | */
22 | public $name = 'Main';
23 |
24 | /**
25 | * @var boolean
26 | */
27 | public $show = false;
28 |
29 | /**
30 | * @return array
31 | */
32 | public function collect()
33 | {
34 | return [
35 | 'status' => http_response_code(),
36 | 'url' => $this->app->request->url(),
37 | 'method' => $this->app->request->method(),
38 | 'ajax' => $this->app->request->ajax(),
39 | ];
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/QueryCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | use Exception;
18 |
19 | class QueryCollector extends Collector
20 | {
21 | /**
22 | * @var string
23 | */
24 | public $name = 'Query';
25 |
26 | /**
27 | * @var array
28 | */
29 | protected $data = [];
30 |
31 | /**
32 | * @return array
33 | */
34 | public function collect()
35 | {
36 | try {
37 | return $this->app->database->queries();
38 | } catch (Exception $exception) {
39 | return [];
40 | }
41 | }
42 |
43 | /**
44 | * @return string
45 | */
46 | public function icon() : string
47 | {
48 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAABO1BMVEUAAAA0SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV6dfK01AAAAaHRSTlMAAQIDBAUGBwgJCwwNEBESExQWGBobHB0fICEjJCUnKCorLC4vMDEyNTY4OkJDRkdKS0xVVldbXV9hY2drcXR1d3+LjI6PkZKVnZ6ipqirr7S3urzDyMrMztHX2dzg4ubo7e/z9ff5/cxGgDsAAAD/SURBVBgZbcEJNwJhGAbQ5y3T2LNkySB8ZE1R9qWsg1CJshRKmuf//wJ11KHOdy/qjED0NF0oOZWPfDIR8gl+LWfYyrn0A3BnqXEOhKllIUYthRi1FCLUmoLxTI07AWQtxzbpIIBOAF3B/etchTXlx6vtGQ8gXpzMoUkEDeatwj0zKyb+k9FElQqvrHk721qdHh8ZsxYiR2mHNQrv1LIQqFLDFohnp8hWjj0BA1ED6Fncsx+KZef7M5+Mh3wCbCrclDY8aCVWigpPJLO78wOmC4B09PrXL75IKpSpNYtD6hQNYOmF7arHBur6w3aBTZXUwaQLf8TsGxwe8na70fADA0edTV3bqnEAAAAASUVORK5CYII=';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/RouteCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | use Closure;
18 |
19 | class RouteCollector extends Collector
20 | {
21 | /**
22 | * @var string
23 | */
24 | public $name = 'Route';
25 |
26 | /**
27 | * @var boolean
28 | */
29 | public $badge = false;
30 |
31 | /**
32 | * @return array
33 | */
34 | public function collect()
35 | {
36 | $route = $this->app->router->current();
37 |
38 | $middleware = [];
39 | foreach ($route->middleware as $layer) {
40 | $middleware[] = $layer instanceof Closure ? 'Closure' : $layer;
41 | }
42 |
43 | return [
44 | 'uri' => $route->uri,
45 | 'name' => $route->name,
46 | 'method' => $route->method,
47 | 'parameter' => $route->parameter,
48 | 'middleware' => $middleware,
49 | 'controller' => $route->controller instanceof Closure ? 'Closure' : $route->controller,
50 | ];
51 | }
52 |
53 | /**
54 | * @return string
55 | */
56 | public function icon() : string
57 | {
58 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAM1BMVEUAAAA0SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV4JtAQBAAAAEHRSTlMAChESIiM3QH+ChZHD6ev9naZH3AAAAGNJREFUKM+tkEEOwjAQxNwAHUoK9f9f2xMIJemhAp8sWZqVFt4sqnd6rEl1FAI5F46mHqrLIBANv4XrasN6A5g2O7YJmB0wf0+38r9QqtZCLy/VJ3Ty+XYr58PhjUuSFBjImB0oNwy5+WrIEgAAAABJRU5ErkJggg==';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/VarsCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | class VarsCollector extends Collector
18 | {
19 | /**
20 | * @var string
21 | */
22 | public $name = 'Vars';
23 |
24 | /**
25 | * @var boolean
26 | */
27 | public $badge = false;
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $data = [];
33 |
34 | /**
35 | * @return array
36 | */
37 | public function collect()
38 | {
39 | return [
40 | 'session' => $this->app->session->all(),
41 | 'request' => [
42 | 'input' => $this->app->request->all(),
43 | 'header' => $this->app->request->header(),
44 | 'cookie' => $this->app->request->cookie(),
45 | ],
46 | 'response' => $this->response(),
47 | ];
48 | }
49 |
50 | /**
51 | * @return string
52 | */
53 | public function icon() : string
54 | {
55 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYAgMAAACdGdVrAAAACVBMVEUAAAA0SV40SV7ssyshAAAAAnRSTlMAQABPjKgAAAAiSURBVAhbY1i1gAEEVi0QDQ0NBVJaq1atQlBQQQacgF7aARFEKp3Ixp/5AAAAAElFTkSuQmCC';
56 | }
57 |
58 | /**
59 | * @return array
60 | */
61 | private function response() : array
62 | {
63 | $data = [];
64 | foreach ($this->app->response->headers() as $key => $value) {
65 | $data[$key] = implode(';', $value);
66 | }
67 |
68 | return $data;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/DataCollector/ViewCollector.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\DataCollector;
16 |
17 | class ViewCollector extends Collector
18 | {
19 | /**
20 | * @var string
21 | */
22 | public $name = 'Views';
23 |
24 | /**
25 | * @var array
26 | */
27 | protected $data = [];
28 |
29 | /**
30 | * @return array
31 | */
32 | public function collect()
33 | {
34 | if (empty($this->data)) {
35 | foreach ($this->app->view->template() as $file) {
36 | $this->data[] = $file->template();
37 | }
38 | }
39 |
40 | return $this->data;
41 | }
42 |
43 | /**
44 | * @return string
45 | */
46 | public function icon() : string
47 | {
48 | return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAA4VBMVEUAAAA0SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV40SV7oubu7AAAASnRSTlMAAQQFBgcIDA0ODxAREhQYGhwdHh8nKSorLS4vMjM2PT9AQkNLTVhcXV5hYmhxdXl7f4CDhpebnaKjsre8wcPIyszc5Obr7e/z9QlAyiEAAADWSURBVBgZbcGJNkJRAEDR81Sm0ICiDBHJlHkuKiTn/z+IW0u9lfaGPaeoABtOUQSyTpEFFpxiHkioRWLKagKI1AoxB2rEr57W4Pjlz7t+ErxqA86MaRE86B0cGnNPcKlNYjp6QVDXD2K+9YigqjIWqfsEJWPmSKqbBDl1LbnkwAxpNUeQVjPgAOTVRYKkWoD18263UYCSmiSI1F1GqmrEQF+fywkGZnea2meobdCqZbL1tsEbQ09OeGTo2glXDEWrpx1H2if5iLHU9u2X9m62Uvy3sszYD18TV3GUlSYLAAAAAElFTkSuQmCC';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/Storage/FileStorage.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar\Storage;
16 |
17 | use Octopy\Debug\Toolbar\Storage;
18 |
19 | class FileStorage extends Storage
20 | {
21 | /**
22 | * @return void
23 | */
24 | public function write()
25 | {
26 | $content = $this->content();
27 | $storage = $this->app->config->get('toolbar.storage', 'storage');
28 | $history = $this->app->toolbar->time() . '.json';
29 |
30 | if ($this->app->filesystem->mkdir($storage)) {
31 | $this->app->filesystem->put($storage . $history, $content);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/Storage/Storage.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Debug\Toolbar;
16 |
17 | use Octopy\Application;
18 | use Octopy\Debug\Toolbar\DataCollector\HistoryCollector;
19 |
20 | abstract class Storage
21 | {
22 | /**
23 | * @var Octopy\Application
24 | */
25 | protected $app;
26 |
27 | /**
28 | * @param Application $app
29 | */
30 | public function __construct(Application $app)
31 | {
32 | $this->app = $app;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | protected function content() : string
39 | {
40 | $content = [
41 | 'time' => $this->app->toolbar->time(),
42 | ];
43 |
44 | foreach ($this->app->toolbar->collectors() as $collector) {
45 | if ($collector instanceof HistoryCollector) {
46 | continue;
47 | }
48 |
49 | $content[strtolower($collector->name)] = $collector->collect();
50 | }
51 |
52 | return json_encode($content, JSON_PRETTY_PRINT);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/exception.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
Included Files
3 |
4 |
5 |
6 | Name |
7 | Location |
8 | Size |
9 |
10 |
11 |
12 | @foreach($data->files as $file)
13 |
14 | {{ basename($file) }} |
15 | {{ $file }} |
16 | {{ byteformatter(filesize($file)) }} |
17 |
18 | @endforeach
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/files.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
Included Files
3 |
4 |
5 |
6 | Name |
7 | Location |
8 | Size |
9 |
10 |
11 |
12 | @foreach($data->files as $file)
13 |
14 | {{ basename($file) }} |
15 | {{ $file }} |
16 | {{ byteformatter(filesize($file)) }} |
17 |
18 | @endforeach
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/history.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
History
3 |
4 |
5 |
6 | Datetime |
7 | Status |
8 | Method |
9 | URL |
10 | Content-Type |
11 | Ajax |
12 | Action |
13 |
14 |
15 |
16 | @foreach($collector->collect() as $json)
17 | @php
18 | foreach ($json->vars->response as $key => $contentype) {
19 | if($key == 'Content-Type') {
20 | break;
21 | }
22 | }
23 | @endphp
24 |
25 | @if($json->time === $time)
26 |
27 | @else
28 |
29 | @endif
30 | {{ date('Y-m-d H:i:s', $json->time) }} |
31 | {{ $json->main->status }} |
32 | {{ $json->main->method }} |
33 | {{ $json->main->url }} |
34 | {{ $contentype }} |
35 | {{ $json->main->ajax ? 'Yes' : 'No' }} |
36 |
37 |
38 | |
39 |
40 | @endforeach
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/query.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
Queries
3 |
4 |
5 | @foreach($data->query as $query)
6 |
7 | {{ $query }} |
8 |
9 | @endforeach
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/route.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
Route
3 |
Matched Route
4 |
5 |
6 |
7 | Name |
8 | {{ $data->route->name !== '' ? $data->route->name : '-' }} |
9 |
10 |
11 | Target |
12 | {{ $data->route->uri }} |
13 |
14 |
15 | Method |
16 | {{ implode(' & ', $data->route->method) }} |
17 |
18 |
19 | Controller |
20 | {{ $data->route->controller }} |
21 |
22 |
23 | Middleware |
24 | @if(! empty($data->route->middleware))
25 | @php($no = 1)
26 | {{ $no }}. {{ $data->route->middleware[0] }} |
27 | @foreach(array_slice($data->route->middleware, 1) as $middleware)
28 |
29 | |
30 | {{ ++$no }}. {{ $middleware }} |
31 |
32 | @endforeach
33 | @else
34 | -
35 | @endif
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/vars.octopy.php:
--------------------------------------------------------------------------------
1 |
2 | @foreach($data->vars as $name => $var)
3 |
{{ ucfirst($name) }}
4 | @if(empty($var))
5 |
{{ ucfirst($name) }} doesn't seem to be active.
6 | @elseif($name == 'request')
7 | @foreach($var as $name => $value)
8 | @if(is_array($value) || (is_object($value)))
9 | @continue(empty($value))
10 |
11 | {{ $name }}
12 |
13 |
14 |
15 | @foreach($value as $key => $val)
16 |
17 | {{ $key }} |
18 | {{ $val }} |
19 |
20 | @endforeach
21 |
22 |
23 | @endif
24 | @endforeach
25 |
26 | @else
27 |
28 |
29 | @foreach($var as $key => $val)
30 |
31 | {{ $key }} |
32 | {{ $val }} |
33 |
34 | @endforeach
35 |
36 |
37 | @endif
38 | @endforeach
39 |
40 |
--------------------------------------------------------------------------------
/system/Debug/Toolbar/View/child/views.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
Templates
3 |
4 |
5 |
6 | NAME |
7 | LOCATION |
8 | SIZE |
9 |
10 |
11 |
12 | @foreach($data->views as $template)
13 |
14 | {{ basename($template) }} |
15 | {{ $template }} |
16 | {{ byteformatter(filesize($template)) }} |
17 |
18 | @endforeach
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/system/Encryption/Exception/CipherKeyException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Encryption\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class CipherKeyException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Encryption/Exception/DecryptException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Encryption\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class DecryptException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Encryption/Exception/EncryptException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Encryption\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class EncryptException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Exception/View/inc/backtrace.octopy.php:
--------------------------------------------------------------------------------
1 |
2 | @foreach ($trace as $index => $row)
3 |
4 |
5 | @if(isset($row['file']) && is_file($row['file']))
6 | @if(isset($row['function']) && in_array($row['function'], ['include', 'include_once', 'require', 'require_once']))
7 | {{ $row['function'] . ' ' . $row['file'] }}
8 | @else
9 | {{ $row['file'] }}
10 | @endif
11 | @else
12 | { PHP Internal Code }
13 | @endif
14 |
15 | {{--
16 | @if(isset($row['class']))
17 | — {{ $row['class'].$row['type'].$row['function'] }}
18 |
19 | @php($identity = uniqid('error') . $index)
20 | @if (! empty($row['args']))
21 | ( arguments )
22 |
23 |
24 | @php
25 | $params = null;
26 | if (mb_substr($row['function'], -1) !== '}') {
27 | $mirror = isset($row['class']) ? new \ReflectionMethod($row['class'], $row['function']) : new \ReflectionFunction($row['function']);
28 | $params = $mirror->getParameters();
29 | }
30 | @endphp
31 | @foreach ($row['args'] as $key => $value)
32 |
33 |
34 |
35 | {{ isset($params[$key]) ? '$'.$params[$key]->name : "#$key" }}
36 |
37 | |
38 | {{{ dump($value) }}} |
39 |
40 | @endforeach
41 |
42 |
43 | @else
44 | ()
45 | @endif
46 | @endif
47 | --}}
48 |
49 | @if (! isset($row['class']) && isset($row['function']))
50 | — {{ $row['function'] }}()
51 | @endif
52 | @if(isset($row['file']) && is_file($row['file']) && isset($row['class']))
53 | {{{ $app->syntax->highlight($row['file'], $row['line'], '3:3') }}}
54 | @endif
55 |
56 | @endforeach
57 |
58 |
--------------------------------------------------------------------------------
/system/Exception/View/inc/files.octopy.php:
--------------------------------------------------------------------------------
1 | @php
2 | $files = array_map(static function($file) {
3 | return new \SplFileInfo($file);
4 | }, get_included_files());
5 | @endphp
6 |
7 |
8 |
9 | # |
10 | File Path |
11 | File Size |
12 |
13 |
14 | @foreach ($files as $i => $file)
15 |
16 | {{ ++$i }}. |
17 | {{ $file->getPathname() }} |
18 | {{ byteformatter($file->getSize()) }} |
19 |
20 | @endforeach
21 |
22 |
23 |
--------------------------------------------------------------------------------
/system/Exception/View/inc/memory.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Memory Limit |
5 | {{ byteformatter(trim(ini_get('memory_limit'), 'M') * 1024 * 1024) }} |
6 |
7 |
8 | Memory Usage |
9 | {{ byteformatter(memory_get_usage(true)) }} |
10 |
11 |
12 | Peak Memory Usage |
13 | {{ byteformatter(memory_get_peak_usage(true)) }} |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/system/Exception/View/inc/response.octopy.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | Response Status |
4 | {{ $code . ' - ' . ($message != null ? $message : $app->response->reason($code)) }} |
5 |
6 |
7 |
8 | @php($headers = $app->response->headers(); ksort($headers))
9 | @if (! empty($headers))
10 | Header
11 |
12 |
13 |
14 | Name |
15 | Value |
16 |
17 |
18 |
19 | @foreach ($headers as $name => $value)
20 |
21 | {{ strip_tags($name) }} |
22 | {{ strip_tags(implode(', ', $value)) }} |
23 |
24 | @endforeach
25 |
26 |
27 | @endif
28 |
--------------------------------------------------------------------------------
/system/Exception/View/inc/server.octopy.php:
--------------------------------------------------------------------------------
1 | @foreach (['_SERVER', '_SESSION'] as $var)
2 | @continue(empty($GLOBALS[$var]) || ! is_array($GLOBALS[$var]))
3 | ${{ $var }}
4 |
5 |
6 |
7 | Name |
8 | Value |
9 |
10 |
11 |
12 | @foreach ($GLOBALS[$var] as $key => $value)
13 | @php
14 | if($var === '_SERVER') {
15 | $key = mb_strtoupper(str_replace('-', '_', $key));
16 |
17 | if(preg_match('/PASSWORD/i', $key)) {
18 | $value = preg_replace('/(.*)/', str_repeat('*', mb_strlen($value)), $value);
19 | }
20 | }
21 | @endphp
22 |
23 | {{ $key }} |
24 |
25 | @if (is_string($value))
26 | @continue($value === '')
27 | {{ htmlspecialchars(strip_tags($value), ENT_SUBSTITUTE, 'UTF-8') }}
28 | @else
29 | {{ print_r($value, true) }}
30 | @endif
31 | |
32 |
33 | @endforeach
34 |
35 |
36 | @endforeach
37 |
38 | @php($constants = get_defined_constants(true))
39 | @if (! empty($constants['user']))
40 | @php(asort($constants['user']))
41 | Constant
42 |
43 |
44 |
45 | Name |
46 | Value |
47 |
48 |
49 |
50 | @foreach ($constants['user'] as $key => $value)
51 |
52 | {{ $key }} |
53 |
54 | @if (! is_array($value) && ! is_object($value))
55 | {{ $value }}
56 | @else
57 | {{ print_r($value, true) }}
58 | @endif
59 | |
60 |
61 | @endforeach
62 |
63 |
64 | @endif
65 |
--------------------------------------------------------------------------------
/system/FileSystem/Exception/FileNotFoundException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\FileSystem\Exception;
16 |
17 | use Exception;
18 |
19 | class FileNotFoundException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Controller.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP;
16 |
17 | use Octopy\Application;
18 | use Octopy\HTTP\Middleware\ControllerMiddleware;
19 |
20 | class Controller
21 | {
22 | /**
23 | * @var Octopy\Application
24 | */
25 | protected $app;
26 |
27 | /**
28 | * @var array
29 | */
30 | protected $middleware = [];
31 |
32 | /**
33 | * @param Application $app
34 | */
35 | public function __construct(Application $app)
36 | {
37 | $this->app = $app;
38 | }
39 |
40 | /**
41 | * @param array $middleware
42 | * @param array $option
43 | * @return mixed
44 | */
45 | public function middleware($middleware = [], array $option = [])
46 | {
47 | if (empty($middleware)) {
48 | return $this->middleware;
49 | }
50 |
51 | foreach ((array) $middleware as $layer) {
52 | $this->middleware[] = [
53 | 'option' => &$option,
54 | 'middleware' => $layer,
55 | ];
56 | }
57 |
58 | return new ControllerMiddleware($option);
59 | }
60 |
61 | /**
62 | * @param Request $request
63 | * @param array $rules
64 | * @return bool
65 | */
66 | public function validate(Request $request, array $rules = [])
67 | {
68 | return $request->validate($rules);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/CheckMaintenanceMode.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | use Closure;
18 | use Octopy\Application;
19 | use Octopy\HTTP\Request;
20 | use Octopy\HTTP\Middleware\Exception\MaintenanceModeException;
21 |
22 | class CheckMaintenanceMode
23 | {
24 | /**
25 | * @var Octopy\Application
26 | */
27 | protected $app;
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $except = [];
33 |
34 | /**
35 | * @param Application $app
36 | */
37 | public function __construct(Application $app)
38 | {
39 | $this->app = $app;
40 | }
41 |
42 | /**
43 | * @param Request $request
44 | * @param Closure $next
45 | * @return Request
46 | */
47 | public function handle(Request $request, Closure $next)
48 | {
49 | if ($request->is($this->except)) {
50 | return $next($request);
51 | }
52 |
53 | if (file_exists($down = $this->app['path']->storage('maintenance.json'))) {
54 | $down = json_decode($this->app['filesystem']->get($down));
55 |
56 | if (in_array($request->ip(), $down->allowed)) {
57 | return $next($request);
58 | }
59 |
60 | throw new MaintenanceModeException($down->message);
61 | }
62 |
63 | return $next($request);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/ControllerMiddleware.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | class ControllerMiddleware
18 | {
19 | /**
20 | * @var array
21 | */
22 | protected $option;
23 |
24 | /**
25 | * @param array $option
26 | * @return void
27 | */
28 | public function __construct(array &$option)
29 | {
30 | $this->option = &$option;
31 | }
32 |
33 | /**
34 | * @param mixed $method
35 | * @return $this
36 | */
37 | public function only($method)
38 | {
39 | $this->option['only'] = is_array($method) ? $method : func_get_args();
40 |
41 | return $this;
42 | }
43 |
44 | /**
45 | * @param mixed $method
46 | * @return $this
47 | */
48 | public function except($method)
49 | {
50 | $this->option['except'] = is_array($method) ? $method : func_get_args();
51 |
52 | return $this;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/Dispatcher.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | use Closure;
18 | use Octopy\HTTP\Request;
19 | use Octopy\Support\Facade\App;
20 |
21 | class Dispatcher
22 | {
23 | /**
24 | * @var array
25 | */
26 | protected $middleware;
27 |
28 | /**
29 | * @param array $middleware
30 | */
31 | public function __construct(array $middleware = [])
32 | {
33 | $this->middleware = $middleware;
34 | }
35 |
36 | /**
37 | * @param array $middleware
38 | * @param Request $object
39 | * @param Closure $next
40 | * @return mixed
41 | */
42 | public function dispatch(Request $object, Closure $next)
43 | {
44 | $middleware = array_reverse($this->middleware);
45 |
46 | $complete = array_reduce($middleware, function (Closure $next, $middleware) {
47 | return $this->create($next, $middleware);
48 | }, $this->next($next));
49 |
50 | return $complete($object);
51 | }
52 |
53 | /**
54 | * @param Closure $next
55 | * @return Closure
56 | */
57 | protected function next(Closure $next)
58 | {
59 | return static function ($object) use ($next) {
60 | return $next($object);
61 | };
62 | }
63 |
64 | /**
65 | * @param Closure $next
66 | * @param callable $middleware
67 | * @return mixed
68 | */
69 | protected function create(Closure $next, $middleware)
70 | {
71 | return static function ($object) use ($next, $middleware) {
72 | if ($middleware instanceof Closure) {
73 | return $middleware($object, $next);
74 | }
75 |
76 | return App::make($middleware)->handle($object, $next);
77 | };
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/Exception/MaintenanceModeException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware\Exception;
16 |
17 | use Exception;
18 |
19 | class MaintenanceModeException extends Exception
20 | {
21 | /**
22 | * @var int
23 | */
24 | protected $code = 503;
25 | }
26 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/Exception/PostTooLargeException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class PostTooLargeException extends RuntimeException
20 | {
21 | /**
22 | * @var int
23 | */
24 | protected $code = 413;
25 | }
26 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/Exception/TokenMismatchException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class TokenMismatchException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/InjectToolbar.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | use Closure;
18 | use Throwable;
19 | use Octopy\Application;
20 | use Octopy\HTTP\Request;
21 | use Octopy\Debug\Toolbar;
22 |
23 | class InjectToolbar
24 | {
25 | /**
26 | * @var array
27 | */
28 | protected $except = [];
29 |
30 | /**
31 | * @var Octopy\Debug\Toolbar
32 | */
33 | protected $toolbar;
34 |
35 | /**
36 | * @param Application $app
37 | * @param Toolbar $toolbar
38 | */
39 | public function __construct(Application $app, Toolbar $toolbar)
40 | {
41 | $this->app = $app;
42 | $this->toolbar = $toolbar;
43 | }
44 |
45 | /**
46 | * @param Request $request
47 | * @param Closure $next
48 | * @return Response
49 | */
50 | public function handle(Request $request, Closure $next)
51 | {
52 | // excepting
53 | $except = array_merge($this->app['config']['toolbar.except'], (array) ('/' . $this->app['config']['toolbar.prefix'] . '*'));
54 |
55 | if (! $this->toolbar->enabled() || $request->is($except)) {
56 | return $next($request);
57 | }
58 |
59 | try {
60 | $response = $next($request);
61 | } catch (Throwable $exception) {
62 | throw $exception;
63 | }
64 |
65 | $this->toolbar->boot($this->app)
66 | ->write($this->app);
67 |
68 | if ($this->app->config['toolbar.inject']) {
69 | $response = $this->toolbar->modify($response);
70 | }
71 |
72 | return $response;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/Middleware.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP;
16 |
17 | use Closure;
18 | use Octopy\HTTP\Middleware\Dispatcher;
19 |
20 | class Middleware
21 | {
22 | /**
23 | * @var array
24 | */
25 | protected $route = [];
26 |
27 | /**
28 | * @var array
29 | */
30 | protected $global = [];
31 |
32 | /**
33 | * @param string $property
34 | * @return array
35 | */
36 | public function __get(string $property) : array
37 | {
38 | return $this->$property;
39 | }
40 |
41 | /**
42 | * @param string $layer
43 | * @param mixed $middleware
44 | */
45 | public function set(string $layer, $middleware = null)
46 | {
47 | if (is_null($middleware)) {
48 | if (! isset($this->global[$layer])) {
49 | $this->global[] = $layer;
50 | }
51 | } else if (! isset($this->route[$layer])) {
52 | $this->route[$layer] = $middleware;
53 | }
54 | }
55 |
56 | /**
57 | * @param string $layer
58 | * @return mixed
59 | */
60 | public function route($layer = null)
61 | {
62 | if (is_null($layer)) {
63 | return $this->route;
64 | }
65 |
66 | if (! is_string($layer)) {
67 | return $layer;
68 | }
69 |
70 | return $this->route[$layer] ?? $layer;
71 | }
72 |
73 | /**
74 | * @return array
75 | */
76 | public function global() : array
77 | {
78 | return $this->global ?? [];
79 | }
80 |
81 | /**
82 | * @param array $middleware
83 | * @param Request $object
84 | * @param Closure $next
85 | * @return Closure
86 | */
87 | public function dispatch(array $middleware, Request $object, Closure $next)
88 | {
89 | return (new Dispatcher($middleware))->dispatch($object, $next);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/ValidatePostSize.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | use Closure;
18 | use Octopy\HTTP\Request;
19 | use Octopy\HTTP\Middleware\Exception\PostTooLargeException;
20 |
21 | class ValidatePostSize
22 | {
23 | /**
24 | * @param Request $request
25 | * @param Closure $next
26 | * @return Request
27 | */
28 | public function handle(Request $request, Closure $next)
29 | {
30 | $max = $this->size();
31 |
32 | if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) {
33 | throw new PostTooLargeException;
34 | }
35 |
36 | return $next($request);
37 | }
38 |
39 | /**
40 | * @return int
41 | */
42 | protected function size() : int
43 | {
44 | if (is_numeric($size = ini_get('post_max_size'))) {
45 | return (int) $size;
46 | }
47 |
48 | $metric = mb_strtoupper(mb_substr($size, -1));
49 |
50 | switch ($metric) {
51 | case 'K':
52 | return (int) $size * 1024;
53 | case 'M':
54 | return (int) $size * 1048576;
55 | case 'G':
56 | return (int) $size * 1073741824;
57 | default:
58 | return (int) $size;
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/system/HTTP/Middleware/VerifyCSRFToken.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Middleware;
16 |
17 | use Closure;
18 | use Octopy\Application;
19 | use Octopy\HTTP\Request;
20 | use Octopy\HTTP\Middleware\Exception\TokenMismatchException;
21 |
22 | class VerifyCSRFToken
23 | {
24 | /**
25 | * @var Octopy\Application
26 | */
27 | protected $app;
28 |
29 | /**
30 | * @var array
31 | */
32 | protected $except = [
33 |
34 | ];
35 |
36 | /**
37 | * @param Application $app
38 | */
39 | public function __construct(Application $app)
40 | {
41 | $this->app = $app;
42 | }
43 |
44 | /**
45 | * @param Request $request
46 | * @param Closure $next
47 | * @return Request
48 | */
49 | public function handle(Request $request, Closure $next)
50 | {
51 | if ($request->method() !== 'POST' || $request->is(array_merge($this->except, ['__toolbar']))) {
52 | return $next($request);
53 | }
54 |
55 | $token = $request->header('X-CSRF-TOKEN') ?? $request->__TOKEN__;
56 |
57 | if ($token === $this->app['session']->get('X-CSRF-TOKEN')) {
58 | $time = time() - $this->app['session']->get('X-CSRF-TOKEN-EXPIRE');
59 | if ($time < $this->app['config']['session.lifetime']) {
60 | return $next($request);
61 | }
62 | }
63 |
64 | throw new TokenMismatchException;
65 | }
66 |
67 | /**
68 | * @return string
69 | */
70 | public function generate() : string
71 | {
72 | if (! $this->app['session']->has('X-CSRF-TOKEN')) {
73 | $token = sha1(random_bytes(32));
74 | } else {
75 | $token = $this->app['session']->get('X-CSRF-TOKEN');
76 | }
77 |
78 | $this->app['session']->set([
79 | 'X-CSRF-TOKEN' => $token,
80 | 'X-CSRF-TOKEN-EXPIRE' => microtime(true),
81 | ]);
82 |
83 | return $token;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/system/HTTP/Request/Collection.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Request;
16 |
17 | use Octopy\Support\Arr;
18 |
19 | class Collection
20 | {
21 | /**
22 | * @var array
23 | */
24 | protected $parameter;
25 |
26 | /**
27 | * @param array $parameter
28 | */
29 | public function __construct(array $parameter = [])
30 | {
31 | $this->parameter = $parameter;
32 | }
33 |
34 | /**
35 | * @param string $key
36 | * @param mixed $default
37 | * @return mixed
38 | */
39 | public function get(string $key, $default = null)
40 | {
41 | $value = Arr::get($this->parameter, $key, $default);
42 |
43 | if (is_numeric($value)) {
44 | $value += 0;
45 | }
46 |
47 | return $value ?? $default;
48 | }
49 |
50 | /**
51 | * @return array
52 | */
53 | public function all() : array
54 | {
55 | return $this->parameter;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/system/HTTP/Request/Exception/HTTPException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Request\Exception;
16 |
17 | use Exception;
18 |
19 | class HTTPException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Request/FileHandler.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Request;
16 |
17 | use Exception;
18 |
19 | class FileHandler
20 | {
21 | /**
22 | * @var array
23 | */
24 | protected $file;
25 |
26 | /**
27 | * @param array $file
28 | */
29 | public function __construct(array $file)
30 | {
31 | $this->file = $file;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function name() : string
38 | {
39 | return $this->file['name'];
40 | }
41 |
42 | /**
43 | * @return string
44 | */
45 | public function type() : string
46 | {
47 | return $this->file['type'];
48 | }
49 |
50 | /**
51 | * @return int
52 | */
53 | public function size() : int
54 | {
55 | return $this->file['size'];
56 | }
57 |
58 | /**
59 | * @return int
60 | */
61 | public function error() : int
62 | {
63 | return $this->file['error'];
64 | }
65 |
66 | /**
67 | * @param string $destination
68 | * @return bool
69 | */
70 | public function move(string $destination = null, bool $replace = false) : bool
71 | {
72 | if ($this->error() > 0) {
73 | return false;
74 | }
75 |
76 | if (is_null($destination)) {
77 | $destination = $this->name();
78 | }
79 |
80 | if (! $replace && file_exists($destination)) {
81 | return true;
82 | }
83 |
84 | try {
85 | return move_uploaded_file($this->file['tmp_name'], $destination);
86 | } catch (Exception $exception) {
87 | throw $exception;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/system/HTTP/Response/DownloadResponse.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Response;
16 |
17 | use Exception;
18 | use Octopy\HTTP\Response;
19 | use Octopy\FileSystem\Exception\FileNotFoundException;
20 |
21 | class DownloadResponse extends Response
22 | {
23 | /**
24 | * @param string $filepath
25 | * @param string $filename
26 | * @param string $disposition
27 | */
28 | public function __construct(string $filepath, string $filename = null, string $disposition = 'attachment')
29 | {
30 | $content = $this->readfile($filepath);
31 |
32 | if (! $filename) {
33 | $filename = last(explode('/', $filepath));
34 | }
35 |
36 | parent::__construct($content, 200, [
37 | 'Cache-Control' => 'must-revalidate',
38 | 'Content-Description' => 'File Transfer',
39 | 'Content-Disposition' => sprintf('%s; filename="%s"', $disposition, $filename),
40 | 'Content-Length' => filesize($filepath),
41 | 'Content-Type' => mime_content_type($filepath),
42 | 'Expires' => 0,
43 | 'Pragma' => 'public',
44 | ]);
45 | }
46 |
47 | /**
48 | * @param string $filepath
49 | * @return string
50 | */
51 | public function readfile(string $filepath) : string
52 | {
53 | if (file_exists($filepath)) {
54 | try {
55 | return file_get_contents($filepath);
56 | } catch (Exception $exception) {
57 | throw $exception;
58 | }
59 | }
60 |
61 | throw new FileNotFoundException;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/system/HTTP/Response/RedirectResponse.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Response;
16 |
17 | use Octopy\HTTP\Response;
18 |
19 | class RedirectResponse extends Response
20 | {
21 | /**
22 | * @param string $location
23 | * @param int $status
24 | * @param array $header
25 | */
26 | public function __construct(string $location = '/', int $status = 302, array $header = [])
27 | {
28 | parent::__construct('', $status, array_merge($header, [
29 | 'Location' => $location,
30 | ]));
31 | }
32 |
33 | /**
34 | * @return $this
35 | */
36 | public function back()
37 | {
38 | return $this->header('Location', $_SERVER['HTTP_REFERER'] ?? '/');
39 | }
40 |
41 | /**
42 | * @param string $name
43 | * @param array $parameter
44 | * @return $this
45 | */
46 | public function route(string $name, array $parameter = [])
47 | {
48 | return $this->header('Location', route($name, $parameter));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/Exception/MethodNotAllowedException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing\Exception;
16 |
17 | use Exception;
18 |
19 | class MethodNotAllowedException extends Exception
20 | {
21 | /**
22 | * @var int
23 | */
24 | protected $code = 405;
25 | }
26 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/Exception/MissingParameterException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing\Exception;
16 |
17 | use Exception;
18 |
19 | class MissingParameterException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/Exception/ResourceControllerException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class ResourceControllerException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/Exception/RouteNameNotExistException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing\Exception;
16 |
17 | use Exception;
18 |
19 | class RouteNameNotExistException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/Exception/RouteNotFoundException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing\Exception;
16 |
17 | use Exception;
18 |
19 | class RouteNotFoundException extends Exception
20 | {
21 | /**
22 | * @var int
23 | */
24 | protected $code = 404;
25 |
26 | /**
27 | * @var string
28 | */
29 | protected $message = 'Page Not Found';
30 | }
31 |
--------------------------------------------------------------------------------
/system/HTTP/Routing/URLGenerator.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\HTTP\Routing;
16 |
17 | use Octopy\Application;
18 | use Octopy\HTTP\Routing\Exception\MissingParameterException;
19 | use Octopy\HTTP\Routing\Exception\RouteNameNotExistException;
20 |
21 | class URLGenerator
22 | {
23 | /**
24 | * @var array
25 | */
26 | protected $app;
27 |
28 | /**
29 | * @param Application $app
30 | */
31 | public function __construct(Application $app)
32 | {
33 | $this->app = $app;
34 | }
35 |
36 | /**
37 | * @param string $name
38 | * @param array $default
39 | * @return string
40 | */
41 | public function route(string $name, array $default = [])
42 | {
43 | $collection = $this->app['router']->collection->alias();
44 | if (array_key_exists($name, $collection)) {
45 | preg_match($collection[$name]->pattern, $collection[$name]->uri, $matches);
46 |
47 | $passed = [];
48 | $default = array_merge($collection[$name]->parameter, $default);
49 |
50 | foreach ($required = array_slice($matches, 1) as $key => $value) {
51 | if (isset($default[$key])) {
52 | $passed[$value] = $default[$key];
53 | }
54 | }
55 |
56 | if (count($passed) !== (count($required) / 2)) {
57 | throw new MissingParameterException;
58 | }
59 |
60 | return str_replace(array_keys($passed), $passed, $collection[$name]->uri);
61 | }
62 |
63 | throw new RouteNameNotExistException("Route name [$name] doesn't exists.");
64 | }
65 |
66 | /**
67 | * @param string $url
68 | * @return string
69 | */
70 | public function url(string $url) : string
71 | {
72 | return $this->app['config']['app.url'] . $url;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/system/Hashing/Driver/Argon2IdHasher.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Hashing\Driver;
16 |
17 | use RuntimeException;
18 |
19 | class Argon2IdHasher extends ArgonHasher
20 | {
21 | /**
22 | * @param string $value
23 | * @param string $hashed
24 | * @return bool
25 | */
26 | public function verify($value, $hashed) : bool
27 | {
28 | if ($this->verify && $this->info($hashed)['algoName'] !== 'argon2id') {
29 | throw new RuntimeException('This password does not use the Argon2id algorithm.');
30 | }
31 |
32 | if (mb_strlen($hashed) === 0) {
33 | return false;
34 | }
35 |
36 | return password_verify($value, $hashed);
37 | }
38 |
39 | /**
40 | * @return int
41 | */
42 | protected function algorithm() : int
43 | {
44 | return PASSWORD_ARGON2ID;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/system/Hashing/Driver/Hasher.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Hashing\Driver;
16 |
17 | abstract class Hasher
18 | {
19 | /**
20 | * @param string $hashed
21 | * @return array
22 | */
23 | public function info($hashed) : array
24 | {
25 | return password_get_info($hashed);
26 | }
27 |
28 | /**
29 | * @param string $value
30 | * @param string $hashed
31 | * @return bool
32 | */
33 | public function verify($value, $hashed) : bool
34 | {
35 | if (mb_strlen($hashed) === 0) {
36 | return false;
37 | }
38 |
39 | return password_verify($value, $hashed);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/system/Hashing/Exception/HashDriverException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Hashing\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class HashDriverException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Language/Exception/TranslationNotDefinedException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Language\Exception;
16 |
17 | use Exception;
18 |
19 | class TranslationNotDefinedException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Logger/Exception/InvalidLogLevelException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Logger\Exception;
16 |
17 | use RuntimeException;
18 |
19 | class InvalidLogLevelException extends RuntimeException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Logger/Exception/InvalidLogPathException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Logger\Exception;
16 |
17 | use Exception;
18 |
19 | class InvalidLogPathException extends Exception
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected $message = 'LogPath can\'t be empty or null.';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Logger/Handler/BaseHandler.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Logger\Handler;
16 |
17 | abstract class BaseHandler
18 | {
19 | /**
20 | * @var array
21 | */
22 | protected $config;
23 |
24 | /**
25 | * @var string
26 | */
27 | protected $datetime;
28 |
29 | /**
30 | * @param array $config
31 | */
32 | public function __construct(array $config)
33 | {
34 | $this->config = $config;
35 |
36 | $this->datetime = date($config['dateformat'] ?? 'Y-m-d H:i:s');
37 | }
38 |
39 | /**
40 | * @param string $property
41 | * @return mixed
42 | */
43 | public function __get(string $property)
44 | {
45 | return $this->$property ?? null;
46 | }
47 |
48 | /**
49 | * @param string $key
50 | * @return mixed
51 | */
52 | abstract public function config(string $key = null);
53 |
54 | /**
55 | * @param mixed $level
56 | * @param string $message
57 | * @return bool
58 | */
59 | abstract public function handle($level, string $message) : bool;
60 | }
61 |
--------------------------------------------------------------------------------
/system/Logger/Handler/FileHandler.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Logger\Handler;
16 |
17 | use Octopy\Support\Arr;
18 | use Octopy\Logger\Exception\InvalidLogPathException;
19 |
20 | class FileHandler extends BaseHandler
21 | {
22 | /**
23 | * @param string $key
24 | * @param mixed $default
25 | * @return mixed
26 | */
27 | public function config(string $key = null, $default = null)
28 | {
29 | return Arr::get($this->config, 'configuration.file.' . $key, $default);
30 | }
31 |
32 | /**
33 | * @param mixed $level
34 | * @param string $message
35 | * @return bool
36 | */
37 | public function handle($level, string $message) : bool
38 | {
39 | if (empty($filepath = $this->config('filepath'))) {
40 | throw new InvalidLogPathException();
41 | }
42 |
43 | if (! is_file($filepath)) {
44 | $fresh = true;
45 |
46 | if (! is_dir($directory = dirname($filepath))) {
47 | mkdir($directory, 0755, true);
48 | }
49 | }
50 |
51 | if (! $fp = @fopen($filepath, 'ab')) {
52 | return false;
53 | }
54 |
55 | $message = sprintf("[%s] %s --> %s \n", mb_strtoupper($level), $this->datetime, $message);
56 |
57 | flock($fp, LOCK_EX);
58 |
59 | for ($written = 0, $length = strlen($message); $written < $length; $written += $result) {
60 | if (($result = fwrite($fp, substr($message, $written))) === false) {
61 | // if we get this far, we'll never see this during travis-ci
62 | break;
63 | }
64 | }
65 |
66 | flock($fp, LOCK_UN);
67 | fclose($fp);
68 |
69 | if (isset($fresh) && $fresh === true) {
70 | chmod($filepath, $this->config('permission') ?? 0644);
71 | }
72 |
73 | return is_int($result);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/AttachmentNotExistException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class AttachmentNotExistException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/ErrorSendingCommandException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class ErrorSendingCommandException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/FailedSendingEmailException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class FailedSendingEmailException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/InvalidRecepientException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class InvalidRecepientException extends Exception
20 | {
21 | /**
22 | * @var int
23 | */
24 | protected $code = 406;
25 | }
26 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/SMTPAuthorizationException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class SMTPAuthorizationException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Mailer/Exception/SMTPConnectionException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Mailer\Exception;
16 |
17 | use Exception;
18 |
19 | class SMTPConnectionErrorException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Octopy.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | /*
16 | |--------------------------------------------------------------------------
17 | | JUST ROOT PATH DIRECTORY PROJECT
18 | |--------------------------------------------------------------------------
19 | */
20 | $basepath = dirname(__DIR__) . '/';
21 |
22 | /*
23 | |--------------------------------------------------------------------------
24 | | LOAD OUR AUTOLOADER
25 | |--------------------------------------------------------------------------
26 | |
27 | | The autoloader allows all of the pieces to work together
28 | | in the framework. We have to load it here, though, so
29 | | that the config files can use the path constants.
30 | */
31 | require 'Autoload.php';
32 |
33 | $autoload = new Octopy\Autoload($basepath, [
34 | 'App' => 'app',
35 | 'Octopy' => 'system',
36 | ]);
37 |
38 | $autoload->composer();
39 |
40 | /**
41 | *
42 | */
43 | require 'Common.php';
44 |
45 | /**
46 | * @var Octopy\Application
47 | */
48 | $app = new Octopy\Application($basepath);
49 |
50 | $app->instance(Octopy\Autoload::class, $autoload);
51 |
52 | /*
53 | |---------------------------------------------------------------
54 | | LAUNCH THE APPLICATION
55 | |---------------------------------------------------------------
56 | | Now that everything is setup, it's time to actually fire
57 | | up the engines and make this app do its thang.
58 | |
59 | */
60 |
61 | return $app;
62 |
--------------------------------------------------------------------------------
/system/Provider/AutoloadServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\Encryption\Exception\DecryptException;
18 |
19 | class AutoloadServiceProvider extends ServiceProvider
20 | {
21 | /**
22 | * @return void
23 | */
24 | public function register()
25 | {
26 | $autoload = $this->app['path']->storage('autoload.php');
27 |
28 | if (file_exists($autoload)) {
29 | try {
30 | $this->app['autoload']->classmap(
31 | $this->app['encrypter']->decrypt(require $autoload)
32 | );
33 | } catch (DecryptException $exception) {
34 | if (! $this->app->console()) {
35 | throw new DecryptException('The MAC is invalid, please re-run autoload cache command.');
36 | }
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/system/Provider/EncryptionServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use RuntimeException;
18 | use Octopy\Encryption\Encrypter;
19 |
20 | class EncryptionServiceProvider extends ServiceProvider
21 | {
22 | /**
23 | * @return void
24 | */
25 | public function register()
26 | {
27 | if (empty(env('APP_KEY')) && $this->app->console()) {
28 | $this->app['config']->set('app', array_merge($this->app['config']['app'], [
29 | 'key' => 'base64:F8EDudSAuRK08KoAtb3otCzYQ9yzF+KlpaN12H/vQAw=',
30 | ]));
31 | }
32 |
33 | $key = $this->key(
34 | $config = $this->app['config']['app']
35 | );
36 |
37 | $this->app->instance('encrypter', new Encrypter($key, $config['cipher']));
38 | }
39 |
40 | /**
41 | * @param array $config
42 | * @return string
43 | */
44 | protected function key(array $config) : string
45 | {
46 | if (empty($key = $config['key'])) {
47 | throw new RuntimeException(
48 | 'No application encryption key has been specified.'
49 | );
50 | }
51 |
52 | if (preg_match('/^base64:/', $key)) {
53 | $key = base64_decode(mb_substr($key, 7));
54 | }
55 |
56 | return $key;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/system/Provider/ResponseServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | class ResponseServiceProvider extends ServiceProvider
18 | {
19 | /**
20 | * @return void
21 | */
22 | public function register()
23 | {
24 | $app = $this->app;
25 | $app->response->macro('flash', function (string $name, array $flash) use ($app) {
26 | $app->session->set($name, $flash);
27 |
28 | return $app->response;
29 | });
30 |
31 | $app->macro('flash', function (string $name) use ($app) {
32 | return $app->session->pull($name, []);
33 | });
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/system/Provider/RouteServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\Encryption\Exception\DecryptException;
18 |
19 | class RouteServiceProvider extends ServiceProvider
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected $namespace;
25 |
26 | /**
27 | * @return void
28 | */
29 | public function boot()
30 | {
31 | $cache = $this->app->storage('route.php');
32 |
33 | if (file_exists($cache)) {
34 | try {
35 | $this->app['router']->load(
36 | $this->app['encrypter']->decrypt(require $cache)
37 | );
38 | } catch (DecryptException $exception) {
39 | if (! $this->app->console()) {
40 | throw new DecryptException('The MAC is invalid, please re-run route cache command.');
41 | }
42 | }
43 | } else {
44 | if (method_exists($this, 'map')) {
45 | $this->map();
46 | }
47 |
48 | $this->app->boot(function () {
49 | $this->app['router']->collection->refresh();
50 | });
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/system/Provider/ServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\Application;
18 |
19 | abstract class ServiceProvider
20 | {
21 | /**
22 | * @var Octopy\Application
23 | */
24 | protected $app;
25 |
26 | /**
27 | * @param Application $app
28 | */
29 | public function __construct(Application $app)
30 | {
31 | $this->app = $app;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/system/Provider/SessionServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\Session;
18 | use SessionHandlerInterface;
19 |
20 | class SessionServiceProvider extends ServiceProvider
21 | {
22 | /**
23 | * @return void
24 | */
25 | public function register()
26 | {
27 | $this->app->instance(SessionHandlerInterface::class, $this->app->make(
28 | Session::handler($this->app['config']['session.handler'])
29 | ));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/system/Provider/ToolbarServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\Support\Facade\Route;
18 |
19 | class ToolbarServiceProvider extends ServiceProvider
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected $namespace = \Octopy\Debug\Toolbar\Controller::class;
25 |
26 | /**
27 | * @return void
28 | */
29 | public function register() : void
30 | {
31 | if ($this->app['config']['app.debug'] && $this->app['config']['toolbar.enabled']) {
32 | $this->app->middleware->set(\Octopy\HTTP\Middleware\InjectToolbar::class);
33 | }
34 | }
35 |
36 | /**
37 | * @return void
38 | */
39 | public function boot() : void
40 | {
41 | Route::group(['prefix' => $this->app['config']['toolbar.prefix'], 'namespace' => $this->namespace], static function ($route) {
42 | $route->get('assets/stylesheet', 'AssetController@stylesheet')
43 | ->name('assets.stylesheet');
44 |
45 | $route->get('assets/javascript/:filename', 'AssetController@javascript')
46 | ->name('assets.javascript');
47 |
48 | $route->get('detail/:time', 'DetailController@index')
49 | ->name('toolbar.detail');
50 | });
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/system/Provider/ValidationServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | class ValidationServiceProvider extends ServiceProvider
18 | {
19 | /**
20 | * @return void
21 | */
22 | public function register()
23 | {
24 | $app = $this->app;
25 | $app->request->macro('validate', function (array $rules) use ($app) {
26 | if (! $app->validator->validate($this, $rules)) {
27 | $message = array_reverse($app->validator->message());
28 |
29 | if ($this->ajax()) {
30 | return $app->response->json($message, 422)->send();
31 | }
32 |
33 | echo $app->response
34 | ->flash('error', $message)
35 | ->redirect()
36 | ->back()
37 | ->send();
38 | exit;
39 | }
40 | });
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/system/Provider/ViewEngineServiceProvider.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Provider;
16 |
17 | use Octopy\View\Engine;
18 |
19 | class ViewEngineServiceProvider extends ServiceProvider
20 | {
21 | /**
22 | * @return void
23 | */
24 | public function register()
25 | {
26 | $app = $this->app;
27 |
28 | $config = $app['config']['view'];
29 | $app->instance('view', new Engine($config['resource'], $config['compiled']));
30 |
31 | // We adding a view macro method in Response class.
32 | $macro = function (string $name, array $data = [], int $status = 200, array $header = []) use ($app) {
33 | $value = $app->view->render($name, $data);
34 |
35 | return $app->response->make($value, $status, $header);
36 | };
37 |
38 | $app->response->macro('view', $macro);
39 | }
40 |
41 | /**
42 | * @return void
43 | */
44 | public function boot()
45 | {
46 | $this->app['view']->share('app', $this->app);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/system/Session/Exception/SessionException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Session\Exception;
16 |
17 | use Exception;
18 |
19 | class SessionException extends Exception
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/Session/Handler/NullSessionHandler.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Session\Handler;
16 |
17 | use SessionHandlerInterface;
18 |
19 | class NullSessionHandler implements SessionHandlerInterface
20 | {
21 | /**
22 | * @@param string $storage
23 | * @@param string $name
24 | * @@return bool
25 | */
26 | public function open($storage, $name)
27 | {
28 | return true;
29 | }
30 |
31 | /**
32 | * @return bool
33 | */
34 | public function close()
35 | {
36 | return true;
37 | }
38 |
39 | /**
40 | * @param string $id
41 | * @return mixed
42 | */
43 | public function read($id)
44 | {
45 | return true;
46 | }
47 |
48 | /**
49 | * @param string $id
50 | * @param mixed $data
51 | * @return bool
52 | */
53 | public function write($id, $data)
54 | {
55 | return true;
56 | }
57 |
58 | /**
59 | * @param string $id
60 | * @return bool
61 | */
62 | public function destroy($id)
63 | {
64 | return true;
65 | }
66 |
67 | /**
68 | * @param int $maxlifetime
69 | * @return bool
70 | */
71 | public function gc($maxlifetime)
72 | {
73 | return true;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/system/Support/Facade/App.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class App extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'app';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Auth.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Auth extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'auth';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Console.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Console extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'console';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Crypt.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Crypt extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'encrypter';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/DB.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class DB extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'database';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Facade.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support;
16 |
17 | use Octopy\Container;
18 |
19 | abstract class Facade
20 | {
21 | /**
22 | * @var Octopy\Container
23 | */
24 | protected static $container;
25 |
26 | /**
27 | * @var array
28 | */
29 | protected static $resolved = [];
30 |
31 | /**
32 | * @param string $method
33 | * @param array $parameter
34 | * @return mixed
35 | */
36 | public static function __callStatic(string $method, array $parameter = [])
37 | {
38 | return static::instance()->$method(...$parameter);
39 | }
40 |
41 | /**
42 | * @return mixed
43 | */
44 | public static function instance()
45 | {
46 | if (array_key_exists(static::$name, static::$resolved)) {
47 | return static::$resolved[static::$name];
48 | }
49 |
50 | return static::$resolved[static::$name] = Container::make(static::$name);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/system/Support/Facade/Route.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Route extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'route';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Schema.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Schema extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'schema';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Session.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Session extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'session';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/Validator.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class Validator extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'validator';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Facade/View.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support\Facade;
16 |
17 | use Octopy\Support\Facade;
18 |
19 | class View extends Facade
20 | {
21 | /**
22 | * @var string
23 | */
24 | protected static $name = 'view';
25 | }
26 |
--------------------------------------------------------------------------------
/system/Support/Syntax/Syntax.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Support;
16 |
17 | use Exception;
18 | use Octopy\Application;
19 | use Octopy\Support\Syntax\CLIParser;
20 | use Octopy\Support\Syntax\HTMLParser;
21 |
22 | class Syntax
23 | {
24 | /**
25 | * @var Octopy\Support\Syntax\CLIParser
26 | * @var Octopy\Support\Syntax\HTMLParser
27 | */
28 | protected $parser;
29 |
30 | /**
31 | * @param Application $app
32 | */
33 | public function __construct(Application $app)
34 | {
35 | switch (PHP_SAPI) {
36 | case 'cli':
37 | $this->parser = $app->make(CLIParser::class);
38 | break;
39 |
40 | default:
41 | $this->parser = $app->make(HTMLParser::class);
42 | break;
43 | }
44 | }
45 |
46 | public function __call(string $method, array $args = [])
47 | {
48 | return $this->parser->$method(...$args);
49 | }
50 |
51 | /**
52 | * @param string $source
53 | * @param int $marker
54 | * @param string $offset
55 | * @param string $lang
56 | * @return string
57 | */
58 | public function highlight(string $source, int $marker = 0, string $offset = null, string $lang = 'php')
59 | {
60 | try {
61 | $source = file_get_contents($source);
62 | } catch (Exception $exception) {
63 | throw $exception;
64 | }
65 |
66 | try {
67 | return $this->parser->highlight($source, $marker, $offset, $lang);
68 | } catch (Exception $exception) {
69 | throw $exception;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/system/Validation/Exception/ValidationRuleException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\Validation\Exception;
16 |
17 | use BadMethodCallException;
18 |
19 | class ValidationRuleException extends BadMethodCallException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/View/Compiler/ControlDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Stream;
18 |
19 | class ControlDirective extends Directive
20 | {
21 | /**
22 | * @param Stream $stream
23 | * @return string
24 | */
25 | public function parse(Stream $stream)
26 | {
27 | if (in_array($stream->token(), [T_IF, T_ELSEIF, T_ELSE])) {
28 | if ($stream->next(T_ELSE)) {
29 | return $this->php('%s :', $stream->code());
30 | }
31 |
32 | return $this->php('%s(%s) :', $stream->code(), $stream->expression());
33 | } else if ($stream->next(T_ENDIF)) {
34 | return $this->php('%s;', $stream->code());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/system/View/Compiler/Directive.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | class Directive
18 | {
19 | /**
20 | * @param string $format
21 | * @param array $args
22 | * @return string
23 | */
24 | protected function php(string $format, ...$args) : string
25 | {
26 | return sprintf('', ...$args);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/system/View/Compiler/HelperDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Stream;
18 |
19 | class HelperDirective extends Directive
20 | {
21 | /**
22 | * @param Stream $stream
23 | * @return string
24 | */
25 | public function parse(Stream $stream)
26 | {
27 | if ($stream->next('csrf')) {
28 | return '';
29 | } else if ($stream->next('method')) {
30 | return '';
31 | } else if ($stream->next('dd') || $stream->next('d') || $stream->next('dump')) {
32 | return $this->php('%s(%s)', $stream->code(), $stream->expression());
33 | } else if ($stream->next('session')) {
34 | return $this->php('if ($app->session->has(%s)) : ', $stream->expression());
35 | } else if ($stream->next('endsession')) {
36 | return $this->php('endif;');
37 | } else if ($stream->next('lang')) {
38 | return $this->php('echo __(%s);', $stream->expression());
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/system/View/Compiler/IncludeDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Stream;
18 |
19 | class IncludeDirective extends Directive
20 | {
21 | /**
22 | * @param Stream $stream
23 | * @return string
24 | */
25 | public function parse(Stream $stream)
26 | {
27 | if ($stream->next(T_INCLUDE)) {
28 | return $this->php('echo $this->render(%s);', $stream->expression());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/system/View/Compiler/IteratorDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Stream;
18 |
19 | class IteratorDirective extends Directive
20 | {
21 | /**
22 | * @param Stream $stream
23 | * @return string
24 | */
25 | public function parse(Stream $stream)
26 | {
27 | if (in_array($stream->token(), [T_FOR, T_FOREACH, T_WHILE])) {
28 | return $this->php('%s(%s) :', $stream->code(), $stream->expression());
29 | } else if (in_array($stream->token(), [T_ENDFOR, T_ENDFOREACH, T_ENDWHILE])) {
30 | return $this->php('%s;', $stream->code());
31 | } else if ($stream->next(T_CONTINUE)) {
32 | if ($stream->expression() === '') {
33 | return $this->php('%s;', $stream->code());
34 | }
35 |
36 | return $this->php('if(%s) : continue; endif;', $stream->expression());
37 | } else if ($stream->next(T_BREAK)) {
38 | if ($stream->expression() === '') {
39 | return $this->php('%s;', $stream->code());
40 | }
41 |
42 | return $this->php('if(%s) : break; endif;', $stream->expression());
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/system/View/Compiler/LayoutDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Parser;
18 | use Octopy\View\Stream;
19 |
20 | class LayoutDirective extends Directive
21 | {
22 | /**
23 | * @param Stream $stream
24 | * @param Parser $parser
25 | * @return string
26 | */
27 | public function parse(Stream $stream, Parser $parser)
28 | {
29 | if ($stream->next('parent') || $stream->next('extend')) {
30 | return $parser->footer($this->php('echo $this->render(%s);', $stream->expression()));
31 | } else if ($stream->next('section') || $stream->next('block')) {
32 | return $this->php('$this->section(%s);', $stream->expression());
33 | } else if ($stream->next('endsection') || $stream->next('endblock')) {
34 | return $this->php('$this->endsection();');
35 | } else if ($stream->next('yield') || $stream->next('child')) {
36 | return $this->php('echo $this->yield(%s);', $stream->expression());
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/system/View/Compiler/RawPHPDirective.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Compiler;
16 |
17 | use Octopy\View\Stream;
18 |
19 | class RawPHPDirective extends Directive
20 | {
21 | /**
22 | * @param Stream $stream
23 | * @return string
24 | */
25 | public function parse(Stream $stream)
26 | {
27 | if ($stream->next('php') && $stream->expression() !== '') {
28 | return $this->php('%s;', $stream->expression());
29 | } else if ($stream->next('php') && $stream->expression() === '') {
30 | return 'next('endphp')) {
32 | return ' ?>';
33 | } else if ($stream->next(T_UNSET)) {
34 | return $this->php('%s(%s);', $stream->code(), $stream->expression());
35 | } else if ($stream->next(T_EXIT)) {
36 | if ($stream->expression() === '') {
37 | return $this->php('%s;', $stream->code());
38 | }
39 |
40 | return $this->php('if(%s) : %s; endif;', $stream->expression(), $stream->code());
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/system/View/Exception/ViewException.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View\Exception;
16 |
17 | use InvalidArgumentException;
18 |
19 | class ViewException extends InvalidArgumentException
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/system/View/Stream.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | namespace Octopy\View;
16 |
17 | final class Stream
18 | {
19 | /**
20 | * @var string
21 | */
22 | protected $code;
23 |
24 | /**
25 | * @var int
26 | */
27 | protected $token;
28 |
29 | /**
30 | * @var string
31 | */
32 | protected $expression;
33 |
34 | /**
35 | * @param array $token
36 | */
37 | public function __construct(array $token, ?string $expression = null)
38 | {
39 | $this->expression = $expression;
40 | [$this->token, $this->code] = $token[1];
41 | }
42 |
43 | /**
44 | * @return string
45 | */
46 | public function __toString() : string
47 | {
48 | return printf('%s(%s)', $this->code(), $this->expression());
49 | }
50 |
51 | /**
52 | * @return string
53 | */
54 | public function code() : string
55 | {
56 | return $this->code;
57 | }
58 |
59 | /**
60 | * @return int
61 | */
62 | public function token() : int
63 | {
64 | return $this->token;
65 | }
66 |
67 | /**
68 | * @return string
69 | */
70 | public function expression() : string
71 | {
72 | if (strstr($this->expression, '(')) {
73 | return mb_substr($this->expression, 1, -1);
74 | }
75 |
76 | return $this->expression;
77 | }
78 |
79 | /**
80 | * @param mixed $expression
81 | * @return bool
82 | */
83 | public function next($expression) : bool
84 | {
85 | return $expression === $this->code || $expression === $this->token;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/testing/ApplicationTest.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | declare(strict_types = 1);
16 |
17 | namespace Octopy\Testing;
18 |
19 | use Octopy\Application;
20 |
21 | class ApplicationTest extends TestCase
22 | {
23 | /**
24 | * @return void
25 | */
26 | public function testAppCreated() : void
27 | {
28 | $this->assertInstanceOf(Application::class, $this->app);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/testing/Config/.gitignore:
--------------------------------------------------------------------------------
1 | !.env*
--------------------------------------------------------------------------------
/testing/Config/env/.env:
--------------------------------------------------------------------------------
1 | # Var
2 | NULL =
3 | FOO = bar
4 | BAR = baz
5 | SPACED = "with spaces"
6 |
7 | # Commented
8 | CNULL =
9 | CFOO = bar
10 | #CBAR = baz
11 | #CZOO = goo # a comment on a commented row
12 | CSPACED = "with spaces" # this is a comment
13 | CQUOTES = "a value with a # character" # this is a comment
14 | DOUBLEQUOTE = "a value with a # character & a quote \" character inside quotes" # " this is a comment
15 |
16 | # Nested
17 | NVAR1 = "Hello"
18 | NVAR2 = "World!"
19 | NVAR3 = "{$NVAR1} {$NVAR2}"
20 | NVAR4 = "${NVAR1} ${NVAR2}"
21 | NVAR5 = "$NVAR1 {NVAR2}"
22 | NVAR6 = "${NVAR_X}"
23 | NVAR7 = "${SER_VAR}"
24 |
25 | # Special Chars
26 | SPVAR1 = "$a6^C7k%zs+e^.jvjXk"
27 | SPVAR2 = "?BUty3koaV3%GA*hMAwH}B"
28 | SPVAR3 = "46ae3e009a9883e4f2c38542e300a16d"
29 | SPVAR4 = "22222:22#2^{"
30 | SPVAR5 = "test some escaped characters like a quote \" or maybe a backslash \\" # not escaped
--------------------------------------------------------------------------------
/testing/Config/env/.env.error:
--------------------------------------------------------------------------------
1 | QWFOO = with space
--------------------------------------------------------------------------------
/testing/TestCase.php:
--------------------------------------------------------------------------------
1 |
11 | * @link : framework.octopy.id
12 | * @license : MIT
13 | */
14 |
15 | declare(strict_types = 1);
16 |
17 | namespace Octopy\Testing;
18 |
19 | use Octopy\Container;
20 | use Octopy\HTTP\Kernel;
21 | use PHPUnit\Framework\TestCase as PHPUnitTestCase;
22 |
23 | abstract class TestCase extends PHPUnitTestCase
24 | {
25 | /**
26 | * @var Octopy\Application
27 | */
28 | protected $app;
29 |
30 | /**
31 | * @return void
32 | */
33 | protected function setUp() : void
34 | {
35 | if (! $this->app) {
36 | ($this->app = Container::make('app'))->make(Kernel::class);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------