yay icon indicating copy to clipboard operation
yay copied to clipboard

Real Time Mode

Open marcioAlmada opened this issue 9 years ago • 23 comments

Should allow to activate pre processing of every included file.

  • [x] A stream wrapper should be available for single file inclusion:

    include 'yay://some/file.php';
    
  • [ ] Composer integration. Allowing files to be preprocessed automatically during inclusion.

  • [ ] Try to take advantage of opcache

marcioAlmada avatar Nov 25 '15 14:11 marcioAlmada

Hello, I've made an attempt at writing a composer plugin for Real-Time mode integration with Yay, and it seems that all that needs to be done is a plugin that patches ClassLoader.php's includeFile function to simply prepend the yay:// wrapper before the filename?

msjyoo avatar Feb 02 '16 05:02 msjyoo

Yes, that's one of the possibilities. But patching ClassLoader.php is a little too ad hoc to my taste and probably won't last long.

The other idea is to hijack the composer autoloader instance and force everything to be included through yay://, but I havent checked if it's possible yet (no time):

$autoloader = include 'vendor/autoload.php';
// do some sorcery with $autoloader instance

And there is also the more formal approach to ask composer project for a configuration or an API change on autoloader that allows registering a wrapper for inclusion.

$autoloader->addWrapper(\Yay\StreamWrapper::PROTOCOL);

marcioAlmada avatar Feb 02 '16 14:02 marcioAlmada

Also, for the real time mode to work decently we would need the stream-is-cacheable RFC to pass. So, any support to pass this RFC (author François Laupretre) is welcome :)

marcioAlmada avatar Feb 02 '16 14:02 marcioAlmada

Hello

I've looked at the composer autoloader and composer plugins only work the cli level, not at the autoloader level so the only way to overload the autoloader is to subscribe to the post-autoloader-dump hook and modify the autoloader after dumping is finished. So I think patching the ClassLoader is the only way since ClassLoader is where the include statement is at and ClassLoader is copy-pasted, not generated so no modification of Composer instance would change anything in ClassLoader unless we edit the file directly.

msjyoo avatar Feb 04 '16 00:02 msjyoo

It's also possible to simply have a cache directory, where the code is dumped postprocessed, and the Composer autoloader can be re-wired to include from that directory as a prefix but then it would not be "real-time".

msjyoo avatar Feb 04 '16 12:02 msjyoo

You could make the files themselves have an explicit call to yay at the top of the file, avoiding any magic:

return \Yay\compile(__FILE__);

This statement would either get yay to compile this file, or look it up in the cache, and in both cases then execute it.

Yay would strip that line out when the file is compiled, obviously.

hikari-no-yume avatar Feb 04 '16 23:02 hikari-no-yume

@TazeTSchnitzel you genius :smirk:

I still want composer integration but that's indeed a really cool idea.

marcioAlmada avatar Feb 05 '16 14:02 marcioAlmada

:D

hikari-no-yume avatar Feb 05 '16 19:02 hikari-no-yume

I just realised that this wouldn't work if what followed wasn't valid PHP syntax.

But you could use __halt_compiler to mitigate that.

hikari-no-yume avatar Feb 05 '16 19:02 hikari-no-yume

Yes of course, otherwise it would fail upon parsing. I'm building a sample bootstrap project to test all the possibilities.

marcioAlmada avatar Feb 05 '16 19:02 marcioAlmada

@TazeTSchnitzel You sir, are a genius! Thanks for that solution.

msjyoo avatar Feb 06 '16 13:02 msjyoo

it... works https://github.com/marcioAlmada/yay-enums/blob/master/enum.tests.php :manic_laugh:

marcioAlmada avatar Mar 28 '16 01:03 marcioAlmada

We are going to use a small php extension for engine integration instead. See #32.

marcioAlmada avatar Sep 23 '16 19:09 marcioAlmada

Can the macros be executed on a function execution, I was looking for something like lisp-like macros.

CMCDragonkai avatar Feb 17 '17 03:02 CMCDragonkai

Why cant we do this in the entry file?

$autoload = require __DIR__.'/vendor/autoload.php';

spl_autoload_unregister(array($autoload, 'loadClass'));

function includeFile($file)
{
	include $file;
	echo "CALLED: {$file} \n";
}

spl_autoload_register(function($class) use ($autoload) {
	if ($file = $autoload->findFile($class)) {
			includeFile($file);
			return true;
	}
}, true, true);

sunel avatar Jun 01 '18 05:06 sunel

@sunel I wouldn't personally under any circumstance bypass/overload the composer autloading. I do believe composer has some 'event'-based system for autloading plugins, I think it is better to utilize that feature, imho

chris-kruining avatar Jun 01 '18 10:06 chris-kruining

I dont think so, composer has plugin system for package event and installer events.

sunel avatar Jun 01 '18 11:06 sunel

@sunel I see a decision has been made, see #32 ;)

chris-kruining avatar Jun 01 '18 12:06 chris-kruining

@sunel https://github.com/preprocess - uses YAY as its base - and If I'm not mistaken it was made by modifying composer autoload.

marcioAlmada avatar Jun 01 '18 18:06 marcioAlmada

@marcioAlmada ya it uses YAY "preprocess" uses a different file extension "pre".

sunel avatar Jun 04 '18 04:06 sunel

@sunel this is so that the preprocessing is opt-in per file. Could look at configuration to find some other way to opt-in and some other scheme for the file creation, but I think it will always be opt-in per file.

assertchris avatar Apr 18 '19 20:04 assertchris

<?php declare(enable_preprocessor=1);

This is indistinguishable from trolling, I'll let you decide :sweat_smile:

marcioAlmada avatar Apr 18 '19 21:04 marcioAlmada

There is an example on how to hook composer's autoloader: https://github.com/ircmaxell/PhpGenerics/blob/master/lib/bootstrap.php

xtlsoft avatar Jul 18 '19 04:07 xtlsoft