PHP code example of iviphp / framework

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

    

iviphp / framework example snippets




declare(strict_types=1);

use Ivi\Framework\Framework;

$framework = Framework::create(
    basePath: dirname(__DIR__),
    environment: 'development',
    consoleName: 'My Application',
    consoleVersion: '1.0.0'
);

$framework->start();

$basePath = $framework->basePath();

$configPath = $framework->path(
    'config/app.php'
);

$basePath = $framework->path();

$framework->path('../secret.txt');

$framework = Framework::create(
    basePath: dirname(__DIR__),
    environment: 'production'
);

$environment = $framework->environment();

if ($framework->isEnvironment('production')) {
    // Production configuration.
}

if (
    $framework->isEnvironment(
        'development',
        'testing'
    )
) {
    // Development or testing behavior.
}

$framework->setEnvironment('testing');

$container = $framework->container();

$service = $framework->make(
    App\Services\Mailer::class
);

if ($framework->has('mailer')) {
    $mailer = $framework->make('mailer');
}

use Ivi\Config\Config;
use Ivi\Container\Container;
use Ivi\Framework\Application;
use Ivi\Framework\Bootstrap\Bootstrapper;
use Ivi\Framework\Contracts\ApplicationInterface;
use Ivi\Framework\FrameworkManager;

$framework->make('app');
$framework->make(Application::class);
$framework->make(ApplicationInterface::class);

$framework->make('container');
$framework->make(Container::class);

$framework->make('config');
$framework->make(Config::class);

$framework->make('bootstrapper');
$framework->make(Bootstrapper::class);

$framework->make('framework');
$framework->make(FrameworkManager::class);

$framework->make('console');
$framework->make('console.manager');

$config = $framework->config();



declare(strict_types=1);

use Ivi\Config\Config;
use Ivi\Framework\Framework;

$config = new Config();

$framework = Framework::create(
    basePath: dirname(__DIR__),
    config: $config
);



declare(strict_types=1);

use Ivi\Container\Container;
use Ivi\Framework\Framework;

$container = new Container();

$framework = Framework::create(
    basePath: dirname(__DIR__),
    container: $container
);

use Ivi\Framework\Contracts\ApplicationInterface;

