Cobble is a framework skeleton using Slim Framework 3, Laravel Eloquent ORM, Twig Template Engine, Symfony VarDumper, PHPMailer and Whoops for error reporting.
In the examples in this README I'll be using
yarn
but you can also usenpm
.
- PHP >=7.4
- Apache/nginx (mod_rewrite needed)
- composer
- npm/yarn
- bash
Run this command to create your project based on this skeleton.
$ git clone https://github.com/Developaaah/cobble.git [my-awesome-project]
$ cd [my-awesome-project]
After that, you need to install all required node modules by typing:
$ npm i
# or
$ yarn
Then, you'll need to install the composer requirements:
$ cd src/
$ composer install
Then, within the src/ directory, you'll have to create a .env
file.
$ cp .env.example .env
You can access all variables everywhere in PHP with
$_ENV[]
From here, you're good to go.
You have multiple scripts available.
script | description |
---|---|
yarn run build |
creates a development dist |
yarn run watch |
creates a development dist including FileWatcher and BrowserSync |
yarn run prod |
creates a production dist without the .env file |
yarn run prod:env |
creates a production dist including the .env file |
I would recommend using a docker container for development, but this is not needed and you can also use XAMP, MAMP, LAMP or something different. In the end you can use whatever you want.
Make sure you have your webserver configured, that it points on
[my-awesome-project]/dist/
and the DocumentRoot is[my-awesome-project]/dist/public/
.
You also need to have
mod_rewrite
enabled.
You can either use your own preferred container, or you just use this container from webdevops.
# create a MariaDB container
$ docker run --name mariadb -e MARIADB_ROOT_PASSWORD="[your-password]" -p 3306:3306 mariadb:latest
# create your dev container (you can also use ":latest" or any other PHP version >7.4)
$ docker run --name [my-awesome-project] -v [path/to/your/dist/folder/]:/app -e WEB_DOCUMENT_ROOT="/app/public" -p 80:80 -p 443:443 --link mariadb:[db-hostname] -d webdevops/php-apache-dev:7.4
If you are on a unix based system and your docker containers won't work, make sure to disable or stop the local apache and mysql server or use different ports.
This skeleton does not use the Eloquent Migrations.
Implemented in this project is the PHP migration from Péter Képes.
If you want to create a new migration you just have to issue this commands.
$ cd database/
$ php migrate.php -c [table-name] ./migrations/
After that, there will be a generated file inside of the database/migrations/
folder.
In this file you can then add a dump of a table.
You can migrate the database tables automatically just by changing the variable in the config and then call the path /migrate
in the running application.
DB_MIGRATION_ENABLED=true
If you want to migrate a specific file and not the hole folder, you can simply call the URL /migrate/[filename-without-extention]
.
Important Do not forget to change the setting in the config back. Especially if you are on production.
If you want to migrate the tables manually, you need CLI access. Then you just have to do:
$ cd database/
$ php migrate.php -m [hostname] -u [username] -p [password] ./migrations/
In case you just want to migrate only one table, simply add the file to the command.
$ php migrate.php -m [hostname] -u [username] -p [password] ./migrations/[migration-filename].sql
If you want to go for production make sure your webserver is configured correctly.
Attention: Don't forget to update your credentials in the config.
The first step is to make some changes to the .env
file.
# change the environment to production
APP_ENV=production
# turn all debug functions off
APP_DEBUG=false
# add the new domain (used for cookies)
APP_URL=my-domain.tld
# if you want to enable template caching
VIEW_CACHE=true
Then just build the project.
$ yarn run prod
# or
$ yarn run prod:env
If you need any help on how to work with any of the Components, check out these docs.
- Slim Framework 3 (Docs)
- Laravel Eloquent ORM (Docs)
- Twig Template Engine (Docs)
- NPM (Docs, Download)
- Yarn (Docs, Download)
- Composer (Docs, Download)
- laravel-mix (Docs)
- PHPMailer (Docs)
- Carbon (Docs)
- VarDumper (Docs)
MIT License
Copyright (c) 2021 developaaah
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.