├── .editorconfig ├── .env.example ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .styleci.yml ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── .htaccess ├── Config │ ├── App.php │ ├── Auth.php │ ├── Constant.php │ ├── Database.php │ ├── Exception.php │ ├── Hashing.php │ ├── Logger.php │ ├── Mail.php │ ├── Session.php │ ├── Toolbar.php │ └── View.php ├── Console │ └── Kernel.php ├── DB │ └── Seeder │ │ └── DatabaseSeeder.php ├── Exception │ └── Handler.php ├── HTTP │ ├── Controller │ │ └── Controller.php │ ├── Kernel.php │ └── Middleware │ │ ├── CheckMaintenanceMode.php │ │ └── VerifyCSRFToken.php ├── Language │ └── en │ │ └── Validation.php ├── Provider │ ├── AppServiceProvider.php │ └── RouteServiceProvider.php ├── Route │ ├── Api.php │ ├── Console.php │ └── Web.php └── View │ └── welcome.octopy.php ├── composer.json ├── octopy ├── phpunit.xml ├── public ├── .htaccess ├── css │ └── style.css ├── favicon.ico ├── img │ ├── octopy.png │ └── wave.svg ├── index.php ├── robots.txt └── web.config ├── server.php ├── storage └── .gitignore ├── system ├── .htaccess ├── Application.php ├── Autoload.php ├── Bootstrap │ ├── BootUpServiceProvider.php │ ├── RegisterEnvironmentVariable.php │ ├── RegisterExceptionHandler.php │ ├── RegisterMiddlewareProvider.php │ ├── RegisterServiceProvider.php │ └── RegisterSystemConfiguration.php ├── Common.php ├── Config │ ├── Container.php │ ├── DotEnv.php │ ├── Exception │ │ └── DotEnvException.php │ └── Repository.php ├── Console │ ├── Argv │ │ └── Argv.php │ ├── Collection.php │ ├── Command │ │ ├── AutoloadCacheCommand.php │ │ ├── AutoloadClearCommand.php │ │ ├── Command.php │ │ ├── DatabaseMigrateCommand.php │ │ ├── DatabaseRefreshCommand.php │ │ ├── DatabaseSeedingCommand.php │ │ ├── GenerateAppKeyCommand.php │ │ ├── MaintenanceDownCommand.php │ │ ├── MaintenanceUpCommand.php │ │ ├── MakeConsoleCommand.php │ │ ├── MakeControllerCommand.php │ │ ├── MakeMiddlewareCommand.php │ │ ├── MakeMigrationCommand.php │ │ ├── MakeModelCommand.php │ │ ├── MakeSeederCommand.php │ │ ├── OctopyServeCommand.php │ │ ├── OptimizeCommand.php │ │ ├── RouteCacheCommand.php │ │ ├── RouteClearCommand.php │ │ ├── RouteListCommand.php │ │ ├── ViewCacheCommand.php │ │ ├── ViewClearCommand.php │ │ └── stub │ │ │ ├── Cache.stub │ │ │ ├── Command.stub │ │ │ ├── Controller.api.stub │ │ │ ├── Controller.plain.stub │ │ │ ├── Controller.resource.stub │ │ │ ├── Middleware.stub │ │ │ ├── Migration.stub │ │ │ ├── Model.stub │ │ │ └── Seeder.stub │ ├── Console.php │ ├── Dispatcher.php │ ├── Exception │ │ ├── InvalidStyleException.php │ │ └── NotEnoughArgumentException.php │ ├── Kernel.php │ ├── Output │ │ ├── Color.php │ │ ├── MenuFormatter.php │ │ ├── Output.php │ │ └── TableFormatter.php │ └── Route.php ├── Container │ ├── Container.php │ └── Exception │ │ └── BindingResolutionException.php ├── Database │ ├── Connection.php │ ├── Database.php │ ├── Driver │ │ └── MySQL.php │ ├── Exception │ │ └── DBException.php │ ├── Migration │ │ ├── BluePrint │ │ │ ├── BluePrint.php │ │ │ └── MySQL.php │ │ ├── Migration.php │ │ └── Schema.php │ ├── Model.php │ ├── Queries.php │ └── Seeder.php ├── Debug │ ├── Toolbar │ │ ├── Asset │ │ │ └── octopy.js │ │ ├── Controller │ │ │ ├── AssetController.php │ │ │ └── DetailController.php │ │ ├── DataCollector │ │ │ ├── Collector.php │ │ │ ├── FileCollector.php │ │ │ ├── HistoryCollector.php │ │ │ ├── MainCollector.php │ │ │ ├── QueryCollector.php │ │ │ ├── RouteCollector.php │ │ │ ├── VarsCollector.php │ │ │ └── ViewCollector.php │ │ ├── Storage │ │ │ ├── FileStorage.php │ │ │ └── Storage.php │ │ ├── Toolbar.php │ │ └── View │ │ │ ├── child │ │ │ ├── exception.octopy.php │ │ │ ├── files.octopy.php │ │ │ ├── history.octopy.php │ │ │ ├── query.octopy.php │ │ │ ├── route.octopy.php │ │ │ ├── vars.octopy.php │ │ │ └── views.octopy.php │ │ │ ├── content.octopy.php │ │ │ ├── javascript.octopy.php │ │ │ └── stylesheet.octopy.php │ └── VarDumper │ │ └── VarDumper.php ├── Encryption │ ├── Encrypter.php │ └── Exception │ │ ├── CipherKeyException.php │ │ ├── DecryptException.php │ │ └── EncryptException.php ├── Exception │ ├── ExceptionHandler.php │ └── View │ │ ├── debug.octopy.php │ │ ├── error.octopy.php │ │ └── inc │ │ ├── backtrace.octopy.php │ │ ├── files.octopy.php │ │ ├── memory.octopy.php │ │ ├── request.octopy.php │ │ ├── response.octopy.php │ │ └── server.octopy.php ├── FileSystem │ ├── Exception │ │ └── FileNotFoundException.php │ ├── FileSystem.php │ └── PathLocator.php ├── Foundation │ └── Auth │ │ └── Auth.php ├── HTTP │ ├── Controller.php │ ├── Kernel.php │ ├── Middleware │ │ ├── CheckMaintenanceMode.php │ │ ├── ControllerMiddleware.php │ │ ├── Dispatcher.php │ │ ├── Exception │ │ │ ├── MaintenanceModeException.php │ │ │ ├── PostTooLargeException.php │ │ │ └── TokenMismatchException.php │ │ ├── InjectToolbar.php │ │ ├── Middleware.php │ │ ├── ValidatePostSize.php │ │ └── VerifyCSRFToken.php │ ├── Request │ │ ├── Collection.php │ │ ├── Curl.php │ │ ├── Exception │ │ │ └── HTTPException.php │ │ ├── FileHandler.php │ │ └── Request.php │ ├── Response │ │ ├── DownloadResponse.php │ │ ├── Header.php │ │ ├── JsonResponse.php │ │ ├── RedirectResponse.php │ │ └── Response.php │ └── Routing │ │ ├── Collection.php │ │ ├── Compiler.php │ │ ├── Dispatcher.php │ │ ├── Exception │ │ ├── MethodNotAllowedException.php │ │ ├── MissingParameterException.php │ │ ├── ResourceControllerException.php │ │ ├── RouteNameNotExistException.php │ │ └── RouteNotFoundException.php │ │ ├── Resource.php │ │ ├── Route.php │ │ ├── Router.php │ │ └── URLGenerator.php ├── Hashing │ ├── Driver │ │ ├── Argon2IdHasher.php │ │ ├── ArgonHasher.php │ │ ├── BcryptHasher.php │ │ └── Hasher.php │ ├── Exception │ │ └── HashDriverException.php │ └── HashManager.php ├── Language │ ├── Exception │ │ └── TranslationNotDefinedException.php │ └── Language.php ├── Logger │ ├── Exception │ │ ├── InvalidLogLevelException.php │ │ └── InvalidLogPathException.php │ ├── Handler │ │ ├── BaseHandler.php │ │ └── FileHandler.php │ └── Logger.php ├── Mailer │ ├── Exception │ │ ├── AttachmentNotExistException.php │ │ ├── ErrorSendingCommandException.php │ │ ├── FailedSendingEmailException.php │ │ ├── InvalidRecepientException.php │ │ ├── SMTPAuthorizationException.php │ │ └── SMTPConnectionException.php │ ├── SMTP.php │ └── Socket.php ├── Octopy.php ├── Provider │ ├── AutoloadServiceProvider.php │ ├── ConsoleServiceProvider.php │ ├── EncryptionServiceProvider.php │ ├── ResponseServiceProvider.php │ ├── RouteServiceProvider.php │ ├── ServiceProvider.php │ ├── SessionServiceProvider.php │ ├── ToolbarServiceProvider.php │ ├── ValidationServiceProvider.php │ └── ViewEngineServiceProvider.php ├── Session │ ├── Exception │ │ └── SessionException.php │ ├── Handler │ │ ├── FileSessionHandler.php │ │ └── NullSessionHandler.php │ └── Session.php ├── Stuff │ └── Inspiring.php ├── Support │ ├── Arr │ │ └── Arr.php │ ├── DateTime │ │ └── DateTime.php │ ├── Facade │ │ ├── App.php │ │ ├── Auth.php │ │ ├── Console.php │ │ ├── Crypt.php │ │ ├── DB.php │ │ ├── Facade.php │ │ ├── Route.php │ │ ├── Schema.php │ │ ├── Session.php │ │ ├── Validator.php │ │ └── View.php │ ├── Macroable │ │ └── Macroable.php │ ├── Str │ │ └── Str.php │ ├── Syntax │ │ ├── CLIParser.php │ │ ├── HTMLParser.php │ │ ├── Syntax.php │ │ └── Vendor │ │ │ ├── prism.min.css │ │ │ └── prism.min.js │ └── VarDump │ │ └── VarDump.php ├── Validation │ ├── Exception │ │ └── ValidationRuleException.php │ ├── ValidationRule.php │ └── Validator.php └── View │ ├── Compiler │ ├── ControlDirective.php │ ├── Directive.php │ ├── HelperDirective.php │ ├── IncludeDirective.php │ ├── IteratorDirective.php │ ├── LayoutDirective.php │ └── RawPHPDirective.php │ ├── Engine.php │ ├── Exception │ └── ViewException.php │ ├── Finder.php │ ├── Parser.php │ ├── Storage.php │ └── Stream.php └── testing ├── ApplicationTest.php ├── Autoload └── AutoloaderTest.php ├── Config ├── .gitignore ├── DotEnvTest.php └── env │ ├── .env │ └── .env.error └── TestCase.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml, yaml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | #-------------------------------------------------------------------- 2 | # APP 3 | #-------------------------------------------------------------------- 4 | APP_NAME = 'Octopy Framework' 5 | APP_KEY = 6 | APP_ENV = local 7 | APP_DEBUG = true 8 | APP_URL = http://localhost/ 9 | 10 | #-------------------------------------------------------------------- 11 | # DATABASE 12 | #-------------------------------------------------------------------- 13 | DB_CONNECTION = mysql 14 | DB_HOST = 127.0.0.1 15 | DB_PORT = 3306 16 | DB_DATABASE = secret 17 | DB_USERNAME = secret 18 | DB_PASSWORD = secret 19 | 20 | #-------------------------------------------------------------------- 21 | # SESSION & COOKIE 22 | #-------------------------------------------------------------------- 23 | SESSION_DRIVER = file 24 | SESSION_LIFETIME = 120 25 | 26 | #-------------------------------------------------------------------- 27 | # MAIL 28 | #-------------------------------------------------------------------- 29 | MAIL_HOST = ssl://smtp.gmail.com 30 | MAIL_PORT = 465 31 | MAIL_USERNAME = null 32 | MAIL_PASSWORD = null 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report about: Create a report to help us improve title: '' 3 | labels: '' 4 | assignees: '' 5 | 6 | --- 7 | 8 | **Describe the bug** 9 | A clear and concise description of what the bug is. 10 | 11 | **To Reproduce** 12 | Steps to reproduce the behavior: 13 | 14 | 1. Go to '...' 15 | 2. Click on '....' 16 | 3. Scroll down to '....' 17 | 4. See error 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Desktop (please complete the following information):** 26 | 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | 33 | - Device: [e.g. iPhone6] 34 | - OS: [e.g. iOS8.1] 35 | - Browser [e.g. stock browser, safari] 36 | - Version [e.g. 22] 37 | 38 | **Additional context** 39 | Add any other context about the problem here. 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request about: Suggest an idea for this project title: '' 3 | labels: '' 4 | assignees: '' 5 | 6 | --- 7 | 8 | **Is your feature request related to a problem? Please describe.** 9 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 10 | 11 | **Describe the solution you'd like** 12 | A clear and concise description of what you want to happen. 13 | 14 | **Describe alternatives you've considered** 15 | A clear and concise description of any alternative solutions or features you've considered. 16 | 17 | **Additional context** 18 | Add any other context or screenshots about the feature request here. 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #------------------------- 2 | # Operating Specific Junk Files 3 | #------------------------- 4 | 5 | # OS X 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | 10 | # OS X Thumbnails 11 | ._* 12 | 13 | # Windows image file caches 14 | Thumbs.db 15 | ehthumbs.db 16 | Desktop.ini 17 | 18 | # Recycle Bin used on file shares 19 | $RECYCLE.BIN/ 20 | 21 | # Windows Installer files 22 | *.cab 23 | *.msi 24 | *.msm 25 | *.msp 26 | 27 | # Windows shortcuts 28 | *.lnk 29 | 30 | # Linux 31 | *~ 32 | 33 | # KDE directory preferences 34 | .directory 35 | 36 | # Linux trash folder which might appear on any partition or disk 37 | .Trash-* 38 | 39 | #------------------------- 40 | # Environment Files 41 | #------------------------- 42 | # These should never be under version control, 43 | # as it poses a security risk. 44 | .env 45 | .vagrant 46 | Vagrantfile 47 | 48 | #------------------------- 49 | # Temporary Files 50 | #------------------------- 51 | 52 | php_errors.log 53 | 54 | #------------------------- 55 | # Test Files 56 | #------------------------- 57 | tests/coverage* 58 | .phpunit.result.cache 59 | 60 | #------------------------- 61 | # Composer 62 | #------------------------- 63 | vendor/ 64 | composer.lock 65 | 66 | #------------------------- 67 | # IDE / Development Files 68 | #------------------------- 69 | 70 | # php-cs-fixer 71 | .php_cs.cache 72 | 73 | # phpenv local config 74 | .php-version 75 | 76 | # Jetbrains editors (PHPStorm, etc) 77 | .idea/ 78 | *.iml 79 | 80 | # Netbeans 81 | nbproject/ 82 | build/ 83 | nbbuild/ 84 | dist/ 85 | nbdist/ 86 | nbactions.xml 87 | nb-configuration.xml 88 | .nb-gradle/ 89 | 90 | # Sublime Text 91 | *.tmlanguage.cache 92 | *.tmPreferences.cache 93 | *.stTheme.cache 94 | *.sublime-workspace 95 | *.sublime-project 96 | .phpintel 97 | /api/ 98 | 99 | # Visual Studio Code 100 | .vscode/ 101 | /results/ 102 | 103 | # Misc 104 | git 105 | sftp-config.json 106 | request.sh -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | risky: false 4 | 5 | disabled: 6 | - concat_without_spaces 7 | - no_empty_phpdoc 8 | - no_blank_lines_after_phpdoc 9 | - ordered_imports 10 | - function_typehint_space 11 | 12 | enabled: 13 | - concat_with_spaces 14 | - phpdoc_annotation_without_dot 15 | - multiline_comment_opening_closing 16 | 17 | finder: 18 | exclude: 19 | - modules 20 | - node_modules 21 | - storage 22 | - vendor 23 | name: 24 | - "*.php" 25 | not-name: 26 | - "*.stub" 27 | - "*.octopy.php" 28 | depth: 29 | - "< 3" 30 | 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.3 5 | 6 | before_script: 7 | - travis_retry composer self-update 8 | - travis_retry composer install --prefer-source --no-interaction 9 | - cp .env.example .env 10 | - php octopy key:generate 11 | 12 | script: 13 | - vendor/bin/phpunit 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 - 2019 Supian M 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | # Security is KING 2 | 3 | Require all denied 4 | 5 | 6 | 7 | Deny from all 8 | 9 | -------------------------------------------------------------------------------- /app/Config/Constant.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | -------------------------------------------------------------------------------- /app/Config/Exception.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | return [ 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | LOG EXCEPTIONS 20 | |-------------------------------------------------------------------------- 21 | | If true, then exceptions will be logged 22 | | 23 | | Default : true 24 | */ 25 | 'log' => true, 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | DO NOT LOG STATUS CODES 30 | |-------------------------------------------------------------------------- 31 | | Any status codes here will NOT be logged if logging is turned on. 32 | | By default, only 404 (Page Not Found) exception are ignored. 33 | | 34 | */ 35 | 'ignored' => [ 36 | 404, 37 | ], 38 | ]; 39 | -------------------------------------------------------------------------------- /app/Config/Hashing.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | return [ 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Default Hash Driver 20 | |-------------------------------------------------------------------------- 21 | | 22 | | This option controls the default hash driver that will be used to hash 23 | | passwords for your application. By default, the bcrypt algorithm is 24 | | used; however, you remain free to modify this option if you wish. 25 | | 26 | | Supported : "bcrypt", "argon", "argon2id" 27 | | 28 | */ 29 | 'driver' => 'bcrypt', 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Bcrypt Options 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may specify the configuration options that should be used when 37 | | passwords are hashed using the Bcrypt algorithm. This will allow you 38 | | to control the amount of time it takes to hash the given password. 39 | | 40 | */ 41 | 'bcrypt' => [ 42 | 'round' => env('BCRYPT_ROUND', 10), 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | Argon Options 48 | |-------------------------------------------------------------------------- 49 | | 50 | | Here you may specify the configuration options that should be used when 51 | | passwords are hashed using the Argon algorithm. These will allow you 52 | | to control the amount of time it takes to hash the given password. 53 | | 54 | */ 55 | 'argon' => [ 56 | 'time' => 2, 57 | 'thread' => 2, 58 | 'memory' => 1024, 59 | ], 60 | ]; 61 | -------------------------------------------------------------------------------- /app/Config/Mail.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | return [ 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | SMTP Host Address 20 | |-------------------------------------------------------------------------- 21 | | 22 | | Here you may provide the host address of the SMTP server used by your 23 | | applications. A default option is provided that is compatible with 24 | | the Gmail mail service which will provide reliable deliveries. 25 | | 26 | */ 27 | 'host' => env('MAIL_HOST', 'ssl://smtp.gmail.com'), 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | SMTP Host Port 32 | |-------------------------------------------------------------------------- 33 | | 34 | | This is the SMTP port used by your application to deliver e-mails to 35 | | users of the application. Like the host we have set this value to 36 | | stay compatible with the Gmail e-mail application by default. 37 | | 38 | */ 39 | 'port' => env('MAIL_PORT', 465), 40 | 41 | /* 42 | |-------------------------------------------------------------------------- 43 | | SMTP Server Authentication 44 | |-------------------------------------------------------------------------- 45 | | 46 | | If your SMTP server requires a username for authentication, you should 47 | | set it here. This will get used to authenticate with your server on 48 | | connection. You may also set the "password" value below this one. 49 | | 50 | */ 51 | 'auth' => [ 52 | 'username' => env('MAIL_USERNAME'), 53 | 'password' => env('MAIL_PASSWORD'), 54 | ], 55 | ]; 56 | -------------------------------------------------------------------------------- /app/Config/View.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | return [ 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | View Storage Paths 20 | |-------------------------------------------------------------------------- 21 | | 22 | | Most templating systems load templates from disk. Here you may specify 23 | | an array of paths that should be checked for your views. Of course 24 | | the usual Octopy view path has already been registered for you. 25 | | 26 | */ 27 | 'resource' => $this->path->app->view('/'), 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | Compiled View Path 32 | |-------------------------------------------------------------------------- 33 | | 34 | | This option determines where all the compiled Octopy templates will be 35 | | stored for your application. Typically, this is within the storage 36 | | directory. However, as usual, you are free to change this value. 37 | | 38 | */ 39 | 'compiled' => $this->path->storage('compiled'), 40 | ]; 41 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\Console; 16 | 17 | use Octopy\Console\Kernel as CLIKernel; 18 | 19 | class Kernel extends CLIKernel 20 | { 21 | // for now I don't have an idea for this section 22 | } 23 | -------------------------------------------------------------------------------- /app/DB/Seeder/DatabaseSeeder.php: -------------------------------------------------------------------------------- 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 DatabaseSeeder extends Seeder 20 | { 21 | /** 22 | * @return void 23 | */ 24 | public function seed() 25 | { 26 | // $this->call(UsersSeeder::class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Exception/Handler.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\Exception; 16 | 17 | use Exception; 18 | use Octopy\HTTP\Request; 19 | use Octopy\Exception\ExceptionHandler; 20 | 21 | class Handler extends ExceptionHandler 22 | { 23 | /** 24 | * @param Exception $exception 25 | */ 26 | public function report(Exception $exception) 27 | { 28 | return parent::report($exception); 29 | } 30 | 31 | /** 32 | * @param Request $request 33 | * @param Exception $exception 34 | * @return mixed 35 | */ 36 | public function render(Request $request, Exception $exception) 37 | { 38 | return parent::render($request, $exception); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/HTTP/Controller/Controller.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\HTTP; 16 | 17 | use Octopy\HTTP\Controller as BaseController; 18 | 19 | class Controller extends BaseController 20 | { 21 | // for now I don't have an idea for this section 22 | } 23 | -------------------------------------------------------------------------------- /app/HTTP/Kernel.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\HTTP; 16 | 17 | use Octopy\HTTP\Kernel as HTTPKernel; 18 | 19 | class Kernel extends HTTPKernel 20 | { 21 | /** 22 | * @var array 23 | */ 24 | protected $middleware = [ 25 | \App\HTTP\Middleware\CheckMaintenanceMode::class, 26 | \App\HTTP\Middleware\VerifyCSRFToken::class, 27 | ]; 28 | 29 | /** 30 | * @var array 31 | */ 32 | protected $routemiddleware = [ 33 | 34 | ]; 35 | } 36 | -------------------------------------------------------------------------------- /app/HTTP/Middleware/CheckMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\HTTP\Middleware; 16 | 17 | use Octopy\HTTP\Middleware\CheckMaintenanceMode as Middleware; 18 | 19 | class CheckMaintenanceMode extends Middleware 20 | { 21 | /** 22 | * @var array 23 | */ 24 | protected $except = [ 25 | 26 | ]; 27 | } 28 | -------------------------------------------------------------------------------- /app/HTTP/Middleware/VerifyCSRFToken.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\HTTP\Middleware; 16 | 17 | use Octopy\HTTP\Middleware\VerifyCSRFToken as Middleware; 18 | 19 | class VerifyCSRFToken extends Middleware 20 | { 21 | /** 22 | * @var array 23 | */ 24 | protected $except = [ 25 | 26 | ]; 27 | } 28 | -------------------------------------------------------------------------------- /app/Provider/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\Provider; 16 | 17 | use Octopy\Provider\ServiceProvider; 18 | 19 | class AppServiceProvider extends ServiceProvider 20 | { 21 | /** 22 | * @return void 23 | */ 24 | public function register() 25 | { 26 | } 27 | 28 | /** 29 | * @return void 30 | */ 31 | public function boot() 32 | { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Provider/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | namespace App\Provider; 16 | 17 | use Octopy\Support\Facade\Route; 18 | use Octopy\Provider\RouteServiceProvider as ServiceProvider; 19 | 20 | class RouteServiceProvider extends ServiceProvider 21 | { 22 | /** 23 | * @var string 24 | */ 25 | protected $namespace = \App\HTTP\Controller::class; 26 | 27 | /** 28 | * @return void 29 | */ 30 | public function map() : void 31 | { 32 | Route::group(['namespace' => $this->namespace], static function ($route) { 33 | $route->load('Web.php'); 34 | 35 | $route->group(['prefix' => 'api'], static function ($route) { 36 | $route->load('Api.php'); 37 | }); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Route/Api.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | -------------------------------------------------------------------------------- /app/Route/Console.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | use Octopy\Stuff\Inspiring; 16 | use Octopy\Support\Facade\Console; 17 | 18 | Console::command('inspire', static function (Octopy\Console\Output $output) { 19 | return $output->comment(Inspiring::quote()); 20 | })->describe('Display an inspiring quote'); 21 | -------------------------------------------------------------------------------- /app/Route/Web.php: -------------------------------------------------------------------------------- 1 | 11 | * @link : framework.octopy.id 12 | * @license : MIT 13 | */ 14 | 15 | use Octopy\HTTP\Response; 16 | use Octopy\Support\Facade\Route; 17 | 18 | Route::get('/', static function (Response $response) { 19 | return $response->view('welcome', [], 200); 20 | }); 21 | -------------------------------------------------------------------------------- /app/View/welcome.octopy.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{ $app->name() }} 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 | 18 | 19 |
20 |
21 |
22 | 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 | 7 | 8 | 9 | 10 | 11 | 12 | @foreach($data->files as $file) 13 | 14 | 15 | 16 | 17 | 18 | @endforeach 19 | 20 |
NameLocationSize
{{ basename($file) }}{{ $file }}{{ byteformatter(filesize($file)) }}
21 |
22 | -------------------------------------------------------------------------------- /system/Debug/Toolbar/View/child/files.octopy.php: -------------------------------------------------------------------------------- 1 |
2 |

