diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4569922b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +#------------------------- +# Docker volumes +#------------------------- + +mariadb +phpmyadmin diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 695054e8..d9f86174 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -1,11 +1,11 @@ -# Dependencies +# Castopod dependencies Castopod uses the following components: -* [Code Igniter 4](https://codeigniter.com) ([MIT License](https://codeigniter.com/user_guide/license.html)) -* [tailwindcss](https://tailwindcss.com/) ([MIT License](https://github.com/tailwindcss/tailwindcss/blob/master/LICENSE)) -* [Tatter\Relations](https://github.com/tattersoftware/codeigniter4-relations) ([MIT License](https://github.com/tattersoftware/codeigniter4-relations/blob/develop/LICENSE)) -* [D3: Data-Driven Documents](https://github.com/d3/d3) ([BSD 3-Clause "New" or "Revised" License](https://github.com/d3/d3/blob/master/LICENSE)) -* [Rollup](https://github.com/rollup/rollup) ([MIT license](https://github.com/rollup/rollup/blob/master/LICENSE.md)) -* [Svelte](https://github.com/sveltejs/svelte) ([MIT license](https://github.com/sveltejs/svelte/blob/master/LICENSE)) -* [User agent list](https://github.com/opawg/user-agents) ([by Open Podcast Analytics Working Group](https://github.com/opawg)) ([MIT license](https://github.com/opawg/user-agents/blob/master/LICENSE)) \ No newline at end of file +- [Code Igniter 4](https://codeigniter.com) ([MIT License](https://codeigniter.com/user_guide/license.html)) +- [tailwindcss](https://tailwindcss.com/) ([MIT License](https://github.com/tailwindcss/tailwindcss/blob/master/LICENSE)) +- [Tatter\Relations](https://github.com/tattersoftware/codeigniter4-relations) ([MIT License](https://github.com/tattersoftware/codeigniter4-relations/blob/develop/LICENSE)) +- [D3: Data-Driven Documents](https://github.com/d3/d3) ([BSD 3-Clause "New" or "Revised" License](https://github.com/d3/d3/blob/master/LICENSE)) +- [Rollup](https://github.com/rollup/rollup) ([MIT license](https://github.com/rollup/rollup/blob/master/LICENSE.md)) +- [Svelte](https://github.com/sveltejs/svelte) ([MIT license](https://github.com/sveltejs/svelte/blob/master/LICENSE)) +- [User agent list](https://github.com/opawg/user-agents) ([by Open Podcast Analytics Working Group](https://github.com/opawg)) ([MIT license](https://github.com/opawg/user-agents/blob/master/LICENSE)) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c5a24ff7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM php:latest + +COPY ./src /castopod +WORKDIR /castopod + +### Install CodeIgniter's server requirements +#-- https://github.com/codeigniter4/appstarter#server-requirements + +# Install intl extension using https://github.com/mlocati/docker-php-extension-installer +RUN apt-get update && apt-get install -y \ + libicu-dev \ + && docker-php-ext-install intl diff --git a/README.md b/README.md index 7d3852ef..7ddfd665 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,99 @@ # Castopod + Castopod is an open-source podcast hosting solution for everyone. Whether you are a beginner, an amateur or a professional, you will get everything you need: create, upload, publish, manage server subscriptions (WebSub embedded server), connect to the usual directories (Apple, Google, Spotify…), connect to the Fediverse (ActivityPub, Mastodon, Pleroma…) and measure your audience (IAB 2.0 compliant) so that you can monetize your content. Take back control: interact with your audience on your plateform (like, share, comment), the social network IS the podcast. Of course you may also export to proprietary social networks(Twitter, Instagram, Youtube, Facebook). Castopod can be hosted on any PHP/MySQL server: Unzip it and you and other podcasters are ready to broadcast professionally. ## Free + Castopod is a free and open-source solution (AGPL v3). Whether you choose to install it on your own server or have it hosted by a professional, all your data and analytics belong to you and you only. ## Social Media + Castopod is a part of Fediverse (Mastodon, Pleroma, PixelFed, PeerTube…). Podcasters and their audience can post, subscribe, like, comment and share natively. Millions of users already on Fediverse will be able to interact seamlessly. ## Flexible + Castopod is compatible with all Podcasts players and platforms (it can automatically generate an RSS feed). Moreover Podcasters can choose to publish on Castopod while keeping their existing hosting solution (it can automatically generate posts from an existing RSS feed). ![Castopod Users](https://podlibre.org/img/Business-31.svg) + +--- + +## Setup your development environment + +Castopod is a web app based on the `php` framework [CodeIgniter 4](https://codeigniter.com). + +To setup a dev environment, we use [Docker](https://www.docker.com/). A `docker-compose.yml` and `Dockerfile` are included in the project's root folder to help you kickstart your contribution. + +> Know that you don't need any prior knowledge of Docker to follow the next steps. However, if you wish to use your own environment, feel free to do so! + +### Prerequisites + +0. Install [docker desktop](https://www.docker.com/products/docker-desktop). + +1. Clone castopod project by running: + +```bash +git clone https://code.podlibre.org/podlibre/castopod.git +``` + +2. Create a `./src/.env` file with the minimum required config to connect the app to the database: + +```env +CI_ENVIRONMENT = development + +database.default.hostname = mariadb +database.default.database = castopod +database.default.username = podlibre +database.default.password = castopod +``` + +> _NB._ You can tweak your environment by setting more environment variables. See the `./src/env` for examples or the [CodeIgniter4 User Guide](https://codeigniter.com/user_guide/index.html) for more info. + +3. Add the repository you've cloned to docker desktop's `Settings` > `Resources` > `File Sharing`. + +### Start dev docker containers + +Go to project's root folder and run: + +```bash +# starts all services declared in docker-compose.yml file +# -d option starts the containers in the background +docker-compose up -d +``` + +> The command will boot 3 containers in the background: +> +> - `castopod_app`: a php based container with codeigniter requirements installed +> - `castopod_mariadb`: a [mariadb](https://mariadb.org/) server for persistent data +> - `castopod_phpmyadmin`: a phpmyadmin server to visualize the mariadb database +> +> _NB._ `./mariadb`, `./phpmyadmin` folders will be mounted in the project's root directory to persist data and logs. + +### Install / update app dependencies using the `composer` service + +The project's dependencies aren't included in the repository, you have to download them using the composer service defined in `docker-compose.yml` + +```bash +docker-compose run --rm composer install --ignore-platform-reqs +``` + +Similarly, you can update the project's dependencies using the same service: + +```bash +docker-compose run --rm composer update --ignore-platform-reqs +``` + +> _NB._ Both commands look for the `composer.json` file to find castopod's php dependencies, all of which live in the `./src/vendor` folder. For more info, check out [Composer documentation](https://getcomposer.org/doc/). + +### Start hacking + +You're all set! Start working your magic by updating the project's files! Help yourself to the [CodeIgniter4 User Guide](https://codeigniter.com/user_guide/index.html) for more insights. + +To see your changes, go to: + +- [localhost:8080](http://localhost:8080/) for the castopod app +- [localhost:8888](http://localhost:8888/) for the phpmyadmin interface: + + - **Username**: podlibre + - **Password**: castopod diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..c3dfe229 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,63 @@ +version: "3" + +networks: + castopod: + +services: + app: + build: + context: . + dockerfile: Dockerfile + container_name: "castopod_app" + command: ["php", "spark", "serve", "--host", "0.0.0.0"] + ports: + - 8080:8080 + volumes: + - ./src:/castopod + depends_on: + - mariadb + networks: + - castopod + + mariadb: + image: mariadb:latest + container_name: "castopod_mariadb" + ports: + - 3306:3306 + volumes: + - mariadb:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: castopod + MYSQL_USER: podlibre + MYSQL_PASSWORD: castopod + networks: + - castopod + + phpmyadmin: + image: phpmyadmin/phpmyadmin:latest + container_name: "castopod_phpmyadmin" + environment: + PMA_HOST: mariadb + PMA_PORT: 3306 + ports: + - 8888:80 + volumes: + - phpmyadmin:/sessions + depends_on: + - mariadb + networks: + - castopod + + composer: + image: composer:latest + container_name: composer + volumes: + - ./src:/var/www/html + working_dir: /var/www/html + networks: + - castopod + +volumes: + mariadb: + phpmyadmin: diff --git a/src/.github/workflows/phpunit.yml b/src/.github/workflows/phpunit.yml new file mode 100644 index 00000000..1e647e08 --- /dev/null +++ b/src/.github/workflows/phpunit.yml @@ -0,0 +1,51 @@ +name: PHPUnit + +on: + pull_request: + branches: + - develop + +jobs: + main: + name: Build and test + + strategy: + matrix: + php-versions: ['7.2', '7.3', '7.4'] + + runs-on: ubuntu-latest + + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php-versions }} + tools: composer, pecl, phpunit + extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3 + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache composer dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader + # To prevent rate limiting you may need to supply an OAuth token in Settings > Secrets + # env: + # https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens + # COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} + + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-text diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 00000000..e82f5252 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,127 @@ +#------------------------- +# Operating Specific Junk Files +#------------------------- + +# OS X +.DS_Store +.AppleDouble +.LSOverride + +# OS X Thumbnails +._* + +# Windows image file caches +Thumbs.db +ehthumbs.db +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Linux +*~ + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +#------------------------- +# Environment Files +#------------------------- +# These should never be under version control, +# as it poses a security risk. +.env +.vagrant +Vagrantfile + +#------------------------- +# Temporary Files +#------------------------- +writable/cache/* +!writable/cache/index.html + +writable/logs/* +!writable/logs/index.html + +writable/session/* +!writable/session/index.html + +writable/uploads/* +!writable/uploads/index.html + +writable/debugbar/* + +php_errors.log + +#------------------------- +# User Guide Temp Files +#------------------------- +user_guide_src/build/* +user_guide_src/cilexer/build/* +user_guide_src/cilexer/dist/* +user_guide_src/cilexer/pycilexer.egg-info/* + +#------------------------- +# Test Files +#------------------------- +tests/coverage* + +# Don't save phpunit under version control. +phpunit + +#------------------------- +# Composer +#------------------------- +vendor/ +composer.lock + +#------------------------- +# IDE / Development Files +#------------------------- + +# Modules Testing +_modules/* + +# phpenv local config +.php-version + +# Jetbrains editors (PHPStorm, etc) +.idea/ +*.iml + +# Netbeans +nbproject/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +.nb-gradle/ + +# Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project +.phpintel +/api/ + +# Visual Studio Code +.vscode/ + +/results/ +/phpunit*.xml +/.phpunit.*.cache diff --git a/src/README.md b/src/README.md new file mode 100644 index 00000000..7c20eb17 --- /dev/null +++ b/src/README.md @@ -0,0 +1,64 @@ +# CodeIgniter 4 Application Starter + +## What is CodeIgniter? + +CodeIgniter is a PHP full-stack web framework that is light, fast, flexible, and secure. +More information can be found at the [official site](http://codeigniter.com). + +This repository holds a composer-installable app starter. +It has been built from the +[development repository](https://github.com/codeigniter4/CodeIgniter4). + +More information about the plans for version 4 can be found in [the announcement](http://forum.codeigniter.com/thread-62615.html) on the forums. + +The user guide corresponding to this version of the framework can be found +[here](https://codeigniter4.github.io/userguide/). + +## Installation & updates + +`composer create-project codeigniter4/appstarter` then `composer update` whenever +there is a new release of the framework. + +When updating, check the release notes to see if there are any changes you might need to apply +to your `app` folder. The affected files can be copied or merged from +`vendor/codeigniter4/framework/app`. + +## Setup + +Copy `env` to `.env` and tailor for your app, specifically the baseURL +and any database settings. + +## Important Change with index.php + +`index.php` is no longer in the root of the project! It has been moved inside the *public* folder, +for better security and separation of components. + +This means that you should configure your web server to "point" to your project's *public* folder, and +not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the +framework are exposed. + +**Please** read the user guide for a better explanation of how CI4 works! +The user guide updating and deployment is a bit awkward at the moment, but we are working on it! + +## Repository Management + +We use Github issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages. +We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss +FEATURE REQUESTS. + +This repository is a "distribution" one, built by our release preparation script. +Problems with it can be raised on our forum, or as issues in the main repository. + +## Server Requirements + +PHP version 7.2 or higher is required, with the following extensions installed: + +- [intl](http://php.net/manual/en/intl.requirements.php) +- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library + +Additionally, make sure that the following extensions are enabled in your PHP: + +- json (enabled by default - don't turn it off) +- [mbstring](http://php.net/manual/en/mbstring.installation.php) +- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) +- xml (enabled by default - don't turn it off) diff --git a/src/app/.htaccess b/src/app/.htaccess new file mode 100644 index 00000000..f24db0ac --- /dev/null +++ b/src/app/.htaccess @@ -0,0 +1,6 @@ + + Require all denied + + + Deny from all + diff --git a/src/app/Common.php b/src/app/Common.php new file mode 100644 index 00000000..780ba3f8 --- /dev/null +++ b/src/app/Common.php @@ -0,0 +1,15 @@ + SYSPATH + * `]; + */ + $psr4 = [ + 'App' => APPPATH, // To ensure filters, etc still found, + APP_NAMESPACE => APPPATH, // For custom namespace + 'Config' => APPPATH . 'Config', + ]; + + /** + * ------------------------------------------------------------------- + * Class Map + * ------------------------------------------------------------------- + * The class map provides a map of class names and their exact + * location on the drive. Classes loaded in this manner will have + * slightly faster performance because they will not have to be + * searched for within one or more directories as they would if they + * were being autoloaded through a namespace. + * + * Prototype: + * + * $Config['classmap'] = [ + * 'MyClass' => '/path/to/class/file.php' + * ]; + */ + $classmap = []; + + //-------------------------------------------------------------------- + // Do Not Edit Below This Line + //-------------------------------------------------------------------- + + $this->psr4 = array_merge($this->psr4, $psr4); + $this->classmap = array_merge($this->classmap, $classmap); + + unset($psr4, $classmap); + } + + //-------------------------------------------------------------------- + +} diff --git a/src/app/Config/Boot/development.php b/src/app/Config/Boot/development.php new file mode 100644 index 00000000..7d6ae48d --- /dev/null +++ b/src/app/Config/Boot/development.php @@ -0,0 +1,32 @@ + '127.0.0.1', + 'port' => 11211, + 'weight' => 1, + 'raw' => false, + ]; + + /* + | ------------------------------------------------------------------------- + | Redis settings + | ------------------------------------------------------------------------- + | Your Redis server can be specified below, if you are using + | the Redis or Predis drivers. + | + */ + public $redis = [ + 'host' => '127.0.0.1', + 'password' => null, + 'port' => 6379, + 'timeout' => 0, + 'database' => 0, + ]; + + /* + |-------------------------------------------------------------------------- + | Available Cache Handlers + |-------------------------------------------------------------------------- + | + | This is an array of cache engine alias' and class names. Only engines + | that are listed here are allowed to be used. + | + */ + public $validHandlers = [ + 'dummy' => \CodeIgniter\Cache\Handlers\DummyHandler::class, + 'file' => \CodeIgniter\Cache\Handlers\FileHandler::class, + 'memcached' => \CodeIgniter\Cache\Handlers\MemcachedHandler::class, + 'predis' => \CodeIgniter\Cache\Handlers\PredisHandler::class, + 'redis' => \CodeIgniter\Cache\Handlers\RedisHandler::class, + 'wincache' => \CodeIgniter\Cache\Handlers\WincacheHandler::class, + ]; +} diff --git a/src/app/Config/Constants.php b/src/app/Config/Constants.php new file mode 100644 index 00000000..b25f71cd --- /dev/null +++ b/src/app/Config/Constants.php @@ -0,0 +1,77 @@ + '', + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'DBDriver' => 'MySQLi', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => (ENVIRONMENT !== 'production'), + 'cacheOn' => false, + 'cacheDir' => '', + 'charset' => 'utf8', + 'DBCollat' => 'utf8_general_ci', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 3306, + ]; + + /** + * This database connection is used when + * running PHPUnit database tests. + * + * @var array + */ + public $tests = [ + 'DSN' => '', + 'hostname' => '127.0.0.1', + 'username' => '', + 'password' => '', + 'database' => ':memory:', + 'DBDriver' => 'SQLite3', + 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS + 'pConnect' => false, + 'DBDebug' => (ENVIRONMENT !== 'production'), + 'cacheOn' => false, + 'cacheDir' => '', + 'charset' => 'utf8', + 'DBCollat' => 'utf8_general_ci', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 3306, + ]; + + //-------------------------------------------------------------------- + + public function __construct() + { + parent::__construct(); + + // Ensure that we always set the database group to 'tests' if + // we are currently running an automated test suite, so that + // we don't overwrite live data on accident. + if (ENVIRONMENT === 'testing') + { + $this->defaultGroup = 'tests'; + + // Under Travis-CI, we can set an ENV var named 'DB_GROUP' + // so that we can test against multiple databases. + if ($group = getenv('DB')) + { + if (is_file(TESTPATH . 'travis/Database.php')) + { + require TESTPATH . 'travis/Database.php'; + + if (! empty($dbconfig) && array_key_exists($group, $dbconfig)) + { + $this->tests = $dbconfig[$group]; + } + } + } + } + } + + //-------------------------------------------------------------------- + +} diff --git a/src/app/Config/DocTypes.php b/src/app/Config/DocTypes.php new file mode 100644 index 00000000..67d5dd20 --- /dev/null +++ b/src/app/Config/DocTypes.php @@ -0,0 +1,33 @@ + '', + 'xhtml1-strict' => '', + 'xhtml1-trans' => '', + 'xhtml1-frame' => '', + 'xhtml-basic11' => '', + 'html5' => '', + 'html4-strict' => '', + 'html4-trans' => '', + 'html4-frame' => '', + 'mathml1' => '', + 'mathml2' => '', + 'svg10' => '', + 'svg11' => '', + 'svg11-basic' => '', + 'svg11-tiny' => '', + 'xhtml-math-svg-xh' => '', + 'xhtml-math-svg-sh' => '', + 'xhtml-rdfa-1' => '', + 'xhtml-rdfa-2' => '', + ]; +} diff --git a/src/app/Config/Email.php b/src/app/Config/Email.php new file mode 100644 index 00000000..d9ca1420 --- /dev/null +++ b/src/app/Config/Email.php @@ -0,0 +1,171 @@ + 0) + { + \ob_end_flush(); + } + + \ob_start(function ($buffer) { + return $buffer; + }); + } + + /* + * -------------------------------------------------------------------- + * Debug Toolbar Listeners. + * -------------------------------------------------------------------- + * If you delete, they will no longer be collected. + */ + if (ENVIRONMENT !== 'production') + { + Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect'); + Services::toolbar()->respond(); + } +}); diff --git a/src/app/Config/Exceptions.php b/src/app/Config/Exceptions.php new file mode 100644 index 00000000..c0245b2a --- /dev/null +++ b/src/app/Config/Exceptions.php @@ -0,0 +1,41 @@ + \CodeIgniter\Filters\CSRF::class, + 'toolbar' => \CodeIgniter\Filters\DebugToolbar::class, + 'honeypot' => \CodeIgniter\Filters\Honeypot::class, + ]; + + // Always applied before every request + public $globals = [ + 'before' => [ + //'honeypot' + // 'csrf', + ], + 'after' => [ + 'toolbar', + //'honeypot' + ], + ]; + + // Works on all of a particular HTTP method + // (GET, POST, etc) as BEFORE filters only + // like: 'post' => ['CSRF', 'throttle'], + public $methods = []; + + // List filter aliases and any before/after uri patterns + // that they should run on, like: + // 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']], + public $filters = []; +} diff --git a/src/app/Config/ForeignCharacters.php b/src/app/Config/ForeignCharacters.php new file mode 100644 index 00000000..8ee6f113 --- /dev/null +++ b/src/app/Config/ForeignCharacters.php @@ -0,0 +1,6 @@ + \CodeIgniter\Format\JSONFormatter::class, + 'application/xml' => \CodeIgniter\Format\XMLFormatter::class, + 'text/xml' => \CodeIgniter\Format\XMLFormatter::class, + ]; + + //-------------------------------------------------------------------- + + /** + * A Factory method to return the appropriate formatter for the given mime type. + * + * @param string $mime + * + * @return \CodeIgniter\Format\FormatterInterface + */ + public function getFormatter(string $mime) + { + if (! array_key_exists($mime, $this->formatters)) + { + throw new \InvalidArgumentException('No Formatter defined for mime type: ' . $mime); + } + + $class = $this->formatters[$mime]; + + if (! class_exists($class)) + { + throw new \BadMethodCallException($class . ' is not a valid Formatter.'); + } + + return new $class(); + } + + //-------------------------------------------------------------------- + +} diff --git a/src/app/Config/Honeypot.php b/src/app/Config/Honeypot.php new file mode 100644 index 00000000..f4444a5d --- /dev/null +++ b/src/app/Config/Honeypot.php @@ -0,0 +1,34 @@ +{label}'; +} diff --git a/src/app/Config/Images.php b/src/app/Config/Images.php new file mode 100644 index 00000000..730ddee7 --- /dev/null +++ b/src/app/Config/Images.php @@ -0,0 +1,31 @@ + \CodeIgniter\Images\Handlers\GDHandler::class, + 'imagick' => \CodeIgniter\Images\Handlers\ImageMagickHandler::class, + ]; +} diff --git a/src/app/Config/Kint.php b/src/app/Config/Kint.php new file mode 100644 index 00000000..09db83dd --- /dev/null +++ b/src/app/Config/Kint.php @@ -0,0 +1,62 @@ + [ + + /* + * The log levels that this handler will handle. + */ + 'handles' => [ + 'critical', + 'alert', + 'emergency', + 'debug', + 'error', + 'info', + 'notice', + 'warning', + ], + + /* + * The default filename extension for log files. + * An extension of 'php' allows for protecting the log files via basic + * scripting, when they are to be stored under a publicly accessible directory. + * + * Note: Leaving it blank will default to 'log'. + */ + 'fileExtension' => '', + + /* + * The file system permissions to be applied on newly created log files. + * + * IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal + * integer notation (i.e. 0700, 0644, etc.) + */ + 'filePermissions' => 0644, + + /* + * Logging Directory Path + * + * By default, logs are written to WRITEPATH . 'logs/' + * Specify a different destination here, if desired. + */ + 'path' => '', + ], + + /** + * The ChromeLoggerHandler requires the use of the Chrome web browser + * and the ChromeLogger extension. Uncomment this block to use it. + */ + // 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [ + // /* + // * The log levels that this handler will handle. + // */ + // 'handles' => ['critical', 'alert', 'emergency', 'debug', + // 'error', 'info', 'notice', 'warning'], + // ] + ]; +} diff --git a/src/app/Config/Migrations.php b/src/app/Config/Migrations.php new file mode 100644 index 00000000..b83fe907 --- /dev/null +++ b/src/app/Config/Migrations.php @@ -0,0 +1,50 @@ + php spark migrate:create + | + | Typical formats: + | YmdHis_ + | Y-m-d-His_ + | Y_m_d_His_ + | + */ + public $timestampFormat = 'Y-m-d-His_'; + +} diff --git a/src/app/Config/Mimes.php b/src/app/Config/Mimes.php new file mode 100644 index 00000000..41014d40 --- /dev/null +++ b/src/app/Config/Mimes.php @@ -0,0 +1,530 @@ + [ + 'application/mac-binhex40', + 'application/mac-binhex', + 'application/x-binhex40', + 'application/x-mac-binhex40', + ], + 'cpt' => 'application/mac-compactpro', + 'csv' => [ + 'text/csv', + 'text/x-comma-separated-values', + 'text/comma-separated-values', + 'application/octet-stream', + 'application/vnd.ms-excel', + 'application/x-csv', + 'text/x-csv', + 'application/csv', + 'application/excel', + 'application/vnd.msexcel', + 'text/plain', + ], + 'bin' => [ + 'application/macbinary', + 'application/mac-binary', + 'application/octet-stream', + 'application/x-binary', + 'application/x-macbinary', + ], + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => [ + 'application/octet-stream', + 'application/x-msdownload', + ], + 'class' => 'application/octet-stream', + 'psd' => [ + 'application/x-photoshop', + 'image/vnd.adobe.photoshop', + ], + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => [ + 'application/pdf', + 'application/force-download', + 'application/x-download', + 'binary/octet-stream', + ], + 'ai' => [ + 'application/pdf', + 'application/postscript', + ], + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => [ + 'application/vnd.ms-excel', + 'application/msexcel', + 'application/x-msexcel', + 'application/x-ms-excel', + 'application/x-excel', + 'application/x-dos_ms_excel', + 'application/xls', + 'application/x-xls', + 'application/excel', + 'application/download', + 'application/vnd.ms-office', + 'application/msword', + ], + 'ppt' => [ + 'application/vnd.ms-powerpoint', + 'application/powerpoint', + 'application/vnd.ms-office', + 'application/msword', + ], + 'pptx' => [ + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'application/x-zip', + 'application/zip', + ], + 'wbxml' => 'application/wbxml', + 'wmlc' => 'application/wmlc', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'gzip' => 'application/x-gzip', + 'php' => [ + 'application/x-php', + 'application/x-httpd-php', + 'application/php', + 'text/php', + 'text/x-php', + 'application/x-httpd-php-source', + ], + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => [ + 'application/x-javascript', + 'text/plain', + ], + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => [ + 'application/x-tar', + 'application/x-gzip-compressed', + ], + 'z' => 'application/x-compress', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => [ + 'application/x-zip', + 'application/zip', + 'application/x-zip-compressed', + 'application/s-compressed', + 'multipart/x-zip', + ], + 'rar' => [ + 'application/x-rar', + 'application/rar', + 'application/x-rar-compressed', + ], + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => [ + 'audio/mpeg', + 'audio/mpg', + 'audio/mpeg3', + 'audio/mp3', + ], + 'aif' => [ + 'audio/x-aiff', + 'audio/aiff', + ], + 'aiff' => [ + 'audio/x-aiff', + 'audio/aiff', + ], + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => [ + 'audio/x-wav', + 'audio/wave', + 'audio/wav', + ], + 'bmp' => [ + 'image/bmp', + 'image/x-bmp', + 'image/x-bitmap', + 'image/x-xbitmap', + 'image/x-win-bitmap', + 'image/x-windows-bmp', + 'image/ms-bmp', + 'image/x-ms-bmp', + 'application/bmp', + 'application/x-bmp', + 'application/x-win-bitmap', + ], + 'gif' => 'image/gif', + 'jpg' => [ + 'image/jpeg', + 'image/pjpeg', + ], + 'jpeg' => [ + 'image/jpeg', + 'image/pjpeg', + ], + 'jpe' => [ + 'image/jpeg', + 'image/pjpeg', + ], + 'jp2' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'j2k' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'jpf' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'jpg2' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'jpx' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'jpm' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'mj2' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'mjp2' => [ + 'image/jp2', + 'video/mj2', + 'image/jpx', + 'image/jpm', + ], + 'png' => [ + 'image/png', + 'image/x-png', + ], + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'css' => [ + 'text/css', + 'text/plain', + ], + 'html' => [ + 'text/html', + 'text/plain', + ], + 'htm' => [ + 'text/html', + 'text/plain', + ], + 'shtml' => [ + 'text/html', + 'text/plain', + ], + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'log' => [ + 'text/plain', + 'text/x-log', + ], + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'xml' => [ + 'application/xml', + 'text/xml', + 'text/plain', + ], + 'xsl' => [ + 'application/xml', + 'text/xsl', + 'text/xml', + ], + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'avi' => [ + 'video/x-msvideo', + 'video/msvideo', + 'video/avi', + 'application/x-troff-msvideo', + ], + 'movie' => 'video/x-sgi-movie', + 'doc' => [ + 'application/msword', + 'application/vnd.ms-office', + ], + 'docx' => [ + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/zip', + 'application/msword', + 'application/x-zip', + ], + 'dot' => [ + 'application/msword', + 'application/vnd.ms-office', + ], + 'dotx' => [ + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/zip', + 'application/msword', + ], + 'xlsx' => [ + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/zip', + 'application/vnd.ms-excel', + 'application/msword', + 'application/x-zip', + ], + 'word' => [ + 'application/msword', + 'application/octet-stream', + ], + 'xl' => 'application/excel', + 'eml' => 'message/rfc822', + 'json' => [ + 'application/json', + 'text/json', + ], + 'pem' => [ + 'application/x-x509-user-cert', + 'application/x-pem-file', + 'application/octet-stream', + ], + 'p10' => [ + 'application/x-pkcs10', + 'application/pkcs10', + ], + 'p12' => 'application/x-pkcs12', + 'p7a' => 'application/x-pkcs7-signature', + 'p7c' => [ + 'application/pkcs7-mime', + 'application/x-pkcs7-mime', + ], + 'p7m' => [ + 'application/pkcs7-mime', + 'application/x-pkcs7-mime', + ], + 'p7r' => 'application/x-pkcs7-certreqresp', + 'p7s' => 'application/pkcs7-signature', + 'crt' => [ + 'application/x-x509-ca-cert', + 'application/x-x509-user-cert', + 'application/pkix-cert', + ], + 'crl' => [ + 'application/pkix-crl', + 'application/pkcs-crl', + ], + 'der' => 'application/x-x509-ca-cert', + 'kdb' => 'application/octet-stream', + 'pgp' => 'application/pgp', + 'gpg' => 'application/gpg-keys', + 'sst' => 'application/octet-stream', + 'csr' => 'application/octet-stream', + 'rsa' => 'application/x-pkcs7', + 'cer' => [ + 'application/pkix-cert', + 'application/x-x509-ca-cert', + ], + '3g2' => 'video/3gpp2', + '3gp' => [ + 'video/3gp', + 'video/3gpp', + ], + 'mp4' => 'video/mp4', + 'm4a' => 'audio/x-m4a', + 'f4v' => [ + 'video/mp4', + 'video/x-f4v', + ], + 'flv' => 'video/x-flv', + 'webm' => 'video/webm', + 'aac' => 'audio/x-acc', + 'm4u' => 'application/vnd.mpegurl', + 'm3u' => 'text/plain', + 'xspf' => 'application/xspf+xml', + 'vlc' => 'application/videolan', + 'wmv' => [ + 'video/x-ms-wmv', + 'video/x-ms-asf', + ], + 'au' => 'audio/x-au', + 'ac3' => 'audio/ac3', + 'flac' => 'audio/x-flac', + 'ogg' => [ + 'audio/ogg', + 'video/ogg', + 'application/ogg', + ], + 'kmz' => [ + 'application/vnd.google-earth.kmz', + 'application/zip', + 'application/x-zip', + ], + 'kml' => [ + 'application/vnd.google-earth.kml+xml', + 'application/xml', + 'text/xml', + ], + 'ics' => 'text/calendar', + 'ical' => 'text/calendar', + 'zsh' => 'text/x-scriptzsh', + '7zip' => [ + 'application/x-compressed', + 'application/x-zip-compressed', + 'application/zip', + 'multipart/x-zip', + ], + 'cdr' => [ + 'application/cdr', + 'application/coreldraw', + 'application/x-cdr', + 'application/x-coreldraw', + 'image/cdr', + 'image/x-cdr', + 'zz-application/zz-winassoc-cdr', + ], + 'wma' => [ + 'audio/x-ms-wma', + 'video/x-ms-asf', + ], + 'jar' => [ + 'application/java-archive', + 'application/x-java-application', + 'application/x-jar', + 'application/x-compressed', + ], + 'svg' => [ + 'image/svg+xml', + 'application/xml', + 'text/xml', + ], + 'vcf' => 'text/x-vcard', + 'srt' => [ + 'text/srt', + 'text/plain', + ], + 'vtt' => [ + 'text/vtt', + 'text/plain', + ], + 'ico' => [ + 'image/x-icon', + 'image/x-ico', + 'image/vnd.microsoft.icon', + ], + ]; + + //-------------------------------------------------------------------- + + /** + * Attempts to determine the best mime type for the given file extension. + * + * @param string $extension + * + * @return string|null The mime type found, or none if unable to determine. + */ + public static function guessTypeFromExtension(string $extension) + { + $extension = trim(strtolower($extension), '. '); + + if (! array_key_exists($extension, static::$mimes)) + { + return null; + } + + return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension]; + } + + //-------------------------------------------------------------------- + + /** + * Attempts to determine the best file extension for a given mime type. + * + * @param string $type + * @param string $proposed_extension - default extension (in case there is more than one with the same mime type) + * + * @return string|null The extension determined, or null if unable to match. + */ + public static function guessExtensionFromType(string $type, ?string $proposed_extension = null) + { + $type = trim(strtolower($type), '. '); + + $proposed_extension = trim(strtolower($proposed_extension)); + + if (! is_null($proposed_extension) && array_key_exists($proposed_extension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposed_extension]) ? [static::$mimes[$proposed_extension]] : static::$mimes[$proposed_extension])) + { + return $proposed_extension; + } + + foreach (static::$mimes as $ext => $types) + { + if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types))) + { + return $ext; + } + } + + return null; + } + + //-------------------------------------------------------------------- + +} diff --git a/src/app/Config/Modules.php b/src/app/Config/Modules.php new file mode 100644 index 00000000..28bbc7d9 --- /dev/null +++ b/src/app/Config/Modules.php @@ -0,0 +1,67 @@ +enabled) + { + return false; + } + + $alias = strtolower($alias); + + return in_array($alias, $this->activeExplorers); + } +} diff --git a/src/app/Config/Pager.php b/src/app/Config/Pager.php new file mode 100644 index 00000000..9b6ed83c --- /dev/null +++ b/src/app/Config/Pager.php @@ -0,0 +1,35 @@ + 'CodeIgniter\Pager\Views\default_full', + 'default_simple' => 'CodeIgniter\Pager\Views\default_simple', + 'default_head' => 'CodeIgniter\Pager\Views\default_head', + ]; + + /* + |-------------------------------------------------------------------------- + | Items Per Page + |-------------------------------------------------------------------------- + | + | The default number of results shown in a single page. + | + */ + public $perPage = 20; +} diff --git a/src/app/Config/Paths.php b/src/app/Config/Paths.php new file mode 100644 index 00000000..6251124c --- /dev/null +++ b/src/app/Config/Paths.php @@ -0,0 +1,77 @@ +setDefaultNamespace('App\Controllers'); +$routes->setDefaultController('Home'); +$routes->setDefaultMethod('index'); +$routes->setTranslateURIDashes(false); +$routes->set404Override(); +$routes->setAutoRoute(true); + +/** + * -------------------------------------------------------------------- + * Route Definitions + * -------------------------------------------------------------------- + */ + +// We get a performance increase by specifying the default +// route since we don't have to scan directories. +$routes->get('/', 'Home::index'); + +/** + * -------------------------------------------------------------------- + * Additional Routing + * -------------------------------------------------------------------- + * + * There will often be times that you need additional routing and you + * need to it be able to override any defaults in this file. Environment + * based routes is one such time. require() additional route files here + * to make that happen. + * + * You will have access to the $routes object within that file without + * needing to reload it. + */ +if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) +{ + require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; +} diff --git a/src/app/Config/Services.php b/src/app/Config/Services.php new file mode 100644 index 00000000..fb85a734 --- /dev/null +++ b/src/app/Config/Services.php @@ -0,0 +1,32 @@ + 'Windows 10', + 'windows nt 6.3' => 'Windows 8.1', + 'windows nt 6.2' => 'Windows 8', + 'windows nt 6.1' => 'Windows 7', + 'windows nt 6.0' => 'Windows Vista', + 'windows nt 5.2' => 'Windows 2003', + 'windows nt 5.1' => 'Windows XP', + 'windows nt 5.0' => 'Windows 2000', + 'windows nt 4.0' => 'Windows NT 4.0', + 'winnt4.0' => 'Windows NT 4.0', + 'winnt 4.0' => 'Windows NT', + 'winnt' => 'Windows NT', + 'windows 98' => 'Windows 98', + 'win98' => 'Windows 98', + 'windows 95' => 'Windows 95', + 'win95' => 'Windows 95', + 'windows phone' => 'Windows Phone', + 'windows' => 'Unknown Windows OS', + 'android' => 'Android', + 'blackberry' => 'BlackBerry', + 'iphone' => 'iOS', + 'ipad' => 'iOS', + 'ipod' => 'iOS', + 'os x' => 'Mac OS X', + 'ppc mac' => 'Power PC Mac', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'linux' => 'Linux', + 'debian' => 'Debian', + 'sunos' => 'Sun Solaris', + 'beos' => 'BeOS', + 'apachebench' => 'ApacheBench', + 'aix' => 'AIX', + 'irix' => 'Irix', + 'osf' => 'DEC OSF', + 'hp-ux' => 'HP-UX', + 'netbsd' => 'NetBSD', + 'bsdi' => 'BSDi', + 'openbsd' => 'OpenBSD', + 'gnu' => 'GNU/Linux', + 'unix' => 'Unknown Unix OS', + 'symbian' => 'Symbian OS', + ]; + + // The order of this array should NOT be changed. Many browsers return + // multiple browser types so we want to identify the sub-type first. + public $browsers = [ + 'OPR' => 'Opera', + 'Flock' => 'Flock', + 'Edge' => 'Spartan', + 'Chrome' => 'Chrome', + // Opera 10+ always reports Opera/9.80 and appends Version/ to the user agent string + 'Opera.*?Version' => 'Opera', + 'Opera' => 'Opera', + 'MSIE' => 'Internet Explorer', + 'Internet Explorer' => 'Internet Explorer', + 'Trident.* rv' => 'Internet Explorer', + 'Shiira' => 'Shiira', + 'Firefox' => 'Firefox', + 'Chimera' => 'Chimera', + 'Phoenix' => 'Phoenix', + 'Firebird' => 'Firebird', + 'Camino' => 'Camino', + 'Netscape' => 'Netscape', + 'OmniWeb' => 'OmniWeb', + 'Safari' => 'Safari', + 'Mozilla' => 'Mozilla', + 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', + 'Lynx' => 'Lynx', + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse', + 'Maxthon' => 'Maxthon', + 'Ubuntu' => 'Ubuntu Web Browser', + 'Vivaldi' => 'Vivaldi', + ]; + + public $mobiles = [ + // legacy array, old values commented out + 'mobileexplorer' => 'Mobile Explorer', + // 'openwave' => 'Open Wave', + // 'opera mini' => 'Opera Mini', + // 'operamini' => 'Opera Mini', + // 'elaine' => 'Palm', + 'palmsource' => 'Palm', + // 'digital paths' => 'Palm', + // 'avantgo' => 'Avantgo', + // 'xiino' => 'Xiino', + 'palmscape' => 'Palmscape', + // 'nokia' => 'Nokia', + // 'ericsson' => 'Ericsson', + // 'blackberry' => 'BlackBerry', + // 'motorola' => 'Motorola' + + // Phones and Manufacturers + 'motorola' => 'Motorola', + 'nokia' => 'Nokia', + 'palm' => 'Palm', + 'iphone' => 'Apple iPhone', + 'ipad' => 'iPad', + 'ipod' => 'Apple iPod Touch', + 'sony' => 'Sony Ericsson', + 'ericsson' => 'Sony Ericsson', + 'blackberry' => 'BlackBerry', + 'cocoon' => 'O2 Cocoon', + 'blazer' => 'Treo', + 'lg' => 'LG', + 'amoi' => 'Amoi', + 'xda' => 'XDA', + 'mda' => 'MDA', + 'vario' => 'Vario', + 'htc' => 'HTC', + 'samsung' => 'Samsung', + 'sharp' => 'Sharp', + 'sie-' => 'Siemens', + 'alcatel' => 'Alcatel', + 'benq' => 'BenQ', + 'ipaq' => 'HP iPaq', + 'mot-' => 'Motorola', + 'playstation portable' => 'PlayStation Portable', + 'playstation 3' => 'PlayStation 3', + 'playstation vita' => 'PlayStation Vita', + 'hiptop' => 'Danger Hiptop', + 'nec-' => 'NEC', + 'panasonic' => 'Panasonic', + 'philips' => 'Philips', + 'sagem' => 'Sagem', + 'sanyo' => 'Sanyo', + 'spv' => 'SPV', + 'zte' => 'ZTE', + 'sendo' => 'Sendo', + 'nintendo dsi' => 'Nintendo DSi', + 'nintendo ds' => 'Nintendo DS', + 'nintendo 3ds' => 'Nintendo 3DS', + 'wii' => 'Nintendo Wii', + 'open web' => 'Open Web', + 'openweb' => 'OpenWeb', + + // Operating Systems + 'android' => 'Android', + 'symbian' => 'Symbian', + 'SymbianOS' => 'SymbianOS', + 'elaine' => 'Palm', + 'series60' => 'Symbian S60', + 'windows ce' => 'Windows CE', + + // Browsers + 'obigo' => 'Obigo', + 'netfront' => 'Netfront Browser', + 'openwave' => 'Openwave Browser', + 'mobilexplorer' => 'Mobile Explorer', + 'operamini' => 'Opera Mini', + 'opera mini' => 'Opera Mini', + 'opera mobi' => 'Opera Mobile', + 'fennec' => 'Firefox Mobile', + + // Other + 'digital paths' => 'Digital Paths', + 'avantgo' => 'AvantGo', + 'xiino' => 'Xiino', + 'novarra' => 'Novarra Transcoder', + 'vodafone' => 'Vodafone', + 'docomo' => 'NTT DoCoMo', + 'o2' => 'O2', + + // Fallback + 'mobile' => 'Generic Mobile', + 'wireless' => 'Generic Mobile', + 'j2me' => 'Generic Mobile', + 'midp' => 'Generic Mobile', + 'cldc' => 'Generic Mobile', + 'up.link' => 'Generic Mobile', + 'up.browser' => 'Generic Mobile', + 'smartphone' => 'Generic Mobile', + 'cellphone' => 'Generic Mobile', + ]; + + // There are hundreds of bots but these are the most common. + public $robots = [ + 'googlebot' => 'Googlebot', + 'msnbot' => 'MSNBot', + 'baiduspider' => 'Baiduspider', + 'bingbot' => 'Bing', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', + 'ask jeeves' => 'Ask Jeeves', + 'fastcrawler' => 'FastCrawler', + 'infoseek' => 'InfoSeek Robot 1.0', + 'lycos' => 'Lycos', + 'yandex' => 'YandexBot', + 'mediapartners-google' => 'MediaPartners Google', + 'CRAZYWEBCRAWLER' => 'Crazy Webcrawler', + 'adsbot-google' => 'AdsBot Google', + 'feedfetcher-google' => 'Feedfetcher Google', + 'curious george' => 'Curious George', + 'ia_archiver' => 'Alexa Crawler', + 'MJ12bot' => 'Majestic-12', + 'Uptimebot' => 'Uptimebot', + ]; +} diff --git a/src/app/Config/Validation.php b/src/app/Config/Validation.php new file mode 100644 index 00000000..97f08c75 --- /dev/null +++ b/src/app/Config/Validation.php @@ -0,0 +1,36 @@ + 'CodeIgniter\Validation\Views\list', + 'single' => 'CodeIgniter\Validation\Views\single', + ]; + + //-------------------------------------------------------------------- + // Rules + //-------------------------------------------------------------------- +} diff --git a/src/app/Config/View.php b/src/app/Config/View.php new file mode 100644 index 00000000..f66b2532 --- /dev/null +++ b/src/app/Config/View.php @@ -0,0 +1,34 @@ +session = \Config\Services::session(); + } + +} diff --git a/src/app/Controllers/Home.php b/src/app/Controllers/Home.php new file mode 100644 index 00000000..8798cdd8 --- /dev/null +++ b/src/app/Controllers/Home.php @@ -0,0 +1,12 @@ + +Message: +Filename: getFile(), "\n"; ?> +Line Number: getLine(); ?> + + + + Backtrace: + getTrace() as $error): ?> + + + + + + diff --git a/src/app/Views/errors/cli/production.php b/src/app/Views/errors/cli/production.php new file mode 100644 index 00000000..7db744ec --- /dev/null +++ b/src/app/Views/errors/cli/production.php @@ -0,0 +1,5 @@ + + + + + 404 Page Not Found + + + + +
+

