Giter Club home page Giter Club logo

Comments (19)

rgbkrk avatar rgbkrk commented on August 20, 2024

Any idea what the cli args would be for those cases?

This is the current layout:

  PHP:
    command: "php"
    "Selection Based": (code) -> ['-r', code]
    "File Based": (filename) -> [filename]

By the way, we don't have a PHP file in the examples directory. Want to add one?

@ciarand added the PHP grammar.

Any ideas @ciarand?

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

Yeah, php -r evals the code and assumes it's PHP code. The <?php is a syntax error in that case.

It sounds like we need to run php -r if it's a snippet of the code and just run php filename.php if it's the whole file. Is that possible in the current API? I haven't had a chance to look recently.

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

Oh duh, it totally looks like that's possible just from that snippet. I might be able to take a look tonight

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

Yeah, a whole file run happens when you don't select any text.

@luishdez - What version are you on of script?

from atom-script.

luishdez avatar luishdez commented on August 20, 2024

Now I'm on 2.1.8

but now my script is executed twice, PHP Still fails but it looks that only fails when the file has not been saved yet.

untitled

If I save it

titled

I think there is no command to support <? tags , but this could do the trick

echo "code-to-execute" | php

the command -r is new so it will fail if someone is using an old version of php. Other option could be to remove the first <? or <?php

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

That's making me go wat. I'm so sorry this isn't working well for you.

Does PHP have any good tools for managing various PHP versions?

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

The double execution is weird. I've got no idea why that's happening and I haven't been able to reproduce locally. What version of PHP are you using?

As to the standard version manager question: There are some, but no standard has yet emerged afaik.

There's

One option would be to strip the <?php if it's present in the file. If it's possible, the cleaner approach would be to pass the contents via stdin to php like @luishdez suggested. I wasn't able to find when the -r switch was added - it's there in the oldest version I have installed (5.3.28).

Another option might be just to put a note in the README. Supporting too many older versions of PHP has the potential to be a huge complexity sink for a very limited gain. 5.2 was released in 2006, 5.3 was released in 2009 and is reaching "we're serious guys we're really not going to support this any more not even security fixes" EOL in like, 2 months.

from atom-script.

luishdez avatar luishdez commented on August 20, 2024

@rgbkrk No problem, thanks to you to share your work :)

I've cleaned .atom folder and install again and now it doesn't execute the script twice. May be something went wrong when I updated the package.

@ciarand I agree, I wouldn't worry about the version, I think that was added with v5 that in fact is pretty old. Anyway using the pipe method will work with all versions.

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

This is kind of making me think we should just let configuration happen in a users init.cson, so they can specify how they want code/args handled.

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

That sounds great @rgbkrk. Is adding a pipe method a possibility as well?

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

Just to tinker with this, I tried running PHP using the two different bindings:

phppppppppppppppp

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

Note that running the whole file works just fine by hitting cmd-i (no selection).

Using pipes would require some ugly footwork with the shell and make future stdin handling completely awkward. I'd like to avoid piping code to an interpreter at all costs.

from atom-script.

luishdez avatar luishdez commented on August 20, 2024

@rgbkrk Create a new file, Untitled "not saved"… most of the time you just want to execute some php code to prove it and added to other file… or generate code with code or similar cases. You don't want to save files for every code you want to test.

Some times you just copy all the content from one file and test some changes … and now you have to be aware to remove that first open tag. Though it's not critical but kinda of annoying.

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

Ah, I see your use case for when this comes up.

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

One option could be that for the PHP selection based runner, we preprocess the text a little bit.

  PHP:
    "Selection Based":
      command: "php"
      args: (code)  ->
        # If the selection starts with "<?php", delete it
        code = code.replace /^\s*<\?php/i, ''
        ['-r', code]
    "File Based":
      command: "php"
      args: (filename) -> [filename]

Any thoughts on that approach?

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

The only problem I see with that is that if you have a mixed file (raw text and PHP, for example) it'll stop processing after the first end tag (?>).

<?php echo "First block"; ?>
Not processed!
<?php echo "second block"; ?>

Turns into

First block
Not processed!
echo "second block"; ?>

from atom-script.

rgbkrk avatar rgbkrk commented on August 20, 2024

Yeah, that's how I usually roll with PHP. I'm thinking we'll stick with the current action and folks will have to select the appropriate amount of text when doing a selection based run. Closing, feel free to re-open if there is a better work around.

from atom-script.

luishdez avatar luishdez commented on August 20, 2024

@rgbkrk I think your proposal will work.

@ciarand The second statement will be execute as well. Not sure why that command works like that, doesn't make any sense, as many other php things…

php -r 'echo "First block"; ?>Not processed!<?php echo "second block"; ?>'

First blockNot processed!second block

from atom-script.

ciarand avatar ciarand commented on August 20, 2024

That's crazy - if ?> is in the selection it will not break if it finds a (first) <?php afterward. Thanks for the clarification @luishdez.

@rgbkrk I was wrong - your suggestion above would work if it only strips the first <?php.

from atom-script.

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.