$framework->bootstrapWith(
    'load.configuration',
    static function (
        ApplicationInterface $application
    ): void {
        $configPath = $application->path(
            'config/app.php'
        );

        if (is_file($configPath)) {
            $values = 

$framework->bootstrapWith(
    'prepare.storage',
    static function (
        ApplicationInterface $application
    ): void {
        $storagePath = $application->path(
            'storage'
        );

        if (!is_dir($storagePath)) {
            mkdir(
                $storagePath,
                0775,
                true
            );
        }
    }
);

$framework->bootstrapWith(
    'load.configuration',
    static function (
        ApplicationInterface $application
    ): void {
        // Updated initialization.
    },
    replace: true
);

$bootstrapper = $framework->bootstrapper();

$names = $bootstrapper->names();

$executed = $bootstrapper->executed();

if ($bootstrapper->has('load.configuration')) {
    // Operation registered.
}

if (
    $bootstrapper->hasExecuted(
        'load.configuration'
    )
) {
    // Operation completed.
}

$current = $bootstrapper->current();



declare(strict_types=1);

namespace App\Providers;

use App\Services\Mailer;
use Ivi\Framework\Providers\ServiceProvider;

final class MailServiceProvider extends ServiceProvider
{
    public function __construct(
        \Ivi\Framework\Contracts\ApplicationInterface $application
    ) {
        parent::__construct(
            $application,
            [
                Mailer::class,
                'mailer',
            ]
        );
    }

    protected function registerServices(): void
    {
        $mailer = new Mailer();

        $this->container()->instance(
            Mailer::class,
            $mailer
        );

        $this->container()->instance(
            'mailer',
            $mailer
        );
    }

    protected function bootServices(): void
    {
        $mailer = $this->make(
            Mailer::class
        );

        $mailer->initialize();
    }
}

use App\Providers\MailServiceProvider;

$framework->provider(
    MailServiceProvider::class
);

$provider = new MailServiceProvider(
    $framework->application()
);

$framework->provider($provider);

$framework->providers([
    App\Providers\ConfigServiceProvider::class,
    App\Providers\DatabaseServiceProvider::class,
    App\Providers\MailServiceProvider::class,
]);

protected function registerServices(): void
{
    // Register container bindings.
}

protected function bootServices(): void
{
    // Resolve services and complete initialization.
}

$provider = $framework->getProvider(
    App\Providers\MailServiceProvider::class
);

if ($provider->isRegistered()) {
    // Provider registration completed.
}

if ($provider->isBooted()) {
    // Provider boot completed.
}

$provider->isRegistering();
$provider->isBooting();

public function __construct(
    ApplicationInterface $application
) {
    parent::__construct(
        $application,
        [
            App\Services\Mailer::class,
            'mailer',
        ]
    );
}

$services = $provider->provides();

if ($provider->providesService('mailer')) {
    // Provider declares the mailer service.
}

$providers = $framework->providersFor(
    'mailer'
);

use App\Providers\MailServiceProvider;

if (
    $framework->hasProvider(
        MailServiceProvider::class
    )
) {
    $provider = $framework->getProvider(
        MailServiceProvider::class
    );
}

$providers = $framework
    ->registeredProviders();

$count = $framework->providerCount();

$framework->bootstrap();

$framework->boot();

if ($framework->isBootstrapped()) {
    // Bootstrap operations completed.
}

if ($framework->isBooting()) {
    // Provider booting is active.
}

if ($framework->isBooted()) {
    // All providers completed booting.
}

if ($framework->isStarted()) {
    // Application is fully initialized.
}

$console = $framework->console();

$consoleManager = $framework
    ->consoleManager();



declare(strict_types=1);

use Ivi\Console\Contracts\InputInterface;
use Ivi\Console\Contracts\OutputInterface;

$framework->command(
    name: 'app:status',
    handler: static function (
        InputInterface $input,
        OutputInterface $output
    ): int {
        $output->success(
            'The application is running.'
        );

        return 0;
    },
    description: 'Display application status.',
    aliases: [
        'status',
    ],
    usage: 'app:status',
    hidden: false
);

$framework->registerCommand(
    new App\Console\Commands\CacheClearCommand()
);

$framework->registerCommands([
    new App\Console\Commands\CacheClearCommand(),
    new App\Console\Commands\DatabaseMigrateCommand(),
]);

$framework->registerCommands(
    $commands,
    replace: true
);

if ($framework->hasCommand('app:status')) {
    $command = $framework->getCommand(
        'app:status'
    );
}

$commands = $framework->commands();

$commands = $framework->commands(
    

$count = $framework->commandCount();

$exitCode = $framework->run();

exit($exitCode);

#!/usr/bin/env php


declare(strict_types=1);

racts\InputInterface;
use Ivi\Console\Contracts\OutputInterface;
use Ivi\Framework\Framework;

$framework = Framework::create(
    basePath: dirname(__DIR__),
    environment: getenv('APP_ENV')
        ?: 'production',
    consoleName: 'My Application',
    consoleVersion: '1.0.0'
);

$framework->command(
    name: 'hello',
    handler: static function (
        InputInterface $input,
        OutputInterface $output
    ): int {
        $name = $input->argument(
            0,
            'Developer'
        );

        $output->success(
            "Hello, {$name}."
        );

        return 0;
    },
    description: 'Display a greeting.',
    usage: 'hello [name]'
);

exit($framework->run());



declare(strict_types=1);

use Ivi\Console\Input\ArgvInput;
use Ivi\Console\Output\ConsoleOutput;

$input = ArgvInput::fromTokens([
    'hello',
    'Gaspard',
]);

$output = new ConsoleOutput();

$exitCode = $framework->execute(
    $input,
    $output
);

$application = $framework->application();

$application = $framework
    ->applicationContract();

public function basePath(): string;

public function path(
    string $path = ''
): string;

public function environment(): string;

public function isEnvironment(
    string ...$environments
): bool;

public function container(): Container;

public function config(): Config;

public function make(string $id): mixed;

public function has(string $id): bool;

public function register(
    ServiceProviderInterface|string $provider
): ServiceProviderInterface;

public function hasProvider(
    string $provider
): bool;

public function providers(): array;

public function bootstrap(): void;

public function isBootstrapped(): bool;

public function boot(): void;

public function isBooted(): bool;



declare(strict_types=1);

use Ivi\Framework\Application;

$application = new Application(
    basePath: dirname(__DIR__),
    environment: 'development'
);

$application->register(
    App\Providers\AppServiceProvider::class
);

$application->start();



declare(strict_types=1);

use Ivi\Framework\FrameworkManager;

$manager = FrameworkManager::create(
    basePath: dirname(__DIR__),
    environment: 'development',
    consoleName: 'My Application',
    consoleVersion: '1.0.0'
);

$manager->registerProviders([
    App\Providers\AppServiceProvider::class,
]);

$manager->start();

Ivi\Framework\Exceptions\FrameworkException



declare(strict_types=1);

use Ivi\Framework\Exceptions\FrameworkException;

try {
    $framework->start();
} catch (FrameworkException $exception) {
    echo $exception->getMessage();

    $context = $exception->context();
}

#!/usr/bin/env php


declare(strict_types=1);

pServiceProvider;
use App\Providers\DatabaseServiceProvider;
use Ivi\Console\Contracts\InputInterface;
use Ivi\Console\Contracts\OutputInterface;
use Ivi\Framework\Contracts\ApplicationInterface;
use Ivi\Framework\Framework;

$framework = Framework::create(
    basePath: dirname(__DIR__),
    environment: getenv('APP_ENV')
        ?: 'production',
    consoleName: 'Example Application',
    consoleVersion: '1.0.0'
);

$framework->bootstrapWith(
    'prepare.storage',
    static function (
        ApplicationInterface $application
    ): void {
        $storage = $application->path(
            'storage'
        );

        if (!is_dir($storage)) {
            mkdir(
                $storage,
                0775,
                true
            );
        }
    }
);

$framework->providers([
    AppServiceProvider::class,
    DatabaseServiceProvider::class,
]);

$framework->command(
    name: 'app:environment',
    handler: static function (
        InputInterface $input,
        OutputInterface $output
    ) use ($framework): int {
        $output->info(
            'Environment: '
            . $framework->environment()
        );

        return 0;
    },
    description: 'Display the application environment.',
    aliases: [
        'env',
    ]
);

exit($framework->run());
text
/project/config/app.php