[ Index ]

PHP Cross Reference of Automap

title

Body

[close]

/Automap/Tools/ -> Check.php (source)

   1  <?php
   2  //=============================================================================
   3  //
   4  // Copyright Francois Laupretre <automap@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 <automap@tekwire.net>
  21  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
  22  * @category Automap
  23  * @package Automap
  24  *///==========================================================================
  25  
  26  //=============================================================================
  27  /**
  28  * This class checks the integrity of a map.
  29  *
  30  * As it is included in the PHK runtime, the code may reference PHK, but not Phool.
  31  *
  32  * API status: Private
  33  * Included in the PHK PHP runtime: Yes
  34  * Implemented in the extension: No
  35  *///==========================================================================
  36  
  37  namespace Automap\Tools {
  38  
  39  if (!class_exists('Automap\Tools\Check',false)) 
  40  {
  41  class Check // Static only
  42  {
  43  
  44  //---
  45  // Returns an array of error messages
  46  
  47  public static function check($map)
  48  {
  49  $checked_targets=array();
  50  $errors=array();
  51  foreach($map->symbols() as $s)
  52      {
  53      try
  54          {
  55          $path=$s['path'];
  56          $ptype=$s['ptype'];
  57          $key=$ptype.$path;
  58          if (isset($checked_targets[$key])) continue;
  59          $checked_targets[$key]=true;
  60          switch($ptype)
  61              {
  62              case \Automap\Mgr::F_EXTENSION:
  63                  // Do nothing
  64                  break;
  65  
  66              case \Automap\Mgr::F_SCRIPT:
  67                  //echo "Checking script at $path\n";
  68                  if (!is_file($path)) throw new \Exception($path.': File not found');
  69                  if (\PHK::fileIsPackage($path))
  70                      throw new \Exception($path.': File is a PHK package (should be a script)');
  71                  break;
  72  
  73              case \Automap\Mgr::F_PACKAGE:
  74                  //echo "Checking package at $path\n";
  75                  if (!is_file($path)) throw new \Exception($path.': File not found');
  76                  if (!\PHK::fileIsPackage($path))
  77                      throw new \Exception($path.': File is not a PHK package');
  78  
  79                  // Suppress notice msg on multiple HALT_COMPILER definitions
  80                  error_reporting(($errlevel=error_reporting()) & ~E_NOTICE);
  81                  $phk_id=\PHK\Mgr::mount($path,\PHK::F_NO_MOUNT_SCRIPT);
  82                  error_reporting($errlevel);
  83                  $pkg=\PHK\Mgr::instance($phk_id);
  84                  self::check(\Automap\Mgr::map($pkg->automap_id()));
  85                  break;
  86  
  87              default:
  88                  throw new \Exception("<$ptype>: Unknown target type");
  89              }
  90          }
  91      catch (\Exception $e)
  92          {
  93          $errors[]=\Automap\Mgr::typeToString($s['stype']).' '.$s['symbol']
  94              .': '.$e->getMessage();
  95          }
  96      }
  97  return $errors;
  98  }
  99  
 100  //---
 101  } // End of class
 102  //===========================================================================
 103  } // End of class_exists
 104  //===========================================================================
 105  } // End of namespace
 106  //===========================================================================
 107  ?>


Generated: Thu Jun 4 18:32:29 2015 Cross-referenced by PHPXref 0.7.1