Skip to content

Read the Code

Stefan Zweifel edited this page Feb 7, 2021 · 7 revisions

Read the Code or "How is the app structured?"

At its core screeenly is a Laravel application. In a typical Laravel installation, the logic and all classes of the application are stored in the /app folder. In screeenly I've decieded to split the actual application code from the Laravel "core" code. You find the code related to screeenly in /modules/Screeenly.

The /modules/Screeenly folder

This folder contains as already said the core of the application. In this section I would like to point out what each subfolder contains and how its content is used throughout the application.

Contracts

Contracts contains interfaces which are bound in Laravels IoC Container. There's for example a CanCaptureScreenshot Interface. This interface is implemented by the PhantomJsBrowser class. If I would like to use a different technology to capture screenshots I could create a new class which implements this interface. Then I simply would have to switch the binding in the ScreeenlyServiceProvider.

Entities

Entities contains simple PHP Objects / Classes with the only purpose to improve and simplify the code a bit.

Guards

Guards contains custom Authentication Guards. You can read more about Guards here. The ScreeenlyTokenGuard is responsible for the authentication of a user during an API call. The class reads the provided ApiKey and checks if it's a valid key. The corresponding user is than added to the current Request Object.

Http

The Http folder is very similar to the default Http folder found in every Laravel application. It contains Controllers, Middlewares, Requests and the routes-files.

Models

Models contains the Eloquent Models of the application. The application is thankfully quite small and doesn't have many models.

Providers

The Providers folder contains our ScreeenlyServiceProvider. This class registers our custom View Namespace, binds our CanCaptureScreenshot Interface to a an Implementation and registers our ScreeenlyTokenGuard.

Resources

In Resources you can find all Blade Views used by the application.

Services

The Services folder contains the core logic how we pass width, height and other parameters from PHP to PhantomJs.