当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheUtil::createLocalDir方法代码示例

本文整理汇总了PHP中CacheUtil::createLocalDir方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheUtil::createLocalDir方法的具体用法?PHP CacheUtil::createLocalDir怎么用?PHP CacheUtil::createLocalDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CacheUtil的用法示例。


在下文中一共展示了CacheUtil::createLocalDir方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * Initialise.
  *
  * Runs at plugin init time.
  *
  * @return void
  */
 public function initialize(GenericEvent $event)
 {
     // register namespace
     // Because the standard kernel classloader already has Doctrine registered as a namespace
     // we have to add a new loader onto the spl stack.
     $autoloader = new UniversalClassLoader();
     $autoloader->register();
     $autoloader->registerNamespaces(array('DoctrineProxy' => 'ztemp/doctrinemodels'));
     $container = $event->getDispatcher()->getContainer();
     $config = $GLOBALS['ZConfig']['DBInfo']['databases']['default'];
     $dbConfig = array('host' => $config['host'], 'user' => $config['user'], 'password' => $config['password'], 'dbname' => $config['dbname'], 'driver' => 'pdo_' . $config['dbdriver']);
     $r = new \ReflectionClass('Doctrine\\Common\\Cache\\' . $container['dbcache.type'] . 'Cache');
     $dbCache = $r->newInstance();
     $ORMConfig = new \Doctrine\ORM\Configuration();
     $container->set('doctrine.configuration', $ORMConfig);
     $ORMConfig->setMetadataCacheImpl($dbCache);
     // create proxy cache dir
     \CacheUtil::createLocalDir('doctrinemodels');
     // setup annotations base
     include_once \ZLOADER_PATH . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
     // setup annotation reader
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $cacheReader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
     $container->set('doctrine.annotationreader', $cacheReader);
     // setup annotation driver
     $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cacheReader);
     $container->set('doctrine.annotationdriver', $annotationDriver);
     // setup driver chains
     $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $container->set('doctrine.driverchain', $driverChain);
     // configure Doctrine ORM
     $ORMConfig->setMetadataDriverImpl($annotationDriver);
     $ORMConfig->setQueryCacheImpl($dbCache);
     $ORMConfig->setProxyDir(\CacheUtil::getLocalDir('doctrinemodels'));
     $ORMConfig->setProxyNamespace('DoctrineProxy');
     if (isset($container['log.enabled']) && $container['log.enabled']) {
         $ORMConfig->setSQLLogger(new \Zikula\Core\Doctrine\Logger\ZikulaSqlLogger());
     }
     // setup doctrine eventmanager
     $dispatcher = new \Doctrine\Common\EventManager();
     $container->set('doctrine.eventmanager', $dispatcher);
     // setup MySQL specific listener (storage engine and encoding)
     if ($config['dbdriver'] == 'mysql') {
         $mysqlSessionInit = new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit($config['charset']);
         $dispatcher->addEventSubscriber($mysqlSessionInit);
     }
     // setup the doctrine entitymanager
     $entityManager = \Doctrine\ORM\EntityManager::create($dbConfig, $ORMConfig, $dispatcher);
     $container->set('doctrine.entitymanager', $entityManager);
 }
开发者ID:planetenkiller,项目名称:core,代码行数:57,代码来源:DoctrineListener.php