Included Files

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | @foreach($data->files as $file) 13 | 14 | 15 | 16 | 17 | 18 | @endforeach 19 | 20 |
NameLocationSize
{{ basename($file) }}{{ $file }}{{ byteformatter(filesize($file)) }}
21 |
22 | -------------------------------------------------------------------------------- /system/Debug/Toolbar/View/child/history.octopy.php: -------------------------------------------------------------------------------- 1 |
2 |

History

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 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 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | @endforeach 41 | 42 |
DatetimeStatusMethodURLContent-TypeAjaxAction
{{ date('Y-m-d H:i:s', $json->time) }}{{ $json->main->status }}{{ $json->main->method }}{{ $json->main->url }}{{ $contentype }}{{ $json->main->ajax ? 'Yes' : 'No' }} 37 | 38 |
43 |
44 | -------------------------------------------------------------------------------- /system/Debug/Toolbar/View/child/query.octopy.php: -------------------------------------------------------------------------------- 1 |
2 |

Queries

3 | 4 | 5 | @foreach($data->query as $query) 6 | 7 | 8 | 9 | @endforeach 10 | 11 |
{{ $query }}
12 |
13 | -------------------------------------------------------------------------------- /system/Debug/Toolbar/View/child/route.octopy.php: -------------------------------------------------------------------------------- 1 |
2 |

