Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Jul 28, 2021
0 parents commit 5293466
Show file tree
Hide file tree
Showing 13 changed files with 728 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
51 changes: 51 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: PHP Composer

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [ 8.0, 7.4 ]
stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

# - name: Run test suite
# run: composer run-script test
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
82 changes: 82 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace Vdlp\Telescope;

use Backend\Helpers\Backend;
use Illuminate\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Application;
use System\Classes\PluginBase;
use Vdlp\Telescope\ServiceProviders\TelescopeServiceProvider;

final class Plugin extends PluginBase
{
private Backend $backend;

public function __construct(Application $app)
{
parent::__construct($app);

$this->backend = $app->make(Backend::class);
}

public function pluginDetails(): array
{
return [
'name' => 'Telescope',
'description' => 'Laravel Telescope integration for October CMS',
'author' => 'Van der Let & Partners',
'icon' => 'icon-area-chart',
'homepage' => 'https://octobercms.com/plugin/vdlp-telescope',
];
}

public function register(): void
{
if (!in_array($this->app->environment(), ['local', 'dev'], true)) {
return;
}

$this->registerAccessGate();

$this->app->register(TelescopeServiceProvider::class);
}

public function registerPermissions(): array
{
return [
'vdlp.telescope.access_dashboard' => [
'tab' => 'Telescope',
'label' => 'Access to the Telescope dashboard',
'roles' => ['developer'],
],
];
}

public function registerNavigation(): array
{
return [
'dashboard' => [
'label' => 'Telescope',
'url' => $this->backend->url('vdlp/telescope/dashboard'),
'iconSvg' => '/plugins/vdlp/telescope/assets/icons/telescope.svg',
'permissions' => ['vdlp.telescope.access_dashboard'],
'order' => 510,
],
];
}

/**
* Register the access gate service.
*/
private function registerAccessGate(): void
{
$this->app->singleton(GateContract::class, static function ($app): GateContract {
return new Gate($app, static function () use ($app) {
return call_user_func($app['auth']->userResolver());
});
});
}
}
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Vdlp.Telescope

Provides a seamless integration of [Laravel Telescope 3.0](https://laravel.com/docs/6.x/telescope) inside October CMS.

Laravel Telescope is an elegant debug assistant for the Laravel framework. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps and more. Telescope makes a wonderful companion to your local Laravel development environment.

![Laravel Telescope Dashboard](https://plugins.vdlp.nl/octobercms/oc-telescope-plugin/dashboard.png)

## Requirements

- October CMS 1.0
- PHP 7.4 or higher

## Installation

Install the plugin using composer:

```
composer require vdlp/oc-telescope-plugin --dev
```

If you plan to use the Telescope plugin on other than your local development environment, you may install the plugin **without** the `--dev` flag.

### Assets

Make sure you have an active theme before publishing the required assets:

```
php artisan vendor:publish --tag telescope-assets --force
```

### Database

Run database migrations (when using database driver = default):

```
php artisan migrate
```

## Configuration

Create configuration file in `config/telescope.php`:

```
php artisan vendor:publish --tag telescope-config
```

## Switching themes

> Each time you switch the default theme you need to re-publish the Telescope assets.
The assets will be stored in your current theme folder: `themes/mytheme/assets/telescope` folder.

## Documentation

Please go to the Laravel website for detailed documentation about Laravel Telescope.

[Telescope for Laravel 6.x](https://laravel.com/docs/6.x/telescope)

## Questions

If you have any question about how to use this plugin, please don't hesitate to contact us at [octobercms@vdlp.nl](mailto:octobercms@vdlp.nl). We're
happy to help you. You can also visit the support forum and drop your questions/issues there.
13 changes: 13 additions & 0 deletions assets/icons/telescope.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions classes/PathHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Vdlp\Telescope\Classes;

use Cms\Classes\Theme;
use Cms\Facades\Cms;

final class PathHelper
{
private ?Theme $theme;

public function __construct()
{
$this->theme = Theme::getActiveTheme();
}

private function hasActiveTheme(): bool
{
return $this->theme !== null;
}

public function getAssetsPath(?string $path = null): string
{
if ($this->theme === null || !$this->hasActiveTheme()) {
return (string) $path;
}

$assetsPath = $this->theme->getPath(
$this->theme->getDirName()
. DIRECTORY_SEPARATOR
. 'assets'
. DIRECTORY_SEPARATOR
. 'telescope'
);

if ($path !== null) {
$assetsPath .= DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR);
}

return $assetsPath;
}

public function getAssetsUrlPath(?string $path = null): string
{
if ($this->theme === null || !$this->hasActiveTheme()) {
return (string) $path;
}

$assetsUrlPath = Cms::url('/themes/' . $this->theme->getDirName() . '/assets/telescope');

if ($path !== null) {
$assetsUrlPath .= '/' . ltrim($path, '/');
}

return $assetsUrlPath;
}
}
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "vdlp/oc-telescope-plugin",
"description": "Laravel Telescope integration for October CMS",
"type": "october-plugin",
"license": "proprietary",
"authors": [
{
"name": "Van der Let & Partners",
"email": "octobercms@vdlp.nl"
}
],
"require": {
"php": "^7.4 || ^8.0",
"composer/installers": "^1.0",
"laravel/telescope": "^3.5"
},
"archive": {
"exclude": [
".editorconfig",
".gitattributes",
".gitignore",
".gitlab-ci.yml",
".idea/"
]
}
}
26 changes: 26 additions & 0 deletions controllers/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Vdlp\Telescope\Controllers;

use Backend\Classes\Controller;
use Backend\Classes\NavigationManager;

final class Dashboard extends Controller
{
public $requiredPermissions = ['vdlp.telescope.access_dashboard'];
public $bodyClass = 'compact-container';

public function __construct()
{
parent::__construct();

NavigationManager::instance()->setContext('Vdlp.Telescope', 'dashboard');
}

public function index(): void
{
$this->pageTitle = 'Laravel Telescope';
}
}
1 change: 1 addition & 0 deletions controllers/dashboard/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe src="/telescope" width="100%" height="100%" frameborder="0"></iframe>
Loading

0 comments on commit 5293466

Please # to comment.