404 - File Not Found

+ +

+ + + + Sorry! Cannot seem to find the page you were looking for. + +

+
+ + diff --git a/src/app/Views/errors/html/error_exception.php b/src/app/Views/errors/html/error_exception.php new file mode 100644 index 00000000..09fddcbd --- /dev/null +++ b/src/app/Views/errors/html/error_exception.php @@ -0,0 +1,401 @@ + + + + + + + + <?= htmlspecialchars($title, ENT_SUBSTITUTE, 'UTF-8') ?> + + + + + + + +
+
+

getCode() ? ' #' . $exception->getCode() : '') ?>

+

+ getMessage() ?> + getMessage())) ?>" + rel="noreferrer" target="_blank">search → +

+
+
+ + +
+

at line

+ + +
+ +
+ +
+ +
+ + + +
+ + +
+ +
    + $row) : ?> + +
  1. +

    + + + + + {PHP internal code} + + + + +   —   + + + ( arguments ) +

    + + + getParameters(); + } + foreach ($row['args'] as $key => $value) : ?> + + + + + + +
    name : "#$key", ENT_SUBSTITUTE, 'UTF-8') ?>
    +
    + + () + + + + +   —   () + +

    + + + +
    + +
    + +
  2. + + +
+ +
+ + +
+ + + +

