| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /*
- * This file is part of the php-phantomjs.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace JonnyW\PhantomJs\Procedure;
- use Symfony\Component\Config\FileLocatorInterface;
- use JonnyW\PhantomJs\Exception\NotExistsException;
- /**
- * PHP PhantomJs
- *
- * @author Jon Wenmoth <contact@jonnyw.me>
- */
- class ProcedureLoader implements ProcedureLoaderInterface
- {
- /**
- * Procedure factory.
- *
- * @var mixed
- * @access protected
- */
- protected $procedureFactory;
- /**
- * File locator.
- *
- * @var \Symfony\Component\Config\FileLocatorInterface
- * @access protected
- */
- protected $locator;
- /**
- * Internal constructor.
- *
- * @access public
- * @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory
- * @param \Symfony\Component\Config\FileLocatorInterface $locator
- */
- public function __construct(ProcedureFactoryInterface $procedureFactory, FileLocatorInterface $locator)
- {
- $this->procedureFactory = $procedureFactory;
- $this->locator = $locator;
- }
- /**
- * Load procedure instance by id.
- *
- * @access public
- * @param string $id
- * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
- */
- public function load($id)
- {
- $path = $this->locator->locate(sprintf('%s.proc', $id));
- $content = $this->loadFile($path);
- $procedure = $this->procedureFactory->createProcedure();
- $procedure->load($content);
- return $procedure;
- }
- /**
- * Load procedure file content.
- *
- * @access protected
- * @param string $file
- * @return string
- * @throws \InvalidArgumentException
- * @throws \JonnyW\PhantomJs\Exception\NotExistsException
- */
- protected function loadFile($file)
- {
- if (!stream_is_local($file)) {
- throw new \InvalidArgumentException(sprintf('Procedure file is not a local file: "%s"', $file));
- }
- if (!file_exists($file)) {
- throw new NotExistsException(sprintf('Procedure file does not exist: "%s"', $file));
- }
- return file_get_contents($file);
- }
- }
|