本文整理汇总了PHP中ReflectionClass::getFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getFilename方法的具体用法?PHP ReflectionClass::getFilename怎么用?PHP ReflectionClass::getFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @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));
}
}
示例2: testConfigure
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;
}
}
示例3: execute
/**
* @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);
}
}
示例4: testIsFresh
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());
}
示例5: getController
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));
}
示例6: loadMetadataForClass
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;
}
示例7: process
/**
* {@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);
}
示例8: register
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']);
}
}
示例9: load
/**
* {@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);
}
示例10: load
/**
* {@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);
}
示例11: getDefaultBaseDir
/**
* 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()) . '/';
}
示例12: configLoad
/**
* 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')));
}
}
示例13: loadMetadataForClass
/**
* @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;
}
示例14: array
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'));
}
示例15: boot
/**
* {@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);
}
}
}