PHP code example of krak / peridocs

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

    

krak / peridocs example snippets




use Krak\Peridocs;

return function($emitter) {
    // the second parameter is optional and is used to configure the DocsContext
    Peridocs\bootstrap($emitter, function() {
        return new DocsContext(null, [
            'headerFmt' => '<h3 id="{id}">{signature}</h3>',
            'showLinks' => false,
            'nsPrefix' => 'Acme\\Prefix\\',
            'numTableRows' => 4,
        ]);
    });
};

// function to test
function addMaybe(int $a, int $b): int {
    return $a == $b ? $a * $a : $a + $b;
}

// in some spec.php file
describe('Demo Package', function() {
    describe('addMaybe', function() {
        docFn(addMaybe::class); // this is the fully qualified name for the function e.g. 'Acme\Prefix\addMaybe'
        docIntro('`addMaybe` optional foreword/introduction.');

        it('usually adds two numbers together', function() {
            expect(addMaybe(1, 2))->equal(3);
        });
        it('but will multiply the two numbers when they are equal', function() {
            expect(addMaybe(3, 3))->equal(9);
        });

        docOutro('This is the optional outro/conclusion to be appended to the text');
    });
});

    expect(addMaybe(1, 2))->equal(3);
    

    expect(addMaybe(3, 3))->equal(9);