Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
notarun committed May 30, 2022
0 parents commit c327f9d
Show file tree
Hide file tree
Showing 43 changed files with 2,150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
config.php
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
> Wrote this a while back, uploading here just for the backup.
## TODO MVC Project

> A simple todo application build with MVC pattern and written in PHP.
#### Requirements
* PHP 7.4
* MySQL 5.7
* Composer

#### Setup
```bash
git clone https://github.com/notarun/todo-php-mvc
cd todo-php
composer install # setup vendor folder for autoloading
cp config.example.php config.php # create config file
vim config.php # edit config file
mysql -u root < schema.sql # import the schema file
composer start # start the dev server (localhost:8080)
```

#### Project Structure
* Routes are defined in `src/routes.php`.
* Dependency containers are defined in `src/containers.php`.
* Validators are defined in `src/validators.php`.
* Views are inside `src/views/` directory.
* Controllers are inside `src/app/Controllers/` directory.
* Models are inside `src/app/Models/` directory.
* Middlewares can be created inside `src/app/Middlewares/` directory.
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "lee.arun/todo-php",
"description": "A simple todo application build with MVC pattern and written in PHP.",
"type": "project",
"license": "MIT",
"scripts": {
"start": "php -S localhost:8080 -t public"
},
"config": {
"process-timeout": 0
},
"autoload": {
"psr-4": {
"App\\": "src/app/",
"Core\\": "src/core/"
}
},
"require": {
"php": ">=7.4"
}
}
21 changes: 21 additions & 0 deletions config.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

// site setting
define('APP_KEY', '');
define('SITE_URL', $_SERVER['HTTP_HOST']);
define('DEVELOPMENT', true);
define('EMAIL_EXPIRY_TIME', 30); // in minutes

// paths
define('SITE_TITLE', 'TODO');
define('PROJECT_DIR', __DIR__);
define('VIEWS_DIR', PROJECT_DIR . '/src/views/');

// class path
define('CONTROLLERS_CLASS_PATH', 'App\\Controllers\\');

// database config
define('DB_HOST', 'localhost');
define('DB_NAME', 'todo_php');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
22 changes: 22 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

# If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
# absolute physical path to the directory that contains this htaccess file.
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>

110 changes: 110 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
:root {
--primary-blue: #00a8cc;
--secondary-blue: #0c7b93;
--primary-white: #fff;
--primary-black: #333;
--primary-orange: #ea9085;
--primary-grey: #979797;
}

body {
margin: 0;
font-size: 18px;
font-family: monospace;
background-color: var(--primary-white);
}

.center { text-align: center; }
.link { text-decoration: none; }
.flex-box { display: flex; }
.heading::before { content: '🗒️ '; }
.link:active, .link-btn:active { color: var(--secondary-blue); }
.nav-item { margin: 0 1em; }

.login-btn, .login-input, .register-input {
width: 100%;
margin: 1em 0 0.4em 0;
display: inline-block;
}

.btn, .input-style, .link-btn {
font-family: inherit;
font-size: inherit;
}

.content-wrapper {
max-width: 520px;
margin: 0 auto;
padding: 0 1em;
}

.navigation {
list-style: none;
display: flex;
justify-content: center;
margin: 1em 0;
padding: 0;
}

.input-style {
box-sizing: border-box;
border-width: 0 0 0.2em 0;
margin: 0.6em 0;
}

.input-style:focus {
outline: none;
border-color: var(--primary-blue);
}

.btn {
border-width: 0;
padding: 0.4em 1em;
border-radius: 4px;
background-color: var(--primary-blue);
color: var(--primary-white);
}

.icon-btn {
border-width: 0;
background-color: var(--primary-white);
font-size: 14px;
padding: 0;
}

.todo-item-list {
list-style: none;
padding: 0;
}

.link-btn {
background-color: var(--primary-white);
color: var(--primary-blue);
border: none;
}

.error {
font-size: 15px;
color: var(--primary-orange);
display: block;
}

.todo-input { width: 100%; }
.input-error { border-color: var(--primary-orange); }
.icon-btn:focus { outline: none; }
.form-group { flex: 6; }
.todo-btn { flex: 1; }
.todo-item .icon-btn { margin: 0 1em 0 0; }
.message-box { color: var(--primary-orange); }
.message-box::before { content: '💬'; }
.strikethrough { color: var(--primary-grey) }
.user-name::before { content: '😀 ' }
.btn-red { background-color: var(--primary-orange); }
.btn-blue { background-color: var(--primary-blue); }
.btn-container { justify-content: flex-start; }
.btn-container form { margin: 1em 1em 0 0; }

.item-link {
text-decoration: none;
color: inherit;
}
7 changes: 7 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// start the session
session_start();

// boot the framework files
require '../src/boot.php';
25 changes: 25 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
DROP DATABASE IF EXISTS `todo_php`;

CREATE DATABASE `todo_php`;

USE `todo_php`;

CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`email` varchar(320) NOT NULL,
`password` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`verified_at` timestamp NULL,
PRIMARY KEY (`id`),
UNIQUE (`email`)
);

CREATE TABLE `todo_list` (
`id` int NOT NULL AUTO_INCREMENT,
`item` text NOT NULL,
`done` BOOLEAN NOT NULL DEFAULT 0,
`created_by` int NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`created_by`) REFERENCES users(`id`)
);
57 changes: 57 additions & 0 deletions src/app/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Controllers;

use Core\View;
use Core\Redirect;

class Controller
{
/**
* Render the view.
*
* @param string $viewName
* @param array $data
* @return void
*/
protected function render(string $viewName, array $data)
{
return View::render($viewName, $data);
}

/**
* Redirect to the specified url.
*
* @param string $uri
* @param array $message
* @return void
*/
protected function redirect(string $uri, array $message = [])
{
return Redirect::to($uri, $message);
}

/**
* Go back to previous url.
*
* @param array $message
* @return void
*/
protected function back(array $message = [])
{
return Redirect::back($message);
}

/**
* Return the JSON data.
*
* @param array $input
* @return void
*/
protected function jsonify(array $input)
{
header('Content-type: application/json');
echo json_encode($input);
exit();
}
}
Loading

0 comments on commit c327f9d

Please sign in to comment.