Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:20
    jakubmisek edited #884
  • 12:19
    jakubmisek edited #884
  • 12:18
    jakubmisek edited #884
  • 12:17
    jakubmisek labeled #884
  • 12:17
    jakubmisek opened #884
  • 12:15

    jakubmisek on php8attributes

    removed C#-like attribute synta… (compare)

  • 11:43

    jakubmisek on php8attributes

    (compare)

  • 11:40

    jakubmisek on master

    htmlspecialchars() parameters d… (compare)

  • Nov 29 23:17
    nestorwheelock starred peachpiecompiler/peachpie
  • Nov 28 15:12

    jakubmisek on master

    cleanup htmlspecialchars() parameter na… (compare)

  • Nov 28 12:11
  • Nov 28 12:03
  • Nov 27 13:55
    jakubmisek edited #765
  • Nov 27 13:42
    jakubmisek edited #765
  • Nov 27 13:41
    jakubmisek edited #765
  • Nov 27 13:32

    jakubmisek on master

    "latest" langversion is 8.0 re… (compare)

  • Nov 27 13:29

    jakubmisek on master

    nullref fix (compare)

  • Nov 27 12:51
    jakubmisek edited #765
  • Nov 27 12:50

    jakubmisek on master

    diagnostic: returning null from… (compare)

  • Nov 27 12:41

    jakubmisek on master

    union type handles "null", retu… (compare)

Viguri
@Viguri
Ok. So I have a PHP service to call (normally from a website) and I have my C# application. I’m able to call a PHP function from C#. I can pass the minimum 3 values to PHO to call the PHP api but I need to “trick” as if I were filling a form. Then after hitting Submit button get the response from the service. And then, back to my C# application (maybe an array since I expect to get many fields). This one approach. Another would be to migrate the PHP (and JS) API to C# and over!! But that’s at the moment to far away of my knowledge, I guess... :)
Jakub Míšek
@jakubmisek
@Viguri not sure how it looks like, or what's the question; you can pretend the PHP code is actually C#. Then - what Submit button? in an HTML page within a <form> element? what's the target of the form? or is it a razor page? Or do you need to alter the $_POST global variable in your PHP code?
Viguri
@Viguri
Exactly. In the original setup you fulfill a form and then via the API (PHP and JS) the data is sent to a server and sends back an XML (that you can get from an URL). I understand that is a complex situation not easy to explain just with words... I try... Basically on the button "onclick" I have a call to a function that resides in the PHP API. Something like <input type="button" id="solic2" class="btn btn-success" onclick="simbriefsubmit('./index_vam_op.php?page=route_reserve_plane');" value="<?php echo BOOKING_CONFIRM_SB; ?>" The function send the form info and the data is captured on the './index_vam_op.php?page=route_reserve_plane' file. You need to provide the capture php file as parameter of the function. On this php file I have the php API file as "include('simbrief.apiv1.php');" On this php file I have: $xmllink = $_GET['ofp_id']; and then the array with the response: "$sb_ofp=$simbrief->ofp_array;" If you like I can share both API files, the php and js files...
Viguri
@Viguri
This is the function called on the submit button:

function simbriefsubmit(outputpage)
{

if (sbworker)
    {
    sbworker.close();
    }

if (SBloop)
    {
    window.clearInterval(SBloop);
    }

api_code = null;
ofp_id = null;
fe_result = null;
timestamp = null;
outputpage_save = null;
outputpage_calc = null;

do_simbriefsubmit(outputpage);
}

function do_simbriefsubmit(outputpage)
{
//CATCH UNDEFINED OUTPUT PAGE, SET IT TO THE CURRENT PAGE

if (outputpage == null || outputpage == false)
    {
    outputpage = location.href;
    }

if (timestamp == null || timestamp == false)
    {
    timestamp = Math.round(+new Date()/1000);
    }

outputpage_save = outputpage;
outputpage_calc = outputpage.replace("http://","");

//MAKESHIFT LOOP IN CASE IT TAKES A MOMENT TO LOAD THE API_CODE VARIABLE

if (api_code == null || api_code == false || typeof(api_code) == 'undefined')
    {
    api_code = 'notset';
    sb_res_load(api_dir+'simbrief.apiv1.php?api_req='+document.getElementsByName('orig')[0].value+document.getElementsByName('dest')[0].value+document.getElementsByName('type')[0].value+timestamp+outputpage_calc);
    setTimeout(function(){do_simbriefsubmit(outputpage);},500);
    return;
    }    
else if (api_code == 'notset')
    {
    setTimeout(function(){do_simbriefsubmit(outputpage);},500);
    return;
    }


//IF API_CODE IS SET, FINALIZE FORM

var apiform = document.getElementById(sbform);
apiform.setAttribute("method", "get");
apiform.setAttribute("action", sbworkerurl);
apiform.setAttribute("target", sbworkerid);

var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "apicode");
input.setAttribute("value", api_code);
apiform.appendChild(input);