示例2: _generateSubclassForCategorisableTemplate

 /**
  * Generates an subclass of the Zikula_Doctrine_Model_EntityCategory class and caches the generated class in a file.
  *
  * @param string $module     Name of the Module to that the model belongs to.
  * @param string $modelClass Classname of the model.
  *
  * @return void
  * @throws Exception Throws when the create of the cache directory fails.
  */
 private static function _generateSubclassForCategorisableTemplate($module, $modelClass)
 {
     $table = Doctrine::getTable($modelClass);
     sscanf($table->getTableName(), Doctrine_Manager::getInstance()->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), $tableName);
     $dir = 'doctrinemodels/GeneratedDoctrineModel/' . str_replace('_', DIRECTORY_SEPARATOR, $modelClass);
     if (CacheUtil::createLocalDir($dir, ServiceUtil::getManager()->getParameter('system.chmod_dir'))) {
         $subclassName = 'GeneratedDoctrineModel_' . $modelClass . '_EntityCategory';
         $fileContents = '<?php class ' . $subclassName . ' extends Zikula_Doctrine_Model_EntityCategory { }';
         $fileName = 'EntityCategory.php';
         // save new model
         file_put_contents(CacheUtil::getLocalDir() . '/' . $dir . '/' . $fileName, $fileContents);
         // save required data for later use
         $modelsInfo = ModUtil::getVar('ZikulaCategoriesModule', 'EntityCategorySubclasses', array());
         $modelsInfo[$subclassName] = array('module' => $module, 'table' => $tableName);
         ModUtil::setVar('ZikulaCategoriesModule', 'EntityCategorySubclasses', $modelsInfo);
     } else {
         throw new Exception('Creation of the cache directory ' . $dir . ' failed');
     }
 }
开发者ID:Silwereth,项目名称:core,代码行数:28,代码来源:Categorisable.php

示例3: pdfIsCached

 /**
  * Check to see if file is cached and current
  * return false if !exists or !current
  * return full filepath if exists and current
  *
  * @param string $title
  * @return mixed boolean/string
  */
 private function pdfIsCached($title)
 {
     $dir = CacheUtil::getLocalDir('NewsPDF');
     if (!is_dir($dir)) {
         CacheUtil::createLocalDir('NewsPDF', 0755, true);
     }
     $title = $title . '.pdf';
     // modify title like the tcpdf::Output() method does
     $title = preg_replace('/[\s]+/', '_', $title);
     $title = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $title);
     $fullpath = $dir . '/' . $title;
     if (file_exists($fullpath)) {
         // check if expired
         if ((time() - filemtime($fullpath)) > ModUtil::getVar('Theme', 'render_lifetime')) {
             return false;
         }
     } else {
         return false;
     }
     return $fullpath;
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:29,代码来源:User.php

示例4: setupThumbDir

 /**
  * Setup or restore storage directory.
  *
  * @param string $dir Storage directory (inside Zikula "ztemp" dir)
  *
  * @return bool
  */
 public function setupThumbDir($dir = null)
 {
     if (is_null($dir)) {
         $dir = $this->getVar('thumb_dir');
     }
     if (!($result = file_exists(CacheUtil::getLocalDir($dir)))) {
         $result = CacheUtil::createLocalDir($dir);
     }
     if ($result) {
         $dir = CacheUtil::getLocalDir($dir);
         $htaccess = "{$dir}/.htaccess";
         if (!file_exists($htaccess)) {
             $template = "{$this->getBaseDir()}/templates/default.htaccess";
             $result = copy($template, $htaccess);
         }
     }
     return $result;
 }
开发者ID:rmaiwald,项目名称:core,代码行数:25,代码来源:Plugin.php

