當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTMLPurifier_DefinitionCacheFactory::instance方法代碼示例

本文整理匯總了PHP中HTMLPurifier_DefinitionCacheFactory::instance方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTMLPurifier_DefinitionCacheFactory::instance方法的具體用法?PHP HTMLPurifier_DefinitionCacheFactory::instance怎麽用?PHP HTMLPurifier_DefinitionCacheFactory::instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HTMLPurifier_DefinitionCacheFactory的用法示例。


在下文中一共展示了HTMLPurifier_DefinitionCacheFactory::instance方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getDefinition

 /**
  * Retrieves a definition
  * @param $type Type of definition: HTML, CSS, etc
  * @param $raw  Whether or not definition should be returned raw
  */
 public function getDefinition($type, $raw = false)
 {
     if (!$this->finalized && $this->autoFinalize) {
         $this->finalize();
     }
     $factory = HTMLPurifier_DefinitionCacheFactory::instance();
     $cache = $factory->create($type, $this);
     if (!$raw) {
         // see if we can quickly supply a definition
         if (!empty($this->definitions[$type])) {
             if (!$this->definitions[$type]->setup) {
                 $this->definitions[$type]->setup($this);
                 $cache->set($this->definitions[$type], $this);
             }
             return $this->definitions[$type];
         }
         // memory check missed, try cache
         $this->definitions[$type] = $cache->get($this);
         if ($this->definitions[$type]) {
             // definition in cache, return it
             return $this->definitions[$type];
         }
     } elseif (!empty($this->definitions[$type]) && !$this->definitions[$type]->setup) {
         // raw requested, raw in memory, quick return
         return $this->definitions[$type];
     }
     // quick checks failed, let's create the object
     if ($type == 'HTML') {
         $this->definitions[$type] = new HTMLPurifier_HTMLDefinition();
     } elseif ($type == 'CSS') {
         $this->definitions[$type] = new HTMLPurifier_CSSDefinition();
     } elseif ($type == 'URI') {
         $this->definitions[$type] = new HTMLPurifier_URIDefinition();
     } else {
         throw new HTMLPurifier_Exception("Definition of {$type} type not supported");
     }
     // quick abort if raw
     if ($raw) {
         if (is_null($this->get($type, 'DefinitionID'))) {
             // fatally error out if definition ID not set
             throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %{$type}.DefinitionID");
         }
         return $this->definitions[$type];
     }
     // set it up
     $this->definitions[$type]->setup($this);
     // save in cache
     $cache->set($this->definitions[$type], $this);
     return $this->definitions[$type];
 }
開發者ID:BackupTheBerlios,項目名稱:oos-svn,代碼行數:55,代碼來源:HTMLPurifier.standalone.php

示例2: getDefinition

 /**
  * Retrieves a definition
  *
  * @param string $type Type of definition: HTML, CSS, etc
  * @param bool $raw Whether or not definition should be returned raw
  * @param bool $optimized Only has an effect when $raw is true.  Whether
  *        or not to return null if the result is already present in
  *        the cache.  This is off by default for backwards
  *        compatibility reasons, but you need to do things this
  *        way in order to ensure that caching is done properly.
  *        Check out enduser-customize.html for more details.
  *        We probably won't ever change this default, as much as the
  *        maybe semantics is the "right thing to do."
  *
  * @throws HTMLPurifier_Exception
  * @return HTMLPurifier_Definition
  */
 public function getDefinition($type, $raw = false, $optimized = false)
 {
     if ($optimized && !$raw) {
         throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false");
     }
     if (!$this->finalized) {
         $this->autoFinalize();
     }
     // temporarily suspend locks, so we can handle recursive definition calls
     $lock = $this->lock;
     $this->lock = null;
     $factory = HTMLPurifier_DefinitionCacheFactory::instance();
     $cache = $factory->create($type, $this);
     $this->lock = $lock;
     if (!$raw) {
         // full definition
         // ---------------
         // check if definition is in memory
         if (!empty($this->definitions[$type])) {
             $def = $this->definitions[$type];
             // check if the definition is setup
             if ($def->setup) {
                 return $def;
             } else {
                 $def->setup($this);
                 if ($def->optimized) {
                     $cache->add($def, $this);
                 }
                 return $def;
             }
         }
         // check if definition is in cache
         $def = $cache->get($this);
         if ($def) {
             // definition in cache, save to memory and return it
             $this->definitions[$type] = $def;
             return $def;
         }
         // initialize it
         $def = $this->initDefinition($type);
         // set it up
         $this->lock = $type;
         $def->setup($this);
         $this->lock = null;
         // save in cache
         $cache->add($def, $this);
         // return it
         return $def;
     } else {
         // raw definition
         // --------------
         // check preconditions
         $def = null;
         if ($optimized) {
             if (is_null($this->get($type . '.DefinitionID'))) {
                 // fatally error out if definition ID not set
                 throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %{$type}.DefinitionID");
             }
         }
         if (!empty($this->definitions[$type])) {
             $def = $this->definitions[$type];
             if ($def->setup && !$optimized) {
                 $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : "";
                 throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra);
             }
             if ($def->optimized === null) {
                 $extra = $this->chatty ? " (try flushing your cache)" : "";
                 throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra);
             }
             if ($def->optimized !== $optimized) {
                 $msg = $optimized ? "optimized" : "unoptimized";
                 $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a {$msg} raw definition)" : "";
                 throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra);
             }
         }
         // check if definition was in memory
         if ($def) {
             if ($def->setup) {
                 // invariant: $optimized === true (checked above)
                 return null;
             } else {
                 return $def;
             }
//.........這裏部分代碼省略.........
開發者ID:dingdong2310,項目名稱:g5_theme,代碼行數:101,代碼來源:HTMLPurifier.standalone.php

示例3: teardownCacheMock

 protected function teardownCacheMock()
 {
     HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
 }
開發者ID:Jaaviieer,項目名稱:PrograWeb,代碼行數:4,代碼來源:ConfigTest.php

示例4: tearDown

 public function tearDown()
 {
     HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
 }
開發者ID:sebbie42,項目名稱:casebox,代碼行數:4,代碼來源:DefinitionCacheFactoryTest.php

示例5: XmlReporter

    }
    $reporter = new XmlReporter();
} elseif (SimpleReporter::inCli() || $AC['txt']) {
    if (!SimpleReporter::inCli()) {
        header('Content-Type: text/plain;charset=UTF-8');
    }
    $reporter = new HTMLPurifier_SimpleTest_TextReporter($AC);
} else {
    $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC);
}
if ($AC['flush']) {
    htmlpurifier_flush($AC['php'], $reporter);
}
// Now, userland code begins to be executed
// setup special DefinitionCacheFactory decorator
$factory = HTMLPurifier_DefinitionCacheFactory::instance();
$factory->addDecorator('Memory');
// since we deal with a lot of config objects
if (!$AC['disable-phpt']) {
    $phpt = PHPT_Registry::getInstance();
    $phpt->php = $AC['php'];
}
// load tests
require 'test_files.php';
$FS = new FSTools();
// handle test dirs
foreach ($test_dirs as $dir) {
    $raw_files = $FS->globr($dir, '*Test.php');
    foreach ($raw_files as $file) {
        $file = str_replace('\\', '/', $file);
        if (isset($test_dirs_exclude[$file])) {
開發者ID:youprofit,項目名稱:casebox,代碼行數:31,代碼來源:index.php

示例6: testURIDefinitionValidation

 function testURIDefinitionValidation()
 {
     $parser = new HTMLPurifier_URIParser();
     $uri = $parser->parse('http://example.com');
     $this->config->set('URI.DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
     generate_mock_once('HTMLPurifier_URIDefinition');
     $uri_def = new HTMLPurifier_URIDefinitionMock();
     $uri_def->expectOnce('filter', array($uri, '*', '*'));
     $uri_def->setReturnValue('filter', true, array($uri, '*', '*'));
     $uri_def->expectOnce('postFilter', array($uri, '*', '*'));
     $uri_def->setReturnValue('postFilter', true, array($uri, '*', '*'));
     $uri_def->setup = true;
     // Since definitions are no longer passed by reference, we need
     // to muck around with the cache to insert our mock. This is
     // technically a little bad, since the cache shouldn't change
     // behavior, but I don't feel too good about letting users
     // overload entire definitions.
     generate_mock_once('HTMLPurifier_DefinitionCache');
     $cache_mock = new HTMLPurifier_DefinitionCacheMock();
     $cache_mock->setReturnValue('get', $uri_def);
     generate_mock_once('HTMLPurifier_DefinitionCacheFactory');
     $factory_mock = new HTMLPurifier_DefinitionCacheFactoryMock();
     $old = HTMLPurifier_DefinitionCacheFactory::instance();
     HTMLPurifier_DefinitionCacheFactory::instance($factory_mock);
     $factory_mock->setReturnValue('create', $cache_mock);
     $this->assertDef('http://example.com');
     HTMLPurifier_DefinitionCacheFactory::instance($old);
 }
開發者ID:artbypravesh,項目名稱:morningpages,代碼行數:28,代碼來源:URITest.php

示例7: getDefinition

 public function getDefinition($type, $raw = false, $optimized = false)
 {
     if ($optimized && !$raw) {
         throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false");
     }
     if (!$this->finalized) {
         $this->autoFinalize();
     }
     $lock = $this->lock;
     $this->lock = null;
     $factory = HTMLPurifier_DefinitionCacheFactory::instance();
     $cache = $factory->create($type, $this);
     $this->lock = $lock;
     if (!$raw) {
         if (!empty($this->definitions[$type])) {
             $def = $this->definitions[$type];
             if ($def->setup) {
                 return $def;
             } else {
                 $def->setup($this);
                 if ($def->optimized) {
                     $cache->add($def, $this);
                 }
                 return $def;
             }
         }
         $def = $cache->get($this);
         if ($def) {
             $this->definitions[$type] = $def;
             return $def;
         }
         $def = $this->initDefinition($type);
         $this->lock = $type;
         $def->setup($this);
         $this->lock = null;
         $cache->add($def, $this);
         return $def;
     } else {
         $def = null;
         if ($optimized) {
             if (is_null($this->get($type . '.DefinitionID'))) {
                 throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %{$type}.DefinitionID");
             }
         }
         if (!empty($this->definitions[$type])) {
             $def = $this->definitions[$type];
             if ($def->setup && !$optimized) {
                 $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : "";
                 throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra);
             }
             if ($def->optimized === null) {
                 $extra = $this->chatty ? " (try flushing your cache)" : "";
                 throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra);
             }
             if ($def->optimized !== $optimized) {
                 $msg = $optimized ? "optimized" : "unoptimized";
                 $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a {$msg} raw definition)" : "";
                 throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra);
             }
         }
         if ($def) {
             if ($def->setup) {
                 return null;
             } else {
                 return $def;
             }
         }
         if ($optimized) {
             $def = $cache->get($this);
             if ($def) {
                 $this->definitions[$type] = $def;
                 return null;
             }
         }
         if (!$optimized) {
             if (!is_null($this->get($type . '.DefinitionID'))) {
                 if ($this->chatty) {
                     $this->triggerError('Due to a documentation error in previous version of HTML Purifier, your ' . 'definitions are not being cached.  If this is OK, you can remove the ' . '%$type.DefinitionRev and %$type.DefinitionID declaration.  Otherwise, ' . 'modify your code to use maybeGetRawDefinition, and test if the returned ' . 'value is null before making any edits (if it is null, that means that a ' . 'cached version is available, and no raw operations are necessary).  See ' . '<a href="http://htmlpurifier.org/docs/enduser-customize.html#optimized">' . 'Customize</a> for more details', E_USER_WARNING);
                 } else {
                     $this->triggerError("Useless DefinitionID declaration", E_USER_WARNING);
                 }
             }
         }
         $def = $this->initDefinition($type);
         $def->optimized = $optimized;
         return $def;
     }
     throw new HTMLPurifier_Exception("The impossible happened!");
 }
開發者ID:harrylongworth,項目名稱:tv-bb,代碼行數:89,代碼來源:HTMLPurifier.standalone.php


注:本文中的HTMLPurifier_DefinitionCacheFactory::instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。