$

+ + + + + + + + + + $value) : ?> + + + + + + +
KeyValue
+ + + + ' . print_r($value, true) ?> + +
+ + + + + + +

Constants

+ + + + + + + + + + $value) : ?> + + + + + + +
KeyValue
+ + + + ' . print_r($value, true) ?> + +
+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Pathuri ?>
HTTP MethodgetMethod(true) ?>
IP AddressgetIPAddress() ?>
Is AJAX Request?isAJAX() ? 'yes' : 'no' ?>
Is CLI Request?isCLI() ? 'yes' : 'no' ?>
Is Secure Request?isSecure() ? 'yes' : 'no' ?>
User AgentgetUserAgent()->getAgentString() ?>
+ + + + + + + + +

$

+ + + + + + + + + + $value) : ?> + + + + + + +
KeyValue
+ + + + ' . print_r($value, true) ?> + +
+ + + + + +
+ No $_GET, $_POST, or $_COOKIE Information to show. +
+ + + + getHeaders(); ?> + + +

Headers

+ + + + + + + + + + + + + + + + + + + + +
HeaderValue
getName(), 'html') ?>getValueLine(), 'html') ?>
+ + +
+ + + setStatusCode(http_response_code()); + ?> +
+ + + + + +
Response StatusgetStatusCode() . ' - ' . $response->getReason() ?>
+ + getHeaders(); ?> + + + +

