GithubHelp home page GithubHelp logo

sformisano / jetrouter Goto Github PK

View Code? Open in Web Editor NEW
64.0 2.0 10.0 64 KB

A lightning fast, easy to use router for WordPress.

License: GNU General Public License v3.0

PHP 100.00%
wp wordpress wordpress-plugin wordpress-router wordpress-url wp-url router php wordpress-packagist composer

jetrouter's Introduction

Full-Stack Dev | Engineering Manager

Thank you for your interest in my profile. I am:

  1. A software engineer with over 15 years of experience working on full-stack web applications, distributed systems, and technical leadership.

  2. A people-first manager who helps teams foster relationships based on trust, empathy, and respect.

  3. A firm believer in growth mindset, radical candor, and servant leadership as the secret superpowers of high-performing teams.

My overarching goal is to create real, long-lasting value for teams, stakeholders, and users.

LinkedIn

jetrouter's People

Contributors

sformisano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jetrouter's Issues

Cache generated dynamic routes

When the router has to dispatch a dynamic route, it has to go through the dynamic routes generation process every time. This becomes a performance concern as the dynamic routes number increases.

Implement a file based dynamic routes caching system, and perhaps have a version configuration property on the Router object so that it can be used to tell whether the cache file is up to date or not.

e.g.

$r = Router::create(['routesVersion' => '1.1')];
// if the cache file was generated when routesVersion was < 1.1, generate it again

Dot (.) in the "namespace".

Hello,

I'm currently looking through the source code but figured I'd ask this here anyway. (I'll update if I find it).

Can namespace values contain a period (dot) character?

The error I'm receiving when using a namespace of "10.1109":

[20-Aug-2018 23:04:00 UTC] PHP Fatal error:  Uncaught exception 'JetRouter\Exception\InvalidRouteException' 
with message ''10.1109/param' is not a valid route path.' in /var/www/html/wp-content/plugins/jetrouter/src/StaticRouteParser.php:35
Stack trace:
#0 /var/www/html/wp-content/plugins/jetrouter/src/DynamicRouteParser.php(82): JetRouter\StaticRouteParser::validateStaticPath('10.1109/param')
#1 /var/www/html/wp-content/plugins/jetrouter/src/DynamicRouteParser.php(217): JetRouter\DynamicRouteParser::validateStaticPathParts('10.1109/{doi}')
#2 /var/www/html/wp-content/plugins/jetrouter/src/RouteParser.php(104): JetRouter\DynamicRouteParser->setPath('10.1109/{doi}')
#3 /var/www/html/wp-content/plugins/jetrouter/src/RouteStore.php(263): JetRouter\RouteParser->__construct('GET', '10.1109/{doi}', 'doiIEEE', Object(Closure))
#4 /var/www/html/wp-content/plugins/jetrouter/src/RouteStore.php(82): JetRouter\RouteStore->addDynamicRoute('GET', '10.1109/{doi}', 'doiIEEE', Object(Closure))
#5 /var/www/html/wp-content/plugins/jetrouter/src/Router.php(117): JetRouter\ in /var/www/html/wp-content/plugins/jetrouter/src/StaticRouteParser.php on line 35

This would be for a URL pattern that matches something like:

www.example.com/10.1109/Test.2018.12345

I've attempted to escape the period using a "", as well as a double "\", and have looked at other regex mechanisms to escape the dot. No luck.

Thanks

Jon

Amend README to mention wpackagist autoload issue and packagist steps

You may want to use this router in a WordPress plugin. Great! But there's a problem when adding this router as composer dependency through composer and wpackagist.

For some reason I did not look into, autoload does not autoload the jetrouter files if the plugin is requested through wpackagist. This is most likely due to the fact that the entry point for a wordpress plugin is its main file, whereas people using autoload simply include the autoload.php file.

This is fine for plugins (case 1):

  • Your main WordPress project requires the plugin through wpackagist
  • Wpackagist adds the plugin in your plugins directory
  • Your plugin's main file loads the autoload.php file
  • All set

(case 2) If, however, you are declaring a plugin as a dependency for another plugin, under the circumstances outlined above you would need to require the plugin, then manually require the plugin's main file which then finally includes the plugin's autoload.php file with all its classes.

This can be done in a much easier and better way. When you normally require a dependency through composer, the dependency's dependencies are autoloaded and you don't have to do a thing.

As mentioned above, this does not happen when you required the jetrouter through wpackagist. It however works 100% fine through the standard packagist repository.

I am therefore now publishing this plugin through both wpackagist and packagist, so that it can be loaded through wpackagist as a root WordPress project dependency (case 2), or through packagist as a plugin or theme dependency (case 2)

TODO: write this in a more concise and understandable way and add this + steps to load through packagist in the README.

Write nonce examples for form submission

We want to encourage devs to use nonces in their form submission processing. Add an example in the README to show that nonces are easy to use with the jetrouter

Creating fake pages programmatically

Do you have any clue on how to programmatically create a 'fake page' or a 'virtual page' for JetRouter routes?

I'm building a dynamic route that queries an external API so I'm like

 use JetRouter\Router;
 
 $config = [];
 
 $r = Router::create($config);

 $r->get('movie/{movie}', 'get_movie', function($movie){
 	include ( get_stylesheet_directory() . '/movie.php' );
 });

and so far so good. In movie.php I have a page template which calls cptemplates_template_content(); which is a wrapper around WordPress' the_content() that applies a WPBakery Page Builder template to whatever the API call returned and then renders the_content().

But WordPress doesn’t recognize what I output as a page because it isn’t.

So when I go like if URL, WP->REQUEST matches 'movie/{movie}' return the Custom Page Template it doesn't work because the plugin doesn't see a page and the browser shows whatever is in movie.php which is a themed empty page with header and footer but no content because I called include ( get_stylesheet_directory() . '/movie.php' ); earlier.

One solution would be to create real pages with the same slug I would query on the external API which obviously is a hassle. I see on the internet that when this situation happens you're supposed to create a 'fake' or 'virtual' dummy page which is very well described here on StackOverflow.

how to get post request ?

i want to create simple contact-us form
i create i get method to render contact-us.twig using timber

and i add form with post method content 3 input (name , email,subject)
now i want to get requested data from form

$rr->post('store-contact-us', 'store_contact_us', function(){
	 // print_r($request);
	echo('<h1>post route</h1>');
  });

how to get this data ?

Fatal error

An error occurs if the route's function or class method doesn't exist before adding a route. Taht condition generates a fatal error before the jetrouter can throw its own exception:

Fatal error: Uncaught Error: Using $this when not in object context in /var/www/jetrouter/src/RouteParser.php:78

I was calling addRoute like this, but had not yet written the get_dashboard class method into the code.

$router->addRoute( 'GET', 'dashboard', 'dashboard_route', __CLASS__ . '::get_dashboard' );

Improve unit tests

Data providers are too bloated, no solid naming convention for test methods nor for data providers. Unit tests need to become more clear and concise.

Idea: make reverse routing available via JS

It may be a good idea to make reverse routing available via JS. We could use a WordPress hook to make a js object with all the data required for reverse routing, plus a function that handles dynamic reverse routing (like the back-end does).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.