var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "outputpage");
input.setAttribute("value", outputpage_calc);
apiform.appendChild(input);

var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "timestamp");
input.setAttribute("value", timestamp);
apiform.appendChild(input);

//LAUNCH FORM

window.name = sbcallerid;
LaunchSBworker();
apiform.submit();

//DETERMINE OFP_ID

ofp_id = timestamp+'_'+md5(document.getElementsByName('orig')[0].value+document.getElementsByName('dest')[0].value+document.getElementsByName('type')[0].value);


//LOOP TO DETECT WHEN THE WORKER PROCESS IS CLOSED

SBloop = window.setInterval(checkSBworker, 500);

}
Sorry if it doesn't look very nice :(
is it possible to attach files here? If so I send you the files...
Daniel Llewellyn
@diddledan
use triple backticks to surround your code:
```php
php code here
```

```js
js code here
```
it's not clear what you're saying you want to happen at all. Please ignore the client javascript and tell us what you want the server to do when it receives a request
Jakub Míšek
@jakubmisek

As Daniels says, the javascript part is irrelevant. It simply posts data to a .php script.

As I understand, the goal is to simulate the HTTP POST to a .php script from C#? So in C# you will be calling a PHP function and that PHP function will "think" it is an HTTP POST?

In general; it would be cleaner to prepare your PHP function to accept arguments instead of hardcoded use of $_GET and $_SERVER. Anyways; you can set the $_GET variable from within C# as well:
var ctx = Context.CreateEmpty("");
ctx.Get = new PhpArray()
{
  { "ofp_id", 123456789 },
};
ctx.Include("", "simbrief.apiv1.php");
Lance Matsushige
@FuriousFop_gitlab

Hi all, I have been trying to set up logging of any kind with wordpress to no avail. I have tried using it the stock wordpress way (by using the application settings and setting debug to true, and I have seen that WP_DEBUG_LOG is set to true by default internally) and when I get a whitescreen of death I can find no logs and nothing reporting back to me. I am unsure if it is some setting in wordpress or something the SDK is doing while it swapped out how it uses the config. I have also tried to integrate into the .net core pipeline with logging, but I have found that there are several places internally that are swallowing errors. I have also tried to just enable app.UseDeveloperExceptionPage(); for everything, but that hasn't done anything either.

My question is this: is there any documentation on setting up debug/error information that isn't just debugging through visual studio? I haven't been able to find anything other than to use the debugger. Some notes about my setup: Plugins Deactivated, Wordpress 5.5.1, wpdotnet-sdk-master as of 9/29/2020.

Any thoughts or direction appreciated.

