PHP code example of selami / stdlib

1. Go to this page and download the library: Download selami/stdlib 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');

/* Start to develop here. Best regards https://php-download.com/ */

    

selami / stdlib example snippets


 
declare(strict_types=1);

use Selami\Stdlib\EqualsBuilder;

class SomeValueObject()
{
	private $value1;
	private $value2;
	
	public function __construct(string $value1, string $value2)
	{
		$this->value1 = $value1;
		$this->value2 = $value2;
	}
	
	public function getValue1() :string 
	{
		return $value1;
	}
	
	public function getValue2() : string
	{
		return $value2;
	}
	
	public function equals($otherObject) : bool
	{
		return EqualsBuilder::create()
			->append($this->value1, $otherObject->getValue1())
			->append($this->value2, $otherObject->getValue2())
        	->isEquals(); 
	}
}


declare(strict_types=1);

use Selami\Stdlib\Resolver;

class BlogService {}

class Controller
{
	private $argument;
	private $service;
	public function __construct(BlogService $service, array $argument)
	{
		$this->service = $service;
		$this->argument = $argument;
	}
}

$arguments = Resolver::getParameterHints(Controller::class, '__construct');

var_dump($arguments);

/* Prints 
array(2) {
  ["service"]=>
  string(11) "BlogService"
  ["argument"]=>
  string(5) "array"
}
*/


declare(strict_types=1);

use Selami\Stdlib\CaseConverter;

$source = 'test string';
$result = CaseConverter::toCamelCase($source); // returns: testString
$result = CaseConverter::toPascalCase($source); // returns: TestString
$result = CaseConverter::toSnakeCase($source); // returns: test_string

 // common.php

declare(strict_types=1);

use Selami\Stdlib\Git\Version;

$gitVersion = Version::short();

$twig->addGlobal('version', $gitVersion);



declare(strict_types=1);

use Selami\Stdlib\BaseUrlExtractor;

$baseUrl = BaseUrlExtractor::getBaseUrl($_SERVER);

echo $baseUrl;

/* Prints base url like:
http://127.0.0.1:8080

http://127.0.0.1:8080/myapp

https://myapp.com
*/