PHP code example of d0niek / php-generic

1. Go to this page and download the library: Download d0niek/php-generic 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/ */

    

d0niek / php-generic example snippets


class UserRepository implements UserRepositoryInterface
{
    ...

    /**
     * @inheritDoc
     */
    public function findAll(): VectorUser
    {
        $users = new VectorUser();
        $mysqli = new \mysqli('localhost:3306', 'user', 'password', 'db');

        $mysqliResult = $mysqli->query('SELECT id, name FROM users LIMIT 10');
        if ($mysqliResult !== false) {
            while (($user = $mysqliResult->fetch_object(User::class)) !== null) {
                $users->push($user);
            }
        }

        $mysqli->close();

        return $users;
    }

    ...
}
bash
$ composer