Daniel Llewellyn
@diddledan
@FuriousFop_gitlab I think to get error_log to work you need to configure .net logging via the appsettings.*.json file(s): https://docs.microsoft.com/en-us/dotnet/core/extensions/logging
specifically it looks like error_log logs under the Error event level.
Lance Matsushige
@FuriousFop_gitlab
Ah those last parts might be the clues I was looking for, I'll give it a shot and let you know if it works. Thanks!
Mathias Berchtold
@matbech
How can I implement 2 different code paths, whether PHP is compiled by PeachPie or otherwise? Like a preprocessor directive to tell PeachPie to ignore some code etc.
Jakub Míšek
@jakubmisek
@matbech there is a global constant PEACHPIE_VERSION which you can check (link for details: https://docs.peachpie.io/php/differences/#peachpie_version)
Jakub Míšek
@jakubmisek

@FuriousFop_gitlab by default all the error logging is passed to the error event and trace output and debug output. So whenever you are running the application from Visual Studio or from VS Code, you have all the logs in your Debug Output window.

In the case of WordPress/WpDotNet specifically, I see it has disabled WP_DEBUG_LOG by default. And it automatically enables WP_DEBUG whenever your aspnet core environment is "Development" (i.e. running from VIsual Studio or VS Code). We have some remarks on that on https://docs.peachpie.io/scenarios/wordpress/overview/#remarks but I understand it needs more clarification.

Lance Matsushige
@FuriousFop_gitlab

@jakubmisek So if I wanted to enable log file messaging during development a la WP_DEBUG_LOG , in theory I should just need to set WP_DEBUG to true and WP_DEBUG_LOG to true also in WpStandard.cs? Or are you saying it ignores WP_DEBUG_LOG in favor of outputting to the output window during development? Do I need to hook up a .net logger for it to use to write to the file system when those values are set?

Thanks @diddledan , setting up logging in the appsettings.*.json file and hooking up a logger to the HostBuilder gets me informational messages, but its not picking up errors yet. I am using Windows Event Log and the following is the settings I have.

"Logging": {
    "EventLog": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  }

Last thing to note, I have tried these in isolation of eachother (meaning using defaults in WP and .net logging, then changing wp settings and removing the logger in .net).

Sorry this is so long, I'm new to Wordpress and trying to figure out some of the wp basics at the same time as the peachpie wp way of doing things.

Lance Matsushige
@FuriousFop_gitlab

@matbech php has a lot of

if(condition){
execute codepath1; 
}else {
execute codepath2
}

style of doing things. Being that its done in php, its not a preprocessor directive. The if condition will always be evaluated at run time. functions.php will be littered with it to make sure only certain js and css files will be loaded for the correct view you are on. It would be cool if you could define something like

#if DEBUG

directly in the php files. You could define a php global constant based on environment settings, or you could go the wordpress way with wp_get_environment_type()

Mathias Berchtold
@matbech
@jakubmisek Thank you ;-)
@FuriousFop_gitlab Yes, it would be nice if PeachPie had some kind of preprocessor to exclude certain code at compile time.
Mathias Berchtold
@matbech
I'm wondering if there are any plans to support something like this: config.php: <?php return [ 'a' => require 'other.config.php' ]; and the other.config.php: <?php return ['a', 'b' ];
Jakub Míšek
@jakubmisek
@FuriousFop_gitlab in case you are using wpdotnet from sources (wpdotnet-sdk project), you can just change the constants in WpStandard.cs. Anyways; finding out what's causing the whitescreen may be also done by debugging the project in VIsual Studio - mostly it's worth trying at the first place.

@FuriousFop_gitlab @matbech
actually, peachpie - when compiling in Release mode - excludes the unreachable code. i.e. following gets optimized out completely:

if (!defined("PEACHPIE_VERSION")) echo "running in PHP";

or

