PHP code example of mtownsend / progress

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

    

mtownsend / progress example snippets


use Mtownsend\Progress\Progress;
use Mtownsend\Progress\Step;

$progress = (new Progress(
    (new Step(31, 'Age'))
        ->notEmpty()
        ->integer()
        ->between(18, 65)
))->get();

// Output:
[
  "total_steps" => 1
  "percentage_complete" => 100.0
  "percentage_incomplete" => 0.0
  "steps_complete" => 1
  "steps_incomplete" => 0
  "complete_step_names" => [
    0 => "Age"
  ]
  "incomplete_step_names" => []
]

use Mtownsend\Progress\Progress;
use Mtownsend\Progress\Step;

$step1 = (new Step('https://marktownsend.rocks', 'Portfolio Site'))->url();
$step2 = (new Step(4, 'Bronze Level Developer'))->integer()->between(1, 5);
$progress = (new Progress($step1, $step2));

$progress->get();

// or an array of Steps
$steps = [
    (new Step('https://marktownsend.rocks', 'Web Site'))->url(),
    (new Step('Laravel Developer', 'Profession'))->notEmpty()->contains('Laravel'),
    (new Step(true, 'Premier Member'))->boolean()->true()
];
$progress = new Progress($steps);

$progress->get();

$step = step('https://marktownsend.rocks', 'Web Site')->url();
$progress = progress($step)->get();

// or an array of Steps
$steps = [
    step('https://marktownsend.rocks', 'Web Site')->url(),
    step('Laravel Developer', 'Profession')->contains('Laravel'),
    step(true, 'Premier Member')->boolean()->true()
];
$progress = progress($steps)->get();

new Progress(mixed Mtownsend\Progress\Step|array $steps);

$steps = [
    (new Step(42, 'Answer To Everything'))->integer(),
    (new Step('https://github.com/mtownsend5512', 'Github Profile'))->notEmpty()->url(),
    (new Step(10, 'Open Source Packages'))->notEmpty()->integer(),
];
$progress = new Progress($steps);
$progress->get();

// Outputs:
[
  "total_steps" => 3
  "percentage_complete" => 100.0
  "percentage_incomplete" => 0.0
  "steps_complete" => 3
  "steps_incomplete" => 0
  "complete_step_names" => [
    0 => "Answer To Everything"
    1 => "Github Profile"
    2 => "Open Source Packages"
  ]
  "incomplete_step_names" => []
]

// To retrieve percentage_complete you can simply do:
$progress->percentage_complete; // 100.0

new Step(mixed $data, string $name);

$step->alnum()
->base64()
->between(mixed $lowerLimit, mixed $upperLimit)
->betweenExclusive(mixed $lowerLimit, mixed $upperLimit)
->betweenLength(int $minLength, int $maxLength)
->boolean()
->choice(array $choices)
->choicesNotEmpty(array $choices)
->classExists()
->contains(string $needle)
->count(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count)
->date(string $value, string $format)
->defined(mixed $constant)
->digit()
->directory()
->e164()
->email()
->endsWith(string $needle)
->eq(mixed $value)
->eqArraySubset(mixed $value)
->extensionLoaded()
->extensionVersion(string $extension, string $operator, mixed $version)
->false()
->file()
->float()
->greaterOrEqualThan(mixed $limit)
->greaterThan(mixed $limit)
->implementsInterface(mixed $class, string $interfaceName)
->inArray(array $choices)
->integer()
->integerish()
->interfaceExists()
->ip(int $flag = null)
->ipv4(int $flag = null)
->ipv6(int $flag = null)
->isArray()
->isArrayAccessible()
->isCallable()
->isCountable()
->isInstanceOf(string $className)
->isJsonString()
->isObject()
->isResource()
->isTraversable()
->keyExists(string|int $key)
->keyIsset(string|int $key)
->keyNotExists(string|int $key)
->length(int $length)
->lessOrEqualThan(mixed $limit)
->lessThan(mixed $limit)
->max(mixed $maxValue)
->maxCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count)
->maxLength(int $maxLength)
->methodExists(mixed $object)
->min(mixed $minValue)
->minCount(array|Countable|ResourceBundle|SimpleXMLElement $countable, int $count)
->minLength(int $minLength)
->noContent()
->notBlank()
->notContains(string $needle)
->notEmpty()
->notEmptyKey(string|int $key)
->notEq(mixed $value)
->notInArray(array $choices)
->notIsInstanceOf(string $className)
->notNull()
->notRegex(string $pattern)
->notSame(mixed $value)
->null()
->numeric()
->objectOrClass()
->phpVersion(string $operator, mixed $version)
->propertiesExist(array $properties)
->propertyExists(string $property)
->range(mixed $minValue, mixed $maxValue)
->readable()
->regex(string $pattern)
->same(mixed $value)
->satisfy(callable $callback)
->scalar(mixed $value)
->startsWith(string $needle)
->string()
->subclassOf(string $className)
->true()
->uniqueValues()
->url()
->uuid()
->version(string $version1, string $operator, string $version2)
->writeable();