本文整理汇总了PHP中Phing::import方法的典型用法代码示例。如果您正苦于以下问题:PHP Phing::import方法的具体用法?PHP Phing::import怎么用?PHP Phing::import使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phing
的用法示例。
在下文中一共展示了Phing::import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callFunction
/**
* Calls function and returns results.
* @return mixed
*/
protected function callFunction()
{
if ($this->class !== null) {
// import the classname & unqualify it, if necessary
$this->class = Phing::import($this->class);
$user_func = array($this->class, $this->function);
$h_func = $this->class . '::' . $this->function;
// human-readable (for log)
} else {
$user_func = $this->function;
$h_func = $user_func;
// human-readable (for log)
}
// put parameters into simple array
$params = array();
foreach ($this->params as $p) {
$params[] = $p->getValue();
}
$this->log("Calling PHP function: " . $h_func . "()");
foreach ($params as $p) {
$this->log(" param: " . $p, PROJECT_MSG_VERBOSE);
}
$return = call_user_func_array($user_func, $params);
return $return;
}
示例2: selectorCreate
/**
* Instantiates the identified custom selector class.
*/
public function selectorCreate()
{
if ($this->classname !== null && $this->classname !== "") {
try {
// assume it's fully qualified, import it
$cls = Phing::import($this->classname);
// make sure class exists
if (class_exists($cls)) {
$this->dynselector = new $cls();
} else {
$this->setError("Selector " . $this->classname . " not initialized, no such class");
}
} catch (Exception $e) {
$this->setError("Selector " . $this->classname . " not initialized, could not create class: " . $e->getMessage());
}
} else {
$this->setError("There is no classname specified");
}
}
示例3: load
/**
* This method is called to load the sources from the reader
* into the buffer of the source.
*/
function load()
{
// Create new Reader
if ($this->classname === null) {
throw new BuildException("No Classname given to TokenSource.");
}
$classname = Phing::import($this->classname);
$this->reader = new $classname($this->project);
// Configure Reader
$this->configureTokenReader($this->reader);
// Load Tokens
try {
while ($token = $this->reader->readToken()) {
$this->tokens[] = $token;
}
} catch (BuildException $e) {
$this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN);
} catch (IOException $e) {
$this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN);
}
}
示例4: getPlatformForTargetDatabase
/**
* Get the Platform class based on the target database type.
* @return Platform Class that implements the Platform interface.
*/
protected function getPlatformForTargetDatabase()
{
$classpath = $this->getPropelProperty("platformClass");
if (empty($classpath)) {
throw new BuildException("Unable to find class path for '{$propname}' property.");
}
// This is a slight hack to workaround camel case inconsistencies for the DDL classes.
// Basically, we want to turn ?.?.?.sqliteDDLBuilder into ?.?.?.SqliteDDLBuilder
$lastdotpos = strrpos($classpath, '.');
if ($lastdotpos) {
$classpath[$lastdotpos + 1] = strtoupper($classpath[$lastdotpos + 1]);
} else {
ucfirst($classpath);
}
if (empty($classpath)) {
throw new BuildException("Unable to find class path for '{$propname}' property.");
}
$clazz = Phing::import($classpath);
return new $clazz();
}
示例5: addDataTypeDefinition
/**
* Adds a data type definition.
* @param string $name Name of tag.
* @param string $class The class path to use.
* @param string $classpath The classpat to use.
*/
function addDataTypeDefinition($typeName, $typeClass, $classpath = null)
{
if (!isset($this->typedefs[$typeName])) {
Phing::import($typeClass, $classpath);
$this->typedefs[$typeName] = $typeClass;
$this->log(" +User datatype: {$typeName} ({$typeClass})", Project::MSG_DEBUG);
} else {
$this->log("Type {$name} ({$class}) already registerd, skipping", Project::MSG_VERBOSE);
}
}
示例6: getImplementation
/** Factory, returns inmplementation of file name mapper as new instance */
public function getImplementation()
{
if ($this->isReference()) {
$o = $this->getRef();
if ($o instanceof FileNameMapper) {
return $o;
}
if ($o instanceof Mapper) {
return $o->getImplementation();
}
$od = $o == null ? "null" : get_class($o);
throw new BuildException($od . " at reference '" . $r->getRefId() . "' is not a valid mapper reference.");
}
if ($this->type === null && $this->classname === null && $this->container == null) {
throw new BuildException("either type or classname attribute must be set for <mapper>");
}
if ($this->container != null) {
return $this->container;
}
if ($this->type !== null) {
switch ($this->type) {
case 'chained':
$this->classname = 'phing.mappers.ChainedMapper';
break;
case 'composite':
$this->classname = 'phing.mappers.CompositeMapper';
break;
case 'identity':
$this->classname = 'phing.mappers.IdentityMapper';
break;
case 'flatten':
$this->classname = 'phing.mappers.FlattenMapper';
break;
case 'glob':
$this->classname = 'phing.mappers.GlobMapper';
break;
case 'regexp':
case 'regex':
$this->classname = 'phing.mappers.RegexpMapper';
break;
case 'merge':
$this->classname = 'phing.mappers.MergeMapper';
break;
default:
throw new BuildException("Mapper type {$this->type} not known");
break;
}
}
// get the implementing class
$cls = Phing::import($this->classname, $this->classpath);
$m = new $cls();
$m->setFrom($this->from);
$m->setTo($this->to);
return $m;
}
示例7: getImplementation
/** Factory, returns inmplementation of file name mapper as new instance */
function getImplementation()
{
if ($this->isReference()) {
$tmp = $this->getRef();
return $tmp->getImplementation();
}
if ($this->type === null && $this->classname === null) {
throw new BuildException("either type or classname attribute must be set for <mapper>");
}
if ($this->type !== null) {
switch ($this->type) {
case 'identity':
$this->classname = 'phing.mappers.IdentityMapper';
break;
case 'flatten':
$this->classname = 'phing.mappers.FlattenMapper';
break;
case 'glob':
$this->classname = 'phing.mappers.GlobMapper';
break;
case 'regexp':
case 'regex':
$this->classname = 'phing.mappers.RegexpMapper';
break;
case 'merge':
$this->classname = 'phing.mappers.MergeMapper';
break;
default:
throw new BuildException("Mapper type {$this->type} not known");
break;
}
}
// get the implementing class
$cls = Phing::import($this->classname, $this->classpath);
$m = new $cls();
$m->setFrom($this->from);
$m->setTo($this->to);
return $m;
}
示例8: catch
}
} catch (Exception $e) {
/* This failed. Can't figure out project directory. Forget it. */
}
/* Switch to whichever project directory the script determined. */
$GLOBALS['PROPERTIES']['project.directory'] = $GLOBALS['PROJECT_DIRECTORY'];
/* Execute Phing. */
try {
$project = new Project();
// hax for Mac OS X 10.5 Leopard, where "dim" ANSI colors are broken...
if (PHP_OS == 'Darwin' && (isset($_SERVER['TERM_PROGRAM']) && $_SERVER['TERM_PROGRAM'] == 'Apple_Terminal' || isset($_ENV['TERM_PROGRAM']) && $_ENV['TERM_PROGRAM'] == 'Apple_Terminal') && version_compare(preg_replace('/^ProductVersion:\\s*([0-9]+\\.[0-9]+)/ms', '$1', shell_exec('sw_vers')), '10.5', 'eq') && !Phing::getProperty('phing.logger.defaults')) {
Phing::setProperty('phing.logger.defaults', new PhingFile(BUILD_DIRECTORY . '/agavi/phing/ansicolorlogger_osxleopard.properties'));
} elseif (stripos(PHP_OS, 'Win') === 0) {
$GLOBALS['LOGGER'] = 'phing.listener.DefaultLogger';
}
$GLOBALS['LOGGER'] = Phing::import($GLOBALS['LOGGER']);
$logger = new AgaviProxyBuildLogger(new $GLOBALS['LOGGER']());
$logger->setMessageOutputLevel($GLOBALS['VERBOSE'] ? Project::MSG_VERBOSE : Project::MSG_INFO);
$logger->setOutputStream($GLOBALS['OUTPUT']);
$logger->setErrorStream($GLOBALS['ERROR']);
$project->addBuildListener($logger);
$project->setInputHandler(new DefaultInputHandler());
$project->setUserProperty('phing.file', $GLOBALS['BUILD']->getAbsolutePath());
$project->setUserProperty('phing.version', Phing::getPhingVersion());
/* Phing fucks with the cwd. Really, brilliant. */
$project->setUserProperty('application.startdir', START_DIRECTORY);
foreach ($GLOBALS['PROPERTIES'] as $name => $value) {
$project->setUserProperty($name, $value);
}
$project->init();
ProjectConfigurator::configureProject($project, $GLOBALS['BUILD']);
示例9: addInputHandler
/**
* Creates the InputHandler and adds it to the project.
*
* @param Project $project the project instance.
*
* @throws BuildException if a specified InputHandler
* class could not be loaded.
*/
private function addInputHandler(Project $project)
{
if ($this->inputHandlerClassname === null) {
$handler = new DefaultInputHandler();
} else {
try {
$clz = Phing::import($this->inputHandlerClassname);
$handler = new $clz();
if ($project !== null && method_exists($handler, 'setProject')) {
$handler->setProject($project);
}
} catch (Exception $e) {
$msg = "Unable to instantiate specified input handler " . "class " . $this->inputHandlerClassname . " : " . $e->getMessage();
throw new ConfigurationException($msg);
}
}
$project->setInputHandler($handler);
}
示例10: createElement
/**
* Creates a named nested element.
*
* Valid creators can be in the form createFoo() or addFoo(Bar).
*
* @param Project $project
* @param object $element Object the XML tag is child of.
* Often a task object.
* @param string $elementName XML tag name
* @return object Returns the nested element.
* @throws BuildException
*/
public function createElement(Project $project, $element, $elementName)
{
$addMethod = "add" . strtolower($elementName);
$createMethod = "create" . strtolower($elementName);
$nestedElement = null;
if (isset($this->nestedCreators[$createMethod])) {
$method = $this->nestedCreators[$createMethod];
try {
// try to invoke the creator method on object
$project->log(" -calling creator " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", Project::MSG_DEBUG);
$nestedElement = $method->invoke($element);
} catch (Exception $exc) {
throw new BuildException($exc);
}
} elseif (isset($this->nestedCreators[$addMethod])) {
$method = $this->nestedCreators[$addMethod];
// project components must use class hints to support the add methods
try {
// try to invoke the adder method on object
$project->log(" -calling adder " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", Project::MSG_DEBUG);
// we've already assured that correct num of params
// exist and that method is using class hints
$params = $method->getParameters();
$classname = null;
if (($hint = $params[0]->getClass()) !== null) {
$classname = $hint->getName();
}
// create a new instance of the object and add it via $addMethod
$clazz = new ReflectionClass($classname);
if ($clazz->getConstructor() !== null && $clazz->getConstructor()->getNumberOfRequiredParameters() === 1) {
$nestedElement = new $classname(Phing::getCurrentProject());
} else {
$nestedElement = new $classname();
}
$method->invoke($element, $nestedElement);
} catch (Exception $exc) {
throw new BuildException($exc);
}
} elseif ($this->bean->implementsInterface("CustomChildCreator")) {
$method = $this->bean->getMethod('customChildCreator');
try {
$nestedElement = $method->invoke($element, strtolower($elementName), $project);
} catch (Exception $exc) {
throw new BuildException($exc);
}
} else {
//try the add method for the element's parent class
$typedefs = $project->getDataTypeDefinitions();
if (isset($typedefs[$elementName])) {
$elementClass = Phing::import($typedefs[$elementName]);
$parentClass = get_parent_class($elementClass);
$addMethod = 'add' . strtolower($parentClass);
if (isset($this->nestedCreators[$addMethod])) {
$method = $this->nestedCreators[$addMethod];
try {
$project->log(" -calling parent adder " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", Project::MSG_DEBUG);
$nestedElement = new $elementClass();
$method->invoke($element, $nestedElement);
} catch (Exception $exc) {
throw new BuildException($exc);
}
}
}
if ($nestedElement === null) {
$msg = $this->getElementName($project, $element) . " doesn't support the '{$elementName}' creator/adder.";
throw new BuildException($msg);
}
}
if ($nestedElement instanceof ProjectComponent) {
$nestedElement->setProject($project);
}
return $nestedElement;
}
示例11: testImportDotPath
/**
* Test the default dot separated class loading
*/
public function testImportDotPath()
{
$className = Phing::import(self::DOTED_CLASS, self::getClassPath());
self::assertEquals(self::DOTED_CLASS_SHORTNAME, $className);
self::assertTrue(class_exists(self::DOTED_CLASS_SHORTNAME));
}
示例12: getBuilderClass
/**
* Imports and returns the classname of the builder class for specified 'type'.
* @param $type The "key" for class to load.
* @return string The unqualified classname.
*/
public static function getBuilderClass($type)
{
if (empty(self::$buildProperties)) {
throw new BuildException("Cannot determine builder class when no build properties have been loaded (hint: Did you call DataModelBuilder::setBuildProperties(\$props) first?)");
}
$propname = 'builder' . ucfirst(strtolower($type)) . 'Class';
$classpath = self::getBuildProperty($propname);
if (empty($classpath)) {
throw new BuildException("Unable to find class path for '{$propname}' property.");
}
// This is a slight hack to workaround camel case inconsistencies for the DDL classes.
// Basically, we want to turn ?.?.?.sqliteDDLBuilder into ?.?.?.SqliteDDLBuilder
$lastdotpos = strrpos($classpath, '.');
if ($lastdotpos) {
$classpath[$lastdotpos + 1] = strtoupper($classpath[$lastdotpos + 1]);
} else {
ucfirst($classpath);
}
return Phing::import($classpath);
}
示例13: createTask
/**
* Create a new task instance and return reference to it. This method is
* sorta factory like. A _local_ instance is created and a reference returned to
* that instance. Usually PHP destroys local variables when the function call
* ends. But not if you return a reference to that variable.
* This is kinda error prone, because if no reference exists to the variable
* it is destroyed just like leaving the local scope with primitive vars. There's no
* central place where the instance is stored as in other OOP like languages.
*
* [HL] Well, ZE2 is here now, and this is still working. We'll leave this alone
* unless there's any good reason not to.
*
* @param string $taskType Task name
* @returns Task A task object
* @throws BuildException
* Exception
*/
function createTask($taskType)
{
try {
$classname = "";
$tasklwr = strtolower($taskType);
foreach ($this->taskdefs as $name => $class) {
if (strtolower($name) === $tasklwr) {
$classname = $class;
break;
}
}
if ($classname === "") {
return null;
}
$cls = Phing::import($classname);
if (!class_exists($cls)) {
throw new BuildException("Could not instantiate class {$cls}, even though a class was specified. (Make sure that the specified class file contains a class with the correct name.)");
}
$o = new $cls();
if ($o instanceof Task) {
$task = $o;
} else {
$this->log(" (Using TaskAdapter for: {$taskType})", Project::MSG_DEBUG);
// not a real task, try adapter
$taskA = new TaskAdapter();
$taskA->setProxy($o);
$task = $taskA;
}
$task->setProject($this);
$task->setTaskType($taskType);
// set default value, can be changed by the user
$task->setTaskName($taskType);
$this->log(" +Task: " . $taskType, Project::MSG_DEBUG);
} catch (Exception $t) {
throw new BuildException("Could not create task of type: " . $taskType, $t);
}
// everything fine return reference
return $task;
}
示例14: getClassname
/**
* Resolves and returns the class name based on the specified property value.
*
* @param string $propname The name of the property that holds the class path (dot-path notation).
* @return string The class name.
* @throws BuildException If the classname cannot be determined or class cannot be loaded.
*/
public function getClassname($propname)
{
$classpath = $this->getBuildProperty($propname);
if (empty($classpath)) {
throw new BuildException("Unable to find class path for '$propname' property.");
}
// This is a slight hack to workaround camel case inconsistencies for the DDL classes.
// Basically, we want to turn ?.?.?.sqliteDDLBuilder into ?.?.?.SqliteDDLBuilder
$lastdotpos = strrpos($classpath, '.');
if ($lastdotpos !== null) {
$classpath{$lastdotpos+1} = strtoupper($classpath{$lastdotpos+1});
} else {
$classpath = ucfirst($classpath);
}
if (empty($classpath)) {
throw new BuildException("Unable to find class path for '$propname' property.");
}
$clazz = Phing::import($classpath);
return $clazz;
}
示例15: setClassName
/**
* Loads a specific formatter class
*/
public function setClassName($className)
{
$classNameNoDot = Phing::import($className);
$this->formatter = new $classNameNoDot();
}