Route

3 |

Matched Route

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | @if(! empty($data->route->middleware)) 25 | @php($no = 1) 26 | 27 | @foreach(array_slice($data->route->middleware, 1) as $middleware) 28 | 29 | 30 | 31 | 32 | @endforeach 33 | @else 34 | - 35 | @endif 36 | 37 | 38 |
Name{{ $data->route->name !== '' ? $data->route->name : '-' }}
Target{{ $data->route->uri }}
Method{{ implode(' & ', $data->route->method) }}
Controller{{ $data->route->controller }}
Middleware{{ $no }}. {{ $data->route->middleware[0] }}
{{ ++$no }}. {{ $middleware }}
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 | 18 | 19 | 20 | @endforeach 21 | 22 |
{{ $key }}{{ $val }}
23 | @endif 24 | @endforeach 25 | 26 | @else 27 | 28 | 29 | @foreach($var as $key => $val) 30 | 31 | 32 | 33 | 34 | @endforeach 35 | 36 |
{{ $key }}{{ $val }}
37 | @endif 38 | @endforeach 39 |
40 | -------------------------------------------------------------------------------- /system/Debug/Toolbar/View/child/views.octopy.php: -------------------------------------------------------------------------------- 1 |
2 |

Templates

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | @foreach($data->views as $template) 13 | 14 | 15 | 16 | 17 | 18 | @endforeach 19 | 20 |
NAMELOCATIONSIZE
{{ basename($template) }}{{ $template }}{{ byteformatter(filesize($template)) }}
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 |
  1. 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 | 38 | 39 | 40 | @endforeach 41 |
    34 | 35 | {{ isset($params[$key]) ? '$'.$params[$key]->name : "#$key" }} 36 | 37 | {{{ dump($value) }}}
    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 |
  2. 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 | 11 | 12 | 13 | 14 | @foreach ($files as $i => $file) 15 | 16 | 17 | 18 | 19 | 20 | @endforeach 21 | 22 |
