Giter Site home page Giter Site logo

Dump double quoted strings about php-generator HOT 6 CLOSED

nette avatar nette commented on May 18, 2024
Dump double quoted strings

from php-generator.

Comments (6)

juniordias-planejar avatar juniordias-planejar commented on May 18, 2024

Maybe something like:

} elseif (is_string($var) && preg_match('/\${(([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(->)*)*(\[[^\]]*\])*)}/', $var)) { return '"' . preg_replace('#\'|\\\\(?=[\'\\\\]|\z)#', '\\\\$0', $var) . '"';

at line 66 of Helpers (_dump)

from php-generator.

dg avatar dg commented on May 18, 2024

Are you talking about function/method body? Simply use $function->setBody('return "Something ${value}";');

from php-generator.

juniordias-planejar avatar juniordias-planejar commented on May 18, 2024

Actually the problem is in an array. One of the array values must be enclosed by double quotes. The example was too simple. The actual code is:

https://gist.github.com/juniordias-planejar/8efd3d66bee6140a990da84e686f4177

At line 24, the value is enclosed by the double quotes. I thought about using sprintf, but this {$primaryKey} can be used multiple times depending on the database table.

from php-generator.

juniordias-planejar avatar juniordias-planejar commented on May 18, 2024

The return comes from an array:

$methodRules->addBody('return ?;', [$requestRules]);

from php-generator.

dg avatar dg commented on May 18, 2024

You can also use Nette\PhpGenerator\PhpLiteral:

$methodRules->addBody('return ?;', [new Nette\PhpGenerator\PhpLiteral('"Something ${value}"')]);

from php-generator.

juniordias-planejar avatar juniordias-planejar commented on May 18, 2024

Thanks! Good suggestion!

If I meet that condition, I can set the array value accordingly:

$requestRules[$col->column_name] = $literal ? new PhpLiteral(sprintf('"%s"', $rules)) : $rules;

When I do $methodRules->addBody('return ?;', [$requestRules]);, the array value for that column_name is double quote escaped.

from php-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.