예제 #1
0
 protected static function getService()
 {
     //TODO: caching
     $config = Config::get('database');
     $serviceName = $config['service'];
     return Virge::service($serviceName);
 }
예제 #2
0
 /**
  * Commit our migrations, pass in a directory will read all files within
  * and commit them as migrations
  * @param string $dir
  */
 public function commitMigrations($dir)
 {
     $fileArray = Virge::dirToArray($dir);
     //TODO: use the Virge ORM
     $sql = "SELECT DISTINCT(`filename`) AS `file` FROM `virge_migration`";
     $result = Database::query($sql);
     $existing = array();
     foreach ($result as $row) {
         $existing[] = $row['file'];
     }
     $files = $fileArray['file'];
     uasort($files, function ($a, $b) use($dir) {
         $aFilename = pathinfo($a, PATHINFO_FILENAME);
         $aDateTime = \DateTime::createFromFormat('Y-m-d-H-i-s', substr($aFilename, strlen($aFilename) - 19));
         $bFilename = pathinfo($b, PATHINFO_FILENAME);
         $bDateTime = \DateTime::createFromFormat('Y-m-d-H-i-s', substr($bFilename, strlen($bFilename) - 19));
         if ($aDateTime < $bDateTime) {
             return -1;
         }
         if ($aDateTime > $bDateTime) {
             return 1;
         }
         if (filemtime($dir . $a) < filemtime($dir . $b)) {
             return 1;
         }
         return -1;
     });
     foreach ($files as $file) {
         if (!in_array($file, $existing)) {
             include $dir . $file;
             $this->logMigration($file);
         }
     }
 }
예제 #3
0
 /**
  * Listen on the given event, and call our callable
  * @param Event $event
  * @return boolean
  * @throws \RuntimeException
  */
 public function listen(Event $event)
 {
     if (is_callable($this->getCallable())) {
         return call_user_func_array($this->getCallable(), array($event));
     }
     if ($this->getMethod() && ($service = Virge::service($this->getCallable()))) {
         return call_user_func_array(array($service, $this->getMethod()), array($event));
     }
     throw new \RuntimeException(sprintf("Invalid listener: %s, cannot listen on event type: %s", get_class($this), get_class($event)));
 }
예제 #4
0
 /**
  * Route a web request
  */
 public function route($uri = null)
 {
     $request = $this->_buildRequest($uri);
     foreach (Routes::getResolvers() as $resolverConfig) {
         $resolver = $resolverConfig['resolver'];
         if (is_string($resolver) && Virge::service($resolver)) {
             $resolver = Virge::service($resolver);
         }
         $method = $resolverConfig['method'];
         if (false !== ($response = call_user_func_array(array($resolver, $method), array($request)))) {
             if ($response instanceof Response) {
                 $response->send();
             } else {
                 $response = new Response($response);
                 $response->send();
             }
             return true;
         }
     }
     $route = $this->_getRoute($request->getURI());
     if (!$route) {
         throw new NotFoundException();
     }
     if (!$route->access()) {
         throw new UnauthorizedAccessException();
     }
     $route->setActive(true);
     if (is_callable($route->getContoller())) {
         return call_user_func($route->getController(), $request);
     }
     $controllerClassname = $route->getController();
     $controller = new $controllerClassname();
     $method = $route->getMethod();
     $response = call_user_func_array(array($controller, $method), array($request));
     if ($response instanceof Response) {
         $response->send();
     } else {
         $response = new Response($response);
         $response->send();
     }
 }
예제 #5
0
<?php

use Virge\Virge;
/**
 * Registers all given handlers with Virge that this Capsule contains
 * @author Michael Kramer
 */
Virge::registerService("router", "\\Virge\\Router\\Service\\RouterService");
Virge::registerService("templating", "\\Virge\\Router\\Service\\TemplateService");
예제 #6
0
<?php

use Virge\Cron\Service\ExpressionService;
use Virge\Cron\Service\JobService;
use Virge\Cron\Service\ScheduleService;
use Virge\Virge;
/**
 * 
 * @author Michael Kramer
 */
Virge::registerService(ExpressionService::SERVICE_ID, new ExpressionService());
Virge::registerService(JobService::SERVICE_ID, new JobService());
Virge::registerService(ScheduleService::SERVICE_ID, new ScheduleService());
예제 #7
0
 /**
  * @return ExpressionService
  */
 protected function getExpressionService()
 {
     return Virge::service(ExpressionService::SERVICE_ID);
 }
예제 #8
0
<?php

use Virge\Virge;
/**
 * 
 * @author Michael Kramer
 */
Virge::registerService('virge/database', '\\Virge\\Database\\Service\\DatabaseService');
Virge::registerService('virge/schema', '\\Virge\\Database\\Service\\SchemaService');
예제 #9
0
<?php

use Virge\Event\Service\EventService;
use Virge\Virge;
/**
 * 
 * @author Michael Kramer
 */
Virge::registerService(EventService::SERVICE_ID, new EventService());
예제 #10
0
<?php

use Virge\Graphite\Service\QueueService;
use Virge\Virge;
/**
 * 
 * @author Michael Kramer
 */
Virge::registerService(QueueService::SERVICE_ID, new QueueService());
예제 #11
0
 /**
  * Compile the config
  */
 public static function compile()
 {
     $configPath = self::get('app_path') . 'config/';
     $configFiles = Virge::dirToArray($configPath);
     $distConfigs = array();
     if ($configFiles) {
         foreach ($configFiles['file'] as $configFile) {
             if (strpos($configFile, '.dist') === false) {
                 continue;
             }
             $configName = self::getConfigNameFromFile($configFile);
             $distConfigs[$configName] = (include_once $configPath . $configFile);
         }
     }
     $compiledConfig = array();
     foreach (self::$_config as $name => $config) {
         if (isset($distConfigs[$name])) {
             $distConfig = $distConfigs[$name];
             $compiledConfig[$name] = array_replace_recursive($distConfig, $config);
         } else {
             $compiledConfig[$name] = $config;
         }
     }
     file_put_contents($configPath . '_compiled.php', serialize($compiledConfig));
 }
예제 #12
0
 /**
  * Register a handler with a given short-name, which maps to the given 
  * class
  * @param string $serviceName
  * @param string $serviceClass
  */
 public static function registerService($serviceName, $serviceClass)
 {
     Virge::registerService($serviceName, $serviceClass);
 }
예제 #13
0
 /**
  * @return QueueService
  */
 protected function getQueueService()
 {
     return Virge::service(QueueService::SERVICE_ID);
 }
예제 #14
0
 protected static function service($serviceId)
 {
     return Virge::service($serviceId);
 }
예제 #15
0
 /**
  * @return SchemaService
  */
 protected function getSchemaService()
 {
     return Virge::service('virge/schema');
 }
예제 #16
0
 /**
  * @return TemplateService
  */
 public function getTemplatingService()
 {
     return Virge::service('templating');
 }
예제 #17
0
 /**
  * Enter into a service
  * @param string $service
  * @param array $arguments
  */
 protected function entry($service, $method, $arguments)
 {
     return call_user_func_array(array(Virge::service($service), $method), $arguments);
 }
예제 #18
0
 /**
  * @return ScheduleService
  */
 protected function getScheduleService()
 {
     return Virge::service(ScheduleService::SERVICE_ID);
 }
예제 #19
0
<?php

use Virge\Virge;
/**
 * Registers all given handlers with Virge that this Capsule contains
 * @author Michael Kramer
 */
Virge::registerService("cli", "\\Virge\\Cli");