Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real Time Mode #11

Open
1 of 4 tasks
marcioAlmada opened this issue Nov 25, 2015 · 23 comments
Open
1 of 4 tasks

Real Time Mode #11

marcioAlmada opened this issue Nov 25, 2015 · 23 comments

Comments

@marcioAlmada
Copy link
Owner

Should allow to activate pre processing of every included file.

  • 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 marcioAlmada mentioned this issue Nov 25, 2015
40 tasks
@marcioAlmada marcioAlmada changed the title Realtime Mode Real Time Mode Nov 25, 2015
@msjyoo
Copy link

msjyoo commented Feb 2, 2016

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?

@marcioAlmada
Copy link
Owner Author

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
Copy link
Owner Author

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 :)

@msjyoo
Copy link

msjyoo commented Feb 4, 2016

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
Copy link

msjyoo commented Feb 4, 2016

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".

@hikari-no-yume
Copy link
Collaborator

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.

@marcioAlmada
Copy link
Owner Author

@TazeTSchnitzel you genius 😏

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

@hikari-no-yume
Copy link
Collaborator

:D

@hikari-no-yume
Copy link
Collaborator

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.

@marcioAlmada
Copy link
Owner Author

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

@msjyoo
Copy link

msjyoo commented Feb 6, 2016

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

@marcioAlmada
Copy link
Owner Author

@marcioAlmada
Copy link
Owner Author

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

@CMCDragonkai
Copy link

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

@sunel
Copy link

sunel commented Jun 1, 2018

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);

@chris-kruining
Copy link

@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

@sunel
Copy link

sunel commented Jun 1, 2018

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

@chris-kruining
Copy link

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

@marcioAlmada
Copy link
Owner Author

marcioAlmada commented Jun 1, 2018

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

@sunel
Copy link

sunel commented Jun 4, 2018

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

@assertchris
Copy link
Collaborator

@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.

@marcioAlmada
Copy link
Owner Author

marcioAlmada commented Apr 18, 2019

<?php declare(enable_preprocessor=1);

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

@xtlsoft
Copy link

xtlsoft commented Jul 18, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants