PHP code example of innmind / hash

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

    

innmind / hash example snippets


use Innmind\OperatingSystem\Factory;
use Innmind\Url\Path;
use Innmind\Hash\{
    Hash,
    Value,
};
use Innmind\Immutable\Set;

$hashes = Factory::build()
    ->filesystem()
    ->mount(Path::of('some-folder/'))
    ->all()
    ->map(Hash::sha512->ofFile(...));
$hashes; // Set<Value>

use Innmind\OperatingSystem\Factory;
use Innmind\Http\{
    Message\Request\Request,
    Message\Method,
    ProtocolVersion,
};
use Innmind\Url\Url;
use Innmind\Server\Control\Server\Command;
use Innmind\Hash\{
    Hash,
    Value,
};

$os = Factory::build();
$os
    ->remote()
    ->http()(new Request(
        Url::of('https://github.com'),
        Method::get,
        ProtocolVersion::v20,
    ))
    ->map(static fn($success) => $success->response()->content())
    ->map(Hash::sha512->ofContent(...))
    ->match(
        static fn($value) => $value, // Value
        static fn() => null, // http call failed
    );

$output = $os
    ->control()
    ->processes()
    ->execute(
        Command::foreground('git')
            ->withOption('version'),
    )
    ->output()
    ->chunks()
    ->map(static fn($chunk) => $chunk[0]); // to only keep the chunk data

Hash::sha512->ofSequence($output); // Value