示例5: downloadAction

 /**
  * @Route("/download/{slug}.zip", requirements={"slug"=".+"})
  * @ParamConverter("entity", class="Cmfcmf\Module\MediaModule\Entity\Collection\CollectionEntity", options={"slug" = "slug"})
  *
  * @param Request          $request
  * @param CollectionEntity $entity
  *
  * @return array
  */
 public function downloadAction(CollectionEntity $entity)
 {
     if (!$this->get('cmfcmf_media_module.security_manager')->hasPermission($entity, 'download')) {
         throw new AccessDeniedException();
     }
     \CacheUtil::createLocalDir('CmfcmfMediaModule');
     $dir = \CacheUtil::getLocalDir('CmfcmfMediaModule');
     $path = $dir . '/' . uniqid(time(), true) . '.zip';
     $zip = new \ZipArchive();
     if ($zip->open($path, \ZipArchive::CREATE) !== true) {
         throw new ServiceUnavailableHttpException('Could not create zip archive!');
     }
     $mediaTypeCollection = $this->get('cmfcmf_media_module.media_type_collection');
     $hasContent = false;
     $usedFileNames = [];
     foreach ($entity->getMedia() as $media) {
         if ($media instanceof AbstractFileEntity && $media->isDownloadAllowed()) {
             /** @var UploadableMediaTypeInterface $mediaType */
             $mediaType = $mediaTypeCollection->getMediaTypeFromEntity($media);
             $filename = $media->getBeautifiedFileName();
             $originalFileExtension = pathinfo($filename, PATHINFO_EXTENSION);
             $originalFilename = pathinfo($filename, PATHINFO_BASENAME);
             for ($i = 1; in_array($filename, $usedFileNames, true); ++$i) {
                 $filename = "{$originalFilename} ({$i})" . (empty($originalFileExtension) ?: ".{$originalFileExtension}");
             }
             $zip->addFile($mediaType->getOriginalWithWatermark($media, 'path', false), $filename);
             $hasContent = true;
         }
     }
     if (!$hasContent) {
         $zip->addFromString('Empty Collection.txt', $this->__('Sorry, the collection appears to be empty or does not have any downloadable files.'));
     }
     $zip->close();
     $response = new BinaryFileResponse($path);
     $response->deleteFileAfterSend(true);
     return $response;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:46,代码来源:CollectionController.php

示例6: initialize

    /**
     * Initialise.
     *
     * Runs at plugin init time.
     *
     * @return void
     */
    public function initialize()
    {
        // register namespace
        // Because the standard kernel classloader already has Doctrine registered as a namespace
        // we have to add a new loader onto the spl stack.
        $autoloader = new Zikula_KernelClassLoader();
        $autoloader->spl_autoload_register();
        include 'lib/DoctrineHelper.php';
        $autoloader->register('Doctrine', dirname(__FILE__) . '/lib/vendor', '\\');
        $autoloader->register('DoctrineProxy', 'ztemp/doctrinemodels', '\\');

        $serviceManager = $this->eventManager->getServiceManager();
        $config = $GLOBALS['ZConfig']['DBInfo']['databases']['default'];
        $dbConfig = array('host' => $config['host'],
                          'user' => $config['user'],
                          'password' => $config['password'],
                          'dbname' => $config['dbname'],
                          'driver' => 'pdo_' . $config['dbdriver'],
                          );
        $r = new \ReflectionClass('Doctrine\Common\Cache\\' . $serviceManager['dbcache.type'] . 'Cache');
        $dbCache = $r->newInstance();
        $ORMConfig = new \Doctrine\ORM\Configuration;
        $serviceManager->attachService('doctrine.configuration', $ORMConfig);
        $ORMConfig->setMetadataCacheImpl($dbCache);

        // create proxy cache dir
        CacheUtil::createLocalDir('doctrinemodels');

        // setup annotations base
        include_once 'lib/vendor/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';

        // setup annotation reader
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();
        $cacheReader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
        $serviceManager->attachService('doctrine.annotationreader', $cacheReader);

        // setup annotation driver
        $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cacheReader);
        $serviceManager->attachService('doctrine.annotationdriver', $annotationDriver);

        // setup driver chains
        $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
        $serviceManager->attachService('doctrine.driverchain', $driverChain);

        // configure Doctrine ORM
        $ORMConfig->setMetadataDriverImpl($annotationDriver);
        $ORMConfig->setQueryCacheImpl($dbCache);
        $ORMConfig->setProxyDir(CacheUtil::getLocalDir('doctrinemodels'));
        $ORMConfig->setProxyNamespace('DoctrineProxy');
        //$ORMConfig->setAutoGenerateProxyClasses(System::isDevelopmentMode());

        if (isset($serviceManager['log.enabled']) && $serviceManager['log.enabled']) {
            $ORMConfig->setSQLLogger(new SystemPlugin_Doctrine_ZikulaSqlLogger());
        }

        // setup doctrine eventmanager
        $eventManager = new \Doctrine\Common\EventManager;
        $serviceManager->attachService('doctrine.eventmanager', $eventManager);

         // setup MySQL specific listener (storage engine and encoding)
        if ($config['dbdriver'] == 'mysql') {
            $mysqlSessionInit = new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit($config['charset']);
            $eventManager->addEventSubscriber($mysqlSessionInit);

            $mysqlStorageEvent = new SystemPlugin_Doctrine_MySqlGenerateSchemaListener($eventManager);
        }

        // setup the doctrine entitymanager
        $entityManager = \Doctrine\ORM\EntityManager::create($dbConfig, $ORMConfig, $eventManager);
        $serviceManager->attachService('doctrine.entitymanager', $entityManager);
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:78,代码来源:Plugin.php

示例7: upgrade

    /**
     * upgrade the Feeds module from an old version
     * This function can be called multiple times
     */
    public function upgrade($oldversion)
    {
        $dom = ZLanguage::getModuleDomain('Feeds');

        // when upgrading let's clear the cache directory
        CacheUtil::clearLocalDir('feeds');

        switch ($oldversion)
        {
            // version 1.0 shipped with PN .7x
            case '1.0':
            // rename table if upgrading from an earlier version
                if (in_array(DBUtil::getLimitedTablename('RSS'), DBUtil::MetaTables())) {
                    DBUtil::renameTable('RSS', 'feeds');
                }
                if (in_array(DBUtil::getLimitedTablename('rss'), DBUtil::MetaTables())) {
                    DBUtil::renameTable('rss', 'feeds');
                }

                // create cache directory
                CacheUtil::createLocalDir('feeds');

                // migrate module vars
                $tables = DBUtil::getTables();
                $sql    = "UPDATE $tables[module_vars] SET pn_modname = 'Feeds' WHERE pn_modname = 'RSS'";
                if (!DBUtil::executeSQL($sql)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

                // create our default category
                $this->setVar('enablecategorization', true);
                if (!$this->_feeds_createdefaultcategory()) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

                // update table
                if (!DBUtil::changeTable('feeds')) {
                    return '1.0';
                }

                // update the permalinks
                $shorturlsep = System::getVar('shorturlsseparator');
                $sql  = "UPDATE $tables[feeds] SET pn_urltitle = REPLACE(pn_name, ' ', '{$shorturlsep}')";
                if (!DBUtil::executeSQL($sql)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

            case '2.1':
                $modvars = array('multifeedlimit' => 0,
                        'feedsperpage' => 10,
                        'usingcronjob' => 0,
                        'key' => md5(time()));

                if (!ModUtil::setVars('Feeds', $modvars)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '2.1';
                }

            // 2.2 -> 2.3 is the Gettext change
            case '2.2':
            case '2.3':
            case '2.4':
            case '2.5':
                $prefix = $this->serviceManager['prefix'];
                $connection = Doctrine_Manager::getInstance()->getConnection('default');
                $sqlStatements = array();
                // N.B. statements generated with PHPMyAdmin
                $sqlStatements[] = 'RENAME TABLE ' . $prefix . '_feeds' . " TO `feeds`";
                $sqlStatements[] = "ALTER TABLE `feeds` 
CHANGE `pn_fid` `fid` INT( 10 ) NOT NULL AUTO_INCREMENT ,
CHANGE `pn_name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_urltitle` `urltitle` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_url` `url` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_obj_status` `obj_status` CHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A',
CHANGE `pn_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
CHANGE `pn_cr_uid` `cr_uid` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `pn_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
CHANGE `pn_lu_uid` `lu_uid` INT( 11 ) NOT NULL DEFAULT '0'";
                foreach ($sqlStatements as $sql) {
                    $stmt = $connection->prepare($sql);
                    try {
                        $stmt->execute();
                    } catch (Exception $e) {
                    }   
                }
            case '2.6.0':
                $this->delVar('feedsperpage');
            case '2.6.1':
            // further upgrade routine
        }

        // update successful
        return true;
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:Installer.php


注:本文中的CacheUtil::createLocalDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。