/** * Init the Symfony Console Provider * * @return BaseController */ protected function initSymfonyConsoleProvider() { if (!$this->mvc->hasCvpp('symfony.console')) { $this->mvc->registerProvider(new ConsoleSymfonyProvider(array('modules' => $this->mvc->setModules(), 'commands' => array(new ListCommand())))); } return $this; }
/** * {@inheritdoc} */ public function register(MVC $mvc) { $this->pdo = new PDO($this->options['dsn'], $this->options['user'], $this->options['passwd'], $this->options['driverOptions']); if (!$mvc->hasCvpp('pdo')) { $mvc->setCvpp('pdo', $this->pdo); } }
/** * Register the properties of the Doctrine DBAL Provider * @access public * @param MVC $mvc * @return void */ public function register(MVC $mvc) { if (!$mvc->hasCvpp('dbal')) { $mvc->setCvpp('dbal', $this->connection); } $config = new Configuration(); $this->connection = DriverManager::getConnection($this->options, $config); }
/** * Example of index action for someone route with the use of the a User model * Using the render view * * @access public * @param MVC $mvc * @return string * @throws \LogicException */ public function index(MVC $mvc) { if (!$mvc->hasCvpp('pdo')) { throw new \LogicException('PDO don\'t exists. Register the MVC\\DataBase\\PdoProvider for use this function.'); } $userModel = new User($mvc->getCvpp('pdo')); $users = $userModel->findAll(); return $mvc->view()->render('User/index.html', array('users' => $users)); }
/** * Register the properties of the Monolog Provider * @access public * @param MVC $mvc * @return void */ public function register(MVC $mvc) { $defaultOptions = array('log_file' => $mvc->getAppDir() . '/logs/app_name.log', 'log_name' => 'app_name'); $options = array_merge($defaultOptions, $this->options); $logger = new Logger($options['log_name']); $logger->pushHandler(new StreamHandler($options['log_file'])); if (!$mvc->hasCvpp('monolog')) { $mvc->setCvpp('monolog', $logger); } }
/** * Register the Console Symfony * * @access public * @param MVC $mvc */ public function register(MVC $mvc) { $application = new Application('Simple PHP MVC', '1.5'); if (!$mvc->hasCvpp('symfony.console')) { $mvc->setCvpp('symfony.console', $application); } foreach ($this->modules as $module) { $module->registerCommands($mvc->getCvpp('symfony.console')); } }
/** * Register the properties of the Doctrine ORM Provider * * @access public * @param MVC $mvc * @return void */ public function register(MVC $mvc) { $default_options = array('params' => array('charset' => null, 'driver' => 'pdo_mysql', 'dbname' => null, 'host' => 'localhost', 'user' => 'root', 'password' => null, 'port' => null), 'dev_mode' => false, 'etities_type' => 'annotations', 'path_entities' => array(), 'proxy_dir' => null); $options = array_merge($default_options, $this->options); if (empty($options['path_entities']) || !is_array($options['path_entities'])) { throw new \Exception('Option path_entities should be an array of path files entities.'); } if ($options['etities_type'] == 'annotations') { $config = Setup::createAnnotationMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } elseif ($options['etities_type'] == 'yaml' || $options['etities_type'] == 'yml') { $config = Setup::createYAMLMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } elseif ($options['etities_type'] == 'xml') { $config = Setup::createXMLMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } if ($mvc->hasCvpp('dbal')) { $entityManager = EntityManager::create($mvc->getCvpp('dbal'), $config); } else { $entityManager = EntityManager::create($options['params'], $config); } if (!$mvc->hasCvpp('dbal')) { $mvc->setCvpp('dbal', $entityManager->getConnection()); } $mvc->setCvpp('em', $entityManager); }