auto-scripts/auto-php


Home Back

import os,sys

print("Writing project structure...")
os.mkdir(sys.argv[1])
os.chdir(sys.argv[1])
os.mkdir("views")

indexphp='''<?php
    require_once "globals.php" ;
    global $router;
    
    /*
     *  $router->get('pattern', function() { });
        $router->post('pattern', function() {  });
        $router->put('pattern', function() {  });
        $router->delete('pattern', function() {  });
        $router->options('pattern', function() {  });
        $router->patch('pattern', function() { });
        $router->all('pattern', function() { });
     * */
    
     $router->get('/', function () {
         echo '<h1>Home page</h1>';
         
     });
     
     $router->get('/fabio', function () {
         echo '<h1>Hello Fabio!</h1>';
         echo 's='.$_GET['s'];
         
     });
     
     $router->set404(function () {
         echo '<h1>Pagina non trovata </h1>';
    });

     
     
      $router->run();

?>
     
'''
f = open("index.php", "w")
f.write(indexphp)
f.close()



globalsphp='''<?php 
# https://github.com/bramus/router/tree/master
require_once __DIR__ . '/Router.php';
$router = new \Bramus\Router\Router();

function template($fileName, $arrayVal=[])
{
    $txt = file_get_contents($fileName);
    return strtr($txt, $arrayVal);
}     

?>
'''
f = open("globals.php", "w")
f.write(globalsphp)
f.close()

print("Download Bramus Router from freemedialab.org")
os.system("curl https://www.freemedialab.org/code/bramus_router/Router.txt > Router.php")


print ("Write .htaccess")
htaccess='''RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

'''
f = open(".htaccess", "w")
f.write(htaccess)
f.close()

Powered by Code, a simple repository browser by Fabio Di Matteo