-
I was wondering if it is possible to manually override the filename (and the path to the file that gets opened when clicked) each time you call I am integrating Ray with Volt which is part of the Phalcon PHP framework and resembles Twig in syntax. To achieve this I have added a
Which then goes into Ray like so: What I would like to be able to do is to customise the Can we do this? I've been digging around in the source, and thought I'd found a solution using Ray's Unfortunately though there are two issues with this. First, I can only debug a string using Here is my wrapper class for <?php
declare(strict_types=1);
namespace Core\View\Helper;
use Phalcon\Di\Injectable as DiInjectable;
use Spatie\Ray\Ray as SpatieRay;
use Spatie\Ray\Settings\SettingsFactory;
/**
* Wrapper class for Spatie\Ray debugging app to be compatible with Volt.
* `ray()` returns an instance of itself to allow for chaining, but this meant that Volt threw an exception
* as a string return value is expected
* Composer requirement: spatie/ray
* @package Core\Helper
*/
class Ray extends DiInjectable
{
public function send(...$args): string
{
$settings = SettingsFactory::createFromConfigFile();
$ray = new SpatieRay($settings);
// FIXME [Ray] can we override the filename showing in Ray, and set to the current Volt file path?
$ray->send($args);
$ray->sendCustom('test', 'file/name/here');
return '';
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
On the Line 11 in 01266d4 You can create should a factory of your own, and make |
Beta Was this translation helpful? Give feedback.
-
So based on the above suggestion of customising the DefaultFactoryOrigin class, I got it working like so: Example of helper class to send data from Phalcon <?php
declare(strict_types=1);
namespace Core\View\Helper;
use Core\View\Helper\Ray\Origin\VoltOriginFactory;
use Exception;
use Spatie\Ray\Ray as SpatieRay;
use Spatie\Ray\Settings\SettingsFactory;
use Spatie\Ray\Payloads\Payload;
/**
* Wrapper class for Spatie\Ray debugging app to be compatible with Volt.
* `ray()` returns an instance of itself to allow for chaining, but this mean that Volt threw an exception
* Composer requirement: spatie/ray
* @package Core\Helper
* @example PHP: (new Core\View\Helper\Ray())->send('test', 123, 456)
* @example Volt: {{ ray('test', 123, 456) }}
* @example Volt: {{ 'test' | ray }}
*/
class Ray
{
/**
* Relay $args through to Spatie\Ray for debugging
* @param mixed $args
* @return string
* @throws Exception
*/
public function send(...$args): string
{
$settings = SettingsFactory::createFromConfigFile();
$ray = new SpatieRay($settings);
if (count($args) === 1) {
$args = $args[key($args)];
}
Payload::$originFactoryClass = VoltOriginFactory::class;
$ray->send($args);
return '';
}
} The important bit though is: Core\View\Helper\Ray\Origin\VoltOriginFactory: <?php
declare(strict_types=1);
namespace Core\View\Helper\Ray\Origin;
use Phalcon\Di\Injectable as DiInjectable;
use Spatie\Ray\Origin\Origin;
use Spatie\Ray\Origin\OriginFactory;
/**
* Custom OriginFactory for Ray that sets the correct template file name / path from Volt
* @package Core\View\Helper\Ray\Origin
*/
class VoltOriginFactory extends DiInjectable implements OriginFactory
{
/**
* Sets the origin file path and line number (not implemented)
* @return Origin
*/
function getOrigin(): Origin
{
return new Origin(
$this->di->get('voltService')->getCompiler()->getTemplatePath(),
null
);
}
} Finally, if you want to add the helper into Volt to make it available for debugging in your // $diContainer must be an instance of Phalcon\Di, this code is normally in your app bootstrap
$volt = new Volt($view, $diContainer);
$compiler = $volt->getCompiler();
$compiler->addFunction(
'ray',
function ($resolvedArgs) {
return '(new Core\View\Helper\Ray())->send(' . $resolvedArgs . ')';
}
); |
Beta Was this translation helpful? Give feedback.
So based on the above suggestion of customising the DefaultFactoryOrigin class, I got it working like so:
Example of helper class to send data from Phalcon