示例#1
0
 /**
  * Creates the appropriate implementation of `FileSystem` based
  * on the configuration of the website.
  */
 public static function create(IPieCrust $pieCrust)
 {
     $postsFs = $pieCrust->getConfig()->getValueUnchecked('site/posts_fs');
     $postsFs = array_map(function ($i) {
         return trim($i);
     }, explode(',', $postsFs));
     $fss = array();
     $fileSystems = $pieCrust->getPluginLoader()->getFileSystems();
     foreach ($fileSystems as $fs) {
         $i = array_search($fs->getName(), $postsFs);
         if ($i !== false) {
             $fss[] = $fs;
             unset($postsFs[$i]);
         }
     }
     if ($postsFs) {
         throw new PieCrustException("Unknown file-system(s): " . implode(', ', $postsFs));
     }
     $fssCount = count($fss);
     if ($fssCount == 1) {
         $pieCrust->getEnvironment()->getLog()->debug("Creating unique file-system.");
         $finalFs = $fss[0];
     } elseif ($fssCount > 1) {
         $pieCrust->getEnvironment()->getLog()->debug("Creating composite file-system.");
         $finalFs = new CompositeFileSystem($fss);
     } else {
         throw new PieCrustException("No file-systems have been created: " . implode(', ', $postsFs));
     }
     $finalFs->initialize($pieCrust);
     return $finalFs;
 }
 /**
  * Gets the repository handler associated with the given source.
  */
 public static function getRepository(IPieCrust $pieCrust, $source, $throwIfNotFound = true)
 {
     $repositories = $pieCrust->getPluginLoader()->getRepositories();
     foreach ($repositories as $repo) {
         if ($repo->supportsSource($source)) {
             return $repo;
         }
     }
     if ($throwIfNotFound) {
         throw new PieCrustException("Can't find a repository handler for source: {$source}");
     }
     return null;
 }
 public static function aboutImportHelpTopic(IPieCrust $pieCrust)
 {
     $importers = $pieCrust->getPluginLoader()->getImporters();
     $output = '';
     $output .= "The `import` command lets you import content from another CMS into PieCrust.\n";
     $output .= "\n";
     $output .= "Available formats:\n";
     $output .= "\n";
     foreach ($importers as $importer) {
         $output .= "`{$importer->getName()}`: " . wordwrap($importer->getDescription(), 70, "\n  ") . "\n\n";
         $firstLine = true;
         foreach (explode("\n", $importer->getHelpTopic()) as $line) {
             if ($firstLine) {
                 $output .= "  - ";
                 $firstLine = false;
             } else {
                 $output .= "    ";
             }
             $output .= wordwrap($line, 70, "\n    ") . "\n";
         }
         $output .= "\n\n";
     }
     return $output;
 }