PHP code example of vulcanphp / hyper-core

1. Go to this page and download the library: Download vulcanphp/hyper-core 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/ */

    

vulcanphp / hyper-core example snippets


    use Hyper\Database;
    $database = new Database([
        // sqlite, mysql, pgsql, cubrid, dblib, firebird, ibm, informix, sqlsrv, oci, odbc
        'driver' => 'sqlite',

        // your custom pdo options. Note: PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION added as default.
        'options' => [],

        // when driver is serverside
        'host' => 'localhost',
        'user' => '{user}',
        'password' => '{password}',
        'port' => 3306,
        'name' => '{database name}',
        'charset' => 'utf8mb4'

        // Learn more: https://www.php.net/manual/en/book.pdo.php
    ]);
    dump($database->prepare('SELECT * FROM students'));
    

    use Hyper\Model;

    class Student extends Model {
        protected string $table = 'students';

        public string $name;
        public int $age;
        public string $department;
    }

    dump(Student::get()->result());
    

    use Hyper\Utils\Image;
    $image = new Image(__DIR__ . '/image.png');
    $image->compress(50);
    $image->resize(720, 360);
    $image->rotate(90);
    $image->bulkResize([540 => 540, 60 => 60]);
    

    use Hyper\Utils\Paginator;
    $paginator = new Paginator(total: 500, limit: 20);
    $paginator->setData([...]);
    dump($paginator->getData(), $paginator->getLinks());
    

    use Hyper\Utils\Ping;
    $http = new Ping();
    $http->download(__DIR__.'/downloads/file.jpg');
    dump($http->get('http://domain.com/download-file'));
    

    use Hyper\Utils\Uploader;
    $uploader = new Uploader(uploadDir: __DIR__ .'/uploads', extensions: ['jpe', 'png'], multiple: true);
    dump($uploader->upload($_FILES['upload']));
    

    use Hyper\Utils\Sanitizer;
    $sanitizer = new Sanitizer(['student_email' => '[email protected]', 'student_age' => '24']);
    dump($sanitizer->email('student_email'), $sanitizer->number('student_age'));
    

    use Hyper\Utils\Validator;
    $validator = new Validator();
    dump($validator->validate([
        'name' => ['

    use Hyper\Helpers\Mail;
    $mail = new Mail();
    $mail->address('[email protected]', 'John Doe');
    $mail->replyTo('[email protected]');
    $mail->subject('Test Mail');
    $mail->body('Hello World, This is Test Mail From Shahin Moyshan');
    $mail->send();
    

    use Hyper\Model;
    use Hyper\Helpers\Orm;

    class Student extends Model {
        use Orm;

        protected function orm(): array {
            return [
                'department' => ['has' => 'one', 'model' => Department::class, 'lazy' => false],
                'subjects' => ['has' => 'many-x', 'model' => Subject::class, 'table' => 'students_subjects'],
                'results' => ['has' => 'many', 'model' => Result::class],
            ];
        }
    }

    dump(Student::with(['subjects', 'results', 'department'])->paginate(20));
    

    use Hyper\Model;
    use Hyper\Helpers\Uploader;

    class Student extends Model {
        use Uploader;

        protected function uploader(): array {
            return [
                [
                    'name' => 'photo',
                    'multiple' => false,
                    'uploadTo' => 'students', // sub directory
                    'maxSize' => 1048576, // 1MB
                    'compress' => 75,
                    'resize' => [540 => 540], // resize main uploaded image
                    'resizes' => [140 => 140, 60 => 60], // create new resized images
                ]
            ];
        }
    }