Exemplo n.º 1
0
 public function __construct($options = [])
 {
     if (is_string($options)) {
         $this->options['email'] = $options;
         unset($options);
     }
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     if (empty($this->options['lang'])) {
         $this->options['lang'] = self::DefaultLang;
     }
     // Apply configuration
     EmbeDi::fly()->apply($this->options, $this);
     // Setup view
     $this->mv = new MiniView($this);
     //		var_dump($_POST);
     if (!empty($_POST['ContactForm'])) {
         $data = (object) $_POST['ContactForm'];
         if (!isset($data->name)) {
             $data->name = $data->email;
         }
         if (!isset($data->subject)) {
             $data->subject = substr($data->body, 0, 32);
         }
         if ($this->validate($data)) {
             $email = $this->mv->render(sprintf('%s/%s', $this->lang, 'contact-email'), ['data' => $data], true);
             $headers = "MIME-Version: 1.0" . "\r\n";
             $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
             $headers .= "From: <{$this->email}>" . "\r\n";
             $headers .= "Reply-to: {$data->name} <{$data->email}>" . "\r\n";
             $this->success = mail($this->email, $data->subject, $email, $headers);
         }
     }
 }
Exemplo n.º 2
0
 public function testIfWIllApplyConfigurationFromArrayUsingFlyweightInstances()
 {
     $config = ['scalar' => 'one', 'foo' => ['blah' => 'new', 'class' => 'EmbeDiTest\\Models\\FooSubComponent'], 'bar' => ['name' => 'Tequila', 'class' => 'EmbeDiTest\\Models\\BarSubComponent'], 'class' => 'EmbeDiTest\\Models\\CompoundComponent'];
     foreach ([1, 2, 3] as $id) {
         $config['scalar'] = $id;
         $comp = EmbeDi::fly()->apply($config);
         /* @var $comp CompoundComponent */
         $this->assertInstanceOf(CompoundComponent::class, $comp);
         $this->assertSame($config['scalar'], $comp->scalar);
         $this->assertInstanceOf(FooSubComponent::class, $comp->foo);
         $this->assertSame($config['foo']['blah'], $comp->foo->blah);
         $this->assertInstanceOf(BarSubComponent::class, $comp->bar);
         $this->assertSame($config['bar']['name'], $comp->bar->name);
     }
     // Configure second instance
     // This instance have different `classField`
     new EmbeDi('second', null, ['classField' => '_cls']);
     $config = ['scalar' => 'one', 'foo' => ['blah' => 'new', '_cls' => 'EmbeDiTest\\Models\\FooSubComponent'], 'bar' => ['name' => 'Tequila', '_cls' => 'EmbeDiTest\\Models\\BarSubComponent'], '_cls' => 'EmbeDiTest\\Models\\CompoundComponent'];
     foreach ([1, 2, 3] as $id) {
         $config['scalar'] = $id;
         $comp = EmbeDi::fly('second')->apply($config);
         /* @var $comp CompoundComponent */
         $this->assertInstanceOf(CompoundComponent::class, $comp);
         $this->assertSame($config['scalar'], $comp->scalar);
         $this->assertInstanceOf(FooSubComponent::class, $comp->foo);
         $this->assertSame($config['foo']['blah'], $comp->foo->blah);
         $this->assertInstanceOf(BarSubComponent::class, $comp->bar);
         $this->assertSame($config['bar']['name'], $comp->bar->name);
     }
 }
Exemplo n.º 3
0
 public function __construct($options = [])
 {
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     // Apply configuration
     EmbeDi::fly()->apply($this->options, $this);
     // Setup view
     $this->mv = new MiniView($this);
 }
Exemplo n.º 4
0
 public function get($configName)
 {
     foreach ($this->storage->sources as $configs) {
         foreach ($configs as $name => $config) {
             if ($name === $configName) {
                 return EmbeDi::fly($this->_instanceId, $this->_presetId)->apply($config);
             }
         }
     }
 }
Exemplo n.º 5
0
 public function __construct($configName = self::DefaultInstanceId)
 {
     $config = new ConfigReader($configName);
     $di = EmbeDi::fly($configName);
     $di->apply($config->toArray(), $this);
     $di->configure($this);
     if (is_string($this->logger)) {
         $loggerClass = $this->logger;
         $this->logger = new $loggerClass();
     }
 }
Exemplo n.º 6
0
 public function __construct($options = [])
 {
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     // Apply configuration
     EmbeDi::fly()->apply($this->options, $this);
     // Setup view
     $this->mv = new MiniView($this);
     // Set auto id if id is default
     if ($this->id === self::DefaultId && self::$idCounter > 0) {
         $this->id = sprintf('%s-%d', $this->id, self::$idCounter++);
     }
 }
