-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bastien
committed
Apr 25, 2014
1 parent
9c56b7f
commit 677bcad
Showing
7 changed files
with
150 additions
and
44 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Sbp; | ||
|
||
class Handler | ||
{ | ||
protected $value; | ||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
public function __call($method, $args) | ||
{ | ||
if(is_object($this->value) && method_exists($this->value, $method)) | ||
{ | ||
return call_user_func_array(array($this->value, $method), $args); | ||
} | ||
if(is_string($this->value)) | ||
{ | ||
if(function_exists('preg_' . $method)) | ||
{ | ||
$function = 'preg_' . $method; | ||
switch($method) | ||
{ | ||
case 'replace': | ||
case 'filter': | ||
case 'replace_callback': | ||
$args = array_merge( | ||
array_slice($args, 0, 2), | ||
array($this->value), | ||
array_slice($args, 2) | ||
); | ||
break; | ||
|
||
case 'split': | ||
case 'match': | ||
case 'match_all': | ||
$args = array_merge( | ||
array_slice($args, 0, 1), | ||
array($this->value), | ||
array_slice($args, 1) | ||
); | ||
break; | ||
|
||
default: | ||
array_unshift($args, $this->value); | ||
break; | ||
} | ||
return call_user_func_array($function, $args); | ||
} | ||
elseif(function_exists('str_' . $method)) | ||
{ | ||
$function = 'str_' . $method; | ||
array_unshift($args, $this->value); | ||
return call_user_func_array($function, $args); | ||
} | ||
} | ||
elseif(is_array($this->value)) | ||
{ | ||
if(function_exists('array_' . $method)) | ||
{ | ||
$function = 'array_' . $method; | ||
array_unshift($args, $this->value); | ||
return call_user_func_array($function, $args); | ||
} | ||
} | ||
array_unshift($args, $this->value); | ||
return call_user_func_array($method, $args); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<? | ||
|
||
$return = "AbcdEF"->replace(/[a-z]/, '#') | ||
$return = "AbcdEF"-->replace(/[a-z]/, '#') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<? | ||
|
||
echo 5-->sqrt() . "\n" | ||
echo 5-->pow(4) . "\n" | ||
$array = { | ||
toto = 4 | ||
tata = 5 | ||
lulu = 6 | ||
} | ||
echo $array-->keys()-->implode(', ') . "\n" | ||
|
||
echo ({ | ||
toto = 4 | ||
tata = 5 | ||
lulu = 6 | ||
}-->keys())-->implode(', ') . "\n" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?php /* Generated By SBP */ | ||
|
||
$return = preg_replace('/[a-z]/', '#', "AbcdEF"); | ||
$return = (new \Sbp\Handler("AbcdEF"))->replace('/[a-z]/', '#'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php /* Generated By SBP */ | ||
|
||
echo (new \Sbp\Handler(5))->sqrt() . "\n"; | ||
echo (new \Sbp\Handler(5))->pow(4) . "\n"; | ||
|
||
$array = array( | ||
'toto' => 4, | ||
'tata' => 5, | ||
'lulu' => 6 | ||
); | ||
echo (new \Sbp\Handler((new \Sbp\Handler($array))->keys()))->implode(', ') . "\n"; | ||
|
||
echo (new \Sbp\Handler((new \Sbp\Handler(array( | ||
'toto' => 4, | ||
'tata' => 5, | ||
'lulu' => 6 | ||
)))->keys()))->implode(', ') . "\n"; |