/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (!class_exists($arguments['class'])) { throw new InvalidArgumentException(sprintf('The class "%s" does not exist.', $arguments['class'])); } // base lib and test directories $r = new ReflectionClass($arguments['class']); list($libDir, $testDir) = $this->getDirectories($r->getFilename()); $path = str_replace($libDir, '', dirname($r->getFilename())); $test = $testDir . '/unit' . $path . '/' . $r->getName() . 'Test.php'; // use either the test directory or project's bootstrap if (!file_exists($bootstrap = $testDir . '/bootstrap/unit.php')) { $bootstrap = sfConfig::get('sf_test_dir') . '/bootstrap/unit.php'; } if (file_exists($test) && $options['force']) { $this->getFilesystem()->remove($test); } if (file_exists($test)) { $this->logSection('task', sprintf('A test script for the class "%s" already exists.', $r->getName()), null, 'ERROR'); } else { $this->getFilesystem()->copy(dirname(__FILE__) . '/skeleton/test/UnitTest.php', $test); $this->getFilesystem()->replaceTokens($test, '##', '##', array('CLASS' => $r->getName(), 'BOOTSTRAP' => $this->getBootstrapPathPhp($bootstrap, $test), 'DATABASE' => $this->isDatabaseClass($r) ? "\n\$databaseManager = new sfDatabaseManager(\$configuration);\n" : '')); } if (isset($options['editor-cmd'])) { $this->getFilesystem()->execute($options['editor-cmd'] . ' ' . escapeshellarg($test)); } }
public function testConfigure() { $prevDumper = $this->getDumpHandler(); $container = new ContainerBuilder(); $container->setDefinition('var_dumper.cloner', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockCloner')); $container->setDefinition('mock_dumper', new Definition('Symfony\\Component\\HttpKernel\\Tests\\EventListener\\MockDumper')); ob_start(); $exception = null; $listener = new DumpListener($container, 'mock_dumper'); try { $listener->configure(); $lazyDumper = $this->getDumpHandler(); VarDumper::dump('foo'); $loadedDumper = $this->getDumpHandler(); VarDumper::dump('bar'); $this->assertSame('+foo-+bar-', ob_get_clean()); $listenerReflector = new \ReflectionClass($listener); $lazyReflector = new \ReflectionFunction($lazyDumper); $loadedReflector = new \ReflectionFunction($loadedDumper); $this->assertSame($listenerReflector->getFilename(), $lazyReflector->getFilename()); $this->assertSame($listenerReflector->getFilename(), $loadedReflector->getFilename()); $this->assertGreaterThan($lazyReflector->getStartLine(), $loadedReflector->getStartLine()); } catch (\Exception $exception) { } VarDumper::setHandler($prevDumper); if (null !== $exception) { throw $exception; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (!class_exists($arguments['class'])) { throw new InvalidArgumentException(sprintf('The class "%s" could not be found.', $arguments['class'])); } $r = new ReflectionClass($arguments['class']); if (0 !== strpos($r->getFilename(), sfConfig::get('sf_lib_dir'))) { throw new InvalidArgumentException(sprintf('The class "%s" is not located in the project lib/ directory.', $r->getName())); } $path = str_replace(sfConfig::get('sf_lib_dir'), '', dirname($r->getFilename())); $test = sfConfig::get('sf_test_dir') . '/unit' . $path . '/' . $r->getName() . 'Test.php'; if (file_exists($test)) { if ($options['force']) { $this->getFilesystem()->remove($test); } else { $this->logSection('task', sprintf('A test script for the class "%s" already exists.', $r->getName())); if (isset($options['editor-cmd'])) { $this->getFilesystem()->sh($options['editor-cmd'] . ' ' . $test); } return 1; } } $template = ''; $database = false; if (!$options['disable-defaults']) { if ($r->isSubClassOf('sfForm')) { $options['without-methods'] = true; if (!$r->isAbstract()) { $template = 'Form'; } } if (class_exists('Propel') && ($r->isSubclassOf('BaseObject') || 'Peer' == substr($r->getName(), -4) || $r->isSubclassOf('sfFormPropel')) || class_exists('Doctrine') && ($r->isSubclassOf('Doctrine_Record') || $r->isSubclassOf('Doctrine_Table') || $r->isSubclassOf('sfFormDoctrine')) || $r->isSubclassOf('sfFormFilter')) { $database = true; } } $tests = ''; if (!$options['without-methods']) { foreach ($r->getMethods() as $method) { if ($method->getDeclaringClass()->getName() == $r->getName() && $method->isPublic()) { $type = $method->isStatic() ? '::' : '->'; $tests .= <<<EOF // {$type}{$method->getName()}() \$t->diag('{$type}{$method->getName()}()'); EOF; } } } $this->getFilesystem()->copy(dirname(__FILE__) . sprintf('/skeleton/test/UnitTest%s.php', $template), $test); $this->getFilesystem()->replaceTokens($test, '##', '##', array('CLASS' => $r->getName(), 'TEST_DIR' => str_repeat('/..', substr_count($path, DIRECTORY_SEPARATOR) + 1), 'TESTS' => $tests, 'DATABASE' => $database ? "\n\$databaseManager = new sfDatabaseManager(\$configuration);\n" : '')); if (isset($options['editor-cmd'])) { $this->getFilesystem()->sh($options['editor-cmd'] . ' ' . $test); } }
public function testIsFresh() { $ref = new \ReflectionClass('Metadata\\Tests\\Fixtures\\TestObject'); touch($ref->getFilename()); sleep(2); $metadata = new ClassMetadata($ref->name); $metadata->fileResources[] = $ref->getFilename(); $this->assertTrue($metadata->isFresh()); sleep(2); clearstatcache($ref->getFilename()); touch($ref->getFilename()); $this->assertFalse($metadata->isFresh()); }
private function getController() { // this happens for example for exceptions (404 errors, etc.) if (null === $this->controller) { return; } $className = get_class($this->controller[0]); $class = new \ReflectionClass($className); $method = $class->getMethod($this->controller[1]); $classCode = file($class->getFilename()); $methodCode = array_slice($classCode, $method->getStartline() - 1, $method->getEndLine() - $method->getStartline() + 1); $controllerCode = ' ' . $method->getDocComment() . "\n" . implode('', $methodCode); return array('file_path' => $class->getFilename(), 'starting_line' => $method->getStartline(), 'source_code' => $this->unindentCode($controllerCode)); }
public function loadMetadataForClass(\ReflectionClass $class) { $metadata = new ClassMetadata($className = $class->getName()); if (false !== ($filename = $class->getFilename())) { $metadata->fileResources[] = $filename; } // this is a bit of a hack, but avoids any timeout issues when a class // is moved into one of the compiled classes files, and Doctrine // Common 2.1 is used. if (false !== strpos($filename, '/classes.php') || false !== strpos($filename, '/bootstrap.php')) { return null; } $hasInjection = false; if ($parentClass = $class->getParentClass()) { $this->buildAnnotations($parentClass, $metadata); $this->buildProperties($parentClass, $metadata, $hasInjection); // temp disabledavoid test failing, only child lookup for now // @todo fix test failing Cannot redeclare class EnhancedProxy_...SecuredController in EnhancedProxy___CG__-JMS-DiExtraBundle-Tests-Functional-Bundle-TestBundle-Controller-SecuredController.php on line 11 //$this->buildMethods($parentClass, $metadata, $hasInjection); } $this->buildAnnotations($class, $metadata); $this->buildProperties($class, $metadata, $hasInjection); $this->buildMethods($class, $metadata, $hasInjection); if (null == $metadata->id && !$hasInjection) { return null; } return $metadata; }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { $configRootPath = sprintf('%sResources%sconfig', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); $jobTemplatesFilePath = sprintf('%s%sjob_templates.yml', $configRootPath, DIRECTORY_SEPARATOR); // retrieve each job config from bundles $jobTemplatesConfig = []; foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFilename()) . $jobTemplatesFilePath)) { // merge job configs if (empty($jobTemplatesConfig)) { $jobTemplatesConfig = Yaml::parse(file_get_contents(realpath($file))); } else { $entities = Yaml::parse(file_get_contents(realpath($file))); foreach ($entities['job_templates'] as $jobName => $jobFileConfig) { // merge result with already existing job templates to add new job templates definition if (isset($jobTemplatesConfig['job_templates'][$jobName])) { $jobTemplatesConfig['job_templates'][$jobName] = array_replace_recursive($jobTemplatesConfig['job_templates'][$jobName], $jobFileConfig); } else { $jobTemplatesConfig[$jobName] = $jobFileConfig; } } } } } // process configurations to validate and merge $config = $this->processConfig($jobTemplatesConfig); // load service $configPath = sprintf('%s%s..%s..%s', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $configRootPath); $loader = new YamlFileLoader($container, new FileLocator($configPath)); $loader->load('services.yml'); // set job templates config $container->setParameter(static::PROVIDER_CONFIG_PARAMETER, $config); }
public function register(Application $app) { $app['swiftmailer.options'] = array_replace(array('host' => 'localhost', 'port' => 25, 'username' => '', 'password' => '', 'encryption' => null, 'auth_mode' => null), isset($app['swiftmailer.options']) ? $app['swiftmailer.options'] : array()); $app['mailer'] = $app->share(function () use($app) { $r = new \ReflectionClass('Swift_Mailer'); require_once dirname($r->getFilename()) . '/../../swift_init.php'; return new \Swift_Mailer($app['swiftmailer.transport']); }); $app['swiftmailer.transport'] = $app->share(function () use($app) { $transport = new \Swift_Transport_EsmtpTransport($app['swiftmailer.transport.buffer'], array($app['swiftmailer.transport.authhandler']), $app['swiftmailer.transport.eventdispatcher']); $transport->setHost($app['swiftmailer.options']['host']); $transport->setPort($app['swiftmailer.options']['port']); $transport->setEncryption($app['swiftmailer.options']['encryption']); $transport->setUsername($app['swiftmailer.options']['username']); $transport->setPassword($app['swiftmailer.options']['password']); $transport->setAuthMode($app['swiftmailer.options']['auth_mode']); return $transport; }); $app['swiftmailer.transport.buffer'] = $app->share(function () { return new \Swift_Transport_StreamBuffer(new \Swift_StreamFilters_StringReplacementFilterFactory()); }); $app['swiftmailer.transport.authhandler'] = $app->share(function () { return new \Swift_Transport_Esmtp_AuthHandler(array(new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(), new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(), new \Swift_Transport_Esmtp_Auth_PlainAuthenticator())); }); $app['swiftmailer.transport.eventdispatcher'] = $app->share(function () { return new \Swift_Events_SimpleEventDispatcher(); }); if (isset($app['swiftmailer.class_path'])) { $app['autoloader']->registerPrefix('Swift_', $app['swiftmailer.class_path']); } }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $entitiesConfig = []; $titlesConfig = []; foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/navigation.yml')) { $bundleConfig = Yaml::parse(file_get_contents(realpath($file))); // merge entity configs if (isset($bundleConfig['oro_menu_config'])) { foreach ($bundleConfig['oro_menu_config'] as $entity => $entityConfig) { if (isset($entitiesConfig['oro_menu_config'][$entity])) { $entitiesConfig['oro_menu_config'][$entity] = array_replace_recursive($entitiesConfig['oro_menu_config'][$entity], $entityConfig); } else { $entitiesConfig['oro_menu_config'][$entity] = $entityConfig; } } } if (isset($bundleConfig['oro_titles'])) { $titlesConfig = array_merge($titlesConfig, is_array($bundleConfig['oro_titles']) ? $bundleConfig['oro_titles'] : []); } } } // process configurations to validate and merge $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $entitiesConfig); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $container->setParameter('oro_menu_config', $config); $container->setParameter('oro_titles', $titlesConfig); }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuredMenus = array(); if (is_file($file = $container->getParameter('kernel.root_dir') . '/config/navigation.yml')) { $configuredMenus = $this->parseFile($file); $container->addResource(new FileResource($file)); } foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/navigation.yml')) { $configuredMenus = array_replace_recursive($configuredMenus, $this->parseFile($file)); $container->addResource(new FileResource($file)); } } $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); // validate menu configurations foreach ($configuredMenus as $rootName => $menuConfiguration) { $configuration = new NavigationConfiguration(); $configuration->setMenuRootName($rootName); $menuConfiguration[$rootName] = $this->processConfiguration($configuration, array($rootName => $menuConfiguration)); } // Set configuration to be used in a custom service $container->setParameter('jb_config.menu.configuration', $configuredMenus); // Last argument of this service is always the menu configuration $container->getDefinition('jb_config.menu.provider')->addArgument($configuredMenus); }
/** * Obtains the default basedir for this widget * @return string */ public function getDefaultBaseDir() { $class = new \ReflectionClass($this); $dir = dirname($class->getFilename()); $dir = str_replace(APPPATH . 'classes' . DIRECTORY_SEPARATOR, '', $dir); return $dir . '/' . strtolower($this->getName()) . '/'; }
/** * Loads the Swift Mailer configuration. * * Usage example: * * <swiftmailer:config transport="gmail"> * <swiftmailer:username>fabien</swift:username> * <swiftmailer:password>xxxxx</swift:password> * <swiftmailer:spool path="/path/to/spool/" /> * </swiftmailer:config> * * @param array $config An array of configuration settings * @param ContainerBuilder $container A ContainerBuilder instance */ public function configLoad(array $config, ContainerBuilder $container) { if (!$container->hasDefinition('swiftmailer.mailer')) { $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config'); $loader->load('swiftmailer.xml'); $container->setAlias('mailer', 'swiftmailer.mailer'); } $r = new \ReflectionClass('Swift_Message'); $container->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename())))); $transport = $container->getParameter('swiftmailer.transport.name'); if (array_key_exists('transport', $config)) { if (null === $config['transport']) { $transport = 'null'; } elseif ('gmail' === $config['transport']) { $config['encryption'] = 'ssl'; $config['auth_mode'] = 'login'; $config['host'] = 'smtp.gmail.com'; $transport = 'smtp'; } else { $transport = $config['transport']; } $container->setParameter('swiftmailer.transport.name', $transport); } $container->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $transport); if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) { $config['port'] = 465; } foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) { if (isset($config[$key])) { $container->setParameter('swiftmailer.transport.' . $transport . '.' . $key, $config[$key]); } } // spool? if (isset($config['spool'])) { $type = isset($config['spool']['type']) ? $config['spool']['type'] : 'file'; $container->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $transport); $container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool'); $container->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type); foreach (array('path') as $key) { if (isset($config['spool'][$key])) { $container->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]); } } } if (array_key_exists('delivery-address', $config)) { $config['delivery_address'] = $config['delivery-address']; } if (isset($config['delivery_address']) && $config['delivery_address']) { $container->setParameter('swiftmailer.single_address', $config['delivery_address']); $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting'))); } else { $container->setParameter('swiftmailer.single_address', null); } if (array_key_exists('disable-delivery', $config)) { $config['disable_delivery'] = $config['disable-delivery']; } if (isset($config['disable_delivery']) && $config['disable_delivery']) { $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole'))); } }
/** * @param \ReflectionClass $class * * @return \Metadata\ClassMetadata */ public function loadMetadataForClass(\ReflectionClass $class) { $classMetadata = new ClassMetadata($name = $class->name); $classMetadata->fileResources[] = $class->getFilename(); foreach ($class->getMethods() as $method) { /** * @var \ReflectionMethod $method */ if ($method->class !== $name) { continue; } $methodAnnotations = $this->reader->getMethodAnnotations($method); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof ParamType) { if (!$classMetadata->hasMethod($method->name)) { $this->addMethod($classMetadata, $method); } $classMetadata->setParameterType($method->getName(), $annotation->name, $annotation->type); $classMetadata->setParameterOptions($method->getName(), $annotation->name, $annotation->options); } if ($annotation instanceof ReturnType) { $classMetadata->setReturnType($method->getName(), $annotation->type); } } } return $classMetadata; }
static function accepted_params($that) { return array('fName' => array(function () use($that) { $ref = new ReflectionClass($that); return dirname($ref->getFilename()) . '/plain/' . str_replace('View_', '', $ref->getName()) . '.php'; }, 'is_string_or_null'), 'data' => array(null, 'is_a_or_null', 'StdClass'), 'env' => array(null, 'is_a_or_null', 'Environment')); }
/** * {@inheritdoc} */ public function boot(Application $app) { $locale = $app['locale']; // New loader types, array and xliff format // alredy loades by Silex\Provider\TranslationServiceProvider $app['translator']->addLoader('yml', new Loader\YamlFileLoader()); $app['translator']->addLoader('xlf', new Loader\XliffFileLoader()); $app['translator']->addLoader('php', new Loader\PhpFileLoader()); // Security $reflClass = new \ReflectionClass('Symfony\\Component\\Security\\Core\\Security'); $file = sprintf('%s/Resources/translations/security.%s.xlf', dirname($reflClass->getFilename()), $locale); $app['translator']->addResource('xlf', $file, $locale, 'security'); // Translation dirs @todo mirar urilizar $app y $app->protect $transDirs = array_unique([sprintf('%s/../Resources/translations', __DIR__), sprintf(sprintf('%s/../../../../../../app/translations', __DIR__))]); foreach ($transDirs as $transDir) { if (!is_dir($transDir) || !is_readable($transDir)) { continue; } $files = $this->getTranslationFiles($transDir, $locale); foreach ($files as $file) { $filename = $file->getRealPath(); // Filename is domain.locale.format list($domain, $locale, $format) = explode('.', basename($filename), 3); $app['translator']->addResource($format, $filename, $locale, $domain); } } }
/** * {@inheritdoc} */ public function isFresh($timestamp) { if ($this->isFreshTimestamp !== $timestamp) { $this->isFreshTimestamp = $timestamp; $this->isFresh = true; $bundles = CumulativeResourceManager::getInstance()->getBundles(); $appRootDir = CumulativeResourceManager::getInstance()->getAppRootDir(); foreach ($bundles as $bundleName => $bundleClass) { $reflection = new \ReflectionClass($bundleClass); $bundleDir = dirname($reflection->getFilename()); $bundleAppDir = ''; /** * This case needs for tests(without app root directory). */ if (is_dir($appRootDir)) { $bundleAppDir = $appRootDir . '/Resources/' . $bundleName; } /** @var CumulativeResourceLoader $loader */ foreach ($this->resourceLoaders as $loader) { if (!$loader->isResourceFresh($bundleClass, $bundleDir, $bundleAppDir, $this, $timestamp)) { $this->isFresh = false; break; } } if (!$this->isFresh) { break; } } } return $this->isFresh; }
/** * Loads a specific configuration. * * @param array $config Extension configuration hash (from behat.yml) * @param ContainerBuilder $container ContainerBuilder instance */ public function load(array $config, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/services')); $loader->load('core.xml'); if (isset($config['mink_loader'])) { $basePath = $container->getParameter('behat.paths.base'); if (file_exists($basePath . DIRECTORY_SEPARATOR . $config['mink_loader'])) { require $basePath . DIRECTORY_SEPARATOR . $config['mink_loader']; } else { require $config['mink_loader']; } } if (isset($config['goutte'])) { if (!class_exists('Behat\\Mink\\Driver\\GoutteDriver')) { throw new \RuntimeException('Install MinkGoutteDriver in order to activate goutte session.'); } $loader->load('sessions/goutte.xml'); } if (isset($config['sahi'])) { if (!class_exists('Behat\\Mink\\Driver\\SahiDriver')) { throw new \RuntimeException('Install MinkSahiDriver in order to activate sahi session.'); } $loader->load('sessions/sahi.xml'); } if (isset($config['zombie'])) { if (!class_exists('Behat\\Mink\\Driver\\ZombieDriver')) { throw new \RuntimeException('Install MinkZombieDriver in order to activate zombie session.'); } $loader->load('sessions/zombie.xml'); } if (isset($config['selenium'])) { if (!class_exists('Behat\\Mink\\Driver\\SeleniumDriver')) { throw new \RuntimeException('Install MinkSeleniumDriver in order to activate selenium session.'); } $loader->load('sessions/selenium.xml'); } if (isset($config['selenium2'])) { if (!class_exists('Behat\\Mink\\Driver\\Selenium2Driver')) { throw new \RuntimeException('Install MinkSelenium2Driver in order to activate selenium2 session.'); } $loader->load('sessions/selenium2.xml'); } $minkParameters = array(); foreach ($config as $ns => $tlValue) { if (!is_array($tlValue)) { $minkParameters[$ns] = $tlValue; } else { foreach ($tlValue as $name => $value) { $container->setParameter("behat.mink.{$ns}.{$name}", $value); } } } $container->setParameter('behat.mink.parameters', $minkParameters); $container->setParameter('behat.mink.default_session', $config['default_session']); $container->setParameter('behat.mink.javascript_session', $config['javascript_session']); $container->setParameter('behat.mink.browser_name', $config['browser_name']); $minkReflection = new \ReflectionClass('Behat\\Mink\\Mink'); $minkLibPath = realpath(dirname($minkReflection->getFilename()) . '/../../../'); $container->setParameter('mink.paths.lib', $minkLibPath); }
public function register(Container $app) { $app['validator'] = function ($app) { if (isset($app['translator'])) { $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validation'); $file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf'; if (file_exists($file)) { $app['translator']->addResource('xliff', $file, $app['locale'], 'validators'); } } return $app['validator.builder']->getValidator(); }; $app['validator.builder'] = function ($app) { $builder = Validation::createValidatorBuilder(); $builder->setConstraintValidatorFactory($app['validator.validator_factory']); $builder->setTranslationDomain('validators'); $builder->addObjectInitializers($app['validator.object_initializers']); $builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']); if (isset($app['translator'])) { $builder->setTranslator($app['translator']); } return $builder; }; $app['validator.mapping.class_metadata_factory'] = function ($app) { return new LazyLoadingMetadataFactory(new StaticMethodLoader()); }; $app['validator.validator_factory'] = function () use($app) { $validators = isset($app['validator.validator_service_ids']) ? $app['validator.validator_service_ids'] : array(); return new ConstraintValidatorFactory($app, $validators); }; $app['validator.object_initializers'] = function ($app) { return array(); }; }
public function getDataSet($fixtures = array()) { $db = Database::get(); if (count($this->tables)) { $partial = new SimpleXMLElement('<schema></schema>'); $partial->addAttribute('version', '0.3'); $xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml'); foreach ($xml->table as $t) { $name = (string) $t['name']; if (in_array($name, $this->tables)) { $this->appendXML($partial, $t); } } $schema = \Concrete\Core\Database\Schema\Schema::loadFromXMLElement($partial, $db); $platform = $db->getDatabasePlatform(); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } } if (empty($fixtures)) { $fixtures = $this->fixtures; } $reflectionClass = new ReflectionClass(get_called_class()); $fixturePath = dirname($reflectionClass->getFilename()) . DIRECTORY_SEPARATOR . 'fixtures'; $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array()); foreach ((array) $fixtures as $fixture) { $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml"; $ds = $this->createMySQLXMLDataSet($path); $compositeDs->addDataSet($ds); } return $compositeDs; }
public function process(ContainerBuilder $container) { $dirs = array(); foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/config/validation')) { $dirs[] = $dir; } } if (is_dir($dir = $container->getParameter('kernel.root_dir') . '/Resources/config/validation')) { $dirs[] = $dir; } $newFiles = array(); if ($dirs) { $finder = new Finder(); $finder->files()->name('*.xml')->in($dirs); foreach ($finder as $file) { $newFiles[] = $file->getPathName(); } } $validatorBuilder = $container->getDefinition('validator.builder'); if (count($newFiles) > 0) { $validatorBuilder->addMethodCall('addXmlMappings', array($newFiles)); } }
/** * Get list of existing translation locales for current translation domain * * @return array */ protected function getTranslationLocales() { if (null === $this->translationLocales) { $translationDirectory = str_replace('/', DIRECTORY_SEPARATOR, $this->translationDirectory); $translationDirectories = array(); foreach ($this->container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); $bundleTranslationDirectory = dirname($reflection->getFilename()) . $translationDirectory; if (is_dir($bundleTranslationDirectory) && is_readable($bundleTranslationDirectory)) { $translationDirectories[] = realpath($bundleTranslationDirectory); } } $domainFileRegExp = $this->getDomainFileRegExp(); $finder = new Finder(); $finder->in($translationDirectories)->name($domainFileRegExp); $this->translationLocales = array(); /** @var $file \SplFileInfo */ foreach ($finder as $file) { preg_match($domainFileRegExp, $file->getFilename(), $matches); if ($matches) { $this->translationLocales[] = $matches[1]; } } $this->translationLocales = array_unique($this->translationLocales); } return $this->translationLocales; }
/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { if (false === $container->hasDefinition('sculpin_twig.loader')) { return; } $definition = $container->getDefinition('sculpin_twig.loader'); $arguments = $definition->getArguments(); $loaders = $arguments[0]; $prependedLoaders = array(); $appendedLoaders = array(); foreach ($container->findTaggedServiceIds('twig.loaders.prepend') as $id => $attributes) { $prependedLoaders[] = new Reference($id); } foreach ($container->findTaggedServiceIds('twig.loaders.append') as $id => $attributes) { $appendedLoaders[] = new Reference($id); } $sourceViewPaths = $container->getParameter('sculpin_twig.source_view_paths'); foreach ($container->getParameter('kernel.bundles') as $class) { $reflection = new \ReflectionClass($class); foreach ($sourceViewPaths as $sourceViewPath) { if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/' . $sourceViewPath)) { $appendedLoaders[] = $dir; } } } $arguments[0] = array_merge($prependedLoaders, $loaders, $appendedLoaders); $definition->setArguments($arguments); }
/** * {@inheritdoc} */ public function loadMetadataForClass(\ReflectionClass $class) { $actionMetadata = new ActionMetadata($class->name); $actionMetadata->fileResources[] = $class->getFilename(); $actionAnnotation = $this->reader->getClassAnnotation($class, Action::class); /** @var Action $actionAnnotation */ if ($actionAnnotation !== null) { $actionMetadata->isAction = true; $actionMetadata->serviceId = $actionAnnotation->serviceId ?: null; $actionMetadata->alias = $actionAnnotation->alias ?: null; } else { return null; } /** @var Security $securityAnnotation */ $securityAnnotation = $this->reader->getClassAnnotation($class, Security::class); if ($securityAnnotation) { $actionMetadata->authorizationExpression = $securityAnnotation->expression; } $methodCount = 0; foreach ($class->getMethods() as $method) { if (!$method->isPublic()) { continue; } $methodMetadata = $this->loadMetadataForMethod($class, $method); if ($methodMetadata) { $actionMetadata->addMethodMetadata($methodMetadata); $methodCount++; } } if ($methodCount < 1) { return null; } return $actionMetadata; }
public function register(Application $app) { if (!class_exists('Locale') && !class_exists('Symfony\\Component\\Locale\\Stub\\StubLocale')) { throw new \RuntimeException('You must either install the PHP intl extension or the Symfony Locale Component to use the Form extension.'); } if (!class_exists('Locale')) { $r = new \ReflectionClass('Symfony\\Component\\Locale\\Stub\\StubLocale'); $path = dirname(dirname($r->getFilename())) . '/Resources/stubs'; require_once $path . '/functions.php'; require_once $path . '/Collator.php'; require_once $path . '/IntlDateFormatter.php'; require_once $path . '/Locale.php'; require_once $path . '/NumberFormatter.php'; } $app['form.secret'] = md5(__DIR__); $app['form.factory'] = $app->share(function () use($app) { $extensions = array(new CoreExtension(), new CsrfExtension($app['form.csrf_provider'])); if (isset($app['validator'])) { $extensions[] = new FormValidatorExtension($app['validator']); if (isset($app['translator'])) { $r = new \ReflectionClass('Symfony\\Component\\Form\\Form'); $app['translator']->addResource('xliff', dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf', $app['locale'], 'validators'); } } return new FormFactory($extensions); }); $app['form.csrf_provider'] = $app->share(function () use($app) { if (isset($app['session'])) { return new SessionCsrfProvider($app['session'], $app['form.secret']); } return new DefaultCsrfProvider($app['form.secret']); }); }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); $dirs = array(); foreach ($config['spec_loader']['paths'] as $path) { $dirs[] = $path; } // register bundles as fixed width directories foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { if (is_dir($dir = $container->getParameter('kernel.root_dir') . '/Resources/' . $bundle . '/fixed_width')) { $dirs[] = $dir; } $reflection = new \ReflectionClass($class); if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/fixed_width')) { $dirs[] = $dir; } } if (is_dir($dir = $container->getParameter('kernel.root_dir') . '/Resources/fixed_width')) { $dirs[] = $dir; } $container->setParameter('giftcards.fixed_width.spec_file_dirs', $dirs); $container->getDefinition('giftcards.fixed_width.file_factory')->replaceArgument(0, new Reference($config['spec_loader']['id']))->replaceArgument(1, new Reference($config['value_formatter_id'])); }
protected function testPluginClassForClosureCall($class) { $reflection = new \ReflectionClass($class); $methods = $reflection->getMethods(); foreach ($methods as $method) { if (strpos($method->getName(), 'around') !== 0) { continue; } $parameters = $method->getParameters(); $chain_closure = $parameters[1]; $chain_closure_var_name = $chain_closure->getName(); $lines = file($method->getFilename()); array_unshift($lines, ''); $method_lines = array_splice($lines, $method->getStartLine(), $method->getEndLine() - $method->getStartLine()); $path = tempnam('/tmp', 'forstrip'); $method_text = implode('', $method_lines); file_put_contents($path, '<' . '?' . 'php' . "\n" . $method_text); $method_text = php_strip_whitespace($path); unlink($path); if (strpos($method_text, '$' . $chain_closure_var_name . '(') === false) { echo $class, " : "; echo 'FAILED: ', ' could not find ' . '$' . $chain_closure_var_name . '()', "\n"; echo ' ' . $reflection->getFilename(), "\n"; echo ' ' . $method->getFilename(), "\n"; } else { // echo $class," : "; // echo 'PASSED',"\n"; } } }
/** * Gets translation files location. * * @return array */ private function getLocations() { $locations = array(); if (class_exists('Symfony\\Component\\Validator\\Validator')) { $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validator'); $locations[] = dirname($r->getFilename()) . '/Resources/translations'; } if (class_exists('Symfony\\Component\\Form\\Form')) { $r = new \ReflectionClass('Symfony\\Component\\Form\\Form'); $locations[] = dirname($r->getFilename()) . '/Resources/translations'; } if (class_exists('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException')) { $r = new \ReflectionClass('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException'); if (file_exists($dir = dirname($r->getFilename()) . '/../../Resources/translations')) { $locations[] = $dir; } else { // Symfony 2.4 and above $locations[] = dirname($r->getFilename()) . '/../Resources/translations'; } } $overridePath = $this->kernel->getRootDir() . '/Resources/%s/translations'; foreach ($this->kernel->getBundles() as $bundle => $class) { $reflection = new \ReflectionClass($class); if (is_dir($dir = dirname($reflection->getFilename()) . '/Resources/translations')) { $locations[] = $dir; } if (is_dir($dir = sprintf($overridePath, $bundle))) { $locations[] = $dir; } } if (is_dir($dir = $this->kernel->getRootDir() . '/Resources/translations')) { $locations[] = $dir; } return $locations; }
/** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { // retrieve each measure config from bundles $measuresConfig = array(); foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/measure.yml')) { // merge measures configs if (empty($measuresConfig)) { $measuresConfig = Yaml::parse(realpath($file)); } else { $entities = Yaml::parse(realpath($file)); foreach ($entities['measures_config'] as $family => $familyConfig) { // merge result with already existing family config to add custom units if (isset($measuresConfig['measures_config'][$family])) { $measuresConfig['measures_config'][$family]['units'] = array_merge($measuresConfig['measures_config'][$family]['units'], $familyConfig['units']); } else { $measuresConfig['measures_config'][$family] = $familyConfig; } } } } } $configs[] = $measuresConfig; // process configurations to validate and merge $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); // load service $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); // set measures config $container->setParameter('akeneo_measure.measures_config', $config); $container->getDefinition('akeneo_measure.manager')->addMethodCall('setMeasureConfig', $config); }
protected function getControllerCode() { $r = new \ReflectionClass($this->controller[0]); $m = $r->getMethod($this->controller[1]); $code = file($r->getFilename()); return ' ' . $m->getDocComment() . "\n" . implode('', array_slice($code, $m->getStartline() - 1, $m->getEndLine() - $m->getStartline() + 1)); }
public function register(Application $app) { $app['validator'] = $app->share(function ($app) { $r = new \ReflectionClass('Symfony\\Component\\Validator\\Validator'); if (isset($app['translator'])) { $app['translator']->addResource('xliff', dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf', $app['locale'], 'validators'); } $params = $r->getConstructor()->getParameters(); if ('validatorInitializers' === $params[2]->getName()) { // BC: to be removed before 1.0 // Compatibility with symfony/validator 2.1 // can be removed once silex requires 2.2 return new Validator($app['validator.mapping.class_metadata_factory'], $app['validator.validator_factory']); } else { return new Validator($app['validator.mapping.class_metadata_factory'], $app['validator.validator_factory'], isset($app['translator']) ? $app['translator'] : new DefaultTranslator()); } }); $app['validator.mapping.class_metadata_factory'] = $app->share(function ($app) { return new ClassMetadataFactory(new StaticMethodLoader()); }); $app['validator.validator_factory'] = $app->share(function () use($app) { $validators = isset($app['validator.validator_service_ids']) ? $app['validator.validator_service_ids'] : array(); return new ConstraintValidatorFactory($app, $validators); }); }