#File PathFile Size
{{ ++$i }}.{{ $file->getPathname() }}{{ byteformatter($file->getSize()) }}
23 | -------------------------------------------------------------------------------- /system/Exception/View/inc/memory.octopy.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
Memory Limit{{ byteformatter(trim(ini_get('memory_limit'), 'M') * 1024 * 1024) }}
Memory Usage{{ byteformatter(memory_get_usage(true)) }}
Peak Memory Usage{{ byteformatter(memory_get_peak_usage(true)) }}
17 | -------------------------------------------------------------------------------- /system/Exception/View/inc/response.octopy.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
Response Status{{ $code . ' - ' . ($message != null ? $message : $app->response->reason($code)) }}
7 | 8 | @php($headers = $app->response->headers(); ksort($headers)) 9 | @if (! empty($headers)) 10 |

Header

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @foreach ($headers as $name => $value) 20 | 21 | 22 | 23 | 24 | @endforeach 25 | 26 |
NameValue
{{ strip_tags($name) }}{{ strip_tags(implode(', ', $value)) }}
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 | 8 | 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 | 24 | 32 | 33 | @endforeach 34 | 35 |
NameValue
{{ $key }} 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 |
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 | 46 | 47 | 48 | 49 | 50 | @foreach ($constants['user'] as $key => $value) 51 | 52 | 53 | 60 | 61 | @endforeach 62 | 63 |
NameValue
{{ $key }} 54 | @if (! is_array($value) && ! is_object($value)) 55 | {{ $value }} 56 | @else 57 |
{{ print_r($value, true) }}
58 | @endif 59 |
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 | --------------------------------------------------------------------------------