custom-script.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. use JonnyW\PhantomJs\Client;
  3. use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;
  4. // Create a file with a custom name
  5. // e.g. custom_procedure.proc and save it
  6. // somewhere. Set the parameters below to
  7. // the name of your file and the location of
  8. // your file. You can have many files in the
  9. // same location and you only need to create
  10. // 1 procedure loader with the path to your
  11. // files. The only restriction is the extension
  12. // your files must be .proc
  13. $fileName = 'custom_procedure';
  14. $filePath = '/path/to/your/procedure/';
  15. $serviceContainer = ServiceContainer::getInstance();
  16. $procedureLoaderFactory = $serviceContainer->get('procedure_loader_factory');
  17. $procedureLoader = $procedureLoaderFactory->createProcedureLoader($filePath); // Set the path to your custom procedure(s)
  18. $client = Client::getInstance();
  19. $client->getProcedureLoader()->addLoader($procedureLoader); // Add new loader with path to you procedures to the chain loader
  20. $request = $client->getMessageFactory()->createRequest();
  21. $response = $client->getMessageFactory()->createResponse();
  22. $request->setType($fileName); // Set the request type to the name of your procedure you want to execute for this request
  23. $client->send($request, $response);
  24. var_dump($response);
  25. // If your debug log contains 'SyntaxError: Parse error'
  26. // then your custom procedure has a javascript error. Try
  27. // setting $client->debug(true) before making your request
  28. // to get more information about your error.
  29. var_dump($client->getLog());