Exemplo n.º 7
0
 public function testIfWillConfigureFromArrayWithPresetWithFlyInComponent()
 {
     $config = ['preseted' => ['one' => ['class' => PresetedComponentFly::class, 'scalar' => 'fxx', 'bar' => ['class' => BarSubComponent::class, 'name' => 'Razmatazz']], 'two' => ['class' => PresetedComponentFly::class, 'scalar' => 'ccc', 'bar' => ['class' => BarSubComponent::class, 'name' => 'Cheyenne']]]];
     // Helper arrays
     $cfg1 = $config['preseted']['one'];
     $cfg2 = $config['preseted']['two'];
     EmbeDi::fly()->addAdapter(new ArrayAdapter($config));
     $comp1 = new PresetedComponentFly('preseted', 'one');
     $this->assertSame($cfg1['scalar'], $comp1->scalar);
     $this->assertInstanceOf(BarSubComponent::class, $comp1->bar);
     $this->assertSame($cfg1['bar']['name'], $comp1->bar->name);
     $comp2 = new PresetedComponentFly('preseted', 'two');
     $this->assertSame($cfg2['scalar'], $comp2->scalar);
     $this->assertInstanceOf(BarSubComponent::class, $comp2->bar);
     $this->assertSame($cfg2['bar']['name'], $comp2->bar->name);
 }
Exemplo n.º 8
0
 public function __construct($options = [])
 {
     if (is_string($options)) {
         $this->options['path'] = $options;
         unset($options);
     }
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     if (empty($this->options['path'])) {
         $this->options['path'] = self::DefaultPath;
     }
     // Apply configuration
     EmbeDi::fly()->apply($this->options, $this);
     // Setup view
     $this->view = new MiniView($this);
     $this->path = sprintf('%s/%s', Staple::fly()->getContentPath(), $this->options['path']);
 }
Exemplo n.º 9
0
 /**
  * Set pagination
  * @param boolean|array|PaginationInterface $pagination
  * @return static
  */
 public function setPagination($pagination)
 {
     // Disable pagination completely
     if (false === $pagination) {
         $this->pagination = false;
         return $this;
     }
     // Configure from array
     if (is_array($pagination)) {
         if (empty($pagination['class'])) {
             $pagination['class'] = Pagination::class;
         }
         $this->pagination = EmbeDi::fly()->apply($pagination);
         return $this;
     }
     // Set object instance
     if ($pagination instanceof PaginationInterface) {
         $this->pagination = $pagination;
         return $this;
     }
     throw new UnexpectedValueException(sprintf('Expected `false` or `array` or `%s`, got %s', PaginationInterface::class, is_object($pagination) ? get_class($pagination) : gettype($pagination)));
 }
Exemplo n.º 10
0
 public function __construct($configName = self::ConfigName)
 {
     $this->loggerInstance = new NullLogger();
     /**
      * TODO This should be made as embedi adapter, currently unsupported
      */
     $config = new ConfigReader($configName);
     $this->di = EmbeDi::fly($configName);
     $this->di->configure($this);
     $this->di->apply($config->toArray(), $this);
 }
Exemplo n.º 11
0
 public function __construct($instanceId = EmbeDi::DefaultInstanceId, $presetId = null)
 {
     $this->_di = EmbeDi::fly($instanceId, $presetId);
     $this->_di->configure($this);
 }
Exemplo n.º 12
0
 /**
  *
  * @param string $rootPath
  */
 public function __construct($rootPath = '')
 {
     $this->di = EmbeDi::fly();
     $this->setRootPath($rootPath);
 }
Exemplo n.º 13
0
 /**
  * Create new mangan instance.
  *
  * **NOTE: While it's ok to use constructor to create Mangan, it is recommended to use
  * Mangan::fly() to create/get instance, as creating new instance has some overhead.**
  * 
  * @param string $connectionId
  */
 public function __construct($connectionId = self::DefaultConnectionId)
 {
     $this->di = EmbeDi::fly($connectionId);
     // Load built-in config
     $config = ConfigManager::getDefault();
     // Gather additional config options via signals
     (new Signal())->emit(new ConfigInit($config, $connectionId));
     // Apply built-in configuration, as other configurations might not exists
     $this->di->apply($config, $this);
     if (empty($connectionId)) {
         $connectionId = self::DefaultConnectionId;
     }
     $this->connectionId = $connectionId;
     // Apply any configurations loaded
     $this->di->configure($this);
     $this->cs = new ConnectionStorage($this, $connectionId);
     if (empty(self::$mn[$connectionId])) {
         self::$mn[$connectionId] = $this;
     }
 }