Skip to content

Commit

Permalink
first init , fat free with basic structure and sample
Browse files Browse the repository at this point in the history
  • Loading branch information
alan authored and alan committed Mar 21, 2017
1 parent a2134e2 commit 2f3bf90
Show file tree
Hide file tree
Showing 28 changed files with 444 additions and 166 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.docker-compose.yml
55 changes: 55 additions & 0 deletions app/controllers/api/basecontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace api;

class BaseController extends \BaseController{

/**
* Create Success API JSON OUTPUT
* @param type $data
*/
public function onSuccess($data, $reason = "", $pagination = "") {
$result = array();
$result['result'] = true;
$result['reason'] = $reason;
if (isset($data["ts"]) && isset($data["data"])) {
$result["ts"] = $data['ts'];
$result["data"] = $data['data'];
} else {
$result["data"] = $data;
}
if($pagination) {
$result['data']['pagination'] = $pagination;
}
$result['v'] = $this->version;
$result['ts'] = time();
$this->output($result);
}

/**
* Create Fail API JSON OUTPUT
* @param type $data
*/
public function onFail($errMsg, $msg = "") {
$result = array(
"result" => false,
"reason" => $errMsg,
"msg" => $msg,
"v" => $this->version,
"time" => time()
);
$this->output($result);

}

/**
* Common JSON OUTPUT
* @param type $output
*/
private function output($output) {
header("Content-Type: application/json", TRUE);
echo json_encode(($output), JSON_HEX_APOS | JSON_HEX_QUOT);
exit();
}

}
20 changes: 20 additions & 0 deletions app/controllers/api/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace api;

class Common extends BaseController{

function get() {
$this->onSuccess("GET");
}
function post() {
$this->onSuccess("POST");
}
function put() {
$this->onSuccess("PUT");
}
function delete() {
$this->onSuccess("DELETE");
}

}
7 changes: 7 additions & 0 deletions app/controllers/basecontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class BaseController{

protected $version = 1;

}
8 changes: 8 additions & 0 deletions app/controllers/web/basecontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace web;

class BaseController extends \BaseController{


}
157 changes: 75 additions & 82 deletions index.php → app/controllers/web/home.php
Original file line number Diff line number Diff line change
@@ -1,82 +1,75 @@
<?php

// Kickstart the framework
$f3=require('lib/base.php');

$f3->set('DEBUG',1);
if ((float)PCRE_VERSION<7.9)
trigger_error('PCRE version is out of date');

// Load configuration
$f3->config('config.ini');

$f3->route('GET /',
function($f3) {
$classes=array(
'Base'=>
array(
'hash',
'json',
'session'
),
'Cache'=>
array(
'apc',
'memcache',
'wincache',
'xcache'
),
'DB\SQL'=>
array(
'pdo',
'pdo_dblib',
'pdo_mssql',
'pdo_mysql',
'pdo_odbc',
'pdo_pgsql',
'pdo_sqlite',
'pdo_sqlsrv'
),
'DB\Jig'=>
array('json'),
'DB\Mongo'=>
array(
'json',
'mongo'
),
'Auth'=>
array('ldap','pdo'),
'Bcrypt'=>
array(
'mcrypt',
'openssl'
),
'Image'=>
array('gd'),
'Lexicon'=>
array('iconv'),
'SMTP'=>
array('openssl'),
'Web'=>
array('curl','openssl','simplexml'),
'Web\Geo'=>
array('geoip','json'),
'Web\OpenID'=>
array('json','simplexml'),
'Web\Pingback'=>
array('dom','xmlrpc')
);
$f3->set('classes',$classes);
$f3->set('content','welcome.htm');
echo View::instance()->render('layout.htm');
}
);

$f3->route('GET /userref',
function($f3) {
$f3->set('content','userref.htm');
echo View::instance()->render('layout.htm');
}
);

$f3->run();
<?php

namespace web;

