addDataSource() public method

Add a new data source
public addDataSource ( Clockwork\DataSource\DataSourceInterface $dataSource )
$dataSource Clockwork\DataSource\DataSourceInterface
コード例 #1
0
 public function register()
 {
     $this->app->singleton('clockwork.laravel', function ($app) {
         return new LaravelDataSource($app);
     });
     $this->app->singleton('clockwork.swift', function ($app) {
         return new SwiftDataSource($app['mailer']->getSwiftMailer());
     });
     $this->app->singleton('clockwork', function ($app) {
         $clockwork = new Clockwork();
         $clockwork->addDataSource(new PhpDataSource())->addDataSource($app['clockwork.laravel'])->addDataSource($app['clockwork.swift']);
         $filter = $app['config']->get('clockwork::config.filter', array());
         if ($app['config']->get('database.default') && !in_array('databaseQueries', $filter)) {
             $clockwork->addDataSource(new EloquentDataSource($app['db']->connection()));
         }
         $storage = new FileStorage($app['path.storage'] . '/clockwork');
         $storage->filter = $filter;
         $clockwork->setStorage($storage);
         return $clockwork;
     });
     $this->registerCommands();
     $app = $this->app;
     $service = $this;
     $this->app->after(function ($request, $response) use($app, $service) {
         if (!$service->isCollectingData()) {
             return;
             // Collecting data is disabled, return immediately
         }
         // don't collect data for configured URIs
         $request_uri = $app['request']->getRequestUri();
         $filter_uris = $app['config']->get('clockwork::config.filter_uris', array());
         $filter_uris[] = '/__clockwork/[0-9\\.]+';
         // don't collect data for Clockwork requests
         foreach ($filter_uris as $uri) {
             $regexp = '#' . str_replace('#', '\\#', $uri) . '#';
             if (preg_match($regexp, $request_uri)) {
                 return;
             }
         }
         $app['clockwork.laravel']->setResponse($response);
         $app['clockwork']->resolveRequest();
         $app['clockwork']->storeRequest();
         if (!$service->isEnabled()) {
             return;
             // Clockwork is disabled, don't set the headers
         }
         $response->headers->set('X-Clockwork-Id', $app['clockwork']->getRequest()->id, true);
         $response->headers->set('X-Clockwork-Version', Clockwork::VERSION, true);
         if ($app['request']->getBasePath()) {
             $response->headers->set('X-Clockwork-Path', $app['request']->getBasePath() . '/__clockwork/', true);
         }
         $extra_headers = $app['config']->get('clockwork::config.headers');
         if ($extra_headers && is_array($extra_headers)) {
             foreach ($extra_headers as $header_name => $header_value) {
                 $response->headers->set('X-Clockwork-Header-' . $header_name, $header_value);
             }
         }
     });
 }
コード例 #2
0
 public function register()
 {
     if ($this->isLegacyLaravel() || $this->isOldLaravel()) {
         $this->package('itsgoingd/clockwork', 'clockwork', __DIR__);
     } else {
         $this->publishes(array(__DIR__ . '/config/clockwork.php' => config_path('clockwork.php')));
     }
     $legacy = $this->isLegacyLaravel() || $this->isOldLaravel();
     $this->app->singleton('clockwork.support', function ($app) use($legacy) {
         return new ClockworkSupport($app, $legacy);
     });
     $this->app->singleton('clockwork.laravel', function ($app) {
         return new LaravelDataSource($app);
     });
     $this->app->singleton('clockwork.swift', function ($app) {
         return new SwiftDataSource($app['mailer']->getSwiftMailer());
     });
     $this->app->singleton('clockwork.eloquent', function ($app) {
         return new EloquentDataSource($app['db'], $app['events']);
     });
     foreach ($this->app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
         $this->app->singleton($name, $callable);
     }
     $this->app->singleton('clockwork', function ($app) {
         $clockwork = new Clockwork();
         $clockwork->addDataSource(new PhpDataSource())->addDataSource($app['clockwork.laravel'])->addDataSource($app['clockwork.swift']);
         if ($app['clockwork.support']->isCollectingDatabaseQueries()) {
             $clockwork->addDataSource($app['clockwork.eloquent']);
         }
         foreach ($app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
             $clockwork->addDataSource($app[$name]);
         }
         $clockwork->setStorage($app['clockwork.support']->getStorage());
         return $clockwork;
     });
     $this->app['clockwork.laravel']->listenToEvents();
     // set up aliases for all Clockwork parts so they can be resolved by the IoC container
     $this->app->alias('clockwork.support', 'Clockwork\\Support\\Laravel\\ClockworkSupport');
     $this->app->alias('clockwork.laravel', 'Clockwork\\DataSource\\LaravelDataSource');
     $this->app->alias('clockwork.swift', 'Clockwork\\DataSource\\SwiftDataSource');
     $this->app->alias('clockwork.eloquent', 'Clockwork\\DataSource\\EloquentDataSource');
     $this->app->alias('clockwork', 'Clockwork\\Clockwork');
     $this->registerCommands();
     if ($this->isLegacyLaravel()) {
         $this->app->middleware('Clockwork\\Support\\Laravel\\ClockworkLegacyMiddleware', array($this->app));
     } else {
         if ($this->isOldLaravel()) {
             $app = $this->app;
             $this->app['router']->after(function ($request, $response) use($app) {
                 return $app['clockwork.support']->process($request, $response);
             });
         }
     }
 }
