custom-script.php 1.5 KB

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