Closed josecelano closed 8 years ago
Hi @josecelano, the JS problem seems to be a bug. TBH, the riot compiler is not tested very well. Normally you would need to setup node.js and grunt to compile riot.js but I wanted to provide a simple PHP solution so that you don't need to setup additional tools just to try the sample. On which system are you trying to run the sample? I'm asking because the behat feature tests run against the frontend and they work on my machine and travis-ci. However, I'll have an idea what causes the problem and will check it later. Regarding PHP 5.6 you would need to change the entire domain model (CargoBackend) not only the Doctrine part. If you want to run the sample on PHP 5.6 you can checkout this release: https://github.com/codeliner/php-ddd-cargo-sample/releases/tag/ChapterFour It is the last version of the sample before the rewrite. But it uses Zend Framework 2 as application framework and Backbone.js in the frontend. Also Doctrine 2.5 features like Embeddables are not implemented in this version.
Hi @codeliner, I think the problem is the riot compiler is not removing line breaks. Regarding your question I am using the laravel homestead vagrant box.
Then I think I am going to use the homestead version for PHP 7
Off topic:
I have been looking for a way to integrate a PHP framework (first Symfony and now Laravel) with a frontend library/framework without duplicating templates and doing too much "cool" unstable stuff. I have only found this presentation:
from @bashofmann, but I had not found any sample until now. This project is the first real implemented project I have seen. Mainly I am a backend developer, I have been using JQuery when I need to implement more dinamic pages but It becomes a mess in long term. I am going to start a new project from scratch and I want to implement something like this sample or PHP+REACTJS. Initially I thougth to use REACTJS but I think RIOTJS is cleaner than REACTJS.
@josecelano That was also my idea but line endings are replaced here: https://github.com/codeliner/php-ddd-cargo-sample/blob/master/CargoUI/src/RiotCompiler.php#L27
and here: https://github.com/codeliner/php-ddd-cargo-sample/blob/master/CargoUI/src/RiotCompiler.php#L61
Problem is, on my machine it works. Can you check the compiler on your system? If you find a solution a PR would be nice :). Unfortunately, I don't have much time atm otherwise I'd install homestead and try it myself :(
Regarding JS integration: What do you want to achieve? Do you want to reuse templates on server and client? If so your only chance is using mustache. You'll find PHP as well as js mustache engines. I've done this in the past and it is nice but mustache is logic less so templates are a bit complex.
The cargo sample is just split into a backend module with a REST API and a frontend module using riot js and this small (buggy :) riot compiler). I prefer riot over react because I don't like react's JSX syntax. Jumping between PHP and JS is enough. Don't want to learn that meta language which also requires a compiler etc. Riot js is super simple but building complex UIs is not that easy. It is recommended to set up a flux architecture. The cargo sample does this with a lightweight custom solution.
Another set up I really like is the one you can find in this sample app: https://github.com/prooph/proophessor-do
There we use small riot.js apps on every page (so no Single Page App and no flux architecture) but each page is served and rendered first with PHP. A special View Helper then renders riot tags dynamically into the layout. The cool thing is you can use PHP in your riot tags for example to inject links like you can see here: https://github.com/prooph/proophessor-do/blob/master/view/riot/user-form.phtml#L47
The riot view helper looks much the same like the one in the cargo sample: https://github.com/prooph/proophessor-do/blob/master/src/App/View/Helper/RiotTag.php
Cheers
I fixed the problem using:
$tagHtml = str_replace('"', "\"", $tagHtml);
$tagHtml = preg_replace( "/\r|\n/", "", $tagHtml);
instead of:
return 'riot.tag("'.$tagName.'", "' . str_replace($this->search, $this->replace, $tagHtml) . '", '.$jsFunc.');';
In RiotCompiler::class.
But now I have more problems regarding PHP 7 exclusive reserved words as 'declare' or funtions type hinting.
@josecelano Do you run homestead on a windows host? And does your git replace \n
with \r\n
when checking out a repo from github?
However, I'll add your fix. Thank you for reporting and finding the bug.
Do you run the cargo sample on PHP 7 now? Or do you mean you have more problems because you are still trying to run the sample with PHP 5.6? The new version of the cargo sample only supports PHP 7 as I said before.
@josecelano Added your fix: https://github.com/codeliner/php-ddd-cargo-sample/commit/a194a2f6b732aed69e22a76198d6fe9e361f814f
Can you verify and close the issue if problem is solved?
Thanks @codeliner. It works.
Yes, I run homestead on a Windows 8.1 host and I replacing \n
with \r\n
becuase my IDE is running on Windows and I have autocrlf = true
option in .gitcofig
.
I have more problems because I still trying to run the sample on PHP 5.6. If I have time I wuold like to port the sample to PHP 5.6.
I have removed PHP 7 features in my fork:
https://github.com/josecelano/php-ddd-cargo-sample
It works on PHP 5.6.15.
@josecelano I've added a note in the readme https://github.com/codeliner/php-ddd-cargo-sample/blob/master/README.md#php-56-compatible-version if other people are also looking for a 5.6 version.
Hi @codeliner . First at all, I have to say it's a very cool sample. I would like to play with it but I would like to run it with other samples in the sample vagrant machine with PHP 5.6. I have removed composer.lock and changed the composer.json to require only PHP 5.6. I removed the return type for these methods
TrackingIdDoctrineType::convertToPHPValue
andDoctrineEntityManagerFactory::__invoke
, and it seems to work, or at least there is no other parser error. But I have a problem with JS:This is the index response:
and there is an error in line 42:
Uncaught SyntaxError: Unexpected token ILLEGAL'. It seems method
RiotCompiler::compileFileis not working well, may be becuase function
str_replace` has a different behavior on PHP 7. Is possible to run the sample on PHP 5.6 or are there a lot of errors like this one?