コード例 #3
0
 public function call()
 {
     $app = $this->app;
     $storage_path_or_clockwork = $this->storage_path_or_clockwork;
     $this->app->container->singleton('clockwork', function () use($app, $storage_path_or_clockwork) {
         if ($storage_path_or_clockwork instanceof Clockwork) {
             return $storage_path_or_clockwork;
         }
         $clockwork = new Clockwork();
         $clockwork->addDataSource(new PhpDataSource())->addDataSource(new SlimDataSource($app))->setStorage(new FileStorage($storage_path_or_clockwork));
         return $clockwork;
     });
     $original_log_writer = $this->app->getLog()->getWriter();
     $clockwork_log_writer = new ClockworkLogWriter($this->app->clockwork, $original_log_writer);
     $this->app->getLog()->setWriter($clockwork_log_writer);
     if ($this->app->config('debug') && preg_match('#/__clockwork(/(?<id>[0-9\\.]+))?#', $this->app->request()->getPathInfo(), $matches)) {
         return $this->retrieveRequest($matches['id']);
     }
     try {
         $this->next->call();
         $this->logRequest();
     } catch (Exception $e) {
         $this->logRequest();
         throw $e;
     }
 }
コード例 #4
0
 public function register()
 {
     $this->app->singleton('clockwork.support', function ($app) {
         return new ClockworkSupport($app);
     });
     $this->app->singleton('clockwork.lumen', function ($app) {
         return new LumenDataSource($app);
     });
     $this->app->singleton('clockwork.swift', function ($app) {
         return new SwiftDataSource($app['mailer']->getSwiftMailer());
     });
     $this->app->singleton('clockwork.eloquent', function ($app) {
         return new EloquentDataSource($app['db'], $app['events']);
     });
     foreach ($this->app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
         $this->app->singleton($name, $callable);
     }
     $this->app->singleton('clockwork', function ($app) {
         $clockwork = new Clockwork();
         $clockwork->addDataSource(new PhpDataSource())->addDataSource($app['clockwork.lumen']);
         if ($app['clockwork.support']->isCollectingDatabaseQueries()) {
             $clockwork->addDataSource($app['clockwork.eloquent']);
         }
         if ($app['clockwork.support']->isCollectingEmails()) {
             $clockwork->addDataSource($app['clockwork.swift']);
         }
         foreach ($app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
             $clockwork->addDataSource($app[$name]);
         }
         $clockwork->setStorage($app['clockwork.support']->getStorage());
         return $clockwork;
     });
     $this->app['clockwork.lumen']->listenToEvents();
     // set up aliases for all Clockwork parts so they can be resolved by the IoC container
     $this->app->alias('clockwork.support', 'Clockwork\\Support\\Lumen\\ClockworkSupport');
     $this->app->alias('clockwork.lumen', 'Clockwork\\DataSource\\LumenDataSource');
     $this->app->alias('clockwork.swift', 'Clockwork\\DataSource\\SwiftDataSource');
     $this->app->alias('clockwork.eloquent', 'Clockwork\\DataSource\\EloquentDataSource');
     $this->app->alias('clockwork', 'Clockwork\\Clockwork');
     $this->registerCommands();
     if ($this->app['clockwork.support']->getConfig('register_helpers', true)) {
         require __DIR__ . '/helpers.php';
     }
 }
