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


PHP Service::isValidKey方法代码示例

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


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

示例1: correctPath

 public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         if (!Element\Service::isValidKey($this->getKey(), "object")) {
             throw new \Exception("invalid key for object with id [ " . $this->getId() . " ] key is: [" . $this->getKey() . "]");
         }
         if ($this->getParentId() == $this->getId()) {
             throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself.");
         }
         $parent = AbstractObject::getById($this->getParentId());
         if ($parent) {
             // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path
             // that is currently in the parent object (in memory), because this might have changed but wasn't not saved
             $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
         if (strlen($this->getKey()) < 1) {
             throw new \Exception("Document requires key, generated key automatically");
         }
     } elseif ($this->getId() == 1) {
         // some data in root node should always be the same
         $this->setParentId(0);
         $this->setPath("/");
         $this->setKey("");
         $this->setType("folder");
     }
     if (Service::pathExists($this->getRealFullPath())) {
         $duplicate = AbstractObject::getByPath($this->getRealFullPath());
         if ($duplicate instanceof self and $duplicate->getId() != $this->getId()) {
             throw new \Exception("Duplicate full path [ " . $this->getRealFullPath() . " ] - cannot save object");
         }
     }
     if (strlen($this->getRealFullPath()) > 765) {
         throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path");
     }
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:41,代码来源:AbstractObject.php

示例2: correctPath

 /**
  * @throws \Exception
  */
 public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         if (!Element\Service::isValidKey($this->getKey(), "asset")) {
             throw new \Exception("invalid filename '" . $this->getKey() . "' for asset with id [ " . $this->getId() . " ]");
         }
         if ($this->getParentId() == $this->getId()) {
             throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself.");
         }
         if ($this->getFilename() === '..' || $this->getFilename() === '.') {
             throw new \Exception('Cannot create asset called ".." or "."');
         }
         $parent = Asset::getById($this->getParentId());
         if ($parent) {
             // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path
             // that is currently in the parent object (in memory), because this might have changed but wasn't not saved
             $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
     } elseif ($this->getId() == 1) {
         // some data in root node should always be the same
         $this->setParentId(0);
         $this->setPath("/");
         $this->setFilename("");
         $this->setType("folder");
     }
     // do not allow PHP and .htaccess files
     if (preg_match("@\\.ph(p[345]?|t|tml|ps)\$@i", $this->getFilename()) || $this->getFilename() == ".htaccess") {
         $this->setFilename($this->getFilename() . ".txt");
     }
     if (Asset\Service::pathExists($this->getRealFullPath())) {
         $duplicate = Asset::getByPath($this->getRealFullPath());
         if ($duplicate instanceof Asset and $duplicate->getId() != $this->getId()) {
             throw new \Exception("Duplicate full path [ " . $this->getRealFullPath() . " ] - cannot save asset");
         }
     }
     if (strlen($this->getRealFullPath()) > 765) {
         throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path");
     }
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:48,代码来源:Asset.php


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