Exemplo n.º 1
1
 /**
  * @throws \Exception
  */
 private function postProcess()
 {
     foreach ($this->config->PostProcessors as $processor) {
         if (Classes::validateProcessor($processor)) {
             $process = Factory::build($processor);
             $process->process($this);
         } else {
             throw new \Exception('Mongular: Attempt to access invalid processor ' . $this->request);
         }
     }
 }
Exemplo n.º 2
0
 public function testJsonFormatter()
 {
     $factory = new Factory();
     $format = $factory->build('json');
     $data = $format->convertToArray($this->rawData);
     $this->assertTrue(is_array($data));
     $this->assertCount(5, $data);
 }
Exemplo n.º 3
0
 public function getGuess($letter)
 {
     $hangman = Factory::build('Hangman');
     $this->template->hangman = $hangman;
     if ($hangman->guess(strtoupper($letter))) {
         $this->template->render('winner');
     }
     $this->template->render('guess');
 }
Exemplo n.º 4
0
 /**
  * @param $parameters
  * @param $class
  * @return array
  * @throws \Exception
  */
 private static function buildParameters($parameters, $class)
 {
     $di_params = array();
     foreach ($parameters as $key => $parameter) {
         $di_class = $parameter->getClass();
         if (is_object($di_class)) {
             $di_params[$parameter->name] = Factory::build('\\' . $di_class->name);
         } else {
             $error = 'Mongular DI error for Controller class ' . $class . ' on parameter ' . $parameter->name;
             throw new \Exception($error);
         }
     }
     return $di_params;
 }
Exemplo n.º 5
0
 public function getDefinition()
 {
     if (empty($this->definitions)) {
         $wordnik = Factory::build('Wordnik');
         $definitions = $wordnik->getDefinitions(strtolower($this->word));
         if (!is_null($definitions)) {
             foreach ($definitions as $definition) {
                 if (isset($definition->text)) {
                     $this->definition = str_ireplace($this->word, '[WORD]', $definition->text);
                     break;
                 }
             }
         }
     }
     return $this->definition;
 }
Exemplo n.º 6
0
 public static function set()
 {
     $num_args = func_num_args();
     if ($num_args === 1) {
         self::$config['url'] = self::URL;
         self::$config['key'] = func_get_arg(0);
         self::$config['url'] = Factory::build('account')->authenticate()->url;
     } elseif ($num_args === 2) {
         self::$config['url'] = $url = func_get_arg(0);
         if ($is_subdomain = strpos($url, '.') === false) {
             self::$config['url'] = self::URL;
         }
         self::$config['key'] = func_get_arg(1);
         if ($is_subdomain) {
             $url = Factory::build('account')->authenticate()->url;
         }
         self::$config['url'] = $url;
     }
 }
Exemplo n.º 7
0
 /**
  * @expectedException \Carpenter\FactoryNotFoundException
  * @expectedExceptionMessage "ImaginaryFactory" is not a registered factory
  */
 public function testNonExistentFactory()
 {
     Factory::build('ImaginaryFactory');
 }
Exemplo n.º 8
0
    public static function build($type)
    {
        $class = 'Format' . $type;
        if (!class_exists($class)) {
            throw new Exception('Missing format class.');
        }
        return new $class();
    }
}
/**
 * Class FormatString
 */
class FormatString implements Format
{
}
/**
 * Class FormatNumber
 */
class FormatNumber implements Format
{
}
try {
    $string = Factory::build('String');
} catch (Exception $e) {
    echo $e->getMessage();
}
try {
    $number = Factory::build('Number');
} catch (Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 9
0
 /**
  * Constructor.
  *
  * @param array $config
  */
 private final function __construct(array $config)
 {
     $this->db = Factory::build(new Configuration($config));
     $this->db->connect();
 }
Exemplo n.º 10
0
<?php

namespace Mongular\Core;

require '../../vendor/autoload.php';
$mongular = Factory::build('\\Mongular\\Core\\Mongular');
/*
 * Uncomment to add memcache support.
 */
//$mongular->addCache();
echo $mongular->build();
Exemplo n.º 11
0
 public function build(string $filter, callable $callback)
 {
     $conditions = $this->parser->parse($filter);
     list($predicates, $types, $rooms) = $this->compiler->compile($conditions);
     return $this->factory->build($filter, $predicates, $types, $rooms, $callback);
 }
Exemplo n.º 12
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
class Factory extends Rtablada\IbmDataStruct\StructFactory
{
    protected static $rules = ['name_short' => 22, 'name_long' => ['length' => 10]];
    protected static $structBuilderType = 'Rtablada\\IbmDataStruct\\IbmStructBuilder';
}
$factory = new Factory();
$values = ['name_long' => 'Ryan Tablada', 'name_short' => 'Ryan Tablada'];
echo $factory->build($values);
Exemplo n.º 13
0
 public function testBuildingFormatParser()
 {
     $factory = new Factory();
     $formatParser = $factory->build('json');
     $this->assertTrue(is_object($formatParser));
 }
Exemplo n.º 14
0
 /**
  * @expectedException Api\Exception\Controller
  */
 public function testIfWeCanBuildNonExistentController()
 {
     $factory = new Factory();
     $controller = $factory->build('InvalidController');
 }
Exemplo n.º 15
0
 /**
  * @param $name
  */
 public static function remove($name)
 {
     Factory::build(__CLASS__);
     unset($_SESSION[$name]);
 }