/** * @return string */ public function getViewTemplate() { // set default view name if (is_null($this->viewTemplate)) { $reflected = new \ReflectionObject($this); $viewTemplate = substr($reflected->getFileName(), 0, -4); $templateFound = false; foreach (self::$viewExtensions as $extension) { if (file_exists($viewTemplate . '.' . ltrim($extension, '.'))) { $templateFound = true; break; } } if (!$templateFound) { // try to get parent template if any $parentReflectedClass = $reflected->getParentClass(); if ($parentReflectedClass->isInstantiable() && $parentReflectedClass->implementsInterface(RenderableActionInterface::class)) { $parentViewTemplate = $parentReflectedClass->newInstance()->getViewTemplate(); $viewTemplate = $parentViewTemplate; } } $this->viewTemplate = $viewTemplate; } return $this->viewTemplate; }
/** * @param AdminInterface $admin * * @return mixed * @throws \RuntimeException */ public function load(AdminInterface $admin) { $filename = $this->cacheFolder . '/route_' . md5($admin->getCode()); $cache = new ConfigCache($filename, $this->debug); if (!$cache->isFresh()) { $resources = array(); $routes = array(); $reflection = new \ReflectionObject($admin); $resources[] = new FileResource($reflection->getFileName()); if (!$admin->getRoutes()) { throw new \RuntimeException('Invalid data type, Admin::getRoutes must return a RouteCollection'); } foreach ($admin->getRoutes()->getElements() as $code => $route) { $routes[$code] = $route->getDefault('_sonata_name'); } if (!is_array($admin->getExtensions())) { throw new \RuntimeException('extensions must be an array'); } foreach ($admin->getExtensions() as $extension) { $reflection = new \ReflectionObject($extension); $resources[] = new FileResource($reflection->getFileName()); } $cache->write(serialize($routes), $resources); } return unserialize(file_get_contents($filename)); }
/** * Gets the Module directory path. * * @return string The Module absolute path * * @api */ public function getPath() { if (null === $this->reflected) { $this->reflected = new \ReflectionObject($this); } return dirname($this->reflected->getFileName()); }
public function getConfiguration(array $config, ContainerBuilder $container) { $configuration = new Configuration($this->getAlias()); $r = new \ReflectionObject($configuration); $container->addResource(new FileResource($r->getFileName())); return $configuration; }
public function testCacheIsFreshAfterCacheClearedWithWarmup() { $input = new ArrayInput(array('cache:clear')); $application = new Application($this->kernel); $application->setCatchExceptions(false); $application->doRun($input, new NullOutput()); // Ensure that all *.meta files are fresh $finder = new Finder(); $metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta'); // simply check that cache is warmed up $this->assertGreaterThanOrEqual(1, count($metaFiles)); foreach ($metaFiles as $file) { $configCache = new ConfigCache(substr($file, 0, -5), true); $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file)); } // check that app kernel file present in meta file of container's cache $containerRef = new \ReflectionObject($this->kernel->getContainer()); $containerFile = $containerRef->getFileName(); $containerMetaFile = $containerFile . '.meta'; $kernelRef = new \ReflectionObject($this->kernel); $kernelFile = $kernelRef->getFileName(); /** @var ResourceInterface[] $meta */ $meta = unserialize(file_get_contents($containerMetaFile)); $found = false; foreach ($meta as $resource) { if ((string) $resource === $kernelFile) { $found = true; break; } } $this->assertTrue($found, 'Kernel file should present as resource'); }
protected function coreTest(array $arguments) { $input = new ArrayInput($arguments); $application = new Application(static::$kernel); $application->setCatchExceptions(false); $application->doRun($input, new NullOutput()); // Ensure that all *.meta files are fresh $finder = new Finder(); $metaFiles = $finder->files()->in(static::$kernel->getCacheDir())->name('*.php.meta'); // simply check that cache is warmed up $this->assertGreaterThanOrEqual(1, count($metaFiles)); foreach ($metaFiles as $file) { $configCache = new ConfigCache(substr($file, 0, -5), true); $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file)); } // check that app kernel file present in meta file of container's cache $containerRef = new \ReflectionObject(static::$kernel->getContainer()); $containerFile = $containerRef->getFileName(); $containerMetaFile = $containerFile . '.meta'; $kernelRef = new \ReflectionObject(static::$kernel); $kernelFile = $kernelRef->getFileName(); /** @var ResourceInterface[] $meta */ $meta = unserialize(file_get_contents($containerMetaFile)); $found = false; foreach ($meta as $resource) { if ((string) $resource === $kernelFile) { $found = true; break; } } $this->assertTrue($found, 'Kernel file should present as resource'); $this->assertRegExp(sprintf('/\'kernel.name\'\\s*=>\\s*\'%s\'/', static::$kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container'); $this->assertEquals(ini_get('memory_limit'), '1024M'); }
public function testAnnotationGenerator() { $client = static::createClient(); $this->assertTrue(AnnotationTagGenerator::$haveBeenRun); $object = new \ReflectionObject($client->getContainer()); $this->assertTrue(strpos(file_get_contents($object->getFileName()), '/* This is a test for annotation generation */') !== false); }
public function setUp() { $this->autoloader = new Loader(); $loaderReflection = new \ReflectionObject($this->autoloader); $this->loaderFilePath = $loaderReflection->getFileName(); spl_autoload_register($this->autoloader); }
public function load($resource, $type = null) { $collection = new RouteCollection(); foreach ($this->adminFactory->getAdmins() as $adminId => $admin) { $routePatternPrefix = $admin->getRoutePatternPrefix(); $routeNamePrefix = $admin->getRouteNamePrefix(); foreach ($admin->getActions() as $action) { $defaults = array( '_controller' => 'WhiteOctoberAdminBundle:Admin:execute', '_white_october_admin.admin' => $adminId, '_white_october_admin.action' => $action->getFullName(), ); $defaults = array_merge($action->getRouteDefaults(), $defaults); $route = new Route($routePatternPrefix.$action->getRoutePatternSuffix(), $defaults, $action->getRouteRequirements()); $collection->add($ups = $routeNamePrefix.'_'.$action->getRouteNameSuffix(), $route); $reflection = new \ReflectionObject($action); $collection->addResource(new FileResource($reflection->getFileName())); } $reflection = new \ReflectionObject($admin); $collection->addResource(new FileResource($reflection->getFileName())); } return $collection; }
public function testGetCollectorPath() { $finder = new Finder(); $collector = new \Itkg\Profiler\DataCollector\CacheDataCollector(); $reflector = new \ReflectionObject($collector); $directory = dirname($reflector->getFileName()); $this->assertEquals($directory . '/../Resources/views/collector/cache.html.php', $finder->getCollectorPath($collector)); }
/** * @return string */ protected function getRootDir() { if (!isset($this['root_dir'])) { $reflObject = new \ReflectionObject($this); $this['root_dir'] = dirname($reflObject->getFileName()); } return realpath($this['root_dir']) ?: $this['root_dir']; }
/** * {@inheritdoc} */ public final function getPath() { if (null === $this->path) { $reflObject = new \ReflectionObject($this); $this->path = dirname($reflObject->getFileName()); } return $this->path; }
/** * Adds the object class hierarchy as resources. * * @param object $object An object instance */ public function addObjectResource($object) { $parent = new \ReflectionObject($object); $this->addResource(new FileResource($parent->getFileName())); while ($parent = $parent->getParentClass()) { $this->addResource(new FileResource($parent->getFileName())); } }
/** * @return string */ public function getRootDir() { if (null === $this->rootDir) { $r = new \ReflectionObject($this); $this->rootDir = str_replace('\\', '/', dirname($r->getFileName())); } return $this->rootDir; }
public function __construct() { $r = new \ReflectionObject($this); $this->path = dirname($r->getFileName()); $this->configDir = dirname($this->path) . '/config'; $this->loadConfiguration(); $this->loadRoutes(); $this->configureTemplating(); }
/** * Return an instance of {@link Twig_Environment}. * * @return \Twig_Environment */ public function getTwigEnvironment() { $cache = realpath(sprintf('%s/../../../../build', __DIR__)); $cache = sprintf('%s/cache/twig', $cache); // Tests should be close to the class that inherits this trait. $class = new \ReflectionObject($this); // Finally construct and return our twig environment. return new \Twig_Environment(new \Twig_Loader_Filesystem(sprintf('%s/templates', dirname($class->getFileName()))), ['cache' => $cache, 'debug' => true]); }
/** * Loads app paths and creates directories */ private function loadPaths() { $reflection = new \ReflectionObject($this); $this['app.root_dir'] = dirname($reflection->getFileName()); $projectDir = dirname($this['app.root_dir']); $this['app.cache_dir'] = $projectDir . '/var/cache/' . $this['app.env']; $this['app.logs_dir'] = $projectDir . '/var/logs'; (new Filesystem())->mkdir(array($this['app.cache_dir'], $this['app.logs_dir'])); }
/** * Return collector template path * Check if collector_name.php.html is defined in the same namespace as collector * @param DataCollector $collector * @throws \Itkg\Profiler\Exception\NotFoundException * @return string */ public function getCollectorPath(DataCollector $collector) { $reflector = new \ReflectionObject($collector); $directory = dirname($reflector->getFileName()); if (file_exists($baseFile = sprintf('%s/../%s/collector/%s.html.php', $directory, self::VIEWS_PATH, $collector->getName()))) { return $baseFile; } throw new NotFoundException(sprintf('No template defined for %s collector', $collector->getName())); }
/** * {@inheritdoc} */ public function load($resource, $type = null) { $collection = new SymfonyRouteCollection(); foreach ($this->adminServiceIds as $id) { $admin = $this->pool->getInstance($id); foreach ($admin->getRoutes()->getElements() as $code => $route) { $collection->add($route->getDefault('_sonata_name'), $route); } $reflection = new \ReflectionObject($admin); if (file_exists($reflection->getFileName())) { $collection->addResource(new FileResource($reflection->getFileName())); } } $reflection = new \ReflectionObject($this->container); if (file_exists($reflection->getFileName())) { $collection->addResource(new FileResource($reflection->getFileName())); } return $collection; }
public function __construct(Handler $app, Request $req, Response $res, $dir = NULL) { if ($dir) { $this->dir = $dir; } else { $ref = new \ReflectionObject($this); $this->dir = dirname($ref->getFileName()); } parent::__construct($app, $req, $res); }
public function setUp() { parent::setUp(); $class = new \ReflectionObject($this); $directory = dirname($class->getFileName()); $sslFile = realpath($directory . '/../Certificate/webmoney.pem'); $sslKey = realpath($directory . '/../Certificate/webmoney.key'); $this->request = new PayoutRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array('webMoneyId' => '811333344777', 'merchantPurse' => 'Z123428476799', 'secretKey' => '226778888', 'sslFile' => $sslFile, 'sslKey' => $sslKey, 'transactionId' => '1444111666', 'requestNumber' => '111222333', 'customerPurse' => 'Z123428476700', 'protectionPeriod' => '60', 'protectionCode' => 'xyZ123', 'invoiceId' => '12345678', 'onlyAuth' => false, 'description' => 'Payout', 'amount' => '12.46')); }
public function getViewDir() { if (null === $this->viewDir) { $r = new \ReflectionObject($this); $kernelParentDir = dirname($this->container->getParameter('kernel.root_dir')) . DIRECTORY_SEPARATOR; $this->viewDir = str_replace('\\', '/', dirname($r->getFileName())); $this->viewDir = str_replace($kernelParentDir, '', $this->viewDir) . DIRECTORY_SEPARATOR . 'views'; } return $this->viewDir; }
/** * Returns the current dirname of this behavior (also works for descendants) * * @return string The absolute directory name */ protected function getTemplatePath() { if (!defined('BEHAVIOR_PROVIDER_BASE_TEMPLATE_PATH')) { $r = new ReflectionObject($this); $dirname = dirname($r->getFileName()); $templatePath = $dirname . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; define('BEHAVIOR_PROVIDER_BASE_TEMPLATE_PATH', $templatePath); } return BEHAVIOR_PROVIDER_BASE_TEMPLATE_PATH; }
/** * Displays an information about single aspect * * @param SymfonyStyle $io Input-output style * @param Aspect $aspect Instance of aspect */ private function showAspectInfo(SymfonyStyle $io, Aspect $aspect) { $refAspect = new \ReflectionObject($aspect); $aspectName = $refAspect->getName(); $io->section($aspectName); $io->writeln('Defined in: <info>' . $refAspect->getFileName() . '</info>'); $docComment = $refAspect->getDocComment(); if ($docComment) { $io->writeln($this->getPrettyText($docComment)); } $this->showAspectPointcutsAndAdvisors($io, $aspect); }
public function render() { $controller = Application::getApp()->getController(); $action = $controller->getAction(); $view = $controller->getView(); $r = new ReflectionObject($action); $action_file = $r->getFileName(); $data = array('action_info' => array('obj' => $action, 'filename' => $action_file)); $r = new ReflectionObject($view); $data['view_info'] = array('obj' => $view, 'filename' => $r->getFileName()); return $this->renderTemplate('Source.Fragments.View', $data); }
public function setUp() { parent::setUp(); $class = new \ReflectionObject($this); $directory = dirname($class->getFileName()); $this->sslFile = realpath($directory . '/Certificate/webmoney.pem'); $this->sslKey = realpath($directory . '/Certificate/webmoney.key'); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setWebMoneyId('811333344777'); $this->gateway->setMerchantPurse('Z123428476799'); $this->gateway->setSecretKey('226778888'); $this->gateway->setSsLFile($this->sslFile); $this->gateway->setSslKey($this->sslKey); $this->gateway->setTestMode(true); }
protected function getAmfScript($request) { $kernel = serialize($this->kernel); $request = serialize($request); $r = new \ReflectionObject($this->kernel); $path = $r->getFileName(); return <<<EOF <?php require_once '{$path}'; \$kernel = unserialize('{$kernel}'); \$kernel->boot(); echo serialize(\$kernel->handleAmf(unserialize('{$request}'))); EOF; }
/** * @param string|\Symfony\Component\Form\FormTypeInterface $formType * @param array &$resources * * @return InputDefinition */ public function createForFormType($formType, array &$resources = []) { $resources[] = new FileResource(__FILE__); $form = $this->formFactory->create($formType); $actualFormType = $form->getConfig()->getType()->getInnerType(); $reflection = new \ReflectionObject($actualFormType); $resources[] = new FileResource($reflection->getFileName()); $inputDefinition = new InputDefinition(); foreach ($form->all() as $name => $field) { if (!$this->isFormFieldSupported($field)) { continue; } $type = InputOption::VALUE_REQUIRED; $default = $field->getConfig()->getOption('data', null); $description = FormUtil::label($field); $inputDefinition->addOption(new InputOption($name, null, $type, $description, $default)); } return $inputDefinition; }
/** * Constructor for all views. * * @param MonitorModelAbstract $model Model containing the information to be displayed by the view. * @param SplPriorityQueue $paths The paths queue. * * @throws Exception */ public function __construct(MonitorModelAbstract $model, SplPriorityQueue $paths = null) { if ($paths === null) { $paths = new SplPriorityQueue(); } // Get the params // TODO: may be removed when new MVC is implemented completely $app = JFactory::getApplication(); if ($app instanceof JApplicationSite) { $this->params = $app->getParams(); $active = $app->getMenu()->getActive(); if ($active) { $this->params->merge($active->params); } } else { $this->params = JComponentHelper::getParams('com_monitor'); } $reflector = new ReflectionObject($this); $paths->insert(dirname($reflector->getFileName()) . '/tmpl', 1); parent::__construct($model, $paths); }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $bundleAlias = $this->getAlias(); $bundleName = substr(Container::camelize($bundleAlias), 8); $configurationClassName = 'Orkestro\\Bundle\\' . $bundleName . 'Bundle\\DependencyInjection\\Configuration'; $configuration = new $configurationClassName($bundleAlias, $container->getParameter('orkestro.db_driver')); $config = $this->processConfiguration($configuration, $configs); $container->setParameter($bundleAlias . '.model_manager_name', $config['model_manager_name']); switch ($config['db_driver']) { case 'orm': $container->setParameter($bundleAlias . '.backend_type_orm', true); break; case 'mongodb': $container->setParameter($bundleAlias . '.backend_type_mongodb', true); break; default: break; } $reflected = new \ReflectionObject($this); $path = dirname($reflected->getFileName()) . '/../Resources/config'; $loader = new Loader\XmlFileLoader($container, new FileLocator($path)); $loader->load('services.xml'); }