1

I'm working on OpenCart project now, which intensely uses XML-configs for extensions (called OCMOD).

XML config is the mix of declarations with injections of PHP/CSS/JavaScript code, see part of real OCMOD modification file below:

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>some name</name>
    <id>some ID</id>
    <version>some version</version>
    <code>some code</code>
    <author>author</author>
    <link><![CDATA[link]]></link>
    <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[
$product_info = $this->model_catalog_product->getProduct($product_id);
        ]]></search>
            <add position="after"><![CDATA[
            // some PHP code here
            $s = 'hello world';
            echo $s;
        ]]></add>
        </operation>
    </file>
</modification>

I use PHPStorm 2019.2 for development. By default it's bundled with plugin to inject code into source files.

Are there any techincs to achieve syntax highlighting for injections into XML-code?

P.S. I've found this answer, but it doesn't fit my needs because PHP-injections in my file don't have <?php and ?> tags.


How to manage lifetime of CString in a Vec?

Is there a better or more idiomatic way to handle the lifetime of a CString in a Vec other than using into_raw()?

Here's my code:

// This fails because the CString gets dropped and then what is pointed to is invalid and invalidates required_layers
let required_layers: Vec<*const c_char> = vec!(
    CString::new("VK_LAYER_LUNARG_standard_validation").expect("CString err A").as_ptr(),
);

// This works because ss0 stays alive, but is going to be error-prone as dropping ss0 somewhere invalidates required_layers
let ss0 = CString::new("VK_LAYER_LUNARG_standard_validation").expect("CString err A");
let required_layers: Vec<*const c_char> = vec!(
    ss0.as_ptr(),
);

// This works, but now requires from_raw() to retake ownership to avoid leaks
let required_layers: Vec<*const c_char> = vec!(
    CString::new("VK_LAYER_LUNARG_standard_validation").expect("CString err A").into_raw(),
);
4

2 回答 2

2

该文件必须与“PHP 文件”文件类型相关联,以便 PhpStorm 在此类文件中提供 PHP 支持。你不能随便拿一个文件说“从这里到那里的这一部分是 PHP”,因为 PHP 支持在 IDE 中还没有“PHP 作为可注入语言”实现。您的文件没有 PHP 标记 ( <?php ... ?>),因此模板日期语言的标准内容在这里没有帮助。

下一个 2019.3 版本的 PhpStorm 将带有 Injectable PHP。ATM 我不知道这是否适用于您的示例(以及它的整体工作方式);基于现有的票据,它意味着被注入到其他已经在使用 PHP 代码的文字中:例如eval(),Markdown 中的 PHP 块和类似的东西。需要等待2019.3 EAP程序启动后再试。


现在这张票似乎完全符合您的需求:https ://youtrack.jetbrains.com/issue/WI-47857 - 观看(星号/投票/评论)以获取任何进展的通知。

它指的是与您类似的案例(请参阅github.com/Combodo/iTop)。

随时用您的示例发表评论(以便开发人员知道需要此类功能)。

于 2019-09-09T12:03:50.840 回答
0

您在 Opencart 中使用的 ocmod 语法不正确。一定是:

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <name>some name</name>
    <id>some ID</id>
    <version>some version</version>
    <code>some code</code>
    <author>author</author>
    <link><![CDATA[link]]></link>
<file path="catalog/controller/product/product.php">
    <operation error="log">
        <search><![CDATA[
            $product_info = $this->model_catalog_product->getProduct($product_id);
        ]]></search>
        <add position="after"><![CDATA[
            // some PHP code here
            $s = 'hello world';
            echo $s;
        ]]></add>
    </operation>
</file>
</modification>
于 2019-09-08T06:48:13.393 回答