It's been a while since I reviewed PHP generators and I was just taking a look again to see if I can use them in some project. But I'm just not seeing how they are useable day to day. I feel every example I see has a simple non generator solution. Here is a random example (no affiliation, they're al...
Not sure starter apps are even relevant anymore, but this is something I've been using for years in my freelance work. Just did a full rebuild with more modern tooling and workflow and decided to open source it. Pairs with a standalone Vue app/admin SPA and a flows repo. Any feedback would be greatl...
Trying to figure out this direct uploads, and keep getting a CORS issue from Digital Ocean, no idea what they want from me. I just keep getting the ... Access to XMLHttpRequest at '....' from origin '...' has been blocked by CORS policy: Response to preflight request doesn't pass access control chec...
I'm just starting to look into and setup Laravel Vapor for the first time. I think for the most part everything looks quite straightforward. However, I have a job that requires some processing using a unix utility that's built for specific version of Ubuntu. I'm not sure what the best approach for t...
Only thing I can think is that it let's us clean things up a bit with a generic helper function which can remove some of the open/close boilerplate for us.
function iterateOverFile(String $file) {
$file = fopen($file);
if (!$file)
die('file does not exist or cannot be opened');
while (($line = fgets($file)) !== false) {
yield $line;
}
fclose($file);
}
So we can just call...
foreach(iterateOverFile($file) as $row) {
doSomeStuffWithRow($row);
}
Currently I have some scenarios like that, but I just use a callback which I believe in the end would be the same thing.
For example...
function iterateOverMe($range, $cb) {
for ($i = 0; $i < $range; $i++) {
$cb($i);
}
}
iterateOverMe(5, function ($i) {
echo $i;
});
So in file example it would look something like...
iterateOverFile($file, function ($row) {
doSomeStuffWithRow($row);
});
Though looking at it now, I suppose an iterator is "cleaner" solution if we potentially need access to data in the parent scope which would avoid having to use use.
Laravel/Vue dev, 15+ years, Toronto. Looking for contract or full-time work, remote preferred. I wrote and open sourced my own starter kits for spinning up new projects, also happy to join existing ones.
This, good to know...
Yes, it's a common example.
Only thing I can think is that it let's us clean things up a bit with a generic helper function which can remove some of the open/close boilerplate for us.
So we can just call...
Currently I have some scenarios like that, but I just use a callback which I believe in the end would be the same thing.
For example...
So in file example it would look something like...
Though looking at it now, I suppose an iterator is "cleaner" solution if we potentially need access to data in the parent scope which would avoid having to use
use.Seems interesting, but where do you define the schema descriptions?
Might be interesting to setup for my starter app, I currently just did this with a little pass through shim:
https://github.com/websanova/starter-laravel-api/blob/main/app/Mcp/Tools/ApiTool.php
So then you can just setup classes as needed for what you want to expose, for example:
https://github.com/websanova/starter-laravel-api/blob/main/app/Mcp/Tools/App/Bookmark/ListBookmarksTool.php
Lets you keep the MCP code a bit more isolated.
Laravel/Vue dev, 15+ years, Toronto. Looking for contract or full-time work, remote preferred. I wrote and open sourced my own starter kits for spinning up new projects, also happy to join existing ones.
websanova.com
github.com/websanova/starter-vue-spa
github.com/websanova/starter-laravel-api
Homestead works great for me.