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


PHP CRM_Utils_File::isChildPath方法代码示例

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


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

示例1: testIsChildPath

 /**
  * Test is child path.
  */
 public function testIsChildPath()
 {
     $testCases = array();
     $testCases[] = array('/ab/cd/ef', '/ab/cd', FALSE);
     $testCases[] = array('/ab/cd', '/ab/cd/ef', TRUE);
     $testCases[] = array('/ab/cde', '/ab/cd/ef', FALSE);
     $testCases[] = array('/ab/cde', '/ab/cd', FALSE);
     $testCases[] = array('/ab/cd', 'ab/cd/ef', FALSE);
     foreach ($testCases as $testCase) {
         $actual = CRM_Utils_File::isChildPath($testCase[0], $testCase[1], FALSE);
         $this->assertEquals($testCase[2], $actual, sprintf("parent=[%s] child=[%s] expected=[%s] actual=[%s]", $testCase[0], $testCase[1], $testCase[2], $actual));
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:16,代码来源:FileTest.php

示例2: replace

 /**
  * Install or upgrade the code for an extension -- and perform any
  * necessary database changes (eg replacing extension metadata).
  *
  * This only works if the extension is stored in the default container.
  *
  * @param string $tmpCodeDir
  *   Path to a local directory containing a copy of the new (inert) code.
  * @throws CRM_Extension_Exception
  */
 public function replace($tmpCodeDir)
 {
     if (!$this->defaultContainer) {
         throw new CRM_Extension_Exception("Default extension container is not configured");
     }
     $newInfo = CRM_Extension_Info::loadFromFile($tmpCodeDir . DIRECTORY_SEPARATOR . CRM_Extension_Info::FILENAME);
     $oldStatus = $this->getStatus($newInfo->key);
     // find $tgtPath, $oldInfo, $typeManager
     switch ($oldStatus) {
         case self::STATUS_UNINSTALLED:
         case self::STATUS_INSTALLED:
         case self::STATUS_DISABLED:
             // There is an old copy of the extension. Try to install in the same place -- but it must go somewhere in the default-container
             list($oldInfo, $typeManager) = $this->_getInfoTypeHandler($newInfo->key);
             // throws Exception
             $tgtPath = $this->fullContainer->getPath($newInfo->key);
             if (!CRM_Utils_File::isChildPath($this->defaultContainer->getBaseDir(), $tgtPath)) {
                 // force installation in the default-container
                 $oldPath = $tgtPath;
                 $tgtPath = $this->defaultContainer->getBaseDir() . DIRECTORY_SEPARATOR . $newInfo->key;
                 CRM_Core_Session::setStatus(ts('A copy of the extension (%1) is in a system folder (%2). The system copy will be preserved, but the new copy will be used.', array(1 => $newInfo->key, 2 => $oldPath)));
             }
             break;
         case self::STATUS_INSTALLED_MISSING:
         case self::STATUS_DISABLED_MISSING:
             // the extension does not exist in any container; we're free to put it anywhere
             $tgtPath = $this->defaultContainer->getBaseDir() . DIRECTORY_SEPARATOR . $newInfo->key;
             list($oldInfo, $typeManager) = $this->_getMissingInfoTypeHandler($newInfo->key);
             // throws Exception
             break;
         case self::STATUS_UNKNOWN:
             // the extension does not exist in any container; we're free to put it anywhere
             $tgtPath = $this->defaultContainer->getBaseDir() . DIRECTORY_SEPARATOR . $newInfo->key;
             $oldInfo = $typeManager = NULL;
             break;
         default:
             throw new CRM_Extension_Exception("Cannot install or enable extension: {$newInfo->key}");
     }
     // move the code!
     switch ($oldStatus) {
         case self::STATUS_UNINSTALLED:
         case self::STATUS_UNKNOWN:
             // There are no DB records to worry about, so we'll just put the files in place
             if (!CRM_Utils_File::replaceDir($tmpCodeDir, $tgtPath)) {
                 throw new CRM_Extension_Exception("Failed to move {$tmpCodeDir} to {$tgtPath}");
             }
             break;
         case self::STATUS_INSTALLED:
         case self::STATUS_INSTALLED_MISSING:
         case self::STATUS_DISABLED:
         case self::STATUS_DISABLED_MISSING:
             // There are DB records; coordinate the file placement with the DB updates
             $typeManager->onPreReplace($oldInfo, $newInfo);
             if (!CRM_Utils_File::replaceDir($tmpCodeDir, $tgtPath)) {
                 throw new CRM_Extension_Exception("Failed to move {$tmpCodeDir} to {$tgtPath}");
             }
             $this->_updateExtensionEntry($newInfo);
             $typeManager->onPostReplace($oldInfo, $newInfo);
             break;
         default:
             throw new CRM_Extension_Exception("Cannot install or enable extension: {$newInfo->key}");
     }
     $this->refresh();
     CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:75,代码来源:Manager.php


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