예제 #1
0
 /**
  * Tests that {@link Director::is_absolute()} works under different environment types
  */
 public function testIsAbsolute()
 {
     $expected = array('C:/something' => true, 'd:\\' => true, 'e/' => false, 's:/directory' => true, '/var/www' => true, '\\Something' => true, 'something/c:' => false, 'folder' => false, 'a/c:/' => false);
     foreach ($expected as $path => $result) {
         $this->assertEquals(Director::is_absolute($path), $result, "Test result for {$path}");
     }
 }
 /**
  * Adds the default languages if they are missing
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $defaultLangs = array_keys($this->defaultLanguages);
     $dbLangCount = SnippetLanguage::get()->filter('Name', $defaultLangs)->filter('UserLanguage', 0)->Count();
     if ($dbLangCount < count($defaultLangs)) {
         foreach ($this->defaultLanguages as $name => $data) {
             if (!SnippetLanguage::get()->find('Name', $name)) {
                 $lang = new SnippetLanguage();
                 $lang->Name = $name;
                 $lang->FileExtension = $data['Extension'];
                 $lang->HighlightCode = $data['HighlightCode'];
                 $lang->UserLanguage = false;
                 $lang->write();
                 DB::alteration_message('Created snippet language "' . $name . '"', 'created');
             }
         }
     }
     //Look for config languages
     $configLanguages = CodeBank::config()->extra_languages;
     if (!empty($configLanguages)) {
         foreach ($configLanguages as $language) {
             //Validate languages
             if (empty($language['Name']) || empty($language['FileName']) || empty($language['HighlightCode']) || empty($language['Brush'])) {
                 user_error('Invalid snippet user language found in config, user languages defined in config must contain a Name, FileName, HighlightCode and Brush file path', E_USER_WARNING);
                 continue;
             }
             $lang = SnippetLanguage::get()->filter('Name', Convert::raw2sql($language['Name']))->filter('HighlightCode', Convert::raw2sql($language['HighlightCode']))->filter('UserLanguage', true)->first();
             if (empty($lang) || $lang === false || $lang->ID <= 0) {
                 if (Director::is_absolute($language['Brush']) || Director::is_absolute_url($language['Brush'])) {
                     user_error('Invalid snippet user language found in config, user languages defined in config must contain a path to the brush relative to the SilverStripe base (' . Director::baseFolder() . ')', E_USER_WARNING);
                     continue;
                 }
                 if (preg_match('/\\.js$/', $language['Brush']) == 0) {
                     user_error('Invalid snippet user language found in config, user languages defined in config must be javascript files', E_USER_WARNING);
                     continue;
                 }
                 //Add language
                 $lang = new SnippetLanguage();
                 $lang->Name = $language['Name'];
                 $lang->FileExtension = $language['FileName'];
                 $lang->HighlightCode = $language['HighlightCode'];
                 $lang->BrushFile = $language['Brush'];
                 $lang->UserLanguage = true;
                 $lang->write();
                 DB::alteration_message('Created snippet user language "' . $language['Name'] . '"', 'created');
             }
         }
     }
 }
예제 #3
0
	/**
	 * @param String Absolute file path, or relative path to {@link Director::baseFolder()}
	 */
	function __construct($fixtureFile) {
		if(!Director::is_absolute($fixtureFile)) $fixtureFile = Director::baseFolder().'/'. $fixtureFile;
		
		if(!file_exists($fixtureFile)) {
			throw new InvalidArgumentException('YamlFixture::__construct(): Fixture path "' . $fixtureFile . '" not found');
		}
		
		$this->fixtureFile = $fixtureFile;
		
		parent::__construct();
	}
예제 #4
0
 /**
  * @param String Absolute file path, or relative path to {@link Director::baseFolder()}
  */
 public function __construct($fixture)
 {
     if (false !== strpos($fixture, "\n")) {
         $this->fixtureString = $fixture;
     } else {
         if (!Director::is_absolute($fixture)) {
             $fixture = Director::baseFolder() . '/' . $fixture;
         }
         if (!file_exists($fixture)) {
             throw new InvalidArgumentException('YamlFixture::__construct(): Fixture path "' . $fixture . '" not found');
         }
         $this->fixtureFile = $fixture;
     }
     parent::__construct();
 }
 /**
  * Get all *.sql database files located in a specific path,
  * keyed by their file name.
  *
  * @param  String $path Absolute folder path
  * @return array
  */
 protected function getDatabaseTemplates($path = null)
 {
     $templates = array();
     if (!$path) {
         $path = $this->config()->database_templates_path;
     }
     // TODO Remove once we can set BASE_PATH through the config layer
     if ($path && !Director::is_absolute($path)) {
         $path = BASE_PATH . '/' . $path;
     }
     if ($path && file_exists($path)) {
         $it = new FilesystemIterator($path);
         foreach ($it as $fileinfo) {
             if ($fileinfo->getExtension() != 'sql') {
                 continue;
             }
             $templates[$fileinfo->getRealPath()] = $fileinfo->getFilename();
         }
     }
     return $templates;
 }