Clockwork

php dev tools integrated to your browser

Clockwork screenshot Clockwork screenshot Clockwork screenshot

Data sources

Data sources are a pattern for collecting the metadata in an extensible way in the Clockwork server-side library. Each data source collects data about a particular topic, eg. a PhpDataSource, LaravelDataSource, or DoctrineDataSource.

Creating a new data source is as simple as creating a class implementing the Clockwork\DataSource\DataSourceInterface interface. Though instead of implementing the interface we recommend extending the Clockwork\DataSource\DataSource base class, which will make you compliant with future interface changes.

You need to implement a single resolve(Request $request) method that will receive the Request data object and extends it with your custom data.

For example, our application uses a custom session implementation, let's create a data source that adds the session data to Clockwork:

use Clockwork\DataSource\DataSource; use Clockwork\Helpers\Request;   class SessionDataSource extends DataSource {   public function resolve(Request $request)   {   $request->session = session()->all();   } }

To use the new data source we need to register it with the main Clockwork class:

clock()->addDataSource(new SessionDataSource);

For more inspiration take a look at the existing data sources included in Clockwork.