Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Calvin Alkan
    @calvinalkan

    got it.

    Im customizing wpemerge more and more to fit my own needs for a big project.

    Im very curious about one thing. When you generate an url condition why do you sha1 the placeholders?

    Atanas Angelov
    @atanas-dev
    Honestly it's been quite some time since I wrote that so I can't tell from the top of my head. Most likely, to avoid preg_quote()-ing the special characters in the parameter syntax used in the url at that stage
    Calvin Alkan
    @calvinalkan
    @atanas-dev
    have you ever considered more performant regex routers like FastRoute which would built the regex in one shot instead of all individually or do you think performance gains would be non noticeable respecting all the WP overhead anyway?
    Atanas Angelov
    @atanas-dev
    I have. I believe there were some limitations last time I checked in terms of possible features and general support - nikic/FastRoute#173
    The common case should be that WP conditions are used (post_id, post_template etc.) rather than custom URL ones so in general this is not too much of a focus for me (unless an obvious performance bottleneck is demonstrated, of course).
    If someone is so inclined, I'm sure there's a way to sneak in a custom solution which passes routes with UrlCondition conditions to FastRoute. Not sure if ::routeUrl() will work though, since reverse construction is not supported in FastRoute
    As for the current performance in WP Emerge - I have not benchmarked it against other solutions but I doubt there's a significant difference in performance when dealing with less than 100 routes, for example, which is the common case.
    Atanas Angelov
    @atanas-dev
    Benchmarking would also not be too accurate since the WP Emerge router supports more than just plain URLs as it covers WP-specific needs thus changing how the whole thing works internally (e.g. the whole route condition abstraction is not present in other URL-only solutions).
    Calvin Alkan
    @calvinalkan

    @atanas-dev FastRoute is still maintained and in fact 2.0 is soon to be released. Nevertheless 1.3 is stable and feature complete. Lumen, Slim and other still use it.

    I could not resist myself and got this done. I have a working version locally which works like this now: ( note that this is basically a complete rewrite of the router and condition factory. )

    • UrlConditions are not needed anymore. They are replaced by FastRoute.
    • All Routing features are still available
    • When a request is dispatched first, the url is matched with FastRoute. Then custom "wp conditions" are evaluated.
    • The router now works with a RouteCollection that is cacheable like in laravel. So neither WpEmerge nor FastRoute will be processing any route creation in production.
    • Everything is lazy loaded and resolved from the service container. Handlers, Middleware and Conditions are only instantiated when a route has matched. Right now as things are all custom conditions get created for every route on every request.
    • Reverse routing to named routes works just like before.

    I assume performance will be a lot higher for sites with many routes but I dont have the time to benchmark things right now and Im also not that experienced in setting up proper benchmarking.

    Ofc I dont have any expectations of this being merged ever ( required php 7.3 ) but Ill share you the repo if you want when Im done, maybe you ll find some ideas for WPEmerge aswell.

    rherault
    @Romaixn
    Hello here ! There is a function to get a custom post type inside a shortcode ? (or good old wpquery ?)
    I also had a question about controllers, how to use them in WordPress? In what cases can they be used?
    Atanas Angelov
    @atanas-dev
    Hi @Romaixn ,
    No, there's no special added functionality for this - WP_Query is the way to go.
    Controllers are used to do any extra request validation or processing for custom routes. More information can be found here: https://docs.wpemerge.com/#/framework/routing/defining-routes
    @calvinalkan happy to hear you got it to work. Feel free to share the repo if you'd like :)
    Calvin Alkan
    @calvinalkan
    @atanas-dev I ll share it when I consider it production ready :) Still some things left and I need to look for a way to implement query() routes.

    Right now I have a suggestion for you tho, maybe you overlooked this at first.

    Whoops has an option to open files directly in the editor of your choice.

    Its as simple as doing this.

    $pretty_page_handler->setEditor('phpstorm');

    Might be a nice addition, the value would then come from the user config of course

    Calvin Alkan
    @calvinalkan
    Also, why did you choose to replicate the Whoops layout files in a custom ? Is there any reason for that that I overlooked. Because it looks like its an exact duplicate of the Whoops HTML
    Atanas Angelov
    @atanas-dev
    The whoops internals are easily accessible via the container so you are free to set the desired editor in your project.
    The files are not 1:1 with what Whoops has bundled. There are some key adjustments necessary in order to have Whoops render without issues when embedded in /wp-admin/ inside WP's admin chrome.
    Calvin Alkan
    @calvinalkan

    Yeah I did that, just thought it might be a nice addition to have this in the config for users who dont read all the 3rd party library APIs like myself :D

    Got it, I had not thought about wp-admin.

    Arthos
    @taliesinpenbardd
    hey all, hope you're doing fine. i'm building a website with a quick booking system, using Laravel Cashier to get the first part of the payment. my ReservationController works fine until now, but the /reservation page has "Page not found" as a title. Obviously it comes from myapp_get_index_404_message() but i'm struggling on how to detect a page that is not going through a page template, a page or anything from WP (since it's built by the controller...). anything i've tested so far works (is_page(), is_page_template(), is_archive(), etc). any idea on how to intercept that? thanks :)
    Atanas Angelov
    @atanas-dev
    App::resolve( WPEMERGE_ROUTING_ROUTER_KEY )->getCurrentRoute() may be of help it will return a route object if a WP Emerge route matches or null.
    Arthos
    @taliesinpenbardd
    Thanks, i'll try that
    Calvin Alkan
    @calvinalkan
    you need do include the html meta tags in your view if you are using routes that use pure url matching
    if not wp considers this a 404 and prints the appropriate meta tags when using get_header()
    Calvin Alkan
    @calvinalkan

    @atanas-dev hey atanas, just wanted to let you know a possible bug I found while working on my own version of wpemerge. Right now when you render a view its almost impossible to catch expection while rendering the php file. Because the __toString() methods gets called recursivly output buffering also gets turned on end off everytime. This results in all the html before the error being print to the screen while everythings after the exception doesnt.

    IMO the output buffering should be one level above the the rendering logic inside the toResponse() method on the PhpView class.

    This way you can properly render exceptions without the view output. Maybe this is due to an edge case in my version but Im pretty certain I have not modified anything relevent inside the view related classes.

    Anyway this is what fixed it form me.

    // Inside PhpView
    public function toResponse() : ResponseInterface {
    
                ob_start();
    
                try {
                    $this->toString();
                } catch (\Throwable $exception) {
    
                    ob_end_clean();
                    throw new ViewException();
    
                }
    
                $content = ob_get_clean();
    
                return ( new Response( $content ) )->setType( 'text/html' );
    
            }
    Calvin Alkan
    @calvinalkan

    Just confirmed this also happens on a fresh install of wpemerge.

    Given the following view:

    <?php
    
    
    ?>
    
    <h2> Foobar</h2>
    
    <?php
    
        non_existing_function();
    
    ?>

    and the following route:

     \App\App::route()->get()->url('foo')->handle(function () {
    
            return \App\App::view('view.php');
    
        });

    The output is the following with the default WP error page:

    "Foobar

    Fatal error: Uncaught Error: Call to undefined function non_existing_function() in /Users/calvinalkan/valet/booking/wp-content/plugins/test-plugin/view.php:10 Stack trace: #0 /Users/calvinalkan/valet/booking/wp-content/plugins/snicco-bookings-"

    It also makes sense why this happens:

    Inside the PhpView:

    public function toString() {
    
            if ( empty( $this->getName() ) ) {
                throw new ViewException( 'View must have a name.' );
            }
    
            if ( empty( $this->getFilepath() ) ) {
                throw new ViewException( 'View must have a filepath.' );
            }
    
            $this->engine->pushLayoutContent( $this );
    
            if ( $this->getLayout() !== null ) {
     // ERROR HAPPENS HERE
                return $this->getLayout()->toString();
            }
    
            return $this->engine->getLayoutContent();
        }
    The output buffering will be cleaned automatically when the script shuts down. The exception in the view causes this. But ofc we dont want to render a half baked view to the user which is why any exceptions need to be caught here and the output buffer needs to be flushed
    Atanas Angelov
    @atanas-dev
    Could you please post an issue on GitHub for this so I can keep track of it? Thanks!
    Calvin Alkan
    @calvinalkan
    Also how do we ensure that the rendered view is not bigger than the max outbut buffer size? This would break the entire routing flow I assume. Is this something very unlikely to happen?
    Alexander
    @xenx-efy
    Hi there, when I'm using \MyApp::core()->assets()->getBundleUrl('frontend', '.css') I'm getting this url http://localhost:80/styles/frontend.css, but it not works. When I using getAssetUrl all works, for what getBundleUrl() function?
    Alexander
    @xenx-efy
    I set 'SCRIPT_DEBUG' to false and all works, thank you). I found the solution above in chat.
    gixan
    @gixan

    Hey. I am trying to get started with WP Emerge. I've been following 0 to 100 Setup.

    However it states I am supposed to get the error:

    Fatal error: Uncaught Error: Class '\App\Controllers\Web\HomeController' not found

    But instead I receive:

    There has been a critical error on this website.

    I assumed it was just because maybe the newer version has a different error but as I kept following the steps where it is supposed to resolve the error, it did not. Everything was fine until I reached that stage and double checked that I pasted in the code correctly in the .php and .json files.

    Does anyone have any pointers on what could be happening or links to any resources? I can't find any resources online on WP Emerge besides this site itself.

    gixan
    @gixan
    The issue seems to have resolved it self I think?
    I executed compser dump-autoloader a few times and it did nothing, then sat around googling and typing this up. When I returned to it, I turned off my MAMP server and turned it on again. Not sure what resolved it.
    Calvin Alkan
    @calvinalkan
    @atanas-dev submitted another possible bug htmlburger/wpemerge#28
    Branislav Stojanovic
    @djex808
    @atanas-dev Is it likely that PHP 8 will be supported in the next 3-4 months? I need to decide if I am going to use the framework for the next project and I would really like to but PHP 8 would be required:)
    Atanas Angelov
    @atanas-dev
    There are plans but I cannot give you an exact ETA :)
    Atanas Angelov
    @atanas-dev
    Just as an FYI, PHP 8 support is in master but there are some other unrelated complications that need to be resolved before a new release happens. I might make a separate branch/hotfix depending on how long it takes.
    Branislav Stojanovic
    @djex808
    If you could at least find some time in the the next few months to make a hotfix for the routes issue that I experienced that would be great :). Though, in the end, I can work around it then rewrite the code later when it becomes available.
    Atanas Angelov
    @atanas-dev
    What specific routes issue are you referring to?
    Atanas Angelov
    @atanas-dev
    Ah, you're referring to the PHP 8 one.
    Branislav Stojanovic
    @djex808
    Yes, yes - sorry for the confusion :)
    Jennifer Eberlei
    @jennifer.eberlei_gitlab
    Hey There, I just did my first release and uploaded it to my staging server. Unfortunately I can't activate it as I get the following error:
    Warning: Use of undefined constant WPEMERGE_APPLICATION_FILESYSTEM_KEY - assumed 'WPEMERGE_APPLICATION_FILESYSTEM_KEY' (this will throw an Error in a future version of PHP) in /var/www/vhosts/rechtsanwalt.com/dev.rechtsanwalt.com/wp-content/plugins/racom-directory/app/src/WordPress/AssetsServiceProvider.php on line 29
    
    Fatal error: Uncaught Pimple\Exception\UnknownIdentifierException: Identifier "WPEMERGE_APPLICATION_FILESYSTEM_KEY" is not defined. in /wp-content/plugins/racom-directory/vendor/pimple/pimple/src/Pimple/Container.php:101 Stack trace: #0 /wp-content/plugins/racom-directory/app/src/WordPress/AssetsServiceProvider.php(29): Pimple\Container->offsetGet() #1 //wp-content/plugins/racom-directory/vendor/htmlburger/wpemerge/src/Application/LoadsServiceProvidersTrait.php(107): RacomDirectory\WordPress\AssetsServiceProvider->bootstrap() #2 /var/www/vhosts/rechtsanwalt.com/dev.rechtsanwalt.com/wp-content/plugins/racom-directory/vendor/htmlburger/wpemerge/src/Application/LoadsServiceProvidersTrait.php(82): WPEmerge\Application\Application->bootstrapServiceProviders() #3 /var/www/vhosts/rechtsanwalt.com/dev.rechtsanwalt.com/wp-content/plugins/racom-directory/vendor/htmlburger/wpem in /var/www/vhosts/rechtsanwalt.com/dev.rechtsanwalt.com/wp-content/plugins/racom-directory/vendor/pimple/pimple/src/Pimple/Container.php on line 101

    When I look for taht definition it is located in AssetsServiceProviderPHP Line 29

            $this->filesystem = $container[ WPEMERGE_APPLICATION_FILESYSTEM_KEY ];

    Do I have to set that somewhere?

    Jennifer Eberlei
    @jennifer.eberlei_gitlab
    I already fixed the warning by adding quotes to the constant but I still get the Fatal Error.
    Atanas Angelov
    @atanas-dev

    Hi @jennifer.eberlei_gitlab ,

    You shouldn't need to edit any files inside /vendor/ for everything to work. My first guess would be is that you need to run composer install --no-dev to install the production dependencies on your server.

    Alternatively, you can use the yarn release command: https://docs.wpemerge.com/#/starter/scripts?id=yarn-release
    This will build all assets, install production dependencies and zip up your theme which you can then upload to your server and unzip.

    Jennifer Eberlei
    @jennifer.eberlei_gitlab
    Thank you for your answer, I did the yarn release command beforehand and uploaded the created zip file
    that's when the error occured
    Atanas Angelov
    @atanas-dev
    The only reason that the constants are not defined is that the WP Emerge framework is not loaded so you'll need to make sure the /vendor/ dependencies are present and the correct path to the autoloader is loaded in functions.php