-1

我想使用字符串“LINE_DOUBLE”从 phppresentation 的边界库访问 LINE_DOUBLE 已尝试使用常量()但没有运气任何其他解决方案将非常有帮助

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Bullet;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Fill;

 public function addLine($val)
        {
          $border = new Border;
          $str = "LINE_DOUBLE";
          $lineShape = $this->currentSlide->createLineShape($val["startX"],$val["startY"],$val["endX"],$val["endY"]);
          $lineShape->getBorder()
          ->setLineStyle(constant("$border::$str"))
          ->setLineWidth($val["width"])
          ->getColor()->setARGB($val["lineColor"]);     
        }
4

2 回答 2

2

有两种方法

  1. 使用constant()功能
->setLineStyle(constant("Border::{$str}"))

$border是一个对象而不是类并且要访问 Class 常量,您需要 Class 而不是它的对象

  1. 使用Reflection
$ref = new ReflectionClass('Border');
->setLineStyle($ref->getConstant($str));

让我知道,如果它们中的任何一个有效或无效

于 2021-05-23T16:52:57.133 回答
0

只需提供对象的完整指定路径 $str = "LINE_DOUBLE"; ->setLineStyle(常量("PhpOffice\PhpPresentation\Style\Border::$str"))

于 2021-05-23T17:25:22.287 回答