Created
May 16, 2011 22:52
-
-
Save jamierumbelow/975552 to your computer and use it in GitHub Desktop.
A potential, CoffeeScript-esque nicer PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------- | |
// NO <?php TAG! | |
// ---------------------- | |
// ---------------------- | |
// SIGNIFICANT WHITESPACE ELIMINATES THE NEED | |
// FOR CURLY BRACES (YAY) | |
// ---------------------- | |
class Sessions extends MY_Controller | |
// ---------------------- | |
// WHY DO VARIABLES NEED TO BEGIN WITH A DOLLAR? | |
// SIMILARILY, WHY DO METHOD CALLS NEED PARENTHESIES? | |
// ---------------------- | |
models = array 'user' | |
// ---------------------- | |
// METHODS DON'T NEED THE 'function' KEYWORD, IT IS DROPPED | |
// AND A DASHROCKET IS USED INSTEAD. LIKE SO: | |
// | |
// function blah($name, $email) | |
// | |
// BECOMES... | |
// | |
// blah (name, email) -> | |
// ---------------------- | |
__construct -> | |
// ---------------------- | |
// NOT SURE ABOUT THIS... 'parent::' becoming '^' | |
// ---------------------- | |
^__construct() | |
// ---------------------- | |
// $this IS REPLACED WITH @, AND static:: IS REPLACED | |
// WITH @@. THE -> OPERATOR IS REPLACED WITH . | |
// ---------------------- | |
@load.model 'session_model' | |
// GET /sessions/new | |
// ---------------------- | |
// METHODS THAT ARE ONE LINE DON'T NEED THE INDENTATION | |
// ---------------------- | |
get_new -> @title = 'Login' | |
// POST /sessions | |
post_create -> | |
// ---------------------- | |
// METHODS THAT RETURN AN ASSOC ARRAY AND ARE THEN | |
// ASSIGNED TO MULTIPLE VARIABLES CAN BE ASSIGNED WITH MASS-ASSIGNMENT, | |
// ELIMINATING THE NEED FOR A $session VARIABLE. | |
// | |
// email, password = @input.post 'session' | |
// | |
// BASICALLY MEANS | |
// | |
// $session = $this->input->post('session'); | |
// $email = $session['email']; | |
// $password = $session['password']; | |
// | |
// ALSO WORKS WITH NUMBERED ARRAYS | |
// | |
// one, two = some_array_method() | |
// | |
// MEANS | |
// | |
// $array = some_array_method(); | |
// $one = $array[0]; | |
// $two = $array[1]; | |
// ---------------------- | |
email, password = @input.post 'session' | |
// Try to log us in | |
// ---------------------- | |
// NO NEED FOR if (!...), JUST USE unless. ALSO, ALL SUPERFLUOUS | |
// PUNCTUATION (brackets, braces etc) ARE REMOVED. | |
// ---------------------- | |
unless @session_model.login email, password | |
@session.set_flashdata 'error', @session_model.login_error | |
redirect 'sessions/new' | |
// Cool! Redirect to the products page and kick some arse | |
@session.set_flashdata 'message', 'Successfully logged in' | |
redirect 'products' | |
// POST /sessions/delete | |
post_delete -> | |
@session.unset_userdata 'user_id' | |
// Redirect | |
@session.set_flashdata 'message', 'Successfully logged out' | |
redirect 'sessions/new' | |
// GET /sessions/edit | |
get_edit -> @title = 'Update Account' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Sessions extends MY_Controller { | |
public $models = array('user'); | |
public function __construct() { | |
parent::__construct(); | |
$this->load->model('session_model'); | |
} | |
// GET /sessions/new | |
public function get_new() { | |
$this->title = 'Login'; | |
} | |
// POST /sessions | |
public function post_create() { | |
// get the POST vars | |
$session = $this->input->post('session'); | |
$email = $session['email']; | |
$password = $session['password']; | |
// Try to log us in | |
if (!$this->session_model->login($email, $password)) { | |
$this->session->set_flashdata('error', $this->session_model->login_error); | |
redirect('sessions/new'); | |
} | |
// Cool! Redirect to the products page and kick some arse | |
$this->session->set_flashdata('message', 'Successfully logged in'); | |
redirect('products'); | |
} | |
// POST /sessions/delete | |
public function post_delete() { | |
// Destroy the user session | |
$this->session->unset_userdata('user_id'); | |
// Redirect | |
$this->session->set_flashdata('message', 'Successfully logged out'); | |
redirect('sessions/new'); | |
} | |
// GET /sessions/edit | |
public function get_edit() { | |
$this->title = 'Update Account'; | |
} | |
} |
I'm looking for solutions like this too. See also:
https://github.com/unu/ladyphp
https://github.com/c9s/gutscript#synopsis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this just a concept, or have you written a parser for this?