Comments (7)
I wrote a bundle for Symfony.
Now you can plug it in through the composer.
https://github.com/Ne-Lexa/roach-php-bundle
from core.
That looks really nice. Good job! I’ll add it to the docs shortly 👍
from core.
Ok I didn't read all the doc lol. Here is the answer
https://roach-php.dev/docs/dependency-injection/#swapping-out-the-container
We can close this :)
from core.
Ok so now the problem is, its not working because Roach now uses Symfony container even for loading their own classes and they are not loaded by Symfony since they're in vendor directory,
You have requested a non-existent service "RoachPHP\Core\Engine".
I think we need a bundle for this then
from core.
Yeah, that’s essentially what the framework integrations would have to do (that’s what the Laravel package does). Mostly providing a bunch of container bindings. I do want to provide a first-party Symfony package eventually, but I’m not super familiar with the Symfony ecosystem and I’ve never written a bundle before, so it’s been going a bit slow.
from core.
I could make it work by creating a bundle, but now I found some issues... services must be public since Roach library are getting them directly via container ($container->get()). Even the services in the userland (MySpider in the examples)
So I need to create some tags:
# RoachPHP\Bundle\DependencyInjection
class RoachPHPExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
// bindings go here
$container->registerForAutoconfiguration(SpiderInterface::class)
->addTag('roach.spider');
$container->registerForAutoconfiguration(ItemProcessorInterface::class)
->addTag('roach.item_processor');
// extensions middlewares etc
}
}
And a compiler pass:
// RoachPHP\Bundle\DependencyInjection\Compiler
class RoachCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// does the trick and inject the container even if its a static method
$container
->getDefinition(Roach::class)
->addMethodCall('useContainer', [new Reference('service_container')])
->setPublic(true);
foreach ($container->findTaggedServiceIds('roach.spider') as $id => $tags) {
$container->getDefinition($id)->setPublic(true);
}
foreach ($container->findTaggedServiceIds('roach.item_processor') as $id => $tags) {
$container->getDefinition($id)->setPublic(true);
}
foreach ($container->findTaggedServiceIds('roach.extension') as $id => $tags) {
$container->getDefinition($id)->setPublic(true);
}
}
}
Not sure if its a good practice to do that in a symfony bundle, probably not
This is my symfony console command:
class AppCommand extends Command
{
public function __construct(private Roach $roach)
{
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
Roach::startSpider(MySpider::class);
return Command::SUCCESS;
}
}
Or creating a Roach service in the bundle, as a wrapper for the actual Roach static class and do something like $roach->startSpider(MySpider::class)
from core.
I added a link to the repo to the docs. I assume the bundle fixes this issue so I'll close it for now.
from core.
Related Issues (20)
- Middleware for Downloader HOT 3
- Run namespace and Request serialization HOT 2
- Is there a documented way to scrape Single Page Applications? HOT 1
- Is there any way of accessing the first item inside a processor or an extension? HOT 2
- No publishable resources for tag [] for publishing config file HOT 2
- Pass Context into Request Middleware HOT 3
- This library is no longer maintained? HOT 2
- Possibly to scrape behind secured sessions
- Self signed certificate HOT 2
- How to process items in batch?
- Laravel 10 support? HOT 1
- No results with specific url HOT 2
- Argument #1 ($timestamp) must be greater than or equal to the current time HOT 1
- How to login and then scrap data from a page that requires auth? HOT 1
- time_sleep_until(): Argument #1 ($timestamp) must be greater than or equal to the current time HOT 4
- Responses dropped by middlewares are not registered HOT 1
- parse method is called even on response status 404 HOT 2
- Requests with ExecuteJavascriptMiddleware are sent twice HOT 1
- Conflict with Laravel 9 HOT 2
- Symfony 5.4.1 issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.