コード例 #5
0
 /**
  * Filter executed before a request processes
  *
  * @param SS_HTTPRequest $request Request container object
  * @param Session $session        Request session
  * @param DataModel $model        Current DataModel
  * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
  */
 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     if (Director::isDev() && class_exists('Clockwork\\Clockwork')) {
         $this->clockwork = new Clockwork();
         if (!DB::get_conn()) {
             global $databaseConfig;
             if ($databaseConfig) {
                 DB::connect($databaseConfig);
             }
         }
         // Wrap the current database adapter in a proxy object so we can log queries
         DB::set_conn(new DatabaseProxy(DB::get_conn()));
         $this->clockwork->addDataSource(new SilverstripeDataSource());
         // Attach a default datasource that comes with
         // the Clockwork library (grabs session info, etc)
         $this->clockwork->addDataSource(new PhpDataSource());
         // Give it a place to store data
         $this->clockwork->setStorage(new FileStorage(TEMP_FOLDER . '/clockwork'));
     }
 }
コード例 #6
0
 public function register()
 {
     $this->app->singleton('clockwork.support', function ($app) {
         return new ClockworkSupport($app);
     });
     $this->app->singleton('clockwork.lumen', function ($app) {
         return new LumenDataSource($app);
     });
     $this->app->singleton('clockwork.eloquent', function ($app) {
         return new EloquentDataSource($app['db'], $app['events']);
     });
     foreach ($this->app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
         $this->app->singleton($name, $callable);
     }
     $this->app->singleton('clockwork', function ($app) {
         $clockwork = new Clockwork();
         $clockwork->addDataSource(new PhpDataSource())->addDataSource(new MonologDataSource($app['log']))->addDataSource($app['clockwork.lumen']);
         $extraDataProviders = $app['config']->get('profiler.extraDataProviders', []);
         foreach ($extraDataProviders as $extraDataProvider) {
             $clockwork->addDataSource(new $extraDataProvider());
         }
         if ($app['clockwork.support']->isCollectingDatabaseQueries()) {
             $clockwork->addDataSource($app['clockwork.eloquent']);
         }
         foreach ($app['clockwork.support']->getAdditionalDataSources() as $name => $callable) {
             $clockwork->addDataSource($app[$name]);
         }
         $clockwork->setStorage($app['clockwork.support']->getStorage());
         return $clockwork;
     });
     $this->app['clockwork.lumen']->listenToEvents();
     // set up aliases for all Clockwork parts so they can be resolved by the IoC container
     $this->app->alias('clockwork.support', 'Clockwork\\Support\\Lumen\\ClockworkSupport');
     $this->app->alias('clockwork.lumen', 'Clockwork\\DataSource\\LumenDataSource');
     $this->app->alias('clockwork.eloquent', 'Clockwork\\DataSource\\EloquentDataSource');
     $this->app->alias('clockwork', 'Clockwork\\Clockwork');
     $this->registerCommands();
 }
コード例 #7
0
ファイル: _ide_helper.php プロジェクト: becast/GameReviewSite
 /**
  * Add a new data source
  *
  * @static 
  */
 public static function addDataSource($dataSource)
 {
     return \Clockwork\Clockwork::addDataSource($dataSource);
 }
コード例 #8
0
ファイル: ClockworkLogger.php プロジェクト: Devitek/orm
 /**
  * @param EntityManagerInterface $em
  * @param Configuration          $configuration
  */
 public function register(EntityManagerInterface $em, Configuration $configuration)
 {
     $debugStack = new DebugStack();
     $configuration->setSQLLogger($debugStack);
     $this->clockwork->addDataSource(new DoctrineDataSource($debugStack, $em->getConnection()->getDriver()->getName()));
 }