PHP code example of sebastiaanluca / php-helpers
1. Go to this page and download the library: Download sebastiaanluca/php-helpers library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
sebastiaanluca / php-helpers example snippets
rand_bool();
str_wrap('foo' , '*' );
is_assoc_array(['color' => 'blue' , 'age' => 31 ]);
is_assoc_array([0 => 'blue' , 7 => 31 ]);
is_assoc_array(['blue' , 31 ]);
is_assoc_array([0 => 'blue' , 1 => 31 ]);
array_expand(['products.desk.price' => 200 ]);
$cars = ['bmw' , 'mercedes' , 'audi' ];
$soldOut = ['audi' , 'bmw' ];
$inStock = array_without($cars, $soldOut);
array_without(['one' , 'two' , 'three' ], 'two' );
$source = ['A' , 'B' , 'C' ];
$removed = array_pull_value($source, 'C' );
$source = ['A' , 'B' , 'C' ];
$removed = array_pull_values($source, ['A' , 'B' ]);
array_hash([1 , 2 , 3 ]);
array_hash(['hash' => 'me' ]);
class ValueObject {
public $property = 'randomvalue' ;
}
object_hash(new ValueObject);
class Hitchhiker {
public function answer () {
return 42 ;
}
}
has_public_method(Hitchhiker::class, 'answer' );
has_public_method(new Hitchhiker, 'answer' );
carbon('2017-01-18 11:30' );
carbon();
temporary_file();
use SebastiaanLuca \PhpHelpers \Classes \Enum ;
class UserStates
{
use Enum ;
public const REGISTERED = 'registered' ;
public const ACTIVATED = 'activated' ;
public const DISABLED = 'disabled' ;
}
UserStates::enums();
(new UserStates)->enums();
use SebastiaanLuca \PhpHelpers \Classes \Enum ;
class UserStates
{
use Enum ;
public const REGISTERED = 'registered' ;
public const ACTIVATED = 'activated' ;
public const DISABLED = 'disabled' ;
}
UserStates::keys();
use SebastiaanLuca \PhpHelpers \Classes \Enum ;
class UserStates
{
use Enum ;
public const REGISTERED = 'registered' ;
public const ACTIVATED = 'activated' ;
public const DISABLED = 'disabled' ;
}
UserStates::values();
namespace Kyle \Helpers ;
use SebastiaanLuca \PhpHelpers \Classes \ProvidesClassInfo ;
class MyClass
{
use ProvidesClassInfo ;
public function __construct ()
{
var_dump($this ->getClassDirectory());
}
}
class SomeClass
{
private function aPrivateMethod () : string
{
return 'private' ;
}
protected function aProtectedMethod () : string
{
return 'protected' ;
}
public function aPublicMethod () : string
{
return 'public' ;
}
}
MethodHelper::hasMethodOfType($class, 'aPrivateMethod' , 'private' );
MethodHelper::hasProtectedMethod($class, 'aProtectedMethod' );
MethodHelper::hasPublicMethod($class, 'aPublicMethod' );
MethodHelper::hasProtectedMethod($class, 'aPrivateMethod' );
MethodHelper::hasPublicMethod($class, 'invalidMethod' );
bash
composer