Comments (19)
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.
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.
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.
Yeah, a whole file run happens when you don't select any text.
@luishdez - What version are you on of script?
from atom-script.
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.
If I save it
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.
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.
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.
@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.
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.
That sounds great @rgbkrk. Is adding a pipe method a possibility as well?
from atom-script.
Just to tinker with this, I tried running PHP using the two different bindings:
from atom-script.
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.
@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.
Ah, I see your use case for when this comes up.
from atom-script.
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.
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.
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.
@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.
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)
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated.
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- Runtime Input
- HTMLDocument.registerElement is deprecated. HOT 1
- TypeError HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- certificate has expired HOT 1
- Port this to Pulsar
- HTMLDocument.registerElement is deprecated.
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated.
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated. HOT 1
- HTMLDocument.registerElement is deprecated.
- HTMLDocument.registerElement is deprecated.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atom-script.