Skip to content

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 9, 2024
2 parents 954e94c + 41116fe commit 3bb115b
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [janhenckens]
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Code Quality
on:
workflow_dispatch:
push:
branches:
- develop
- develop-v5
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: ci
uses: studioespresso/.github/.github/workflows/ci.yml@main
with:
craft_version: '5'
jobs: '["ecs", "phpstan"]'
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Create Release
run-name: Create release for ${{ github.event.client_payload.version }}

on:
repository_dispatch:
types:
- craftcms/new-release
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: ncipollo/release-action@v1
with:
body: ${{ github.event.client_payload.notes }}
makeLatest: ${{ github.event.client_payload.latest }}
name: ${{ github.event.client_payload.version }}
prerelease: ${{ github.event.client_payload.prerelease }}
tag: ${{ github.event.client_payload.tag }}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Dumper plugin for Craft CMS 3.x
# Dumper for Craft CMS

Bringing larapack/dd to Craft 3
Easy dump & "dump&die" functions for Twig.

## Requirements

This plugin requires Craft CMS 3.0.0-beta.29 or later.
This plugin works with Craft CMS 3, 4 or 5.

## Installation

Expand All @@ -22,7 +22,7 @@ To install the plugin, follow these instructions.

## Using Dumper

When you install the plugin, you'll be able to use larapack/dd in your Twig templates like this:
When you install the plugin, you'll be able to use `` Symfony\VarDumper`` in your Twig templates like this:

{{ d(entry) }}

Expand All @@ -33,4 +33,4 @@ Or you can "dump and die"
Works on strings, arrays, object, etc.


###### Brought to you by [Studio Espresso](https://studioespresso.co)
###### Brought to you by [Studio Espresso](https://www.studioespresso.co)
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "studioespresso/craft-dumper",
"description": "Bringing larapack/dd to Craft CMS",
"description": "Bringing symfony/VarDumper to Craft CMS",
"type": "craft-plugin",
"version": "5.0.0-alpha.2",
"version": "5.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -11,19 +11,28 @@
"dumper"
],
"support": {
"docs": "https://github.com/studioespresso/craft3-dumper/blob/master/README.md",
"issues": "https://github.com/studioespresso/craft3-dumper/issues"
"docs": "https://github.com/studioespresso/craft-dumper/blob/master/README.md",
"issues": "https://github.com/studioespresso/craft-dumper/issues"
},
"license": "MIT",
"authors": [
{
"name": "Studio Espresso",
"homepage": "https://studioespresso.dev"
"homepage": "https://www.studioespresso.co"
}
],
"require": {
"craftcms/cms": "^4.0.0|^5.0.0-alpha"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main"
},
"scripts": {
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G"
},
"repositories": [
{
"type": "composer",
Expand All @@ -42,7 +51,13 @@
"schemaVersion": "1.0.0",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/studioespresso/craft3-dumper/master/CHANGELOG.md",
"changelogUrl": "https://raw.githubusercontent.com/studioespresso/craft-dumper/master/CHANGELOG.md",
"class": "studioespresso\\craftdumper\\CraftDumper"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 3
paths:
- src
1 change: 0 additions & 1 deletion src/CraftDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

class CraftDumper extends Plugin
{

/**
* @var Plugin
*/
Expand Down
111 changes: 53 additions & 58 deletions src/web/twig/DumperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Symfony\Component\VarDumper\VarDumper;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Template;
use Twig\TwigFunction;
use Twig_Extension;

/**
* Plugin represents the Craft Dumper Twig Extension.
Expand All @@ -20,27 +20,27 @@

class DumperExtension extends AbstractExtension
{
// Public Methods
// =========================================================================
// Public Methods
// =========================================================================

/**
* Get Name
*
* @return string
*/
public function getName()
{
return 'Dumper';
}
/**
* Get Name
*
* @return string
*/
public function getName()
{
return 'Dumper';
}


/**
* Get Functions
*
* @return array
*/
public function getFunctions()
{
/**
* Get Functions
*
* @return array
*/
public function getFunctions()
{
// dump is safe if var_dump is overridden by xdebug
$isDumpOutputHtmlSafe = extension_loaded('xdebug')
&& (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
Expand All @@ -49,67 +49,62 @@ public function getFunctions()
&& (false === ini_get('html_errors') || ini_get('html_errors'))
|| 'cli' === PHP_SAPI;

return [
new TwigFunction('d', [$this, 'd']),
new TwigFunction('dd', [$this, 'dd'], [
return [
new TwigFunction('d', [$this, 'd']),
new TwigFunction('dd', [$this, 'dd'], [
'is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [],
'needs_context' => false,
'needs_environment' => false,
'debug' => true,
]),
new TwigFunction('dump', [$this, 'dump'], [
'is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [],
'needs_context' => true,
'is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [],
'needs_context' => true,
'needs_environment' => true,
]),
];
}
];
}

/**
* @param $variable
*/
public function d()
{
foreach ( func_get_args() as $item ) {
echo VarDumper::dump( $item );
}
/**
* @param $variable
*/
public function d()
{
foreach (func_get_args() as $item) {
echo VarDumper::dump($item);
}
echo '<style>pre.sf-dump { z-index: 0; !important} </style>';
}
}


/**
* @param $variable
*/
public function dd()
{
$i = 0;
$len = count( func_get_args() );
foreach ( func_get_args() as $item ) {
if ( $i == $len - 1 ) {
echo dd( $item );
} else {
echo VarDumper::dump( $item );
}
$i ++;
}
/**
* @param $variable
*/
public function dd()
{
$i = 0;
$len = count(func_get_args());
foreach (func_get_args() as $item) {
if ($i == $len - 1) {
/** @phpstan-ignore-next-line */
echo dd($item);
} else {
echo VarDumper::dump($item);
}
$i++;
}
echo '<style>pre.sf-dump { z-index: 0; !important} </style>';
}

/**
* Override dump version of Symfony's VarDumper component
*
* @param \Twig_Environment $env
* @param array $context
* @param mixed ...$vars
*
* @return string|null
*/
public function dump(Environment $env, array $context, ...$vars)
{
if (!$vars) {
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
if (!$value instanceof Template) {
$vars[$key] = $value;
}
}
Expand All @@ -121,4 +116,4 @@ public function dump(Environment $env, array $context, ...$vars)

echo ob_get_clean();
}
}
}

0 comments on commit 3bb115b

Please sign in to comment.