1. Go to this page and download the library: Download spotlibs/php-lib 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/ */
spotlibs / php-lib example snippets
declare(strict_types=1);
use Spotlibs\PhpLib\Exceptions\StdException;
use Spotlibs\PhpLib\Exceptions\AccessException;
class ExceptionUsage
{
public function ThrowingException()
{
throw new AccessException('You shall not pass!');
}
// you can also throw any exception by static function of StdException
public function ThrowingStandardException()
{
throw StdException::create(
StdException::HEADER_EXCEPTION,
'Invalid headers to access this resource',
);
}
}
declare(strict_types=1);
use Spotlibs\PhpLib\Responses\StdResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use App\Models\Post;
class DailyNews extends Controller
{
public function index(Request $request): Response
{
Post::create([
'headline' => 'Top 10 Countries with Best Cyber Security, Finland Ranked First',
'content' => 'Here are the top 10 countries with the best cyber securities based on the data published by Mix Mode and 2024 Global Security Index:'
]);
return StdResponse::success('Daily news posted.');
}
}
declare(strict_types=1);
use Spotlibs\PhpLib\Dtos\TraitDtos;
class Person
{
use TraitDtos;
public string $name;
public int $age;
public array $hobbies;
}
class Introduction
{
protected Person $person;
public function __construct()
{
// pass associative array to construct DTO
$this->person = new Person([
'name' => 'John',
'age' => 30,
'hobbies' => ['fishing', 'sleeping', 'coding']
]);
}
public function index(): void
{
echo "Hi, my name is " . $this->person->name . ". I am " . $this->person->age . " year(s) old" . PHP_EOL;
}
}
declare(strict_types=1);
use Spotlibs\PhpLib\Facades\Queue;
use App\Jobs\SendMoney;
use App\Models\Employee;
class Payday
{
public function index(Request $request): void
{
$employees = Employee::get();
foreach ($employees as $employee) {
Queue::pushOn('payday', new SendMoney());
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.