本文整理汇总了PHP中ClassLoader::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::getDefault方法的具体用法?PHP ClassLoader::getDefault怎么用?PHP ClassLoader::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Main
*
* @param string[] $args
* @return int
*/
public static function main(array $args)
{
$command = null;
if (empty($args)) {
$class = new XPClass(self::class);
$source = $class->getClassLoader();
$markdown = $class->getComment();
} else {
if ('@' === $args[0][0]) {
$resource = substr($args[0], 1);
if (null === ($source = ClassLoader::getDefault()->findResource($resource))) {
Console::$err->writeLine('No help topic named ', $resource);
return 2;
}
$markdown = $source->getResource($resource);
} else {
$class = $args[0];
if (null === ($source = ClassLoader::getDefault()->findClass($class))) {
Console::$err->writeLine('No class named ', $class);
return 2;
}
$markdown = $source->loadClass($class)->getComment();
}
}
self::render(Console::$out, $markdown, $source);
return 1;
}
示例2: setUp
/**
* Sets up test case
*
*/
public function setUp()
{
try {
$this->classname = $this->testClassName();
$this->interfacename = $this->testClassName('I');
} catch (IllegalStateException $e) {
throw new PrerequisitesNotMetError($e->getMessage());
}
// Create an archive
$this->tempfile = new TempFile($this->name);
$archive = new Archive($this->tempfile);
$archive->open(ARCHIVE_CREATE);
$this->add($archive, $this->classname, '
uses("util.Comparator", "' . $this->interfacename . '");
class ' . $this->classname . ' extends Object implements ' . $this->interfacename . ', Comparator {
public function compare($a, $b) {
return strcmp($a, $b);
}
}
');
$this->add($archive, $this->interfacename, 'interface ' . $this->interfacename . ' { } ');
$archive->create();
// Setup classloader
$this->classloader = new ArchiveClassLoader($archive);
ClassLoader::getDefault()->registerLoader($this->classloader, TRUE);
}
示例3: deployBean
/**
* Deploy
*
* @param remote.server.deploy.Deployable deployment
*/
public function deployBean($deployment)
{
if ($deployment instanceof IncompleteDeployment) {
throw new DeployException('Incomplete deployment originating from ' . $deployment->origin, $deployment->cause);
}
$this->cat && $this->cat->info($this->getClassName(), 'Begin deployment of', $deployment);
// Register beans classloader. This classloader must be put at the beginning
// to prevent loading of the home interface not implmenenting BeanInterface
$cl = $deployment->getClassLoader();
ClassLoader::getDefault()->registerLoader($cl, TRUE);
$impl = $cl->loadClass($deployment->getImplementation());
$interface = $cl->loadClass($deployment->getInterface());
$directoryName = $deployment->getDirectoryName();
// Fetch naming directory
$directory = NamingDirectory::getInstance();
// Create beanContainer
// TBI: Check which kind of bean container has to be created
$beanContainer = StatelessSessionBeanContainer::forClass($impl);
$this->cat && $beanContainer->setTrace($this->cat);
// Create invocation handler
$invocationHandler = new ContainerInvocationHandler();
$invocationHandler->setContainer($beanContainer);
// Now bind into directory
$directory->bind($directoryName, Proxy::newProxyInstance($cl, array($interface), $invocationHandler));
$this->cat && $this->cat->info($this->getClassName(), 'End deployment of', $impl->getName(), 'with ND entry', $directoryName);
return $beanContainer;
}
示例4: __construct
/**
* Constructor
*
* @param lang.ClassLoader classLoader
*/
public function __construct($classLoader = NULL)
{
if (NULL === $classLoader) {
$this->classLoader = ClassLoader::getDefault();
} else {
$this->classLoader = $classLoader;
}
}
示例5: valueOf
/**
* Returns a value for the given serialized string
*
* @param server.protocol.Serializer serializer
* @param remote.protocol.SerializedData serialized
* @param [:var] context default array()
* @return var
*/
public function valueOf($serializer, $serialized, $context = array())
{
$oid = $serialized->consumeSize();
$serialized->consume('{');
$interface = $serializer->valueOf($serialized, $context);
$serialized->consume('}');
return Proxy::newProxyInstance(ClassLoader::getDefault(), array(XPClass::forName($serializer->packageMapping($interface))), RemoteInvocationHandler::newInstance((int) $oid, $context['handler']));
}
示例6: fixture
/**
* Creates a fixrture
*
* @return util.PropertyManager
*/
private function fixture()
{
$class = ClassLoader::getDefault()->defineClass('NonSingletonPropertyManager', 'util.PropertyManager', array(), '{
public static function newInstance() {
return new self();
}
}');
return $class->getMethod('newInstance')->invoke(NULL);
}
示例7: __construct
/**
* Setup method.
*
* @param string package
* @param string stateName
* @param string functionality
* @param [:var] params default array()
*/
public function __construct($package, $stateName, $functionality, $params = array())
{
static $i = 0;
parent::__construct($package);
// Generate unique classname and put it into the environment
// That way, the classloader will already know this class in
// WorkflowScriptletRequest::initialize() and be able to load
// and instantiate it.
$stateName = 'Mock·' . $i++ . $stateName;
$this->state = ClassLoader::getDefault()->defineClass($package . '.mock.state.' . $stateName . 'State', 'scriptlet.xml.workflow.AbstractState', array(), $functionality)->newInstance();
$_SERVER['STATE'] = $stateName;
// Set some defaults
$_SERVER['PRODUCT'] = 'xp';
$_SERVER['LANGUAGE'] = 'en_US';
}
示例8: anyOfType
/**
* Accessor method for a type matcher.
*
* @param typeName string
*/
public static function anyOfType($typeName)
{
$builder = new MockProxyBuilder();
$builder->setOverwriteExisting(FALSE);
$interfaces = array(XPClass::forName('unittest.mock.arguments.IArgumentMatcher'));
$parentClass = NULL;
$type = XPClass::forName($typeName);
if ($type->isInterface()) {
$interfaces[] = $type;
} else {
$parentClass = $type;
}
$proxyClass = $builder->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
return $proxyClass->newInstance(new TypeMatcher($typeName));
}
示例9: createMock
/**
* Builds a stub instance for the specified type.
*
* @param string typeName
* @param boolean overrideAll
* @return lang.Object
*/
public function createMock($typeName, $overrideAll = TRUE)
{
$type = Type::forName($typeName);
if (!$type instanceof XPClass) {
throw new IllegalArgumentException('Cannot mock other types than XPClass types.');
}
$parentClass = NULL;
$interfaces = array(XPClass::forName('unittest.mock.IMock'));
if ($type->isInterface()) {
$interfaces[] = $type;
} else {
$parentClass = $type;
}
$proxy = new MockProxyBuilder();
$proxy->setOverwriteExisting($overrideAll);
$proxyClass = $proxy->createProxyClass(ClassLoader::getDefault(), $interfaces, $parentClass);
$mock = $proxyClass->newInstance(new MockProxy());
$this->mocks[] = $mock;
return $mock;
}
示例10: __construct
/**
* Constructor
*
* @param util.cmd.ParamString args
*/
public function __construct(ParamString $args)
{
$dsn = new DSN($args->value(0));
$this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn));
$this->package = $args->value('package', 'p', 'db');
$this->host = $args->value('host', 'h', $dsn->getHost());
$this->naming = $args->value('nstrategy', 'n', '');
if ('' != $this->naming) {
DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance());
}
$this->prefix = $args->value('prefix', 'pv', '');
$this->ptargets = explode('|', $args->value('ptargets', 'pt', ''));
$this->pexclude = $args->value('pexclude', 'pe', FALSE);
$xsls = array();
$lang = $args->value('lang', 'l', 'xp5.php');
if ($this->getClass()->getPackage()->providesPackage(strtr($lang, '.', '_'))) {
$resources = $this->getClass()->getPackage()->getPackage(strtr($lang, '.', '_'))->getResources();
foreach ($resources as $resource) {
$filename = substr($resource, strrpos($resource, DIRECTORY_SEPARATOR) + 1);
if (substr($filename, -8, 8) !== '.php.xsl') {
continue;
}
$xsls[] = $resource;
}
} else {
$packagepath = strtr($this->getClass()->getPackage()->getName(), '.', DIRECTORY_SEPARATOR);
$xsls[] = $packagepath . DIRECTORY_SEPARATOR . $lang . '.xsl';
}
foreach ($xsls as $resource) {
$processor = new DomXSLProcessor();
$processor->setBase(__DIR__);
$processor->setXSLBuf(ClassLoader::getDefault()->getResource($resource));
$processor->setParam('package', $this->package);
if ($this->prefix) {
$processor->setParam('prefix', $this->prefix);
$processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets));
}
$this->processor[] = $processor;
}
}
示例11: detailsForPackage
/**
* Returns details for a given package. Note: Results from this method
* are cached.
*
* @param string package
* @return [:var] details or NULL
*/
public static function detailsForPackage($package)
{
if (!isset(xp::$meta[$package])) {
$cl = ClassLoader::getDefault();
$info = strtr($package, '.', '/') . '/package-info.xp';
if (!$cl->providesResource($info)) {
return NULL;
}
$tokens = token_get_all($cl->getResource($info));
$details = array();
$comment = NULL;
for ($i = 0, $s = sizeof($tokens); $i < $s; $i++) {
switch ($tokens[$i][0]) {
case T_DOC_COMMENT:
$comment = $tokens[$i][1];
break;
case T_STRING:
if ('package' === $tokens[$i][1]) {
$details[DETAIL_COMMENT] = trim(preg_replace('/\\n \\* ?/', "\n", "\n" . substr($comment, 4, strpos($comment, '* @') - 2)));
}
break;
}
}
xp::$meta[$package] = $details;
}
return xp::$meta[$package];
}
示例12: nonExistantResourceStream
public function nonExistantResourceStream()
{
ClassLoader::getDefault()->getResourceAsStream('::DOES-NOT-EXIST::');
}
示例13: loadNonExistantUri
public function loadNonExistantUri()
{
ClassLoader::getDefault()->loadUri('non/existant/Class.class.php');
}
示例14: withPositionalOptionListenerOption
public function withPositionalOptionListenerOption()
{
$class = ClassLoader::getDefault()->defineClass('net.xp_framework.unittest.tests.WithPositionalOptionTestFixture', 'xp.unittest.DefaultListener', array(), '{
public static $options= array();
#[@arg(position= 0)]
public function setOption($value) { self::$options[__FUNCTION__]= $value; }
}');
$return = $this->runner->run(array('-l', $class->getName(), '-', '-o', 'value'));
$this->assertEquals(array('setOption' => 'value'), $class->getField('options')->get(NULL));
}
示例15: nullInterfaces
public function nullInterfaces()
{
Proxy::getProxyClass(ClassLoader::getDefault(), null);
}