if (!function_exists("str_contains")) {
 function str_contains(){/*...*/};

Additionally you can define compile-time constants (https://docs.peachpie.io/php/msbuild/#defineconstants) so the compiler may remove and substitute more code based on that.

@FuriousFop_gitlab what's specific to wpdotnet is automatic setting of WP_DEBUG constant depending on current aspnet core environment (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0). Whenever the environment is Development, the WP_DEBUG is set to TRUE implicitly
Mathias Berchtold
@matbech
Like every 2nd time I compile the project, I get errors like this: vendor\laminas\laminas-validator\src\ValidatorPluginManager.php(514,9): error PHP4046: Call to a member function addInitializer() on void
The code looks like:
public function __construct($configOrContainerInstance = null, array $v3config = [])
    {
        parent::__construct($configOrContainerInstance, $v3config);

        $this->addInitializer([$this, 'injectTranslator']);
To me it looks like a weird compiler bug which does not always trigger as I'm able to compile the project successfully sometimes.
Jakub Míšek
@jakubmisek
@matbech it really looks like a weird bug, thank you! I've created an issue for that at peachpiecompiler/peachpie#882 and hopefully, we'll fix it within the next update
Jakub Míšek
@jakubmisek
@FuriousFop_gitlab note to the error logging in aspnet core - currently they are only logged into VIsual Studio's output window when debugging; but it's a good point they should be passed to aspnet core logger!
Mathias Berchtold
@matbech
warning PHP5009: Call to undefined method: Locale::getDefault(), is Locale not supported yet or do I have to add some additional Peachpie package (I have already added Peachpie.Library)?
It seems this is part of intl — Internationalization Functions, which isn't listed here: https://docs.peachpie.io/compatibility-status/
Jakub Míšek
@jakubmisek
@matbech yes, intl is not implemented yet. You should also see a warning that Locale is an unknown class.
FYI Peachpie.Library package reference is added implicitly.
Davide
@bertasoft

Hey Guys, i need to get header response from php, i'm compiling php at runtime, take a look
`using (var ms = new MemoryStream())
{
using (var ctx = Context.CreateConsole(string.Empty, string.Empty, ms, new string[] { }))
{
ctx.WorkingDirectory = fullpath;
ctx.RootPath = fullpath;

                    var url = requestResponse.Request.Url.AbsolutePath.NoHttpHttps();

                    ctx.Get.AddVariable("iso", lingua.CodiceIso);
                    ctx.Get.AddVariable("url", url);

                    ctx.Server.AddVariable("DOCUMENT_ROOT", fullpath.Replace("\\", "/"));
                    ctx.Server.AddVariable("HTTPS", Settings.Config.WebPath.StartsWith("https://") ? "on" : "off");
                    ctx.Server.AddVariable("HTTP_HOST", Settings.Config.WebPath.NoHttpHttps());
                    ctx.Server.AddVariable("QUERY_STRING", "url=" + url + "&iso=" + lingua.CodiceIso + "&" + requestResponse.Request.QueryString);
                    ctx.Server.AddVariable("HTTP_ACCEPT", string.Join(",", requestResponse.Request.AcceptTypes));
                    ctx.Server.AddVariable("HTTP_USER_AGENT", requestResponse.Request.UserAgent);

                    var location = new Pchp.Core.Location(fullpath, 0, 0);

                    var script = Provider.CreateScript((new Context.ScriptOptions()
                    {
                        Context = ctx,
                        Location = location,
                        EmitDebugInformation = true,
                        IsSubmission = false,
                        AdditionalReferences = new string[]
                        {
                            //typeof(Library.Graphics.PhpImage).Assembly.Location,
                            typeof(Peachpie.Library.Network.CURLFunctions).Assembly.Location,
                            typeof(Presentation.Code.DowebPhpExtension).Assembly.Location
                        },

                    }), scriptare);

                    script.Evaluate(ctx, ctx.Globals, null);

                    requestResponse.Response.StatusCode = ctx.HttpPhpContext.StatusCode;

                }

                result = ms.ReadAllBytes();
            }

`

how to take the Redirect 301 from there? ctx.HttpPhpContext is null and GetOrCreateContext(this HttpContext) doen't exist in NET 4.8
Jakub Míšek
@jakubmisek

@bertasoft hi,
Context.CreateConsole creates a console context - therefore it does not implement HTTP related features and behaves like a CLI PHP program.

For what you need, add a reference to Peachpie.AspNetCore.Web, and create the Context in the following way:

var ctx = requestResponse.GetOrCreateContext();

in this way, also all the HTTP related $_SERVER variables will be initialized for you correctly

Just for info, you use Provider.CreateScript to dynamically compile the PHP script by purpose?

Davide
@bertasoft
I tried to install Peachpie.AspNetCore.Web but VS give me this "Could not install package 'Peachpie.AspNetCore.Web 0.9.990'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author." We are a web farms and we use an online editor to build web sites. The platform is based on IIS / NET 4.8 and accept HTML + PHP - The php is parsed with a call to PHP on FastCGI with HttpClient and the result is returned from an http handler (ashx). I'd like to remove FastCGI / PHP / HttpClient and the TCP delay with Peachpie. How to work around the mentioned error? :) Thanks
Jakub Míšek
@jakubmisek
0.9.999 is pretty old one. Use 1.0.0-preview3
Oh, for IIS (asp.net) there is Peachpie.RequestHandler package. The next update 1.0.0-preview4 will provide a Context factory you need
Davide
@bertasoft
Can "Peachpie.RequestHandler" build a context ? I read that it can only be useful for launch compiled PHP replacing standard HttpHandler. An estimation of ETA of 1.0.0-preview4 ? Thanks
Davide
@bertasoft
Something that can also be useful is that Provider.CreateScript can automatically parse includes inside main script php and compile them. I need this because our developers write php code inside an ace editor, they cannot touch c#.
Jakub Míšek
@jakubmisek
Yes, internally this assembly provides context for asp.net request pipelines. Probably within a week will be released.
Can your devs write within a project? The C# project may just reference it and compile as a dependency.
Davide
@bertasoft
Our devs write php code with notepad++ inside that code there are some includes, now I have to parse that includes and build a single string with all the code and feed Provider.CreateScript - it's be interesting if that includes are scanned and parse automatically. Thanks, i'll wait for .GetOrCreateContext() for IIS / NET 4.8
Jakub Míšek
@jakubmisek
@bertasoft right, but can you have an MSBuild project file next to those PHP files? so you could reference it from your C# project
You can have a project file like this https://docs.peachpie.io/php/msbuild/ , it might be anywhere in your solution, and PHP files will get compiled together with your C# project
Davide
@bertasoft
Unfortunately the files are stored inside another db - I'll take a look to your suggestion, i'd like to offer you a coffee :)
Jakub Míšek
@jakubmisek
@bertasoft sounds good!