Headers

+ + + + + + + + + + $value) : ?> + + + + + + +
HeaderValue
getHeaderLine($name), 'html') ?>
+ + +
+ + +
+ + +
    + +
  1. + +
+
+ + +
+ + + + + + + + + + + + + + + + +
Memory Usage
Peak Memory Usage:
Memory Limit:
+ +
+ +
+ +
+ + + + + diff --git a/src/app/Views/errors/html/production.php b/src/app/Views/errors/html/production.php new file mode 100644 index 00000000..cca49c2e --- /dev/null +++ b/src/app/Views/errors/html/production.php @@ -0,0 +1,25 @@ + + + + + + + Whoops! + + + + + +
+ +

Whoops!

+ +

We seem to have hit a snag. Please try again later...

+ +
+ + + + diff --git a/src/app/Views/welcome_message.php b/src/app/Views/welcome_message.php new file mode 100644 index 00000000..f2a7389b --- /dev/null +++ b/src/app/Views/welcome_message.php @@ -0,0 +1,324 @@ + + + + + Welcome to CodeIgniter 4! + + + + + + + + + + + +
+ + + +
+ +

Welcome to CodeIgniter

+ +

The small framework with powerful features

+ +
+ +
+ + + +
+ +

About this page

+ +

The page you are looking at is being generated dynamically by CodeIgniter.

