Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aalfiann committed Dec 16, 2016
0 parents commit c936647
Show file tree
Hide file tree
Showing 1,079 changed files with 82,649 additions and 0 deletions.
57 changes: 57 additions & 0 deletions database/islim.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 15, 2016 at 07:56 PM
-- Server version: 5.6.21
-- PHP Version: 5.6.3

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `islim`
--

-- --------------------------------------------------------

--
-- Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
`username` varchar(50) NOT NULL,
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`username`, `created`, `status`) VALUES
('abdul', '2016-12-12 14:39:15', 'active'),
('alfian', '2016-12-14 14:39:27', 'suspended'),
('aziz', '2016-12-13 14:39:21', 'active'),
('muhammad', '2016-12-11 14:39:05', 'active');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`username`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
9 changes: 9 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


Copyright (c) 2016 M ABD AZIZ ALFIAN

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.
207 changes: 207 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
iSlim3-basic
=======
[![Travis branch](https://img.shields.io/travis/rust-lang/rust/master.svg)](https://github.com/aalfiann/iSlim3-basic)
[![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)](https://github.com/aalfiann/iSlim3-basic/blob/master/license.md)

I call this "iSlim" because I heart [Slim Framework](http://www.slimframework.com/).<br>
iSlim version 3 is the easiest and flexible way to create your PHP application using PSR 7 way,<br>
which is look alike MVC pattern and Bootstrap 4.


Getting Started
---------------
1. Get or download the project
2. Install it using Composer

Folder System
---------------
* classes/
* logs/
* models/
* public/
* routers/
* name.router.php (routes by functionalities)
* templates/

### classes/

Here is the place for your application classes

### logs/

Here is the place your custom log.
You can add your custom log in your any container or router.

Example adding custom log in a router post
```php
$app->post('/user/new', function (Request $request, Response $response) {
echo 'This is a POST route';
$this->logger->addInfo("Response post is succesfully complete!!!");
});
```

### models/

Add the model classes here.
We are using PDO MySQL for the Database.

Example of models class:

Starter.php

```php

namespace models;

class Starter {

protected $db;

function __construct($db=null) {
if (!empty($db))
{
$this->db = $db;
}
}

// Get all data from database mysql
public function getAll() {
$r = array();

$sql = "SELECT * FROM user a order by a.created;";
$stmt = $this->db->prepare($sql);

if ($stmt->execute()) {
if ($stmt->rowCount() > 0){
$r = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
else{
$r = 0;
}
} else {
$r = 0;
}

return $r;
$stmt->Close();
}

public function setHello() {
return array(
'hello' => "Hello World!!!",
'description1' => "Use this document as a way to quickly start any new project.",
'description2' => "All you get is this text and a mostly barebones HTML document.",
'author' => "iSlim3 is forged by M ABD AZIZ ALFIAN"
);
}
}
```

### public/

All the public files:
* Images, CSS and JS files which is inside a theme folder.
* index.php (this is required to run the core of Slim Framework)

### routers/

All the files with the routes. Each file contents the routes of an specific functionality.
It is very important that the names of the files inside this folder follow this pattern: name.router.php

Example of router file:

index.router.php

```php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

//Hello Word
$app->get('/', function (Request $request, Response $response) {
$oStuff = new models\Starter();
$hello = $oStuff->setHello();

$response = $this->viewfrontend->render($response, "index.html", [
"hello" => $hello['hello'],
"description1" => $hello['description1'],
"description2" => $hello['description2'],
"author" => $hello['author'],
"router" => $this->router]);
return $response;
})->setName("/");

//POST route
$app->post('/user/new', function (Request $request, Response $response) {
echo 'This is a POST route';
});

// PUT route
$app->put('/user/update', function (Request $request, Response $response) {
echo 'This is a PUT route';
});

// DELETE route
$app->delete('/user/delete', function (Request $request, Response $response) {
echo 'This is a DELETE route';
});
```

### templates/

There are already 2 default themes in iSlim3:
* default (using twig way)
* defaultPHP (using render PHP)

iSlim3 have two type of templates:

1. Render as PHP
2. Use Twig

Default templates type is using twig, You can find change this configuration in config.php that placed in root folder.

Example Config.php
```php
/**
* Configuration App
*
* @var $config['displayErrorDetails'] to display error details on slim
* @var $config['addContentLengthHeader'] to set the Content-Length header which makes Slim behave more predictably
*
*/
$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;

/**
* Configuration Templates
*
* @var $config['templateRender'] is how slim3 to render a template. There are two options 'twig' or 'php'
* @var $config['twigcache'] is cache options in twig only (won't work if you use it on php render)
* @var $config['theme'] is options to choose which one theme will be use.
*
* Note: if You choose theme defaultPHP, make sure you have set templateRender to 'php'
*/
$config['templateRender'] = 'twig';
$config['twigcache'] = false;
$config['theme'] = 'default';

/**
* Configuration PDO MySQL Database
*
* @var $config['db']['host'] = where is database was hosted
* @var $config['db']['user'] = username database to login
* @var $config['db']['pass'] = pass database to login
* @var $config['db']['dbname'] = the database name
*/
$config['db']['host'] = 'localhost';
$config['db']['user'] = 'root';
$config['db']['pass'] = 'root';
$config['db']['dbname'] = 'iSlim';
```

How to Contribute
-----------------
### Pull Requests

1. Fork the iSlim3 repository
2. Create a new branch for each feature or improvement
3. Send a pull request from each feature branch to the develop branch
118 changes: 118 additions & 0 deletions src/classes/Custom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* This is just example how to create Your own simple library class
* This library is not used in everywhere so You can change or delete this class
*
*/

namespace classes;

class Custom {

/**
* File get contents in curl way
*
* @param $url = Address to get contents
*/
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

/**
* Replace any string and allow integer only without change the string itself
*
* @param $string = input string
*/
function integeronly($string)
{
$nn = preg_replace("/[^0-9]/", "", $string );
return $nn;
}

/**
* Determine limit for request more than 1000 row
*
* @param $itemsperpage = input how much items per page to show
*/
function IsBigData($itemsperpage)
{
$hasil = false;
if($itemsperpage > 1000)
{
$hasil = true;
}
return $hasil;
}

/**
* Convert encoded json data to prettyPrint in old way
* This function is support for PHP below 5.4 as JSON_PRETTY_PRINT is not supported at all
*
* @param $json = input encoded data json here
*/
function prettyPrint( $json )
{
$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = NULL;
$json_length = strlen( $json );

for( $i = 0; $i < $json_length; $i++ ) {
$char = $json[$i];
$new_line_level = NULL;
$post = "";
if( $ends_line_level !== NULL ) {
$new_line_level = $ends_line_level;
$ends_line_level = NULL;
}
if ( $in_escape ) {
$in_escape = false;
} else if( $char === '"' ) {
$in_quotes = !$in_quotes;
} else if( ! $in_quotes ) {
switch( $char ) {
case '}': case ']':
$level--;
$ends_line_level = NULL;
$new_line_level = $level;
break;

case '{': case '[':
$level++;
case ',':
$ends_line_level = $level;
break;

case ':':
$post = " ";
break;

case " ": case "\t": case "\n": case "\r":
$char = "";
$ends_line_level = $new_line_level;
$new_line_level = NULL;
break;
}
} else if ( $char === '\\' ) {
$in_escape = true;
}
if( $new_line_level !== NULL ) {
$result .= "\n".str_repeat( "\t", $new_line_level );
}
$result .= $char.$post;
}

return $result;
}

}
Loading

0 comments on commit c936647

Please sign in to comment.