Page 1 of 5

dll will not recignize using pure mode in phpcore

PostPosted: April 7th, 2014, 1:47 pm
by RobertPlummer
Hi Guys,
I'm a software developer, I like Object Oriented php, I think it is very powerful, I also love c#. And that it is now dynamic, in part, make it a powerful combination. I'm working on a project, it is php based (more here) and I can't get the .net PhpCore to auto implement it at runtime.

Here is my web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />
</system.web>
<phpNet>
<classLibrary>
<add assembly="WikiLingo" />
<add assembly="mscorlib" />
</classLibrary>
</phpNet>
</configuration>

Here is the command I use to build the php to a dll:
phpc ^
/target:dll ^
/pure+ ^
/lang:CLR ^
/out:WikiLingo.dll ^
/recurse:../wikiLingo\WikiLingo ^
/recurse:../wikiLingo\WikiLingoWYSIWYG ^
/recurse:../wikiLingo\WYSIWYGWikiLingo ^
/recurse:../wikiLingo\Types ^
/skip:../wikiLingo\WikiLingo\Test ^
/skip:../wikiLingo\WikiLingoWYSIWYG\Test ^
/skip:../wikiLingo\WYSIWYGWikiLingo\Test 2>out.log

Here is the output:
https://github.com/wikiLingo/wikiLingo.net

Here is the project I want to show off using wikiLingo in c#:
https://github.com/wikiLingo/wikiLingo.net-examples

Can you help me along? I'd like to take full advantage of the c# dynamic types. The .net dll loads just fine, but it is just too strongly typed. Perhaps I'm missing something. Perhaps you can't mix pure mode and and phpcore?

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 8th, 2014, 1:10 pm
by Jakub Misek
Hi Robert,

Thanks for your question.

I've tested wikiLingo and it compiles pretty nice in the pure mode.

The result is a .NET assembly containing PHP types and functions organized in namespaces as it is in PHP.

Note it emits
Code: Select all
[EditorBrowsable(EditorBrowsableState.Never)]
attribute over CLR constructors and methods, so you won't see them in C# IntelliSense. Anyway dynamic works nice. There is explicit support for dynamic meta objects in Phalanger already.

Resulting assembly can be just referenced within your C# project together with PhpNetCore.dll (and since Phalanger 4.0 PhpNetCore.Parsers.dll). In app.config (or web.config) you can just reference PhpNetClasslibrary and PhpNet* extensions you need.

I'm attaching my sample C# project.

Note/Todo: you can specify
Code: Select all
[assembly: \Export]
class AssemblyInfo{}
in the PHP code, Phalanger then generates nice strongly typed methods you can use in C# and you can see in IntelliSense (however there is bug in the current version of Phalanger, and compilation fails) Also with this attribute, C# constructors will be generated and you wont have to pass (ScriptContext.CurrentContext, true) parameters and you won't have to call __construct explicitly.

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 8th, 2014, 3:23 pm
by Jakub Misek
I've fixed compilation in pure mode with [Export] attribute (see above) and compiled wikiLingo as a reference (attached).

Please feel free to download and reference to your C# project to see whether it is visible in IntelliSense as expected. (it is built against Phalanger 4.0)

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 9th, 2014, 6:14 pm
by RobertPlummer
Thanks for your help! I cant' wait to use the parser in .net! Phalanger (and Jakub) rules!

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 17th, 2014, 6:03 pm
by RobertPlummer
I finally got a chance to try this out, it is now asking for Phalanger v4. Which I do not have and cannot find online. One thing that does work is:

var parser = new WikiLingo.Parser(PHP.Core.ScriptContext.CurrentContext, true);

However, the __construct method isn't called, is this by design? Am I doing something wrong?

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 17th, 2014, 10:10 pm
by Jakub Misek
You are calling internal .ctor which does not invoke __construct method.

You have to use attribute [\Export] to create C# constructor that calls __construct or to call __construct by yourself.

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 18th, 2014, 2:41 am
by RobertPlummer
Would it be at all possible to perform a pull request on wikiLingo, perhaps WikiLingo\Parser, showing how to do this? I think it would really help with the understanding of how to use Phalanger. You could even link to it, for a real world example, as we want to go full steam with .net.

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 18th, 2014, 2:42 am
by RobertPlummer
Just a side note, 98% of my work is open source. I wouldn't ask you to do this if it was for personal gain, I want Phalanger to be understood well, on a grand scale.

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 21st, 2014, 2:23 pm
by RobertPlummer
Can you put "[assembly: \Export]" within comments? Like this:

Code: Select all
/**
 * Class Parser
 * @package WikiLingo
 * [assembly: \Export]
 */
class Parser extends Definition {}


Or, better yet, can we use PHPDoc's comments, which allow you to build documentation and develop at the same time? PHPDoc is kind of a standard. If we did that, not only would IDE's like phpStorm, and the documentation builder bind to the comments, but also .net.

Code: Select all
/**
 * Class Parser
 * @package WikiLingo
 */
class Parser extends Definition {}


Here we let PHPDoc know that there is a namespace called "WikiLingo" and that there is a class in it called "Parser". If we utilized those comment, it would really bind Phalanger to php.

Re: dll will not recignize using pure mode in phpcore

PostPosted: April 21st, 2014, 5:56 pm
by Jakub Misek
[assembly: \Export] cannot be put within comments.

Phalanger already contains support for PHPDoc. Internally it is able to parse and process such comments. Generating .NET-like XML documentation has to be done.