dll will not recignize using pure mode in phpcore

Discussion about the open-source Phalanger [?] project.

dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 7th, 2014, 1:47 pm

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?
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby Jakub Misek » April 8th, 2014, 1:10 pm

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.
You do not have the required permissions to view the files attached to this post.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: dll will not recignize using pure mode in phpcore

Postby Jakub Misek » April 8th, 2014, 3:23 pm

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)
You do not have the required permissions to view the files attached to this post.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 9th, 2014, 6:14 pm

Thanks for your help! I cant' wait to use the parser in .net! Phalanger (and Jakub) rules!
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 17th, 2014, 6:03 pm

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?
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby Jakub Misek » April 17th, 2014, 10:10 pm

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.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 18th, 2014, 2:41 am

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.
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 18th, 2014, 2:42 am

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.
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby RobertPlummer » April 21st, 2014, 2:23 pm

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.
RobertPlummer
 
Posts: 37
Joined: April 7th, 2014, 1:45 pm

Re: dll will not recignize using pure mode in phpcore

Postby Jakub Misek » April 21st, 2014, 5:56 pm

[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.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Next

Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 2 guests

User Control Panel

Login

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 124 on September 25th, 2020, 6:57 am

Users browsing this forum: No registered users and 2 guests