+ +

If you would like to edit this page you will find it located at:

+ +
app/Views/welcome_message.php
+ +

The corresponding controller for this page can be found at:

+ +
app/Controllers/Home.php
+ +
+ +
+ +
+ +

Go further

+ +

+ + Learn +

+ +

The User Guide contains an introduction, tutorial, a number of "how to" + guides, and then reference documentation for the components that make up + the framework. Check the User Guide !

+ +

+ + Discuss +

+ +

CodeIgniter is a community-developed open source project, with several + venues for the community members to gather and exchange ideas. View all + the threads on CodeIgniter's forum, or chat on Slack !

+ +

+ + Contribute +

+ +

CodeIgniter is a community driven project and accepts contributions + of code and documentation from the community. Why not + + join us ?

+ +
+ +
+ + + + + + + + + + + + + diff --git a/src/app/index.html b/src/app/index.html new file mode 100644 index 00000000..b702fbc3 --- /dev/null +++ b/src/app/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/src/builds b/src/builds new file mode 100644 index 00000000..268e7a81 --- /dev/null +++ b/src/builds @@ -0,0 +1,163 @@ +#!/usr/bin/env php + 'vcs', + 'url' => GITHUB_URL, + ]; + } + + // Define the "require" + $array['require']['codeigniter4/codeigniter4'] = 'dev-develop'; + unset($array['require']['codeigniter4/framework']); + } + + // Release + else + { + // Clear 'minimum-stability' + unset($array['minimum-stability']); + + // If the repo is configured then clear it + if (isset($array['repositories'])) + { + // Check for the CodeIgniter repo + foreach ($array['repositories'] as $i => $repository) + { + if ($repository['url'] == GITHUB_URL) + { + unset($array['repositories'][$i]); + break; + } + } + if (empty($array['repositories'])) + { + unset($array['repositories']); + } + } + + // Define the "require" + $array['require']['codeigniter4/framework'] = LATEST_RELEASE; + unset($array['require']['codeigniter4/codeigniter4']); + } + + // Write out a new composer.json + file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . PHP_EOL); + $modified[] = $file; + } + else + { + echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL; + } + } + else + { + echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL; + } +} + +// Paths config and PHPUnit XMLs +$files = [ + __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php', + __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist', + __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml', +]; + +foreach ($files as $file) +{ + if (is_file($file)) + { + $contents = file_get_contents($file); + + // Development + if ($dev) + { + $contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents); + } + + // Release + else + { + $contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents); + } + + file_put_contents($file, $contents); + $modified[] = $file; + } +} + +if (empty($modified)) +{ + echo 'No files modified' . PHP_EOL; +} +else +{ + echo 'The following files were modified:' . PHP_EOL; + foreach ($modified as $file) + { + echo " * {$file}" . PHP_EOL; + } + echo 'Run `composer update` to sync changes with your vendor folder' . PHP_EOL; +} diff --git a/src/composer.json b/src/composer.json new file mode 100644 index 00000000..8c683a33 --- /dev/null +++ b/src/composer.json @@ -0,0 +1,31 @@ +{ + "name": "codeigniter4/appstarter", + "type": "project", + "description": "CodeIgniter4 starter app", + "homepage": "https://codeigniter.com", + "license": "MIT", + "require": { + "php": ">=7.2", + "codeigniter4/framework": "^4" + }, + "require-dev": { + "mikey179/vfsstream": "1.6.*", + "phpunit/phpunit": "8.5.*" + }, + "autoload-dev": { + "psr-4": { + "Tests\\Support\\": "tests/_support" + } + }, + "scripts": { + "test": "phpunit", + "post-update-cmd": [ + "@composer dump-autoload" + ] + }, + "support": { + "forum": "http://forum.codeigniter.com/", + "source": "https://github.com/codeigniter4/CodeIgniter4", + "slack": "https://codeigniterchat.slack.com" + } +} diff --git a/src/env b/src/env new file mode 100644 index 00000000..bc1a1567 --- /dev/null +++ b/src/env @@ -0,0 +1,93 @@ +#-------------------------------------------------------------------- +# Example Environment Configuration file +# +# This file can be used as a starting point for your own +# custom .env files, and contains most of the possible settings +# available in a default install. +# +# By default, all of the settings are commented out. If you want +# to override the setting, you must un-comment it by removing the '#' +# at the beginning of the line. +#-------------------------------------------------------------------- + +#-------------------------------------------------------------------- +# ENVIRONMENT +#-------------------------------------------------------------------- + +# CI_ENVIRONMENT = production + +#-------------------------------------------------------------------- +# APP +#-------------------------------------------------------------------- + +# app.baseURL = '' +# app.forceGlobalSecureRequests = false + +# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler' +# app.sessionCookieName = 'ci_session' +# app.sessionSavePath = NULL +# app.sessionMatchIP = false +# app.sessionTimeToUpdate = 300 +# app.sessionRegenerateDestroy = false + +# app.cookiePrefix = '' +# app.cookieDomain = '' +# app.cookiePath = '/' +# app.cookieSecure = false +# app.cookieHTTPOnly = false + +# app.CSRFProtection = false +# app.CSRFTokenName = 'csrf_test_name' +# app.CSRFCookieName = 'csrf_cookie_name' +# app.CSRFExpire = 7200 +# app.CSRFRegenerate = true +# app.CSRFExcludeURIs = [] + +# app.CSPEnabled = false + +#-------------------------------------------------------------------- +# DATABASE +#-------------------------------------------------------------------- + +# database.default.hostname = localhost +# database.default.database = ci4 +# database.default.username = root +# database.default.password = root +# database.default.DBDriver = MySQLi + +# database.tests.hostname = localhost +# database.tests.database = ci4 +# database.tests.username = root +# database.tests.password = root +# database.tests.DBDriver = MySQLi + +#-------------------------------------------------------------------- +# CONTENT SECURITY POLICY +#-------------------------------------------------------------------- + +# contentsecuritypolicy.reportOnly = false +# contentsecuritypolicy.defaultSrc = 'none' +# contentsecuritypolicy.scriptSrc = 'self' +# contentsecuritypolicy.styleSrc = 'self' +# contentsecuritypolicy.imageSrc = 'self' +# contentsecuritypolicy.base_uri = null +# contentsecuritypolicy.childSrc = null +# contentsecuritypolicy.connectSrc = 'self' +# contentsecuritypolicy.fontSrc = null +# contentsecuritypolicy.formAction = null +# contentsecuritypolicy.frameAncestors = null +# contentsecuritypolicy.mediaSrc = null +# contentsecuritypolicy.objectSrc = null +# contentsecuritypolicy.pluginTypes = null +# contentsecuritypolicy.reportURI = null +# contentsecuritypolicy.sandbox = false +# contentsecuritypolicy.upgradeInsecureRequests = false + +#-------------------------------------------------------------------- +# HONEYPOT +#-------------------------------------------------------------------- + +# honeypot.hidden = 'true' +# honeypot.label = 'Fill This Field' +# honeypot.name = 'honeypot' +# honeypot.template = '' diff --git a/src/license.txt b/src/license.txt new file mode 100644 index 00000000..2fb1bdd4 --- /dev/null +++ b/src/license.txt @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014-2019 British Columbia Institute of Technology +Copyright (c) 2019-2020 CodeIgniter Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/phpunit.xml.dist b/src/phpunit.xml.dist new file mode 100644 index 00000000..96947df5 --- /dev/null +++ b/src/phpunit.xml.dist @@ -0,0 +1,60 @@ + + + + + ./tests + + + + + + ./app + + ./app/Views + ./app/Config/Routes.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/public/.htaccess b/src/public/.htaccess new file mode 100644 index 00000000..699e1c1f --- /dev/null +++ b/src/public/.htaccess @@ -0,0 +1,48 @@ +# Disable directory browsing +Options All -Indexes + +# ---------------------------------------------------------------------- +# Rewrite engine +# ---------------------------------------------------------------------- + +# Turning on the rewrite engine is necessary for the following rules and features. +# FollowSymLinks must be enabled for this to work. + + Options +FollowSymlinks + RewriteEngine On + + # If you installed CodeIgniter in a subfolder, you will need to + # change the following line to match the subfolder you need. + # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase + # RewriteBase / + + # Redirect Trailing Slashes... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.*)/$ /$1 [L,R=301] + + # Rewrite "www.example.com -> example.com" + RewriteCond %{HTTPS} !=on + RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] + RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] + + # Checks to see if the user is attempting to access a valid file, + # such as an image or css document, if this isn't true it sends the + # request to the front controller, index.php + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.*)$ index.php/$1 [L] + + # Ensure Authorization header is passed along + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + + + # If we don't have mod_rewrite installed, all 404's + # can be sent to index.php, and everything works as normal. + ErrorDocument 404 index.php + + +# Disable server signature start + ServerSignature Off +# Disable server signature end diff --git a/src/public/favicon.ico b/src/public/favicon.ico new file mode 100644 index 00000000..7ecfce21 Binary files /dev/null and b/src/public/favicon.ico differ diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 00000000..3eaa592a --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,45 @@ +systemDirectory, '/ ') . '/bootstrap.php'; + +/* + *--------------------------------------------------------------- + * LAUNCH THE APPLICATION + *--------------------------------------------------------------- + * Now that everything is setup, it's time to actually fire + * up the engines and make this app do its thang. + */ +$app->run(); diff --git a/src/public/robots.txt b/src/public/robots.txt new file mode 100644 index 00000000..9e60f970 --- /dev/null +++ b/src/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/src/spark b/src/spark new file mode 100644 index 00000000..396ad59c --- /dev/null +++ b/src/spark @@ -0,0 +1,61 @@ +#!/usr/bin/env php +systemDirectory, '/ ') . '/bootstrap.php'; + +// Grab our Console +$console = new \CodeIgniter\CLI\Console($app); + +// We want errors to be shown when using it from the CLI. +error_reporting(-1); +ini_set('display_errors', 1); + +// Show basic information before we do anything else. +$console->showHeader(); + +// fire off the command in the main framework. +$response = $console->run(); +if ($response->getStatusCode() >= 300) +{ + exit($response->getStatusCode()); +} diff --git a/src/tests/README.md b/src/tests/README.md new file mode 100644 index 00000000..545ccfed --- /dev/null +++ b/src/tests/README.md @@ -0,0 +1,108 @@ +# Running Application Tests + +This is the quick-start to CodeIgniter testing. Its intent is to describe what +it takes to set up your application and get it ready to run unit tests. +It is not intended to be a full description of the test features that you can +use to test your application. Those details can be found in the documentation. + +## Resources +* [CodeIgniter 4 User Guide on Testing](https://codeigniter4.github.io/userguide/testing/index.html) +* [PHPUnit docs](https://phpunit.readthedocs.io/en/8.3/index.html) + +## Requirements + +It is recommended to use the latest version of PHPUnit. At the time of this +writing we are running version 8.5.2. Support for this has been built into the +**composer.json** file that ships with CodeIgniter and can easily be installed +via [Composer](https://getcomposer.org/) if you don't already have it installed globally. + + > composer install + +If running under OS X or Linux, you can create a symbolic link to make running tests a touch nicer. + + > ln -s ./vendor/bin/phpunit ./phpunit + +You also need to install [XDebug](https://xdebug.org/index.php) in order +for code coverage to be calculated successfully. + +## Setting Up + +A number of the tests use a running database. +In order to set up the database edit the details for the `tests` group in +**app/Config/Database.php** or **phpunit.xml**. Make sure that you provide a database engine +that is currently running on your machine. More details on a test database setup are in the +*Docs>>Testing>>Testing Your Database* section of the documentation. + +If you want to run the tests without using live database you can +exclude @DatabaseLive group. Or make a copy of **phpunit.dist.xml** - +call it **phpunit.xml** - and comment out the named "database". This will make +the tests run quite a bit faster. + +## Running the tests + +The entire test suite can be run by simply typing one command-line command from the main directory. + + > ./phpunit + +You can limit tests to those within a single test directory by specifying the +directory name after phpunit. + + > ./phpunit app/Models + +## Generating Code Coverage + +To generate coverage information, including HTML reports you can view in your browser, +you can use the following command: + + > ./phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/ -d memory_limit=1024m + +This runs all of the tests again collecting information about how many lines, +functions, and files are tested. It also reports the percentage of the code that is covered by tests. +It is collected in two formats: a simple text file that provides an overview as well +as a comprehensive collection of HTML files that show the status of every line of code in the project. + +The text file can be found at **tests/coverage.txt**. +The HTML files can be viewed by opening **tests/coverage/index.html** in your favorite browser. + +## PHPUnit XML Configuration + +The repository has a ``phpunit.xml.dist`` file in the project root that's used for +PHPUnit configuration. This is used to provide a default configuration if you +do not have your own configuration file in the project root. + +The normal practice would be to copy ``phpunit.xml.dist`` to ``phpunit.xml`` +(which is git ignored), and to tailor it as you see fit. +For instance, you might wish to exclude database tests, or automatically generate +HTML code coverage reports. + +## Test Cases + +Every test needs a *test case*, or class that your tests extend. CodeIgniter 4 +provides a few that you may use directly: +* `CodeIgniter\Test\CIUnitTestCase` - for basic tests with no other service needs +* `CodeIgniter\Test\CIDatabaseTestCase` - for tests that need database access + +Most of the time you will want to write your own test cases to hold functions and services +common to your test suites. + +## Creating Tests + +All tests go in the **tests/** directory. Each test file is a class that extends a +**Test Case** (see above) and contains methods for the individual tests. These method +names must start with the word "test" and should have descriptive names for precisely what +they are testing: +`testUserCanModifyFile()` `testOutputColorMatchesInput()` `testIsLoggedInFailsWithInvalidUser()` + +Writing tests is an art, and there are many resources available to help learn how. +Review the links above and always pay attention to your code coverage. + +### Database Tests + +Tests can include migrating, seeding, and testing against a mock or live1 database. +Be sure to modify the test case (or create your own) to point to your seed and migrations +and include any additional steps to be run before tests in the `setUp()` method. + +1 Note: If you are using database tests that require a live database connection +you will need to rename **phpunit.xml.dist** to **phpunit.xml**, uncomment the database +configuration lines and add your connection details. Prevent **phpunit.xml** from being +tracked in your repo by adding it to **.gitignore**. diff --git a/src/tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php b/src/tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php new file mode 100644 index 00000000..1bfd4a33 --- /dev/null +++ b/src/tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php @@ -0,0 +1,61 @@ + [ + 'type' => 'varchar', + 'constraint' => 31, + ], + 'uid' => [ + 'type' => 'varchar', + 'constraint' => 31, + ], + 'class' => [ + 'type' => 'varchar', + 'constraint' => 63, + ], + 'icon' => [ + 'type' => 'varchar', + 'constraint' => 31, + ], + 'summary' => [ + 'type' => 'varchar', + 'constraint' => 255, + ], + 'created_at' => [ + 'type' => 'datetime', + 'null' => true, + ], + 'updated_at' => [ + 'type' => 'datetime', + 'null' => true, + ], + 'deleted_at' => [ + 'type' => 'datetime', + 'null' => true, + ], + ]; + + $this->forge->addField('id'); + $this->forge->addField($fields); + + $this->forge->addKey('name'); + $this->forge->addKey('uid'); + $this->forge->addKey(['deleted_at', 'id']); + $this->forge->addKey('created_at'); + + $this->forge->createTable('factories'); + } + + public function down() + { + $this->forge->dropTable('factories'); + } +} diff --git a/src/tests/_support/Database/Seeds/ExampleSeeder.php b/src/tests/_support/Database/Seeds/ExampleSeeder.php new file mode 100644 index 00000000..1b14ceda --- /dev/null +++ b/src/tests/_support/Database/Seeds/ExampleSeeder.php @@ -0,0 +1,40 @@ + 'Test Factory', + 'uid' => 'test001', + 'class' => 'Factories\Tests\NewFactory', + 'icon' => 'fas fa-puzzle-piece', + 'summary' => 'Longer sample text for testing', + ], + [ + 'name' => 'Widget Factory', + 'uid' => 'widget', + 'class' => 'Factories\Tests\WidgetPlant', + 'icon' => 'fas fa-puzzle-piece', + 'summary' => 'Create widgets in your factory', + ], + [ + 'name' => 'Evil Factory', + 'uid' => 'evil-maker', + 'class' => 'Factories\Evil\MyFactory', + 'icon' => 'fas fa-book-dead', + 'summary' => 'Abandon all hope, ye who enter here', + ], + ]; + + $builder = $this->db->table('factories'); + + foreach ($factories as $factory) + { + $builder->insert($factory); + } + } +} diff --git a/src/tests/_support/DatabaseTestCase.php b/src/tests/_support/DatabaseTestCase.php new file mode 100644 index 00000000..8b094d30 --- /dev/null +++ b/src/tests/_support/DatabaseTestCase.php @@ -0,0 +1,51 @@ +mockSession(); + } + + /** + * Pre-loads the mock session driver into $this->session. + * + * @var string + */ + protected function mockSession() + { + $config = config('App'); + $this->session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config); + \Config\Services::injectMock('session', $this->session); + } +} diff --git a/src/tests/database/ExampleDatabaseTest.php b/src/tests/database/ExampleDatabaseTest.php new file mode 100644 index 00000000..2de0b6ae --- /dev/null +++ b/src/tests/database/ExampleDatabaseTest.php @@ -0,0 +1,42 @@ +findAll(); + + // Make sure the count is as expected + $this->assertCount(3, $objects); + } + + public function testSoftDeleteLeavesRow() + { + $model = new ExampleModel(); + $this->setPrivateProperty($model, 'useSoftDeletes', true); + $this->setPrivateProperty($model, 'tempUseSoftDeletes', true); + + $object = $model->first(); + $model->delete($object->id); + + // The model should no longer find it + $this->assertNull($model->find($object->id)); + + // ... but it should still be in the database + $result = $model->builder()->where('id', $object->id)->get()->getResult(); + + $this->assertCount(1, $result); + } +} diff --git a/src/tests/session/ExampleSessionTest.php b/src/tests/session/ExampleSessionTest.php new file mode 100644 index 00000000..6ec0d011 --- /dev/null +++ b/src/tests/session/ExampleSessionTest.php @@ -0,0 +1,18 @@ +session->set('logged_in', 123); + + $value = $this->session->get('logged_in'); + + $this->assertEquals(123, $value); + } +} diff --git a/src/tests/unit/HealthTest.php b/src/tests/unit/HealthTest.php new file mode 100644 index 00000000..1d059d05 --- /dev/null +++ b/src/tests/unit/HealthTest.php @@ -0,0 +1,33 @@ +assertTrue($test); + } + + public function testBaseUrlHasBeenSet() + { + $env = $config = false; + + // First check in .env + if (is_file(HOMEPATH . '.env')) + { + $env = (bool) preg_grep("/^app\.baseURL = './", file(HOMEPATH . '.env')); + } + + // Then check the actual config file + $reader = new \Tests\Support\Libraries\ConfigReader(); + $config = ! empty($reader->baseUrl); + + $this->assertTrue($env || $config); + } +} diff --git a/src/writable/.htaccess b/src/writable/.htaccess new file mode 100644 index 00000000..f24db0ac --- /dev/null +++ b/src/writable/.htaccess @@ -0,0 +1,6 @@ + + Require all denied + + + Deny from all + diff --git a/src/writable/cache/index.html b/src/writable/cache/index.html new file mode 100644 index 00000000..b702fbc3 --- /dev/null +++ b/src/writable/cache/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/src/writable/logs/index.html b/src/writable/logs/index.html new file mode 100644 index 00000000..b702fbc3 --- /dev/null +++ b/src/writable/logs/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/src/writable/session/index.html b/src/writable/session/index.html new file mode 100644 index 00000000..b702fbc3 --- /dev/null +++ b/src/writable/session/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/src/writable/uploads/index.html b/src/writable/uploads/index.html new file mode 100644 index 00000000..b702fbc3 --- /dev/null +++ b/src/writable/uploads/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + +