vendor/doctrine-common/lib/Doctrine/Common/Cache/XcacheCache.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 /*
       
     3  *  $Id$
       
     4  *
       
     5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
     6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
     7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
     8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
     9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    16  *
       
    17  * This software consists of voluntary contributions made by many individuals
       
    18  * and is licensed under the LGPL. For more information, see
       
    19  * <http://www.doctrine-project.org>.
       
    20  */
       
    21 
       
    22 namespace Doctrine\Common\Cache;
       
    23 
       
    24 /**
       
    25  * Xcache cache driver.
       
    26  *
       
    27  * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
       
    28  * @link    www.doctrine-project.org
       
    29  * @since   2.0
       
    30  * @version $Revision: 3938 $
       
    31  * @author  Benjamin Eberlei <kontakt@beberlei.de>
       
    32  * @author  Guilherme Blanco <guilhermeblanco@hotmail.com>
       
    33  * @author  Jonathan Wage <jonwage@gmail.com>
       
    34  * @author  Roman Borschel <roman@code-factory.org>
       
    35  * @author  David Abdemoulaie <dave@hobodave.com>
       
    36  */
       
    37 class XcacheCache extends AbstractCache
       
    38 {
       
    39     /**
       
    40      * {@inheritdoc}
       
    41      */
       
    42     public function getIds()
       
    43     {
       
    44         $this->_checkAuth();
       
    45         $keys = array();
       
    46 
       
    47         for ($i = 0, $count = xcache_count(XC_TYPE_VAR); $i < $count; $i++) {
       
    48             $entries = xcache_list(XC_TYPE_VAR, $i);
       
    49 
       
    50             if (is_array($entries['cache_list'])) {
       
    51                 foreach ($entries['cache_list'] as $entry) {
       
    52                     $keys[] = $entry['name'];
       
    53                 }
       
    54             }
       
    55         }
       
    56 
       
    57         return $keys;
       
    58     }
       
    59 
       
    60     /**
       
    61      * {@inheritdoc}
       
    62      */
       
    63     protected function _doFetch($id)
       
    64     {
       
    65         return $this->_doContains($id) ? unserialize(xcache_get($id)) : false;
       
    66     }
       
    67 
       
    68     /**
       
    69      * {@inheritdoc}
       
    70      */
       
    71     protected function _doContains($id)
       
    72     {
       
    73         return xcache_isset($id);
       
    74     }
       
    75 
       
    76     /**
       
    77      * {@inheritdoc}
       
    78      */
       
    79     protected function _doSave($id, $data, $lifeTime = 0)
       
    80     {
       
    81         return xcache_set($id, serialize($data), (int) $lifeTime);
       
    82     }
       
    83 
       
    84     /**
       
    85      * {@inheritdoc}
       
    86      */
       
    87     protected function _doDelete($id)
       
    88     {
       
    89         return xcache_unset($id);
       
    90     }
       
    91 
       
    92 
       
    93     /**
       
    94      * Checks that xcache.admin.enable_auth is Off
       
    95      *
       
    96      * @throws \BadMethodCallException When xcache.admin.enable_auth is On
       
    97      * @return void
       
    98      */
       
    99     protected function _checkAuth()
       
   100     {
       
   101         if (ini_get('xcache.admin.enable_auth')) {
       
   102             throw new \BadMethodCallException('To use all features of \Doctrine\Common\Cache\XcacheCache, you must set "xcache.admin.enable_auth" to "Off" in your php.ini.');
       
   103         }
       
   104     }
       
   105 }