PHP Classes

File: App/Console/ArgumentHolder.php

Recommend this page to a friend!
  Classes of Igor Dyshlenko   PHP Image Crawler   App/Console/ArgumentHolder.php   Download  
File: App/Console/ArgumentHolder.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Image Crawler
Crawl Web site pages to find images in the pages
Author: By
Last change:
Date: 2 years ago
Size: 989 bytes
 

Contents

Class file image Download
<?php


namespace App\Console;


class
ArgumentHolder
{
   
/**
     * @var array
     */
   
private $parameters = [];

   
/**
     * @var array
     */
   
private $options = [];

    public function
__construct()
    {
       
$args = $_SERVER['argv'];
        for (
$i=1, $iMax = count($args); $i < $iMax; $i++) {
           
$argument = $args[$i];
            if ((
$argument[0] ?? '') === '-') {
               
$this->options[$argument[1] ?? ''] = substr($argument, 2);
            } else {
               
$this->parameters[] = $argument;
            }
        }
    }

   
/**
     * @param int $paramName
     *
     * @return string|null
     */
   
public function getParameter(int $paramName): ?string
   
{
        return
$this->parameters[$paramName] ?? null;
    }

   
/**
     * @param string $optionName
     *
     * @return string|null
     */
   
public function getOption(string $optionName): ?string
   
{
        return
$this->options[$optionName] ?? null;
    }
}