/**
  * Add a dot-notation or PEAR-notation class (and optionally
  * classpath) to the list of locations
  * 
  * @param string $classname
  * @param string $classpath
  * @return string
  */
 public static function addLocation($classname, $classpath = null)
 {
     /// check if this is a PEAR-style path (@see http://pear.php.net/manual/en/standards.naming.php)
     if (strpos($classname, '.') === false && strpos($classname, '_') !== false) {
         $cls = $classname;
         $classname = str_replace('_', '.', $classname);
     } else {
         $cls = StringHelper::unqualify($classname);
     }
     // 1- temporarily replace escaped '.' with another illegal char (#)
     $tmp = str_replace('\\.', '##', $classname);
     // 2- swap out the remaining '.' with DIR_SEP
     $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
     // 3- swap back the escaped '.'
     $tmp = str_replace('##', '.', $tmp);
     $path = dirname($tmp);
     if (!empty($classpath)) {
         $path = $classpath . DIRECTORY_SEPARATOR . $path;
     }
     self::$locations[$path] = true;
     return $cls;
 }
Example #2
0
 /**
  * Create a datatype instance and return reference to it
  * See createTask() for explanation how this works
  *
  * @param  string         $typeName Type name
  * @return object         A datatype object
  * @throws BuildException
  *                                 Exception
  */
 public function createDataType($typeName)
 {
     try {
         $cls = "";
         $typelwr = strtolower($typeName);
         foreach ($this->typedefs as $name => $class) {
             if (strtolower($name) === $typelwr) {
                 $cls = StringHelper::unqualify($class);
                 break;
             }
         }
         if ($cls === "") {
             return null;
         }
         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.)");
         }
         $type = new $cls();
         $this->log("  +Type: {$typeName}", Project::MSG_DEBUG);
         if (!$type instanceof DataType) {
             throw new Exception("{$class} is not an instance of phing.types.DataType");
         }
         if ($type instanceof ProjectComponent) {
             $type->setProject($this);
         }
     } catch (Exception $t) {
         throw new BuildException("Could not create type: {$typeName}", $t);
     }
     // everything fine return reference
     return $type;
 }
Example #3
0
 /**
  * Import a path, supporting the following conventions:
  * - PEAR style (@link http://pear.php.net/manual/en/standards.naming.php)
  * - PSR-0 (@link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
  * - dot-path
  *
  * @param string $dotPath   Path
  * @param mixed  $classpath String or object supporting __toString()
  *
  * @return string         The unqualified classname (which can be instantiated).
  *
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     if (strpos($dotPath, '.') !== false) {
         $classname = StringHelper::unqualify($dotPath);
     } else {
         $classname = $dotPath;
         $dotPath = '';
         $shortClassName = $classname;
         if ($lastNsPos = strripos($shortClassName, '\\')) {
             $namespace = substr($shortClassName, 0, $lastNsPos);
             $shortClassName = substr($shortClassName, $lastNsPos + 1);
             $dotPath = str_replace('\\', '.', $namespace) . '.';
         }
         $dotPath .= str_replace('_', '.', $shortClassName);
     }
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     if (class_exists($classname)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     // 1- temporarily replace escaped '.' with another illegal char (#)
     $tmp = str_replace('\\.', '##', $dotClassname);
     // 2- swap out the remaining '.' with DIR_SEP
     $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
     // 3- swap back the escaped '.'
     $tmp = str_replace('##', '.', $tmp);
     $classFile = $tmp . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }
Example #4
0
 /**
  * Import a dot-path notation class path.
  * @param string $dotPath
  * @param mixed $classpath String or object supporting __toString()
  * @return string The unqualified classname (which can be instantiated).
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     /// check if this is a PEAR-style path (@link http://pear.php.net/manual/en/standards.naming.php)
     if (strpos($dotPath, '.') === false && strpos($dotPath, '_') !== false) {
         $classname = $dotPath;
         $dotPath = str_replace('_', '.', $dotPath);
     } else {
         $classname = StringHelper::unqualify($dotPath);
     }
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     if (class_exists($classname)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     // 1- temporarily replace escaped '.' with another illegal char (#)
     $tmp = str_replace('\\.', '##', $dotClassname);
     // 2- swap out the remaining '.' with DIR_SEP
     $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
     // 3- swap back the escaped '.'
     $tmp = str_replace('##', '.', $tmp);
     $classFile = $tmp . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }
Example #5
0
 /**
  * Get the the name for an element.
  * When possible the full classnam (phing.tasks.system.PropertyTask) will
  * be returned.  If not available (loaded in taskdefs or typedefs) then the
  * XML element name will be returned.
  *
  * @param Project $project
  * @param object $element The Task or type element.
  * @return string Fully qualified class name of element when possible.
  */
 function getElementName(Project $project, $element)
 {
     $taskdefs = $project->getTaskDefinitions();
     $typedefs = $project->getDataTypeDefinitions();
     // check if class of element is registered with project (tasks & types)
     // most element types don't have a getTag() method
     $elClass = get_class($element);
     if (!in_array('getTag', get_class_methods($elClass))) {
         // loop through taskdefs and typesdefs and see if the class name
         // matches (case-insensitive) any of the classes in there
         foreach (array_merge($taskdefs, $typedefs) as $elName => $class) {
             if (0 === strcasecmp($elClass, StringHelper::unqualify($class))) {
                 return $class;
             }
         }
         return "{$elClass} (unknown)";
     } else {
         // ->getTag() method does exist, so use it
         $elName = $element->getTag();
         if (isset($taskdefs[$elName])) {
             return $taskdefs[$elName];
         } elseif (isset($typedefs[$elName])) {
             return $typedefs[$elName];
         } else {
             return "{$elName} (unknown)";
         }
     }
 }
Example #6
0
 /**
  * Import a dot-path notation class path.
  * @param string $dotPath
  * @param mixed $classpath String or object supporting __toString()
  * @return string The unqualified classname (which can be instantiated).
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     $classname = StringHelper::unqualify($dotPath);
     if (class_exists($classname, false)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     $classFile = strtr($dotClassname, '.', DIRECTORY_SEPARATOR) . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }