Permalink
Browse files

few more string methods, integer comments, type handling and more obj…

…ect types
  • Loading branch information...
1 parent d666c24 commit baf180756ba5011689564f9419e5949e2f8d7ae1 Scott Nicol committed Apr 11, 2012
View
BIN .DS_Store
Binary file not shown.
View
21 index.php
@@ -10,15 +10,20 @@
*/
$string = new String("Hey");
-echo $string -> join(' ', 'user', 'over', 'there!') -> value;
+echo $string->join(' ', 'user', 'over', 'there!')->value;
/** Some more crazy string work
$string = new String("Foo Bar Baz Gaz");
echo $string->join(' ', 'bar ', 'foo ', ' gaz', ' baz')->reverse()->append("Just for the LOLS")->value;
*/
+/**
+ * Showing off built-in object methods and html methods
+ */
$html = new String("<p>See the code for current documentation!</p>");
+// Also see htmlencode() as well as htmldecode()!
+
$html->htmldecode();
echo $html->value;
@@ -32,8 +37,20 @@
/**
* Create a new integer object
*/
-$int = new Integer(0.1);
+$int = new Integer(1);
echo $int->abs()->value;
+/**
+ * Create a new double object
+ */
+$double = new Double(0.1);
+
+echo $double->value;
+
+/**
+ * Create a new boolean object
+ */
+$boolean = new Boolean(true);
+var_dump($boolean->value);
View
19 lib/objects/boolean.php
@@ -0,0 +1,19 @@
+<?php
+
+ class Boolean extends Object {
+
+ /**
+ * @var boolean
+ */
+ public $value = null;
+
+ /**
+ * constructor
+ */
+ public function __construct($value){
+ if(parent::type($value)=="boolean"){
+ $this->value = $value;
+ }
+ }
+
+ }
View
17 lib/objects/dictionary.php
@@ -0,0 +1,17 @@
+<?php
+
+ class Dictionary extends Object {
+
+ /**
+ * @var dict
+ */
+ public $value = null;
+
+ /**
+ * constructor
+ */
+ public function __construct(){
+ // Dicts will be in a special format which is still under provision
+ }
+
+ }
View
19 lib/objects/double.php
@@ -0,0 +1,19 @@
+<?php
+
+ class Double extends Object {
+
+ /**
+ * @var double
+ */
+ public $value = null;
+
+ /**
+ * constructor
+ */
+ public function __construct($double){
+ if(parent::type($double)=="double"){
+ $this->value = $double;
+ }
+ }
+
+ }
View
38 lib/objects/integer.php
@@ -5,13 +5,15 @@ class Integer extends Object {
/**
* @var int
*/
- public $value = 0;
+ public $value = null;
/**
* constructor
*/
public function __construct($integer){
- $this->value = $integer;
+ if(parent::type($integer)=="integer"){
+ $this->value = $integer;
+ }
}
/**
@@ -24,27 +26,52 @@ public function abs(){
$this->value = abs($this->value);
return $this;
}
-
+
+ /**
+ * @public acos
+ * oo-syntax: acos();
+ * @return object
+ */
public function acos(){
$this->value = acos($this->value);
return $this;
}
+ /**
+ * @public acosh
+ * oo-syntax: acosh();
+ * @return object
+ */
public function acosh(){
$this->value = acosh($this->value);
return $this;
}
+ /**
+ * @public asin
+ * oo-syntax: asin();
+ * @return object
+ */
public function asin(){
$this->value = asin($this->value);
return $this;
}
+ /**
+ * @public asinh
+ * oo-syntax: asinh();
+ * @return object
+ */
public function asinh(){
$this->value = asinh($this->value);
return $this;
}
+ /**
+ * @public atan2
+ * oo-syntax: atan2();
+ * @return object
+ */
public function atan2($axis, $val2){
if($axis == "y"){
$this->value = atan2($this->value, $val2);
@@ -55,6 +82,11 @@ public function atan2($axis, $val2){
}
}
+ /**
+ * @public atan
+ * oo-syntax: atan();
+ * @return object
+ */
public function atan(){
$this->value = atan($this->value);
return $this;
View
4 lib/objects/object.php
@@ -16,4 +16,8 @@ public function is_a($class){
}
}
+ public function type($var){
+ return gettype($var);
+ }
+
}
View
42 lib/objects/string.php
@@ -3,15 +3,17 @@
class String extends Object {
/**
- * @var String
+ * @var string
*/
- public $value = "";
+ public $value = false;
/**
* constructor
*/
public function __construct($string){
- $this->value = $string;
+ if(parent::type($string)=="string"){
+ $this->value = $string;
+ }
}
/**
@@ -48,12 +50,12 @@ public function bin2hex(){
}
/**
- * @public explode
+ * @public split
* normal syntax: explode($delimiter, $string, $limit);
- * oo-syntax: explode($delimiter, $limit);
+ * oo-syntax: split($delimiter, $limit);
* @return array|false
*/
- public function explode($delimiter, $limit){
+ public function split($delimiter, $limit=null){
if($delimiter == ""){
return FALSE;
} else {
@@ -178,4 +180,32 @@ public function join($glue = ' '){
return $this;
}
+ /**
+ * @public first
+ * oo-syntax: first();
+ * @return string(1)
+ */
+ public function first(){
+ return substr($this->value, 0, 1);
+ }
+
+ /**
+ * @public uppercase
+ * oo-syntax: uppercase();
+ * @return object
+ */
+ public function uppercase(){
+ $this->value = ucfirst($this->value);
+ return $this;
+ }
+
+ /**
+ * @public lowercase
+ * oo-syntax: lowercase();
+ * @return object
+ */
+ public function lowercase(){
+ $this->value = strtolower($this->value);
+ return $this;
+ }
}

0 comments on commit baf1807

Please sign in to comment.