[ Index ]

PHP Cross Reference of PHK Manager

title

Body

[close]

/PHK/Virtual/ -> Node.php (source)

   1  <?php
   2  //=============================================================================
   3  //
   4  // Copyright Francois Laupretre <phk@tekwire.net>
   5  //
   6  //   Licensed under the Apache License, Version 2.0 (the "License");
   7  //   you may not use this file except in compliance with the License.
   8  //   You may obtain a copy of the License at
   9  //
  10  //       http://www.apache.org/licenses/LICENSE-2.0
  11  //
  12  //   Unless required by applicable law or agreed to in writing, software
  13  //   distributed under the License is distributed on an "AS IS" BASIS,
  14  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15  //   See the License for the specific language governing permissions and
  16  //   limitations under the License.
  17  //
  18  //=============================================================================
  19  /**
  20  * @copyright Francois Laupretre <phk@tekwire.net>
  21  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
  22  * @category PHK
  23  * @package PHK
  24  *///==========================================================================
  25  
  26  namespace PHK\Virtual {
  27  
  28  if (!class_exists('PHK\Virtual\Node',false))
  29  {
  30  //============================================================================
  31  /**
  32  * A virtual node
  33  *
  34  * This is a node of the virtual tree. This abstract class can be extended with
  35  * a directory (Dir class) or a file (File class)
  36  *
  37  * API status: Private
  38  * Included in the PHK PHP runtime: Yes
  39  * Implemented in the extension: No
  40  *///==========================================================================
  41  
  42  abstract class Node        // Base class - never instantiated
  43  {
  44  protected $flags;
  45  
  46  protected $path;
  47  
  48  protected $tree=null;    // Back pointer to the tree
  49  
  50  //---- Flags
  51  
  52  const TN_DC_FLAG_MASK=DC::COMPRESS_TYPE; // Low bits reserved for compr type
  53  
  54  const TN_STRIP_SOURCE=8;    // Strip source files
  55  const TN_NO_AUTOLOAD=16;    // Don't register symbols in Automap
  56  const TN_PKG=32;            // File is a PHK package
  57  
  58  //---
  59  
  60  abstract public function type(); // returns type string
  61  
  62  //---
  63  // Default: do nothing
  64  
  65  public function displayPackage($html) {}
  66  
  67  //---
  68  
  69  public function isPackage()
  70  {
  71  return ($this->flags & self::TN_PKG);
  72  }
  73  
  74  //---
  75  // Default: error if the method is not overloaded
  76  
  77  public function getDir()
  78  {
  79  throw new \Exception($this->path.': Cannot getDir() on a '.$this->type());
  80  }
  81  
  82  //---
  83  // Default: error
  84  
  85  public function read()
  86  {
  87  throw new \Exception($this->path.': Cannot read() a '.$this->type());
  88  }
  89  
  90  //---
  91  
  92  protected function flagString()
  93  {
  94  $flagString='';
  95  if ($this->flags & self::TN_PKG) $flagString .=',package';
  96  else
  97      {
  98      if ($this->flags & self::TN_STRIP_SOURCE) $flagString .=',strip';
  99      if ($this->flags & self::TN_NO_AUTOLOAD) $flagString .=',no_autoload';
 100      }
 101  
 102  return $flagString;
 103  }
 104  
 105  //---
 106  
 107  // Cannot call setFlags() here, as it will call the derived
 108  // method when it is defined (as in \PHK\Virtual\File)
 109  
 110  protected function __construct($path,$tree)
 111  {
 112  $this->path=$path;
 113  $this->tree=$tree;
 114  $this->flags=0;
 115  }
 116  
 117  //---
 118  
 119  protected function import($edata)
 120  {
 121  list($this->flags)=array_values(unpack('va',$edata));
 122  return substr($edata,2);
 123  }
 124  
 125  // <CREATOR> //---------------
 126  
 127  abstract public function export(\PHK\Build\Creator $phk,\PHK\Build\DataStacker $stacker,$map);
 128  
 129  //---
 130  
 131  protected function nodeExport($derived_edata)
 132  {
 133  return pack('v',$this->flags).$derived_edata;
 134  }
 135  
 136  //---
 137  
 138  public function setFlags($flags)
 139  {
 140  $this->flags=$flags;
 141  }
 142  
 143  //---
 144  
 145  private static function computeFlags(array $modifiers,$flags=0)
 146  {
 147  foreach($modifiers as $name => $value)
 148      {
 149      if (is_null($value)) continue;
 150      switch ($name)
 151          {
 152              case 'autoload':
 153                  if ($value) $flags &= ~self::TN_NO_AUTOLOAD;
 154                  else $flags |= self::TN_NO_AUTOLOAD;
 155                  break;
 156  
 157              case 'strip':
 158                  if ($value) $flags |= self::TN_STRIP_SOURCE;
 159                  else $flags &= ~self::TN_STRIP_SOURCE;
 160                  break;
 161  
 162              case 'compression':
 163                  switch($value)
 164                      {
 165                      case 'no':
 166                      case 'none':
 167                          $c=DC::COMPRESS_NONE;
 168                          break;
 169                      case 'gz':
 170                      case 'gzip':
 171                          $c=DC::COMPRESS_GZIP;
 172                          break;
 173                      case 'bz':
 174                      case 'bz2':
 175                      case 'bzip2':
 176                          $c=DC::COMPRESS_BZIP2;
 177                          break;
 178                      default:
 179                          throw new \Exception($value.': Unknown compression method');
 180                      }
 181                  $flags = ($flags & ~DC::COMPRESS_TYPE) | $c;
 182                  break;
 183          // Ignore other modifiers
 184          }
 185      }
 186  return $flags;
 187  }
 188  
 189  //---
 190  
 191  public function modify($modifiers)
 192  {
 193  $this->setFlags(self::computeFlags($modifiers,$this->flags));
 194  }
 195  
 196  // </CREATOR> //---------------
 197  
 198  //---
 199  } // End of class
 200  //===========================================================================
 201  } // End of class_exists
 202  //===========================================================================
 203  } // End of namespace
 204  //===========================================================================
 205  ?>


Generated: Thu Jun 4 18:33:15 2015 Cross-referenced by PHPXref 0.7.1