Beispiel #1
0
 /**
  * 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;
 }
 /**
  * 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");
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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();
 }
Beispiel #5
0
 /**
  * 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);
     }
 }
Beispiel #6
0
 /** 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;
 }
Beispiel #7
0
 /** 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;
 }
Beispiel #8
0
    }
} 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 f***s 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']);
Beispiel #9
0
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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));
 }
Beispiel #12
0
 /**
  * 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);
 }
Beispiel #13
0
 /**
  * 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;
 }
  /**
   * 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;
  }
Beispiel #15
0
 /**
  * Loads a specific formatter class
  */
 public function setClassName($className)
 {
     $classNameNoDot = Phing::import($className);
     $this->formatter = new $classNameNoDot();
 }
Beispiel #16
0
 /**
  * Creates a new condition and returns the reference to it
  *
  * @param  string         $conditionType
  * @return Condition
  * @throws BuildException
  */
 public function createCondition($conditionType)
 {
     try {
         $classname = "";
         $tasklwr = strtolower($conditionType);
         foreach ($this->typedefs 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 Condition) {
             return $o;
         } else {
             throw new BuildException("Not actually a condition");
         }
     } catch (Exception $e) {
         throw new BuildException("Could not create condition of type: " . $conditionType, $e);
     }
 }
 /**
  * Creates and configures a new Platform class.
  *
  * @param PDO $con
  *
  * @return Platform
  * @throws BuildException
  */
 public function getConfiguredPlatform(PDO $con = null, $database = null)
 {
     $buildConnection = $this->getBuildConnection($database);
     //First try to load platform from the user provided build properties
     if ($this->getBuildProperty('platformClass')) {
         // propel.platform.class = platform.${propel.database}Platform by default
         $clazz = $this->getClassname('platformClass');
     } elseif (null !== $buildConnection['adapter']) {
         $clazz = Phing::import('platform.' . ucfirst($buildConnection['adapter']) . 'Platform');
     } else {
         return null;
     }
     $platform = new $clazz();
     if (!$platform instanceof PropelPlatformInterface) {
         throw new BuildException("Specified platform class ({$clazz}) does not implement teh PropelPlatformInterface interface.");
     }
     if ($this->getBuildProperty('disableIdentifierQuoting')) {
         $platform->setIdentifierQuoting(false);
     } else {
         $platform->setIdentifierQuoting(true);
     }
     $platform->setConnection($con);
     $platform->setGeneratorConfig($this);
     return $platform;
 }
 function getAssembledReader()
 {
     $instream = $this->primaryReader;
     $filterReadersCount = count($this->filterChains);
     $finalFilters = array();
     // Collect all filter readers of all filter chains used ...
     for ($i = 0; $i < $filterReadersCount; $i++) {
         $filterchain =& $this->filterChains[$i];
         $filterReaders = $filterchain->getFilterReaders();
         $readerCount = count($filterReaders);
         for ($j = 0; $j < $readerCount; $j++) {
             $finalFilters[] = $filterReaders[$j];
         }
     }
     // ... then chain the filter readers.
     $filtersCount = count($finalFilters);
     if ($filtersCount > 0) {
         for ($i = 0; $i < $filtersCount; $i++) {
             $filter = $finalFilters[$i];
             if ($filter instanceof PhingFilterReader) {
                 // This filter reader is an external class.
                 $className = $filter->getClassName();
                 $classpath = $filter->getClasspath();
                 $project = $filter->getProject();
                 if ($className !== null) {
                     $cls = Phing::import($className, $classpath);
                     $impl = new $cls();
                 }
                 if (!$impl instanceof FilterReader) {
                     throw new Exception($className . " does not extend phing.system.io.FilterReader");
                 }
                 $impl->setReader($instream);
                 // chain
                 $impl->setProject($this->getProject());
                 // what about $project above ?
                 if ($impl instanceof Parameterizable) {
                     $impl->setParameters($filter->getParams());
                 }
                 $instream = $impl;
                 // now that it's been chained
             } elseif ($filter instanceof ChainableReader && $filter instanceof Reader) {
                 if ($this->getProject() !== null && $filter instanceof BaseFilterReader) {
                     $filter->setProject($this->getProject());
                 }
                 $instream = $filter->chain($instream);
             } else {
                 throw new Exception("Cannot chain invalid filter: " . get_class($filter));
             }
         }
     }
     return $instream;
 }
Beispiel #19
0
 /**
  * Gets an instance of the object.
  *
  * @return     object An instance of the object associated with this type.
  */
 public function getInstance()
 {
     if ($this->classname === null) {
         throw new BuildException('The classname attribute must be specified');
     }
     if ($this->instance === null) {
         try {
             Phing::import($this->classname, $this->classpath);
         } catch (BuildException $be) {
             /* Cannot import the file. */
             throw new BuildException(sprintf('Object from class %s cannot be instantiated', $this->classname), $be);
         }
         $class = $this->classname;
         $this->instance = new $class();
     }
     return $this->instance;
 }