class Home extends BaseController{

function index($f3){
$classes=array(
'Base'=>
array(
'hash',
'json',
'session'
),
'Cache'=>
array(
'apc',
'memcache',
'wincache',
'xcache'
),
'DB\SQL'=>
array(
'pdo',
'pdo_dblib',
'pdo_mssql',
'pdo_mysql',
'pdo_odbc',
'pdo_pgsql',
'pdo_sqlite',
'pdo_sqlsrv'
),
'DB\Jig'=>
array('json'),
'DB\Mongo'=>
array(
'json',
'mongo'
),
'Auth'=>
array('ldap','pdo'),
'Bcrypt'=>
array(
'mcrypt',
'openssl'
),
'Image'=>
array('gd'),
'Lexicon'=>
array('iconv'),
'SMTP'=>
array('openssl'),
'Web'=>
array('curl','openssl','simplexml'),
'Web\Geo'=>
array('geoip','json'),
'Web\OpenID'=>
array('json','simplexml'),
'Web\Pingback'=>
array('dom','xmlrpc')
);
$f3->set('classes',$classes);
$f3->set('content','welcome.htm');
echo \View::instance()->render('layout.htm');
}

function userref($f3) {
$f3->set('content','userref.htm');
echo \View::instance()->render('layout.htm');
}

}



2 changes: 2 additions & 0 deletions app/dict/en.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

SERVER_ERROR="SERVER_ERROR"
5 changes: 5 additions & 0 deletions app/models/basemodel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?

class BaseModel {

}
18 changes: 18 additions & 0 deletions app/views/layout.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="<?php echo $ENCODING; ?>" />
<title>Powered by
<?php echo $PACKAGE; ?>
</title>
<link rel="stylesheet" href="lib/code.css" type="text/css" />
<link rel="stylesheet" href="ui/css/base.css" type="text/css" />
<link rel="stylesheet" href="ui/css/theme.css" type="text/css" />
</head>

<body>
<?php echo $this->render(Base::instance()->get('content')); ?>
</body>

