本文整理汇总了PHP中class_alias函数的典型用法代码示例。如果您正苦于以下问题:PHP class_alias函数的具体用法?PHP class_alias怎么用?PHP class_alias使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了class_alias函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoload
/**
* Creates class alias from class which is defined in class map.
*
* @param string $sClass Class name.
*/
public function autoload($sClass)
{
$sClass = strtolower($sClass);
if (array_key_exists($sClass, $this->getClassMap())) {
class_alias($this->map[$sClass], $sClass);
}
}
示例2: setUp
class ModelLoaderTest extends \PHPUnit_Framework_TestCase
{
protected $project;
protected function setUp()
{
parent::setUp();
define('MODEL_DIR', 'Test\\Model');
define('DEBUG_MODE', true);
if (!class_exists('\\Test\\Model\\Project')) {
$this->project = new class extends ModelEx
{
protected $table = 'projects';
protected $primaryKey = 'project_id';
};
class_alias(get_class($this->project), '\\Test\\Model\\Project');
}
}
public function testMetadataIsAppliedToParentModel()
{
$modelExtender = $this->getMockBuilder(ModelExtender::class)->disableOriginalConstructor()->setMethods(['extend'])->getMock();
$modelExtender->expects($this->once())->method('extend')->willReturnCallback(function ($model, $args) {
$this->assertEquals(['offset' => 0, 'limit' => 2, 'conditions' => [['project', '=', '3']]], $args);
return $model;
});
$nodes = ['project' => ['self' => ['name' => 'Project', 'offset' => 0, 'limit' => 2, 'conditions' => [['project', '=', '3']]]]];
/** @var ModelLoader $modelLoader */
$modelLoader = (new Injector())->make('Minute\\Model\\ModelLoader', [':modelExtender' => $modelExtender]);
$modelLoader->createRelations($nodes['project']);
}
}
示例3: autoloadPSR0
/**
* Autoload function for SimpleSAMLphp modules following PSR-0.
*
* @param string $className Name of the class.
* @deprecated This method will be removed in SSP 2.0.
*
* TODO: this autoloader should be removed once everything has been migrated to namespaces.
*/
public static function autoloadPSR0($className)
{
$modulePrefixLength = strlen('sspmod_');
$classPrefix = substr($className, 0, $modulePrefixLength);
if ($classPrefix !== 'sspmod_') {
return;
}
$modNameEnd = strpos($className, '_', $modulePrefixLength);
$module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
$path = explode('_', substr($className, $modNameEnd + 1));
if (!self::isModuleEnabled($module)) {
return;
}
$file = self::getModuleDir($module) . '/lib/' . join('/', $path) . '.php';
if (!file_exists($file)) {
return;
}
require_once $file;
if (!class_exists($className, false)) {
// the file exists, but the class is not defined. Is it using namespaces?
$nspath = join('\\', $path);
if (class_exists('SimpleSAML\\Module\\' . $module . '\\' . $nspath)) {
// the class has been migrated, create an alias and warn about it
\SimpleSAML_Logger::warning("The class '{$className}' is now using namespaces, please use 'SimpleSAML\\Module\\{$module}\\" . "{$nspath}' instead.");
class_alias("SimpleSAML\\Module\\{$module}\\{$nspath}", $className);
}
}
}
示例4: registerLegacyAliases
private static function registerLegacyAliases()
{
foreach (self::$oldToNewMap as $old => $new) {
class_alias($new, $old);
# bool class_alias ( string $original原类 , string $alias别名 [,bool $autoload =TRUE是否原类不存在自动加载 ])基于用户定义的类 original 创建别名 alias。 这个别名类和原有的类完全相同
}
}
示例5: classAlias
public function classAlias($alias)
{
foreach ($alias as $key => $value) {
// Register Class Alias
class_alias($value, $key);
}
}
示例6: load
public function load(ServiceContainer $container)
{
// This exists for PHP 5.3 compatibility
if (!interface_exists('\\JsonSerializable')) {
class_alias('Knp\\JsonSchemaBundle\\Model\\JsonSerializable', 'JsonSerializable');
}
}
示例7: load
/**
* Load the file corresponding to a given class.
*
* This method is registerd in the bootstrap file as an SPL auto-loader.
*
* @param string $class
* @return void
*/
public static function load($class)
{
// First, we will check to see if the class has been aliased. If it has,
// we will register the alias, which may cause the auto-loader to be
// called again for the "real" class name to load its file.
if (isset(static::$aliases[$class])) {
class_alias(static::$aliases[$class], $class);
} elseif (isset(static::$mappings[$class])) {
require static::$mappings[$class];
return;
}
// If the class namespace is mapped to a directory, we will load the
// class using the PSR-0 standards from that directory accounting
// for the root of the namespace by trimming it off.
foreach (static::$namespaces as $namespace => $directory) {
if (starts_with($class, $namespace)) {
return static::load_namespaced($class, $namespace, $directory);
}
}
// If the class uses PEAR-ish style underscores for indicating its
// directory structure we'll load the class using PSR-0 standards
// standards from that directory, trimming the root.
foreach (static::$underscored as $prefix => $directory) {
if (starts_with($class, $prefix)) {
return static::load_namespaced($class, $prefix, $directory);
}
}
// If all else fails we will just iterator through the mapped
// PSR-0 directories looking for the class. This is the last
// resort and slowest loading option for the class.
static::load_psr($class);
}
示例8: aliasesClass
function aliasesClass()
{
$config = $GLOBALS['Config']['App'];
foreach ($config['Aliases'] as $class => $alias) {
class_alias($class, $alias);
}
}
示例9: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//set theme layout directory
$paths = $this->app['config']->get('view.paths');
$themePath = $this->app['path.public'] . '/themes/';
array_push($paths, $themePath);
$this->app['config']->set('view.paths', $paths);
//bind themeConfig object
$this->app['px.themeConfig'] = $this->app->share(function ($app) {
return new ThemeConfig();
});
$this->app->bind('px.theme', function ($app) {
return new ThemeManager($app['px.themeConfig']);
});
//register ThemeFacade class as alias to "theme"
class_alias(__NAMESPACE__ . '\\ThemeFacade', 'pxTheme');
//extend blade engine by adding @px.theme and @px.layout compile function
$this->app['view.engine.resolver']->resolve('blade')->getCompiler()->extend(function ($view) {
$themePattern = '/(?<!\\w)(\\s*)@px.theme(\\s*\\(.*\\))/';
$layoutPattern = '/(?<!\\w)(\\s*)@px.layout(\\s*\\(.*\\))/';
$layoutIncludePattern = '/(?<!\\w)(\\s*)@px.include(\\s*\\(.*)\\)/';
//$layoutIncludePattern = '/(?<!\w)(\s*)@px.include(\s*\(.*\))/';
$view = preg_replace($themePattern, '$1<?php pxTheme::setTheme$2;?>', $view);
$view = preg_replace($layoutPattern, '$1<?php pxTheme::setLayout$2;?>', $view);
$view = preg_replace($layoutIncludePattern, '$1<?php echo $__env->make(pxTheme::path$2), array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $view);
$view = preg_replace($layoutPattern, '$1<?php pxTheme::setLayout$2;?>', $view);
return $view;
});
}
示例10: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->bind('Amqp', 'Bschmitt\\Amqp\\Amqp');
if (!class_exists('Amqp')) {
class_alias('Bschmitt\\Amqp\\Facades\\Amqp', 'Amqp');
}
}
示例11: load
/**
* {@inheritdoc}
*/
public function load(string $alias) : bool
{
// Skip recursive aliases if defined
if (in_array($alias, $this->resolving)) {
return false;
}
// Set it as the resolving class for when
// we want to block recursive resolving
$this->resolving[] = $alias;
if (isset($this->cache[$alias])) {
// If we already have the alias in the cache don't bother resolving again
$class = $this->cache[$alias];
} elseif ($class = $this->resolveAlias($alias)) {
// We've got a plain alias, now we can skip the others as this
// is the most powerful one.
} elseif ($class = $this->resolveNamespaceAlias($alias)) {
// We've got a namespace alias, we can skip pattern matching.
} elseif (!($class = $this->resolvePatternAlias($alias))) {
// Lastly we'll try to resolve it through pattern matching. This is the most
// expensive match type. Caching is recommended if you use this.
return false;
}
// Remove the resolving class
array_pop($this->resolving);
if (!$this->exists($class)) {
return false;
}
// Create the actual alias
class_alias($class, $alias);
if (!isset($this->cache[$alias])) {
$this->cache[$alias] = $class;
}
return true;
}
示例12: __construct
/**
* Constructor
*/
public function __construct()
{
$this->container = Container::getInstance();
// set dependencies
$this->container['hook'] = function ($c) {
return new \Binocle\Core\Hook();
};
$this->container['template'] = function ($c) {
return new \Binocle\Core\Template($c);
};
$this->container['asset'] = function ($c) {
return new \Binocle\Core\Template\Asset();
};
$this->container['config'] = function ($c) {
return new \Binocle\Core\Config();
};
$this->container['posttype'] = function ($c) {
return new \Binocle\Core\Posttype();
};
// set aliases
class_alias('Binocle\\Core\\Facades\\Asset', 'Asset');
class_alias('Binocle\\Core\\Facades\\Hook', 'Hook');
class_alias('Binocle\\Core\\Facades\\Config', 'Config');
class_alias('Binocle\\Core\\Facades\\Posttype', 'Posttype');
}
示例13: boot
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('sirgrimorum/cms');
AliasLoader::getInstance()->alias('TransArticle', 'Sirgrimorum\\Cms\\TransArticles\\Facades\\TransArticle');
AliasLoader::getInstance()->alias('Translations', 'Sirgrimorum\\Cms\\Translations\\Facades\\Translations');
AliasLoader::getInstance()->alias('CrudLoader', 'Sirgrimorum\\Cms\\CrudLoader\\Facades\\CrudLoader');
//define a constant that the rest of the package can use to conditionally use pieces of Laravel 4.1.x vs. 4.0.x
$this->app['administrator.4.1'] = version_compare(\Illuminate\Foundation\Application::VERSION, '4.1') > -1;
//set up an alias for the base laravel controller to accommodate >=4.1 and <4.1
if (!class_exists('AdministratorBaseController')) {
// Verify alias is not already created
if ($this->app['administrator.4.1']) {
class_alias('Illuminate\\Routing\\Controller', 'AdministratorBaseController');
} else {
class_alias('Illuminate\\Routing\\Controllers\\Controller', 'AdministratorBaseController');
}
}
// Registering the validator extension with the validator factory
$this->app['validator']->resolver(function ($translator, $data, $rules, $messages) {
return new ValidatorExtension($translator, $data, $rules, $messages);
});
//include our filters, view composers, and routes
include __DIR__ . '/../filters.php';
include __DIR__ . '/../routes.php';
}
示例14: autoload
public static function autoload($classname) {
if(strpos($classname, "_")) {
$prefix = explode("_", $classname);
} else {
$prefix = explode("\\", $classname);
}
if(!isset(self::$_Registered[$prefix[0]])) {
return false;
}
if($prefix[1] == "SWExtension") {
if(count($prefix) == 3 && $prefix[2] == sha1($prefix[0]."-GenKey")) {
$origClass = $classname;
$doAlias = true;
$classname = str_replace("\\".$prefix[2], "\\GenKey", $classname);
} else {
$doAlias = false;
}
}
$path = self::$_Registered[$prefix[0]]."/";
$classNamePath = str_replace(array("_", "\\"), "/", $classname);
if(file_exists($path.$classNamePath.".php")) {
require_once($path.$classNamePath.".php");
}
if($prefix[1] == "SWExtension" && $doAlias) {
class_alias(ltrim($classname, "\\"), ltrim($origClass, "\\"));
}
}
示例15: setUp
class ModelBridgeTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
parent::setUp();
define('MODEL_DIR', 'Test\\Model');
if (!class_exists('\\Test\\Model\\Blog')) {
$blog = new class extends ModelEx
{
protected $table = 'blogs';
protected $primaryKey = 'blog_id';
};
class_alias(get_class($blog), '\\Test\\Model\\Blog');
}
if (!class_exists('\\Test\\Model\\Post')) {
$post = new class extends ModelEx
{
protected $table = 'posts';
protected $primaryKey = 'post_id';
};
class_alias(get_class($post), '\\Test\\Model\\Post');
}
if (!class_exists('\\Test\\Model\\Comment')) {
$comment = new class extends ModelEx
{
protected $table = 'comments';
protected $primaryKey = 'comment_id';
};
class_alias(get_class($comment), '\\Test\\Model\\Comment');
}
if (!class_exists('\\Test\\Model\\User')) {
$user = new class extends ModelEx
{
protected $table = 'users';
protected $primaryKey = 'user_id';
};
class_alias(get_class($user), '\\Test\\Model\\User');
}
}
public function testModelToJsClasses()
{
/** @var ModelParserGet $modelParser */
$models = ['blogs[2]', 'posts[blogs.blog_id][2] as stories', 'comments[blogs.blog_id] as comment', 'users[stories.post_id] as teller'];
$modelParser = (new Injector())->make('Minute\\Model\\ModelParserGet', [$models]);
$parents = $modelParser->getParentsWithChildren();
$this->assertArrayHasKey('blogs', $parents, 'Parents has blogs key');
/** @var ModelBridge $modelBridge */
$modelBridge = (new Injector())->make('Minute\\Model\\ModelBridge');
$template = $modelBridge->modelToJsClasses($parents['blogs']);
$this->markTestSkipped('to be fixed');
$this->assertContains('BlogItem = (function (_super) {', $template, 'BlogItem is present');
$this->assertContains('this.stories = (new StoryArray(this));', $template, 'BlogItem has stories');
$this->assertContains('this.comment = (new CommentArray(this)).create();', $template, 'BlogItem has a comment item');
$this->assertContains("_super.call(this, BlogItem, parent, 'blogs', 'Blog', 'blog_id', null);", $template, 'BlogItemArray is correctly initialized');
$this->assertContains("this.teller = (new TellerArray(this)).create();", $template, 'StoryItem has teller item');
$this->assertContains("this.teller = (new TellerArray(this)).create();", $template, 'StoryItem has teller item');
$this->assertContains("_super.call(this, StoryItem, parent, 'stories', 'Post', 'post_id', 'blog_id');", $template, 'StoryItemArray is correctly initialized');
$this->assertContains("_super.call(this, CommentItem, parent, 'comment', 'Comment', 'comment_id', 'blog_id');", $template, 'CommentItemArray is correctly initialized');
}
}