Beispiel #1
0
 private function analyzeDirectory($analyzer, $path)
 {
     $dir = new DirectoryIterator($path);
     foreach ($dir as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if ($entry->isDir()) {
             $this->analyzeDirectory($analyzer, $entry->getPathname());
             continue;
         }
         $ext = \Sledgehammer\file_extension($entry->getFilename());
         if (in_array($ext, array('php'))) {
             try {
                 $analyzer->open($entry->getPathname());
             } catch (Exception $e) {
                 //					\Sledgehammer\report_exception($e);
                 $this->fail($e->getMessage());
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Aan de hand van de url de betreffende action functie aanroepen.
  * Valt terug op file() en folder() functies, als de geen action functie gevonden wordt.
  *
  * @return Component
  */
 public function generateContent()
 {
     $this->initDepth();
     $url = Url::getCurrentURL();
     $folders = $url->getFolders();
     $filename = $url->getFilename();
     $folder_count = count($folders);
     if ($folder_count == $this->depth) {
         $extension = \Sledgehammer\file_extension($filename, $file);
         if ($extension === null && $this->handle_filenames_without_extension == false) {
             // Ongeldige bestandsnaam? (geen  extentie)
             error_log('filename without extension, redirecting to "' . $filename . '/"', E_NOTICE);
             return new Redirect($filename . '/');
             // Redirect naar dezelfde url, maar dan als mapnaam
         }
         if ($this->publicMethods === null) {
             notice('Check if the parent::__construct() is called in ' . get_class($this) . '__construct()');
         }
         $function = str_replace('-', '_', $file);
         if (substr($function, -7) != '_folder' && in_array($function, $this->publicMethods)) {
             return $this->{$function}($extension);
             // Roept bijvoorbeeld de $this->index('html') functie aan.
         }
         return $this->file($filename);
     }
     if ($folder_count > $this->depth) {
         if ($folder_count != $this->depth + 1) {
             $filename = false;
             // Deze submap heeft nog 1 of meer submappen.
         }
         $folder = $folders[$this->depth];
         $function = str_replace('-', '_', $folder) . '_folder';
         if (in_array($function, $this->publicMethods)) {
             return $this->{$function}($filename);
             // Roept bijvoorbeeld de $this->fotos_folder('index.html') functie aan.
         }
         return $this->folder($folder, $filename);
     }
     warning('Not enough (virtual) subfolders in URI', 'VirtualFolder depth(' . $this->depth . ') exceeds maximum(' . count($folders) . ')');
     return $this->onFolderNotFound();
     // @todo eigen event?
 }
Beispiel #3
0
 /**
  * Import definitions inside a folder.
  * Checks "autoloader.ini" for additional settings.
  *
  * @param string $path
  * @param array  $settings
  */
 public function importFolder($path, $settings = [])
 {
     $composer = false;
     if (file_exists($path . '/composer.json')) {
         if (substr($path, -1) !== '/') {
             $path .= '/';
         }
         $composer = json_decode(file_get_contents($path . 'composer.json'), true);
     }
     if ($composer && isset($composer['sledgehammer'])) {
         $settings += ['matching_filename' => true, 'mandatory_definition' => true, 'mandatory_superclass' => true, 'one_definition_per_file' => true, 'detect_accidental_output' => true, 'notice_ambiguous' => true];
     }
     $settings = $this->loadSettings($path, $settings);
     if ($composer) {
         $locations = [];
         $trace = [];
         $preventDefault = true;
         if (isset($composer['autoload']['classmap'])) {
             foreach ($composer['autoload']['classmap'] as $entry) {
                 $paths = is_array($entry) ? $entry : array($entry);
                 foreach ($paths as $entryPath) {
                     if (empty($entryPath) || $entry === '.') {
                         \Sledgehammer\notice('Empty autoload.classmap in "composer.json" isn\'t supported');
                         $preventDefault = false;
                         break;
                     } elseif (is_dir($path . $entryPath)) {
                         $locations[] = $entryPath;
                         $trace[] = 'classmap';
                     }
                 }
             }
         }
         $namespaces = [];
         if (isset($composer['autoload']['psr-0'])) {
             $namespaces += $composer['autoload']['psr-0'];
         }
         if (isset($composer['autoload']['psr-4'])) {
             $namespaces += $composer['autoload']['psr-4'];
         }
         if (isset($composer['autoload-dev']['psr-0'])) {
             $namespaces += $composer['autoload-dev']['psr-0'];
         }
         if (isset($composer['autoload-dev']['psr-4'])) {
             $namespaces += $composer['autoload-dev']['psr-4'];
         }
         foreach ($namespaces as $namespace => $entry) {
             $paths = is_array($entry) ? $entry : array($entry);
             foreach ($paths as $entryPath) {
                 if (in_array($entryPath, array('', '/', '.'))) {
                     $preventDefault = false;
                     break 2;
                 }
                 $locations[] = $entryPath;
                 $trace[] = 'psr-0 (' . $namespace . ')';
             }
         }
         if ($preventDefault) {
             foreach ($locations as $i => $entry) {
                 if (is_dir($path . $entry)) {
                     if (in_array($entry, $settings['ignore_folders'])) {
                         continue;
                     }
                     $this->importFolder($path . $entry, $settings);
                 } elseif (is_file($path . $entry)) {
                     if (in_array($entry, $settings['ignore_files'])) {
                         continue;
                     }
                     $this->importFile($path . $entry, $settings);
                 } else {
                     // Allow invalid composer.json configurations, not Sledgehammers problem.
                     // \Sledgehammer\notice('Invalid "composer.json" entry: '.$trace[$i].': "'.$entry.'"', 'file or directory: "'.$path.$entry.'" not found');
                 }
             }
             return;
         }
     }
     $useCache = $this->enableCache && $settings['cache_level'] > 0;
     if ($useCache) {
         --$settings['cache_level'];
         $scanCount = false;
         $folder = basename($path);
         if ($folder == 'classes') {
             $folder = basename(dirname($path));
         }
         $cacheFile = \Sledgehammer\TMP_DIR . 'AutoLoader/' . $folder . '_' . md5($path) . '.php';
         if (!\Sledgehammer\mkdirs(dirname($cacheFile))) {
             $this->enableCache = false;
             $useCache = false;
         } elseif (file_exists($cacheFile)) {
             $mtimeCache = filemtime($cacheFile);
             $revalidateCache = $mtimeCache < time() - $settings['revalidate_cache_delay'];
             // Is er een delay ingesteld en is deze nog niet verstreken?;
             $mtimeFolder = $revalidateCache ? \Sledgehammer\mtime_folders($path, array('php'), $scanCount) : 0;
             if ($mtimeFolder !== false && $mtimeCache > $mtimeFolder) {
                 // Is het cache bestand niet verouderd?
                 if ($this->loadDatabase($cacheFile, true, $scanCount)) {
                     if ($settings['revalidate_cache_delay'] && $revalidateCache) {
                         // is het cache bestand opnieuw gevalideerd?
                         touch($cacheFile);
                         // de mtime van het cache-bestand aanpassen, (voor het bepalen of de delay is vertreken)
                     }
                     return;
                 }
             }
         }
     }
     // Import files & subfolders
     try {
         $dir = new DirectoryIterator($path);
     } catch (Exception $e) {
         \Sledgehammer\notice($e->getMessage());
         return;
     }
     foreach ($dir as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if ($entry->isDir()) {
             if (in_array($entry->getPathname(), $settings['ignore_folders'])) {
                 continue;
             }
             $this->importFolder($entry->getPathname(), $settings);
         }
         if (\Sledgehammer\file_extension($entry->getFilename()) == 'php') {
             if (in_array($entry->getPathname(), $settings['ignore_files']) == false) {
                 $this->importFile($entry->getPathname(), $settings);
             }
         }
     }
     if ($useCache) {
         $this->saveDatabase($cacheFile, $this->relativePath($path), $scanCount);
     }
 }