Exemplo n.º 1
0
 /**
  * The class constructor - registers the main object in the
  * OPL registry.
  */
 public function __construct()
 {
     if (Opl_Registry::exists('opc')) {
         throw new Opc_CannotCreateAnotherInstance_Exception();
     }
     Opl_Registry::register('opc', $this);
 }
Exemplo n.º 2
0
 /**
  * @covers Opf_Class::__construct
  */
 public function testConstructorBasic()
 {
     $this->_optMock->expects($this->atLeastOnce())->method('register');
     Opl_Registry::register('opt', $this->_optMock);
     $opf = new Opf_Class();
     $this->assertTrue(Opl_Registry::exists('opf'));
 }
Exemplo n.º 3
0
 /**
  * The informator that prints the basic OPT configuration to the error
  * output.
  *
  * @param Opc_Exception $exception The exception
  */
 protected function _printBasicConfiguration($exception)
 {
     if (!Opl_Registry::exists('opc')) {
         return false;
     }
     $opc = Opl_Registry::get('opc');
     echo '<p class="directive">Caching directory: <span>' . htmlspecialchars($opc->cacheDir) . "</span></p>\r\n";
     echo '<p class="directive">Caching expiry time: <span>' . htmlspecialchars($opc->expiryTime) . "</span></p>\r\n";
 }
Exemplo n.º 4
0
 /**
  * Creates the new translation object.
  * 
  * @param Opc_Translate_Adapter $adapter The default translation adapter.
  */
 public function __construct(Opc_Translate_Adapter $adapter)
 {
     if (!Opl_Registry::exists('opc')) {
         throw new Opc_ClassInstanceNotExists_Exception();
     }
     $this->_opc = Opl_Registry::get('opc');
     $this->_defaultLanguage = $this->_opc->defaultLanugage;
     $this->_defaultAdapter = $adapter;
 }
Exemplo n.º 5
0
 /**
  * Returns the main OPL library class that threw the exception.
  *
  * @return Opl_Class The main class of the exception library.
  */
 public function getLibrary()
 {
     $name = explode('_', get_class_name($this));
     $name = strtolower($name[0]);
     if (Opl_Registry::exists($name)) {
         return Opl_Registry::get($name);
     }
     return null;
 }
Exemplo n.º 6
0
 /**
  * Creates the adapter and applies the options.
  * 
  * @param array $options The adapter options.
  */
 public function __construct(array $options = array())
 {
     if (!Opl_Registry::exists('opc')) {
         throw new Opc_ClassInstanceNotExists_Exception();
     }
     $this->_opc = Opl_Registry::get('opc');
     if (isset($options['directory'])) {
         $this->setDirectory($options['directory']);
     }
     if (isset($options['fileExistsCheck'])) {
         $this->_fileExistsCheck = (bool) $options['fileExistsCheck'];
     }
 }
Exemplo n.º 7
0
 /**
  * Creates a new caching object and connects to it.
  * 
  * @param array $options Options
  */
 public function __construct(array $options = array())
 {
     if (!Opl_Registry::exists('opc')) {
         throw new Opc_ClassInstanceNotExists_Exception();
     }
     $this->_opc = Opl_Registry::get('opc');
     if (isset($options['directory'])) {
         $this->setDirectory($options['directory']);
     }
     if (isset($options['expiryTime'])) {
         $this->setExpiryTime($options['expiryTime']);
     }
     if (isset($options['key'])) {
         $this->setKey($options['key']);
     }
 }
Exemplo n.º 8
0
 /**
  * Starts the console application. The method checks the action to run,
  * parses the arguments and fires it.
  *
  * @throws Opl_Console_Exception
  * @param array $argv The argument list.
  */
 public function run(array $argv)
 {
     $action = isset($argv[1]) ? $argv[1] : $this->_default;
     if (!Opl_Registry::exists('stdout')) {
         Opl_Registry::set('stdout', new Opl_Stream_Console_Output());
     }
     if (!Opl_Registry::exists('stdin')) {
         Opl_Registry::set('stdin', new Opl_Stream_Console_Input());
     }
     if (isset($this->_actions[$action])) {
         unset($argv[0], $argv[1]);
         $getopt = new Opl_Getopt(Opl_Getopt::ALLOW_LONG_ARGS | Opl_Getopt::ALLOW_SHORT_ARGS | Opl_Getopt::AUTO_HELP);
         foreach ($this->_actions[$action]->getParams() as $option) {
             $getopt->addOption($option);
         }
         if (!$getopt->parse(array_values($argv))) {
             // TODO: Exception goes here!
             return;
         }
         $this->runAction($action, $getopt->getIterator()->getArrayCopy());
     } else {
         if ($this->_flags & self::AUTO_HELP) {
             $this->showHelp();
         } else {
             throw new Opl_Console_Exception('The specified action \'' . $action . '\' does not exist.');
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Creates new paginator.
  * 
  * @param integer $all The amout of all items
  * @param integer $limit Items per page
  * @return void
  */
 public function __construct($all = null, $limit = null)
 {
     if (!Opl_Registry::exists('opc')) {
         throw new Opc_ClassInstanceNotExists_Exception();
     }
     $opc = Opl_Registry::get('opc');
     if (is_null($limit)) {
         $limit = $opc->itemsPerPage;
     }
     if (!is_null($opc->paginatorDecorator)) {
         $this->set('decorator', $opc->paginatorDecorator);
     }
     if (is_array($opc->paginatorDecoratorOptions)) {
         $this->decorator->loadConfig($opc->paginatorDecoratorOptions);
     }
     $this->set('all', $all);
     $this->set('limit', $limit);
 }
Exemplo n.º 10
0
 /**
  * Sets up the test suite.
  */
 protected function setUp()
 {
     if (!Opl_Registry::exists('opc')) {
         $opc = new Opc_Class();
     }
 }
Exemplo n.º 11
0
 /**
  * Performs the main initialization of OPT. If the optional argument `$config` is
  * specified, it is transparently sent to Opt_Class::loadConfig(). Before using this
  * method, we are obligated to configure the library and load the necessary extensions.
  *
  * @param mixed $config = null The optional configuration to be loaded
  */
 public function setup($config = null)
 {
     if (is_array($config)) {
         $this->loadConfig($config);
     }
     if ($this->pluginDir !== null) {
         $this->loadPlugins();
     }
     if ($this->cdfDir === null) {
         $this->cdfDir = $this->sourceDir;
     }
     if (Opl_Registry::exists('opl_translate')) {
         $this->setTranslationInterface(Opl_Registry::get('opl_translate'));
     }
     if (Opl_Registry::getState('opl_debug_console') || $this->debugConsole) {
         $this->debugConsole = true;
         Opt_Support::initDebugConsole($this);
     }
     // Register a default inflector, if the programmer didn't set any.
     if (!$this->_inflector instanceof Opt_Inflector_Interface) {
         $this->_inflector = new Opt_Inflector_Standard($this);
     }
     $this->_securePath($this->compileDir);
     $this->_init = true;
     return true;
 }
Exemplo n.º 12
0
 /**
  * @covers Opl_Registry::exists
  */
 public function testExistence()
 {
     Opl_Registry::set('foo', 'bar');
     $this->assertTrue(Opl_Registry::exists('foo'));
 }