public static function autoload($className) { $className = str_replace('.', '_', $className); $className = str_replace(DIRECTORY_SEPARATOR, '_', $className); $className = str_replace('/', '_', $className); if (class_exists($className, false) || interface_exists($className, false)) { return false; } $classFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . $className . '.php'; if (file_exists($classFile)) { require $classFile; return true; } // Search modules directories foreach (self::_get_modules_dirs() as $module_dir) { $classFile = $module_dir . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $className . '.php'; if (file_exists($classFile)) { require $classFile; return true; } } // Search templates directories $lang_class_path = self::_build_search_path($className . '.php', "web", self::detect_language()); foreach (self::_build_search_path($className . '.php', "web", self::detect_language(), true) as $candidate) { if (file_exists($candidate)) { require $candidate; return true; } } return false; }
/** * {@inheritdoc} */ public function register(Container $app) { $app['puli.factory'] = function () { $factoryClass = PULI_FACTORY_CLASS; return new $factoryClass(); }; $app['puli.repository'] = function ($app) { return $app['puli.factory']->createRepository(); }; $app['puli.discovery'] = function ($app) { return $app['puli.factory']->createDiscovery(); }; $app['puli.url_generator'] = function ($app) { return $app['puli.factory']->createUrlGenerator($app['puli.discovery']); }; if (isset($app['twig'])) { if (interface_exists('Puli\\UrlGenerator\\Api\\UrlGenerator')) { $app->extend('twig', function ($twig, $app) { $twig->addExtension(new PuliExtension($app['puli.repository'], $app['puli.url_generator'])); return $twig; }); } $app->extend('twig.loader', function ($loader, $app) { $loader->addLoader(new PuliTemplateLoader($app['puli.repository'])); return $loader; }); } }
/** * Replace App::uses with use <Classname>; * * @param string $contents * @return string */ protected function _replaceAppUses($contents) { $pattern = '#App::uses\\(\\s*[\'"]([a-z0-9_]+)[\'"]\\s*,\\s*[\'"]([a-z0-9/_]+)(?:\\.([a-z0-9/_]+))?[\'"]\\)#i'; $replacement = function ($matches) { $matches = $this->_mapClassName($matches); // Chop Lib out as locations moves those files to the top level. // But only if Lib is not the last folder. if (isset($matches[3]) && substr($matches[3], 0, 4) === 'Lib/') { $use = $matches[2] . '\\' . substr($matches[3], 4) . '\\' . $matches[1]; } elseif (count($matches) === 4) { $use = $matches[2] . '\\' . $matches[3] . '\\' . $matches[1]; } elseif ($matches[2] === 'Vendor') { $this->out(sprintf('<info>Skip %s as it is a vendor library.</info>', $matches[1]), 1, Shell::VERBOSE); return $matches[0]; } else { $use = 'Cake\\' . $matches[2] . '\\' . $matches[1]; if (!class_exists($use) && !interface_exists($use)) { $use = 'App\\' . substr($use, 5); } } $use = str_replace('/', '\\', $use); return 'use ' . $use; }; return preg_replace_callback($pattern, $replacement, $contents, -1, $count); }
/** * @throws WrongArgumentException * @return PrimitiveIdentifier **/ public function of($class) { $className = $this->guessClassName($class); Assert::isTrue(class_exists($className, true) || interface_exists($className, true), "knows nothing about '{$className}' class/interface"); $this->ofClassName = $className; return $this; }
/** * {@inheritdoc} */ protected function configureFormFields(FormMapper $formMapper) { $formMapper->tab('tab.bruery_classification_category_general')->with('tab.group.bruery_classification_category_general', array('class' => 'col-md-8'))->end()->with('tab.group.bruery_classification_category_options', array('class' => 'col-md-4'))->end()->end(); if ($this->hasProvider()) { $formMapper->tab('tab.bruery_classification_category_settings')->with('tab.group.bruery_classification_category_settings', array('class' => 'col-md-8'))->end()->end(); } $formMapper->tab('tab.bruery_classification_category_general')->with('tab.group.bruery_classification_category_general')->add('name')->add('description', 'textarea', array('required' => false))->end()->end(); if ($this->hasSubject()) { if ($this->getSubject()->getParent() !== null || $this->getSubject()->getId() === null) { // root category cannot have a parent $formMapper->tab('tab.bruery_classification_category_general')->with('tab.group.bruery_classification_category_general')->add('parent', 'sonata_category_selector', array('category' => $this->getSubject() ?: null, 'model_manager' => $this->getModelManager(), 'class' => $this->getClass(), 'required' => true, 'context' => $this->getSubject()->getContext() ?: $this->getDefaultContext()))->end()->end(); } } $position = $this->hasSubject() && !is_null($this->getSubject()->getPosition()) ? $this->getSubject()->getPosition() : 0; $formMapper->tab('tab.bruery_classification_category_general')->with('tab.group.bruery_classification_category_options')->add('enabled', null, array('required' => false))->add('position', 'integer', array('required' => false, 'data' => $position))->end()->end(); if (interface_exists('Sonata\\MediaBundle\\Model\\MediaInterface')) { $formMapper->tab('tab.bruery_classification_category_general')->with('tab.group.bruery_classification_category_general')->add('media', 'sonata_type_model_list', array('required' => false), array('link_parameters' => array('provider' => 'sonata.media.provider.image', 'context' => 'sonata_category')))->end()->end(); } if ($this->hasProvider()) { $instance = $this->getSubject(); if ($instance && $instance->getId()) { $this->provider->load($instance); $this->provider->buildEditForm($formMapper); } else { $this->provider->buildCreateForm($formMapper); } } }
/** * Construct a new mock builder. * * Each value in `$types` can be either a class name, or an ad hoc mock * definition. If only a single type is being mocked, the class name or * definition can be passed without being wrapped in an array. * * @param mixed $types The types to mock. * @param MockFactory $factory The factory to use. * @param HandleFactory $handleFactory The handle factory to use. * @param InvocableInspector $invocableInspector The invocable inspector. * @param FeatureDetector $featureDetector The feature detector to use. * * @throws MockException If invalid input is supplied. */ public function __construct($types, MockFactory $factory, HandleFactory $handleFactory, InvocableInspector $invocableInspector, FeatureDetector $featureDetector) { $this->isTraitSupported = $featureDetector->isSupported('trait'); $this->isAnonymousClassSupported = $featureDetector->isSupported('class.anonymous'); $this->isRelaxedKeywordsSupported = $featureDetector->isSupported('parser.relaxed-keywords'); $this->isEngineErrorExceptionSupported = $featureDetector->isSupported('error.exception.engine'); $this->isDateTimeInterfaceSupported = interface_exists('DateTimeInterface'); $this->factory = $factory; $this->handleFactory = $handleFactory; $this->invocableInspector = $invocableInspector; $this->featureDetector = $featureDetector; $this->types = array(); $this->parentClassName = null; $this->customMethods = array(); $this->customProperties = array(); $this->customStaticMethods = array(); $this->customStaticProperties = array(); $this->customConstants = array(); $this->isFinalized = false; $this->emptyCallback = function () { }; if (null !== $types) { $this->like($types); } }
/** * Loads a class from a PHP file. The filename must be formatted * as "$class.php". * * If $dirs is a string or an array, it will search the directories * in the order supplied, and attempt to load the first matching file. * * If $dirs is null, it will split the class name at underscores to * generate a path hierarchy (e.g., "Zend_Example_Class" will map * to "Zend/Example/Class.php"). * * If the file was not found in the $dirs, or if no $dirs were specified, * it will attempt to load it from PHP's include_path. * * @param string $class - The full class name of a Zend component. * @param string|array $dirs - OPTIONAL Either a path or an array of paths * to search. * @return void * @throws Zend_Exception */ public static function loadClass($class, $dirs = null) { if (class_exists($class, false) || interface_exists($class, false)) { return; } if (null !== $dirs && !is_string($dirs) && !is_array($dirs)) { #require_once 'Zend/Exception.php'; throw new Zend_Exception('Directory argument must be a string or an array'); } $file = self::standardiseFile($class); if (!empty($dirs)) { // use the autodiscovered path $dirPath = dirname($file); if (is_string($dirs)) { $dirs = explode(PATH_SEPARATOR, $dirs); } foreach ($dirs as $key => $dir) { if ($dir == '.') { $dirs[$key] = $dirPath; } else { $dir = rtrim($dir, '\\/'); $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; } } $file = basename($file); self::loadFile($file, $dirs, true); } else { self::loadFile($file, null, true); } if (!class_exists($class, false) && !interface_exists($class, false)) { #require_once 'Zend/Exception.php'; throw new Zend_Exception("File \"{$file}\" does not exist or class \"{$class}\" was not found in the file"); } }
/** * Find classes which are used as parameters types of the specified method and are not declared. * * @param string $file * @param \ReflectionClass $classReflection * @param string $methodName * @param string $entityType * @return string[] */ protected function _findMissingClasses($file, $classReflection, $methodName, $entityType) { $missingClasses = []; if ($classReflection->hasMethod($methodName)) { $constructor = $classReflection->getMethod($methodName); $parameters = $constructor->getParameters(); /** @var $parameter \ReflectionParameter */ foreach ($parameters as $parameter) { preg_match('/\[\s\<\w+?>\s([\w\\\\]+)/s', $parameter->__toString(), $matches); if (isset($matches[1]) && substr($matches[1], -strlen($entityType)) == $entityType) { $missingClassName = $matches[1]; try { if (class_exists($missingClassName)) { continue; } } catch (\Magento\Framework\Exception\LocalizedException $e) { } $sourceClassName = $this->getSourceClassName($missingClassName, $entityType); if (!class_exists($sourceClassName) && !interface_exists($sourceClassName)) { $this->_log->add( Log::CONFIGURATION_ERROR, $missingClassName, "Invalid {$entityType} for nonexistent class {$sourceClassName} in file {$file}" ); continue; } $missingClasses[] = $missingClassName; } } } return $missingClasses; }
/** * Load the file for a class * * @param string $class The class that will be loaded * @return boolean True on success */ public static function loadClass($class) { // pre-empt further searching for the named class or interface. // do not use autoload, because this method is registered with // spl_autoload already. if (class_exists($class, false) || interface_exists($class, false)) { return; } // if class start with a 'Nooku' it is a Nooku class. // create the path and register it with the loader. switch (substr($class, 0, 6)) { case 'Picman': $word = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', substr_replace($class, '', 0, 6))); $parts = explode('_', $word); if (count($parts) > 1) { $path = KInflector::pluralize(array_shift($parts)) . DS . implode(DS, $parts); } else { $path = $word; } if (is_file(dirname(__FILE__) . DS . $path . '.php')) { KLoader::register($class, dirname(__FILE__) . DS . $path . '.php'); } break; } $classes = KLoader::register(); if (array_key_exists(strtolower($class), $classes)) { include $classes[strtolower($class)]; return true; } return false; }
/** * Autoloading of maxAPI classes */ function maxAPIAutoload($className) { if (class_exists($className, false) || interface_exists($className, false)) { return; } include_once $className . '.php'; }
/** * Autoload a class * * @param string $class Classname to load * * @return bool */ function CAS_autoload($class) { // Static to hold the Include Path to CAS static $include_path; // Check only for CAS classes if (substr($class, 0, 4) !== 'CAS_') { return false; } // Setup the include path if it's not already set from a previous call if (empty($include_path)) { $include_path = array(dirname(dirname(__FILE__)), dirname(dirname(__FILE__)) . '/../test/'); } // Declare local variable to store the expected full path to the file foreach ($include_path as $path) { $file_path = $path . '/' . str_replace('_', '/', $class) . '.php'; $fp = @fopen($file_path, 'r', true); if ($fp) { fclose($fp); include $file_path; if (!class_exists($class, false) && !interface_exists($class, false)) { die(new Exception('Class ' . $class . ' was not present in ' . $file_path . ' [CAS_autoload]')); } return true; } } $e = new Exception('Class ' . $class . ' could not be loaded from ' . $file_path . ', file does not exist (Path="' . implode(':', $include_path) . '") [CAS_autoload]'); $trace = $e->getTrace(); if (isset($trace[2]) && isset($trace[2]['function']) && in_array($trace[2]['function'], array('class_exists', 'interface_exists'))) { return false; } if (isset($trace[1]) && isset($trace[1]['function']) && in_array($trace[1]['function'], array('class_exists', 'interface_exists'))) { return false; } die((string) $e); }
public function implementsInterface($interface) { if (!interface_exists($interface)) { throw new ReflectionException("Interface " . $interface . " does not exist "); } // todo add actual checking }
protected static function autoload($class) { $className = $class; if (class_exists($className, false) || interface_exists($className, false)) { return true; } $directory = ''; if (App::isCategoryType($class, self::APP_LOADER_MODEL)) { //this is a model $directory = CODE_BASE . DIRECTORY_SEPARATOR . self::APP_MODEL_DIRECTORY_NAME . DIRECTORY_SEPARATOR; $class = App::resolveCategory($class, self::APP_LOADER_MODEL); } else { if (App::isCategoryType($class, self::APP_LOADER_CONTROLLER)) { //this is a controller $directory = CODE_BASE . DIRECTORY_SEPARATOR . self::APP_CONTROLLER_DIRECTORY_NAME; $class = App::resolveCategory($class, self::APP_LOADER_CONTROLLER); } else { //this is used library $directory = CODE_BASE . DIRECTORY_SEPARATOR . self::APP_LIBRARY_DIRECTORY_NAME; } } $file = $directory . DIRECTORY_SEPARATOR . $class . '.php'; if (is_file($file)) { include $file; } return true; }
/** * Constructor * * @param string $interfaceName * @param MethodDataProviderFactory $methodDataProviderFactory * @param Reader $reader */ public function __construct($interfaceName, MethodDataProviderFactory $methodDataProviderFactory, Reader $reader) { Tebru\assertThat(interface_exists($interfaceName), '"%s" is not a valid interface', $interfaceName); $this->reflectionClass = new ReflectionClass($interfaceName); $this->methodDataProviderFactory = $methodDataProviderFactory; $this->reader = $reader; }
/** * {@inheritdoc} */ protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata) { $reflection = new \ReflectionClass($metadata->getClass('model')); $translatableInterface = TranslatableInterface::class; $translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface); $repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName()); $repositoryClass = $translatable ? TranslatableResourceRepository::class : EntityRepository::class; if ($container->hasParameter($repositoryClassParameterName)) { $repositoryClass = $container->getParameter($repositoryClassParameterName); } if ($metadata->hasClass('repository')) { $repositoryClass = $metadata->getClass('repository'); } $repositoryReflection = new \ReflectionClass($repositoryClass); $definition = new Definition($repositoryClass); $definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]); $definition->setLazy(!$repositoryReflection->isFinal()); if ($metadata->hasParameter('translation')) { $translatableRepositoryInterface = TranslatableResourceRepositoryInterface::class; $translationConfig = $metadata->getParameter('translation'); if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) { if (isset($translationConfig['fields'])) { $definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]); } } } $container->setDefinition($metadata->getServiceId('repository'), $definition); }
public static function getPropertyType(ReflectionProperty $property) { if (empty($property->getDocComment())) { return null; } if (strpos($property->getDocComment(), '@var ') === false) { return null; } $typeName = preg_split('/\\s/', substr($property->getDocComment(), strpos($property->getDocComment(), '@var ') + 5))[0]; if (class_exists($typeName) || interface_exists($typeName)) { return $typeName; } $paths = self::getUseStatements($property->getDeclaringClass()); if ($property->getDeclaringClass()->getNamespaceName()) { $paths[] = $property->getDeclaringClass()->getNamespaceName(); } $paths[] = ''; foreach ($paths as $alias => $path) { if (strtolower($alias) == strtolower($typeName)) { return $path; } else { if (class_exists($path . '\\' . $typeName) || interface_exists($path . '\\' . $typeName)) { return $path . '\\' . $typeName; } } } return Constants::normalizeType(strtolower($typeName)); }
/** * {@inheritdoc} */ protected function configureFormFields(FormMapper $formMapper) { $formMapper->add('name')->add('description', 'textarea', array('required' => false))->add('context')->add('enabled', null, array('required' => false)); if (interface_exists('Sonata\\MediaBundle\\Model\\MediaInterface')) { $formMapper->add('media', 'sonata_type_model_list', array('required' => false), array('link_parameters' => array('provider' => 'sonata.media.provider.image', 'context' => 'sonata_collection'))); } }
public static function autoload($class) { $filename = self::_autoloaderClassToFile($class); if (!$filename) { return false; } $proLocation = substr_replace(BETTER_ANALYTICS_PLUGIN_DIR, '-pro', -1); $allowed = false; if (file_exists($proLocation . $filename)) { $betterAnalyticsInternal = get_transient('ba_int'); if (@$betterAnalyticsInternal['v'] || strpos(@$_SERVER['SCRIPT_NAME'], '/plugins.php') !== false || strpos(@$_SERVER['SCRIPT_NAME'], '/tools.php') !== false || $class == 'DigitalPointBetterAnalytics_Helper_Api') { $allowed = true; } } if ($allowed) { include $proLocation . $filename; return class_exists($class, false) || interface_exists($class, false); } $ecommerceLocation = substr_replace(BETTER_ANALYTICS_PLUGIN_DIR, '-ecommerce', -1); if (file_exists($ecommerceLocation . $filename)) { include $ecommerceLocation . $filename; return class_exists($class, false) || interface_exists($class, false); } elseif (file_exists(BETTER_ANALYTICS_PLUGIN_DIR . $filename)) { include BETTER_ANALYTICS_PLUGIN_DIR . $filename; return class_exists($class, false) || interface_exists($class, false); } }
/** * Mediboard class autoloader * * @param string $class Class to be loaded * * @return bool */ function mbAutoload($class) { $file_exists = false; $time = microtime(true); // Entry already in cache if (isset(CApp::$classPaths[$class])) { // The class is known to not be in MB if (CApp::$classPaths[$class] === false) { return false; } // Load it if we can if ($file_exists = file_exists(CApp::$classPaths[$class])) { CApp::$performance["autoloadCount"]++; return include_once CApp::$classPaths[$class]; } } // File moved ? if (!$file_exists) { unset(CApp::$classPaths[$class]); } // CSetup* class if (preg_match('/^CSetup(.+)$/', $class, $matches)) { $dirs = array("modules/{$matches['1']}/setup.php"); } else { $class_file = $class; $suffix = ".class"; // Namespaced class if (strpos($class_file, "\\") !== false) { $namespace = explode("\\", $class_file); // Mediboard class if ($namespace[0] === "Mediboard") { array_shift($namespace); $class_file = implode("/", $namespace); } else { $class_file = "vendor/" . implode("/", $namespace); $suffix = ""; } } $class_file .= $suffix; $dirs = array("classes/{$class_file}.php", "classes/*/{$class_file}.php", "mobile/*/{$class_file}.php", "modules/*/classes/{$class_file}.php", "modules/*/classes/*/{$class_file}.php", "modules/*/classes/*/*/{$class_file}.php", "install/classes/{$class_file}.php"); } $rootDir = CAppUI::conf("root_dir"); $class_path = false; foreach ($dirs as $dir) { $files = glob("{$rootDir}/{$dir}"); foreach ($files as $filename) { include_once $filename; // The class was found if (class_exists($class, false) || interface_exists($class, false)) { $class_path = $filename; break 2; } } } // Class not found, it is not in MB CApp::$classPaths[$class] = $class_path; SHM::put("class-paths", CApp::$classPaths); CApp::$performance["autoload"][$class] = (microtime(true) - $time) * 1000; return $class_path !== false; }
function __autoload($className) { if (function_exists('smartyAutoload') and smartyAutoload($className)) { return true; } $className = str_replace(chr(0), '', $className); $classDir = dirname(__FILE__) . '/../classes/'; $overrideDir = dirname(__FILE__) . '/../override/classes/'; $file_in_override = file_exists($overrideDir . $className . '.php'); $file_in_classes = file_exists($classDir . $className . '.php'); // This is a Core class and its name is the same as its declared name if (substr($className, -4) == 'Core') { require_once $classDir . substr($className, 0, -4) . '.php'; } else { if ($file_in_override && $file_in_classes) { require_once $classDir . str_replace(chr(0), '', $className) . '.php'; require_once $overrideDir . $className . '.php'; } elseif (!$file_in_override && $file_in_classes) { require_once $classDir . str_replace(chr(0), '', $className) . '.php'; $classInfos = new ReflectionClass($className . ((interface_exists($className, false) or class_exists($className, false)) ? '' : 'Core')); if (!$classInfos->isInterface() && substr($classInfos->name, -4) == 'Core') { eval(($classInfos->isAbstract() ? 'abstract ' : '') . 'class ' . $className . ' extends ' . $className . 'Core {}'); } } elseif ($file_in_override && !$file_in_classes) { require_once $overrideDir . $className . '.php'; } } }
public static function autoload($className) { include_once $className . self::CLASS_FILE_EXT; if (!class_exists($className, false) && !interface_exists($className, false)) { self::fatalError("Class file for '{$className}' cannot be found."); } }
/** * Retrieve informations about a class in classes index and load it * * @param string $classname */ public function load($classname) { // Retrocompatibility if (isset(PrestaShopAutoload::$class_aliases[$classname]) && !interface_exists($classname, false) && !class_exists($classname, false)) { return eval('class ' . $classname . ' extends ' . PrestaShopAutoload::$class_aliases[$classname] . ' {}'); } // regenerate the class index if the requested file doesn't exists if (isset($this->index[$classname]) && $this->index[$classname]['path'] && !is_file($this->root_dir . $this->index[$classname]['path']) || isset($this->index[$classname . 'Core']) && $this->index[$classname . 'Core']['path'] && !is_file($this->root_dir . $this->index[$classname . 'Core']['path'])) { $this->generateIndex(); } // If $classname has not core suffix (E.g. Shop, Product) if (substr($classname, -4) != 'Core') { $class_dir = isset($this->index[$classname]['override']) && $this->index[$classname]['override'] === true ? $this->normalizeDirectory(_PS_ROOT_DIR_) : $this->root_dir; // If requested class does not exist, load associated core class if (isset($this->index[$classname]) && !$this->index[$classname]['path']) { require_once $class_dir . $this->index[$classname . 'Core']['path']; if ($this->index[$classname . 'Core']['type'] != 'interface') { eval($this->index[$classname . 'Core']['type'] . ' ' . $classname . ' extends ' . $classname . 'Core {}'); } } else { // request a non Core Class load the associated Core class if exists if (isset($this->index[$classname . 'Core'])) { require_once $this->root_dir . $this->index[$classname . 'Core']['path']; } if (isset($this->index[$classname])) { require_once $class_dir . $this->index[$classname]['path']; } } } elseif (isset($this->index[$classname]['path']) && $this->index[$classname]['path']) { require_once $this->root_dir . $this->index[$classname]['path']; } }
function hanga_anonymous($class) { /* This array has a map of (class => file) */ // classes {{{ static $classes = array('haanga' => '/../Haanga.php', 'haanga_ast' => '/AST.php', 'haanga_extension_filter' => '/Extension/Filter.php', 'haanga_extension' => '/Extension.php', 'haanga_extension_tag_spaceless' => '/Extension/Tag/Spaceless.php', 'haanga_extension_tag_exec' => '/Extension/Tag/Exec.php', 'haanga_extension_tag_inline' => '/Extension/Tag/Inline.php', 'haanga_extension_tag_upper' => '/Extension/Tag/Upper.php', 'haanga_extension_tag_trans' => '/Extension/Tag/Trans.php', 'haanga_extension_tag_templatetag' => '/Extension/Tag/Templatetag.php', 'haanga_extension_tag_tryinclude' => '/Extension/Tag/Tryinclude.php', 'haanga_extension_tag_setsafe' => '/Extension/Tag/Setsafe.php', 'haanga_extension_tag_dictsort' => '/Extension/Tag/Dictsort.php', 'haanga_extension_tag_min' => '/Extension/Tag/Min.php', 'haanga_extension_tag_lower' => '/Extension/Tag/Lower.php', 'haanga_extension_tag_currenttime' => '/Extension/Tag/Currenttime.php', 'haanga_extension_tag_firstof' => '/Extension/Tag/Firstof.php', 'haanga_extension_tag_buffer' => '/Extension/Tag/Buffer.php', 'haanga_extension_tag_cycle' => '/Extension/Tag/Cycle.php', 'haanga_extension_filter_urlencode' => '/Extension/Filter/Urlencode.php', 'haanga_extension_filter_default' => '/Extension/Filter/Default.php', 'haanga_extension_filter_length' => '/Extension/Filter/Length.php', 'haanga_extension_filter_truncatechars' => '/Extension/Filter/Truncatechars.php', 'haanga_extension_filter_intval' => '/Extension/Filter/Intval.php', 'haanga_extension_filter_translation' => '/Extension/Filter/Translation.php', 'haanga_extension_filter_trans' => '/Extension/Filter/Trans.php', 'haanga_extension_filter_stringformat' => '/Extension/Filter/Stringformat.php', 'haanga_extension_filter_capfirst' => '/Extension/Filter/Capfirst.php', 'haanga_extension_filter_reverse' => '/Extension/Filter/Reverse.php', 'haanga_extension_filter_substr' => '/Extension/Filter/Substr.php', 'haanga_extension_filter_upper' => '/Extension/Filter/Upper.php', 'haanga_extension_filter_isarray' => '/Extension/Filter/Isarray.php', 'haanga_extension_filter_empty' => '/Extension/Filter/Empty.php', 'haanga_extension_filter_trim' => '/Extension/Filter/Trim.php', 'haanga_extension_filter_hostname' => '/Extension/Filter/Hostname.php', 'haanga_extension_filter_count' => '/Extension/Filter/Count.php', 'haanga_extension_filter_truncatewords' => '/Extension/Filter/Truncatewords.php', 'haanga_extension_filter_dictsort' => '/Extension/Filter/Dictsort.php', 'haanga_extension_filter_exists' => '/Extension/Filter/Exists.php', 'haanga_extension_filter_title' => '/Extension/Filter/Title.php', 'haanga_extension_filter_cut' => '/Extension/Filter/Cut.php', 'haanga_extension_filter_date' => '/Extension/Filter/Date.php', 'haanga_extension_filter_lower' => '/Extension/Filter/Lower.php', 'haanga_extension_filter_slugify' => '/Extension/Filter/Slugify.php', 'haanga_extension_filter_join' => '/Extension/Filter/Join.php', 'haanga_extension_filter_escape' => '/Extension/Filter/Escape.php', 'haanga_extension_filter_pluralize' => '/Extension/Filter/Pluralize.php', 'haanga_extension_filter_safe' => '/Extension/Filter/Safe.php', 'haanga_extension_filter_null' => '/Extension/Filter/Null.php', 'haanga_extension_tag' => '/Extension/Tag.php', 'hg_parser' => '/Compiler/Tokenizer.php', 'haanga_compiler_parser' => '/Compiler/Parser.php', 'haanga_compiler_tokenizer' => '/Compiler/Tokenizer.php', 'haanga_yytoken' => '/Compiler/Parser.php', 'haanga_yystackentry' => '/Compiler/Parser.php', 'haanga_compiler_exception' => '/Compiler/Exception.php', 'haanga_compiler_runtime' => '/Compiler/Runtime.php', 'haanga_compiler' => '/Compiler.php', 'haanga_exception' => '/Exception.php', 'haanga_generator_php' => '/Generator/PHP.php'); // }}} // deps {{{ static $deps = array('haanga_extension_filter' => array(0 => 'haanga_extension'), 'haanga_extension_filter_translation' => array(0 => 'haanga_extension_filter_trans'), 'haanga_extension_tag' => array(0 => 'haanga_extension'), 'hg_parser' => array(0 => 'haanga_compiler_parser'), 'haanga_compiler_runtime' => array(0 => 'haanga_compiler')); // }}} $class = strtolower($class); if (isset($classes[$class])) { if (!empty($deps[$class])) { foreach ($deps[$class] as $zclass) { if (!class_exists($zclass, false) && !interface_exists($zclass, false)) { require __DIR__ . $classes[$zclass]; } } } if (!class_exists($class, false) && !interface_exists($class, false)) { require __DIR__ . $classes[$class]; } return true; } return false; }
/** * Handles autoloading of classes, interfaces or traits. * @param string * @return void */ public function tryLoad($type) { $type = ltrim(strtolower($type), '\\'); // PHP namespace bug #49143 $info =& $this->list[$type]; if ($this->autoRebuild && empty($this->checked[$type]) && (is_array($info) ? !is_file($info[0]) : $info < self::RETRY_LIMIT)) { $info = is_int($info) ? $info + 1 : 0; $this->checked[$type] = TRUE; if ($this->rebuilt) { $this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION')); } else { $this->rebuild(); } } if (isset($info[0])) { Nette\Utils\LimitedScope::load($info[0], TRUE); if ($this->autoRebuild && !class_exists($type, FALSE) && !interface_exists($type, FALSE) && (PHP_VERSION_ID < 50400 || !trait_exists($type, FALSE))) { $info = 0; $this->checked[$type] = TRUE; if ($this->rebuilt) { $this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION')); } else { $this->rebuild(); } } self::$count++; } }
/** * @author WN * @param string $type * @throws InvalidClassException */ public function __construct($type) { if (!class_exists($type) && !interface_exists($type)) { throw new InvalidClassException('Class [' . $type . '] in not valid class.'); } $this->type = $type; }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); if (!in_array($this->type, array('form', 'filter'))) { throw new \Exception('Please override $this->type in your test class specifying template to use (either form or filter)'); } $rendererEngine = new TwigRendererEngine(array($this->type . '_admin_fields.html.twig')); $csrfManagerClass = interface_exists('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface') ? 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface' : 'Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'; $renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfManagerClass)); $this->extension = new FormExtension($renderer); $twigPaths = array(__DIR__ . '/../../../Resources/views/Form'); //this is ugly workaround for different build strategies and, possibly, //different TwigBridge installation directories if (is_dir(__DIR__ . '/../../../vendor/symfony/twig-bridge/Resources/views/Form')) { $twigPaths[] = __DIR__ . '/../../../vendor/symfony/twig-bridge/Resources/views/Form'; } elseif (is_dir(__DIR__ . '/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form')) { $twigPaths[] = __DIR__ . '/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form'; } else { $twigPaths[] = __DIR__ . '/../../../../../symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form'; } $loader = new StubFilesystemLoader($twigPaths); $this->environment = new \Twig_Environment($loader, array('strict_variables' => true)); $this->environment->addGlobal('sonata_admin', $this->getSonataAdmin()); $this->environment->addExtension(new TranslationExtension(new StubTranslator())); $this->environment->addExtension($this->extension); $this->extension->initRuntime($this->environment); }
public function loadClass($class) { $class = strtolower($class); if (class_exists($class, false) || interface_exists($class, false)) { return true; } if (isset($this->classes[$class])) { try { require $this->classes[$class]; } catch (sfException $e) { $e->printStackTrace(); } catch (Exception $e) { sfException::createFromException($e)->printStackTrace(); } return true; } if (sfContext::hasInstance() && ($module = sfContext::getInstance()->getModuleName()) && isset($this->classes[$module . '/' . $class])) { try { require $this->classes[$module . '/' . $class]; } catch (sfException $e) { $e->printStackTrace(); } catch (Exception $e) { sfException::createFromException($e)->printStackTrace(); } return true; } return false; }
/** * @param ServiceDescriptor $sd * @throws NonExistentClassException */ public function check(ServiceDescriptor $sd) { if ($sd->isAlias()) { return; } $class = $sd->getDefinition()->getClass(); if ($this->isParameter($class)) { $class = $sd->getContainer()->getParameter(trim($class, '%')); } $factoryClass = $sd->getDefinition()->getFactoryClass(); if ($this->isParameter($factoryClass)) { $factoryClass = $sd->getContainer()->getParameter(trim($factoryClass, '%')); } if (is_null($class) && is_null($factoryClass)) { return; } if (interface_exists($class) && is_null($factoryClass)) { return; } if (interface_exists($class) && class_exists($factoryClass)) { return; } if (!class_exists($class)) { throw new NonExistentClassException(sprintf('the class %s for the service %s does not exists', $class, $sd->getServiceName())); } }
public function testGenerator() { /** @var OpsWay\Test2\Solid\I $generator */ $generator = OpsWay\Test2\Solid\Factory::create('i'); $generator->generate(); $this->assertFileExists($file = __DIR__ . '/../../test/I/IGeometric.php'); include $file; $this->assertTrue(interface_exists('IGeometric')); $this->assertFileExists($file = __DIR__ . '/../../test/I/IAngular.php'); include $file; $this->assertTrue(interface_exists('IAngular')); $this->assertFileExists($file = __DIR__ . '/../../test/I/ISquarable.php'); include $file; $this->assertTrue(interface_exists('ISquarable')); $this->assertFileExists($file = __DIR__ . '/../../test/I/Square.php'); include $file; $this->assertTrue(class_exists('Square')); $this->assertTrue(in_array('IGeometric', class_implements('Square'))); $this->assertFileExists($file = __DIR__ . '/../../test/I/Circle.php'); include $file; $this->assertTrue(class_exists('Circle')); $this->assertTrue(in_array('IGeometric', class_implements('Circle'))); $this->assertTrue(method_exists('IGeometric', 'square')); $this->assertTrue(method_exists('ISquarable', 'square')); $this->assertTrue(method_exists('IAngular', 'countAngles')); }
public function setUp() { if (!interface_exists('JMS\\TranslationBundle\\Translation\\ExtractorInterface')) { $this->markTestSkipped('JMS Translator Bundle does not exist'); } $this->fooAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); $this->barAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface'); // php 5.3 BC $fooAdmin = $this->fooAdmin; $barAdmin = $this->barAdmin; $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($fooAdmin, $barAdmin) { switch ($id) { case 'foo_admin': return $fooAdmin; case 'bar_admin': return $barAdmin; } return null; })); $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface'); $this->pool = new Pool($container, '', ''); $this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin')); $this->adminExtractor = new AdminExtractor($this->pool, $logger); $this->adminExtractor->setLogger($logger); }