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.

userlond
  • 3,632
  • 2
  • 36
  • 53
  • For PhpStorm, to treat a code like PHP, the file must be associated with "PHP File" file type. You cannot take random file and say "this bit is PHP" as PHP support does not have "PHP as Injectable Language" implementation in IDE yet. Next 2019.3 version of PhpStorm will come with Injectable PHP. ATM I do not know if that will work for your example (and how it works overall) as it has no PHP tags... Need to wait for 2019.3 EAP program to start and only then try it. – LazyOne Sep 08 '19 at 09:59
  • Right now this tickets seems like a match (not yet implemented: https://youtrack.jetbrains.com/issue/WI-47857) -- it refers to a similar cases like yours (see https://github.com/Combodo/iTop/blob/develop/datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml#L641). Feel free to comment there with your examples (so devs know that there is a demand for such feature). – LazyOne Sep 08 '19 at 10:00
  • @LazyOne, thanks for reply and comment in YouTrack. You may answer the question and I'll accept it. – userlond Sep 09 '19 at 01:17

2 Answers2

2

The file must be associated with "PHP File" file type in order for PhpStorm to provide PHP support in such file. You cannot take a random file and say "this section from here to there is PHP" as PHP support does not have "PHP as Injectable Language" implementation in IDE yet. Your file has no PHP tags (<?php ... ?>) therefore standard thing with Template Date Language will not help here.

Next 2019.3 version of PhpStorm will come with Injectable PHP. ATM I do not know if that will work for your example (and how it works overall); based on existing tickets it meant to be injected into other literals that are already using PHP code: e.g. eval(), PHP blocks in Markdown and stuff like that. Need to wait for 2019.3 EAP program to start and only then try it.


Right now this ticket seems to be an exact match for your needs: https://youtrack.jetbrains.com/issue/WI-47857 -- watch it (star/vote/comment) to get notified on any progress.

It refers to a similar cases like yours (see github.com/Combodo/iTop).

Feel free to comment there with your examples (so devs know that there is a demand for such feature).

LazyOne
  • 158,824
  • 45
  • 388
  • 391
0

You use not correct syntax for ocmod to use in Opencart. Must be:

<?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>
K. B.
  • 1,388
  • 2
  • 13
  • 25
  • I've fixed snippet to represent full ocmod-file, not extracted snippet. But your answer doesn't help to solve problem. – userlond Sep 08 '19 at 07:09
  • are you really have checked at the whole code? in your code you use `file name=` must be `file path=`. And you use ``, `position="after"` must be placed to `` – K. B. Sep 08 '19 at 07:14
  • You are right about the OCMOD syntax, but the question related to highlight support in IDE. – userlond Sep 09 '19 at 01:14
  • Nevertheless, you are right, I've made changes in question, thanks. – userlond Sep 09 '19 at 01:25