</html>
4 changes: 4 additions & 0 deletions app/views/userref.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="content">
<?php echo Markdown::instance()->
convert(Base::instance()->read('../readme.md')); ?>
</div>
74 changes: 74 additions & 0 deletions app/views/welcome.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<div class="header center">
<p><img src="ui/images/logo.png"></p>
</div>
<div class="content">
<h2>Version
<?php echo $VERSION; ?>
</h2>
<p>The first thing you might want to do is visualize your directory structures. Fat-Free gives you total control over your Web site. Organize your folders in any way that pleases you (or your development team if you're part of a group). Decide where
you want to store the following:</p>
<ul>
<li>Application and code libraries</li>
<li>HTML templates</li>
<li>Graphics and media files</li>
<li>Javascript and CSS files</li>
<li>Database (if you plan to use an embedded DB like SQLite)</li>
<li>Configuration files</li>
<li>Uploads/Downloads</li>
</ul>
<p>For security reasons, consider relocating the <code>lib/</code> folder to a path that's not Web-accessible. If you decide to move this folder, just change the line in <code>index.php</code> containing <code>require 'lib/base.php';</code> so it points
to the new location. The <code>lib/</code> folder also contains framework plug-ins that extend F3's capabilities. You can change the default location of all plug-ins by moving the files to your desired subdirectory. Then, it's just a matter of
pointing the <code>PLUGINS</code> global variable to the new location. You may delete the plug-ins that you don't need. You can reinstate them later as you find necessary.</p>
<p>F3 can autoload OOP classes for you. Just add the path to the <code>AUTOLOAD</code> variable.</p>
<p>When you're ready to write your F3-enabled site, you can start editing the rest of the code contained in the <code>index.php</code> file that displayed this Web page. Developing PHP applications will never be the same!</p>
<h2>PHP Dependencies</h2>
<p>Some framework features in this version will not be available if PHP is not configured with the modules needed by your application.</p>
<table>
<tr>
<th>Class/Plug-in</th>
<th>PHP Module</th>
</tr>
<?php foreach ($classes as $class=>$modules): ?>
<tr>
<td>
<?php echo $class; ?>
</td>
<td>
<?php foreach ($modules as $module): ?>
<input type="checkbox" <?php echo extension_loaded($module)? 'checked': ''?> onclick="return false">
<?php echo $module; ?><br>
<?php endforeach; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<ul>
<li>The <code>Base</code> class requires all listed PHP modules enabled to function properly.</li>
<li>The <code>Cache</code> class will use any available module in the list. If none can be found, it will use the filesystem as fallback.</li>
<li>The <code>DB\SQL</code> class requires the <code>pdo</code> module and a PDO driver relevant to your application.</li>
<li>The <code>Bcrypt</code> class will use the <code>mcrypt</code> or <code>openssl</code> module for entropy generation. Otherwise, it employs a custom random function.</li>
<li>The <code>Web</code> class will use the <code>curl</code> module for HTTP requests to another server. If this is not detected, it will use other transports available, such as the HTTP stream wrapper or native sockets.</li>
<li>The <code>geoip</code> module listed in the <code>Web\Geo</code> class is optional; the class will use an alternative Web service for geo-location.</li>
<li>Other framework classes in the list need all its listed modules enabled.</li>
</ul>
<h2>Need Help?</h2>
<p>If you have any questions regarding the framework, technical support is available at <code><a href="https://groups.google.com/forum/?fromgroups#!forum/f3-framework">https://groups.google.com/forum/?fromgroups#!forum/f3-framework</a></code></p>
<p>Need live support? You can talk to the development team and the rest of the Fat-Free community via IRC. We're on the FreeNode (<code>chat.freenode.net</code>) <code>#fatfree</code> channel. If the channel appears quiet, the development team might
just be busy with the next great release, or it's probably due to time zone differences. Just hang around.</p>
<p>The <strong><a href="<?php echo $BASE; ?>/userref">User Reference</a></strong> is designed to serve as a handbook and programming guide. However, the online documentation at <a href="https://github.com/bcosca/fatfree" onclick="window.open(this.href); return false;"><code>https://github.com/bcosca/fatfree</code></a> provides the latest and most comprehensive information about the framework.</p>
<h2>Fair Licensing</h2>
<p><b>Fat-Free Framework is free software covered by the terms of the GNU Public License (GPL v3).</b> You may not use the software, documentation, and samples except in compliance with the license. If the terms and conditions of this license are too
restrictive for your use, alternative licensing is available for a very reasonable fee.</p>
<p>If you feel that this software is one great weapon to have in your programming arsenal, it saves you a lot of time and money, use it for commercial gain or in your business organization, please consider making a donation to the project. A significant
amount of time, effort, and money has been spent on this project. Your donations help keep this project alive and the development team motivated. Donors and sponsors get priority support commensurate to your contribution (24-hour response time
on business days).</p>
<h2>Support F3</h2>
<p>F3 is community-driven software. Support the development of the Fat-Free Framework. Your contributions help keep this project alive.</p>
<p>
<a href="bitcoin:18cJLaAYT5mmu72GeoMgajbKFcmCZEjK12" target="_blank"><img src="ui/images/bitcoin.png"></a>
</p>
</div>
<div class="footer center">
<p>Fat-Free Framework is licensed under the terms of the GPL, either v3 or later<br> Copyright &copy; 2009-2016 F3::Factory/Bong Cosca &lt;bong&#46;cosca&#64;yahoo&#46;com&gt;</p>
<p class="stats"><code><?php echo Base::instance()->format('Page rendered in {0} msecs / Memory usage {1} Kibytes',round(1e3*(microtime(TRUE)-$TIME),2),round(memory_get_usage(TRUE)/1e3,1)); ?></code></p>
</div>
Loading

0 comments on commit 2f3bf90

Please sign in to comment.