Created
May 24, 2011 03:06
-
-
Save nijikokun/988083 to your computer and use it in GitHub Desktop.
Objectification
This file contains hidden or 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
/* Objectification Framework | |
* ^- I made this shit up. What now. | |
* | |
* PHP/Java Mixin | |
* | |
* Rewrite how PHP utilizes Objects. This way everything is constant. | |
* No more shitty function naming, no more shitty coding. | |
* | |
* This is still in SPEC, it's not functional yet. | |
* | |
* @author Nijikokun <nijikokun@gmail.com> | |
* @copyright Copyright (c) 2011, Nijiko Yonskai | |
* @todo Every fucking thing. | |
* @lyric We are three white douchebags in JAPAN. | |
* @lyric Wow look at all this japanese money. | |
* @lyric It's called YEN, i've heard it's really expensive, DUMP IT IN THE RIVER. | |
*/ | |
class Base { | |
private $imported; | |
private $imported_functions; | |
public function __construct() { | |
$this->imported = array(); | |
$this->imported_functions = array(); | |
} | |
protected function import($object) { | |
$new_import = new $object(); | |
$import_name = get_class($new_import); | |
$import_functions = get_class_methods($new_import); | |
array_push($this->imported, array($import_name, $new_import)); | |
foreach($import_functions as $key => $function_name) { | |
$this->imported_functions[$function_name] = &$new_import; | |
} | |
} | |
public function __call($method, $args) { | |
if(array_key_exists($method, $this->imported_functions)) { | |
$args[] = $this; | |
return call_user_func_array(array($this->imported_functions[$method], $method), $args); | |
} | |
throw new Exception ('Call to undefined method/class function: ' . $method); | |
} | |
} | |
class Object extends Base { | |
private $variable = null; | |
public function __construct() { | |
parent::__construct(); | |
$arguments = func_get_args(); | |
$this->variable = $arguments[0]; | |
switch(strtolower($this->getType)) { | |
case "string": | |
$this->import('_String'); | |
} | |
} | |
function getType() { | |
return gettype($this->variable); | |
} | |
} | |
class _String { | |
function isEmpty(&$that) { | |
if (!empty($that->variable)) return false; | |
if (strlen($that->variable) > 0) return false; | |
return true; | |
} | |
function contains(&$that, $item, $bool = false) { | |
return strstr($that->variable, $item, $bool); | |
} | |
function equals(&$that, $item) { | |
return ($that->variable == $item); | |
} | |
function equalsIgnoreCase(&$that, $item) { | |
return (!$this->isEmpty($that)) ? ((strlen($that->variable) == strlen($item)) && (($that->variable == $item) || (strtolower($that->variable) == strtolower($item)))) : false; | |
} | |
function toUpperCase(&$that) { | |
return strtoupper(&$that->variable); | |
} | |
function toLowerCase(&$that) { | |
return strtolower(&$that->variable); | |
} | |
function startsWith(&$that, $needle) { | |
return (substr(&$that->variable, 0, 1) == $needle); | |
} | |
function endsWith(&$that, $needle) { | |
return (substr(&$that->variable, -1) == $needle); | |
} | |
function trim(&$that, $masking = "") { | |
return ($masking == "") ? trim($that->variable) : trim($that->variable, $masking); | |
} | |
function toString(&$that) { | |
return &$that->variable; | |
} | |
} | |
class _Array { | |
function isEmpty(&$that) { | |
if (is_array($that->variable)) { | |
foreach ($that->variable as $value) | |
if (!array_empty($value)) return false; | |
} elseif (!empty($that->variable)) { | |
return false; | |
} | |
return true; | |
} | |
function contains(&$that, $key) { | |
if(is_array($that->variable) || is_object($that->variable)) { | |
if(is_object($that->variable) ){ | |
$temp_array = get_object_vars($that->variable); | |
if(in_array($key, $temp_array)) | |
return true; | |
} | |
if(is_array($that->variable) && in_array($key, $that->variable)) | |
return true; | |
foreach($that->variable as $array_element) { | |
if((is_array($array_element) || is_object($array_element)) && $this->contains($that, $key, $array_element)) { | |
return TRUE; exit; | |
} | |
} | |
} | |
return false; | |
} | |
function trim(&$that) { | |
} | |
function toString(&$that, $return = true) { | |
return str_replace(array("\n", "\r", "\r\n"), " ", var_export($that->variable, $return)); | |
} | |
} | |
class _Number { | |
} | |
class _Double { | |
} | |
class _Float { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment