Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloamgomes committed Sep 30, 2018
0 parents commit e22d9cf
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Paulo Gomes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
@@ -0,0 +1,53 @@
# Cockpit CMS Kint Addon

This addon extends Cockpit CMS (Next) core by providing debug functionality based on the [Kint PHP Library](https://github.com/kint-php/kint/).

## Installation

Installation can be performed with or without php composer (But keep in mind that after downloaded/extracted the addon must be named Kint).

### Without php composer
1. Download zip and extract to 'your-cockpit-docroot/addons/Kint' (e.g. cockpitcms/addons/Kint)
2. Install Kint dependency using composer
```bash
$ cd your-cockpit-docroot/addons/Kint
$ composer install
```

### Using php composer
1. Install addon using composer
```bash
$ cd your-cockpit-docroot/addons
$ composer create-project pauloamgomes/cockpit-cms-kint Kint
```

## Configuration

No configuration is required.

## Usage

The Cockpit Kint is a developer addon, to be used for example when implementing your own addons, there are two basic methods:

1. **Dump** - will dump the variables to the screen
```php
$this->app->module('kint')->dump($var1, $var2, ...);
```
![Dump Example](https://monosnap.com/image/C1FThi1HjjLoel2KT0UGz6BdE3AnDJ.png)

2. **Console** - will dump the variables to the browser console
```php
$this->app->module('kint')->console($var1, $var2, ...);
```
![Console Example](https://monosnap.com/image/jGiLieSG0cmwYBluFMv2yrEddUz7io.png)

If the debug functions are called during an API request, the output will be logged using the HTTP headers instead:

![Headers](https://monosnap.com/image/6O4anzYhKpZwNdiFyKnXhEis6CWwAZ.png)


## Copyright and license

Copyright 2018 pauloamgomes under the MIT license.


48 changes: 48 additions & 0 deletions bootstrap.php
@@ -0,0 +1,48 @@
<?php

/**
* @file
* Cockpit module bootstrap implementation.
*/

// Kint library.
require __DIR__ . '/vendor/autoload.php';

$this->module('kint')->extend([
'dump' => function() {
$_SESSION['kint_dump'][] = func_get_args();
},
'console' => function() {
$_SESSION['kint_console'][] = func_get_args();
},
]);

if (!COCKPIT_API_REQUEST) {
$app->on('shutdown', function() {
// Kint output.
if (!empty($_SESSION['kint_dump'])) {
$args = $_SESSION['kint_dump'];
d($args);
unset($_SESSION['kint_dump']);
}
// Kint console output.
if (!empty($_SESSION['kint_console'])) {
$args = $_SESSION['kint_console'];
j($args);
unset($_SESSION['kint_console']);
}
});
}
else {
$app->on('after', function() {
if (!empty($_SESSION['kint_dump'])) {
header('X-Cockpit-Kint-Dump: ' . json_encode($_SESSION['kint_dump']));
unset($_SESSION['kint_dump']);
}
if (!empty($_SESSION['kint_console'])) {
header('X-Cockpit-Kint-Console: ' . json_encode($_SESSION['kint_console']));
unset($_SESSION['kint_console']);
}
});
}

20 changes: 20 additions & 0 deletions composer.json
@@ -0,0 +1,20 @@
{
"name": "pauloamgomes/cockpit-cms-kint",
"type": "project",
"description": "Kint addon for Cockpit Headless CMS",
"keywords": ["cms", "headless", "api", "cockpit", "debug", "kint"],
"homepage": "https://github.com/pauloamgomes/cockpit-cms-kint",
"license": "MIT",
"authors": [
{
"name": "Paulo Gomes",
"email": "pauloamgomes@gmail.com",
"homepage": "https://www.pauloamgomes.net"
}
],
"require": {
"php": "^7.0",
"kint-php/kint": "^3.0@dev",
"kint-php/kint-js": "^2.0"
}
}

0 comments on commit e22d9cf

Please sign in to comment.