Overview

Namespaces

  • Net
    • Bazzline
      • Component
        • ApiDocumentBuilder
          • Builder
          • Command
          • Process
          • Requirement
          • Service

Classes

  • Net\Bazzline\Component\ApiDocumentBuilder\Builder\Apigen
  • Net\Bazzline\Component\ApiDocumentBuilder\Command\Builder
  • Net\Bazzline\Component\ApiDocumentBuilder\Command\CleanDirectory
  • Net\Bazzline\Component\ApiDocumentBuilder\Process\CreateNewProjectInTheCache
  • Net\Bazzline\Component\ApiDocumentBuilder\Requirement\CachedProjectHasChanges
  • Net\Bazzline\Component\ApiDocumentBuilder\Service\ApplicationLocator

Interfaces

  • Net\Bazzline\Component\ApiDocumentBuilder\Builder\BuilderInterface

Exceptions

  • Net\Bazzline\Component\ApiDocumentBuilder\Service\InvalidArgumentException
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 
<?php
/**
 * @author Net\Bazzline\Component\Locator
 * @since 2015-06-07
 */

namespace Net\Bazzline\Component\ApiDocumentBuilder\Service;

/**
 * Class ApplicationLocator
 *
 * @package Net\Bazzline\Component\ApiDocumentBuilder\Service
 */
class ApplicationLocator
{
    /**
     * @var $sharedInstancePool
     */
    private $sharedInstancePool = array();

    /**
     * @return \Net\Bazzline\Component\Cli\Arguments\Arguments
     */
    public function getCliArguments()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\Cli\Arguments\Arguments');
    }

    /**
     * @return \Net\Bazzline\Component\Cli\ProgressBar\ProgressBar
     */
    public function getCliProgressBar()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\Cli\ProgressBar\ProgressBar');
    }

    /**
     * @return \Net\Bazzline\Component\ApiDocumentBuilder\Builder\Apigen
     */
    public function getApigenBuilder()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\ApiDocumentBuilder\Builder\Apigen');
    }

    /**
     * @return \Net\Bazzline\Component\CommandCollection\Filesystem\Create
     */
    public function getCreateDirectory()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\CommandCollection\Filesystem\Create');
    }

    /**
     * @return \Net\Bazzline\Component\CommandCollection\Vcs\Git
     */
    public function getGit()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\CommandCollection\Vcs\Git');
    }

    /**
     * @return \Net\Bazzline\Component\CommandCollection\Filesystem\Remove
     */
    public function getRemoveDirectory()
    {
        return $this->fetchFromSharedInstancePool('\Net\Bazzline\Component\CommandCollection\Filesystem\Remove');
    }

    /**
     * @param string $className
     * @return object
     * @throws InvalidArgumentException
     */
    final protected function fetchFromSharedInstancePool($className)
    {
        if ($this->isNotInSharedInstancePool($className)) {
            if (!class_exists($className)) {
                throw new InvalidArgumentException(
                    'class "' . $className . '" does not exist'
                );
            }
            
            $instance = new $className();
            $this->addToSharedInstancePool($className, $instance);
        }

        return $this->getFromSharedInstancePool($className);
    }

    /**
     * @param string $className
     * @param object $instance
     * @return $this
     */
    private function addToSharedInstancePool($className, $instance)
    {
        $this->sharedInstancePool[$className] = $instance;

        return $this;
    }

    /**
     * @param string $className
     * @return null|object
     */
    private function getFromSharedInstancePool($className)
    {
        return $this->sharedInstancePool[$className];
    }

    /**
     * @param string $className
     * @return boolean
     */
    private function isNotInSharedInstancePool($className)
    {
        return (!isset($this->sharedInstancePool[$className]));
    }
}
PHP Api Document Builder by bazzline.net API documentation generated by ApiGen