Jump to content

Symprowire - PHP MVC Framework for ProcessWire 3.x // v0.6.0-rc1


Recommended Posts

Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Service-Provider

It acts as a Drop-In Replacement Module to handle the Request/Response outside the ProcessWire Admin. Even tough Symfony or any other mature MVC Framework could be intimidating at first, Symprowire tries to abstract Configuration and Symfony Internals away as much as possible to give you a quick start and lift the heavy work for you.

The main Goal is to give an easy path to follow an MVC Approach during development with ProcessWire and open up the available eco-system.

You can find the GitHub Repo and more Information here: https://github.com/Luis85/symprowire

Documentation

Last Update

Requirements

  • PHP ^7.4
  • Fresh ProcessWire ^3.0.181 with a Blank Profile
  • Composer 2 (v1 should work, not recommended)
  • The usual Symfony Requirements

Features

  • Twig
  • Dependency Injection
  • Monolog for Symprowire
  • Support for .env
  • YAML Configuration
  • Symfony Console and Console Commands
  • Symfony Webprofiler
  • Full ProcessWire access inside your Controller and Services
  • Webpack Encore support

Caveats

Symfony is no small Framework and will come with a price in terms of Memory Usage and added Overhead. To give you a taste I installed Tracy Debugger alongside to compare ProcessWire profiling with the included Symfony Webprofiler

Screenshot_2.thumb.jpg.e10951ef6fa51650b28349018601967d.jpgScreenshot_3.thumb.jpg.d44499e5b10ede41c363ee171c2285a1.jpgScreenshot_4.thumb.jpg.f1b0cb9bcb17e07d8179ec52c6ebe049.jpg

So in a fresh install Symprowire would atleast add another 2MB of Memory usage and around 40ms in response time, should be less in production due to the added overhead of the Webprofiler in dev env

 

Edited by LuisM
new Release
  • Like 6
Link to comment
Share on other sites

@netcarver oh wow thanks for the Larawire mention. Didnt knew there where similar attempts but with Laravel.

Anyways, I have a slow day in the office and wanted to clean up a bit. So meet PoC v.0.1.0. I completly encapsulated Symfony now to dont mess with ProcessWires file/directory structure and keep things clean. 
I think, this should be a good base to develop this thing further. Am happy 🙂

  • Like 1
Link to comment
Share on other sites

I just finished to clean up the repo and pushed Symprowire as stand-alone module to GIT. 

I marked the commit as RC-1 

The Framework should work right now like every other Symfony App handling wise, with the exception of twig templates bound to the processwire directory structure.
Next would be to integrate ProcessWire Services like logger, input et all as Symfony Services and autowire them into the Controller.

Stay tuned, oh and feel free to comment 🙂

  • Like 2
Link to comment
Share on other sites

  • LuisM changed the title to Symprowire - MVC Framework // v0.2.0-rc1

Release RC1 v0.2.0 -> https://github.com/Luis85/symprowire/releases/tag/v0.2.0-rc-1

  • added Session Handshake to integrate PW Session into Symfony
  • added $page, $pages, $input, $session, $modules, $users as member to AbstractController 
  • added Symprowire autowire Services outside of userland into /lib/src and added own Namespace for the lib
  • added Repositories (Pages, Modules, User) to the lib
  • added UserRepository to HomeController::index() as Dependency Injection for Demonstration / as Example
  • Like 2
Link to comment
Share on other sites

Looking forward to your experience @netcarver 🙂

What I actually dont like at all right now is how I hand over the Request handling.

My idea is, to use ProcessWire as a DBAL and load Pages via a Repository to centralize modification, loading of PageData and use the Admin to create a Structure, Content and handle Templates and let Symprowire use Entities as simple DTO to reflect ProcessWire Templates.

I think this will open up a clear Migrations path later on and will make Form creation easy with the symfony/forms component.

Right now I add a replace hook on TemplateFile render() and the used frontcontroller template will allow UrlSegments to be set.

I must admit, Routing is not something I have invested much tought into yet. Maybe you guys have some ideas what could work best here 

@teppo

@bernhard

@netcarver

Link to comment
Share on other sites

26 minutes ago, bernhard said:

I've never used symfony (only the CLI component) so I have to admit that I don't understand what you are doing here, sorry 😉 

Oh hahaha, my question is more about, what would be the best method/hook to intercept ProcessWire rendering or routing to replace the Response completly.

Link to comment
Share on other sites

Release v0.3.0-rc1

- added Webpack Encore Support
- removed Symprowire Autload condition. Symprowire is now configured to server every request except admin
- implemented recommended template structure into lib/twig 
- added more context and information to the HomeController
- added $user and $session as Global Twig Variable // both as ProcessWire Objects
- implemented example Webpack Encore Application using stimulus.js served by lib/twig

Link to comment
Share on other sites

  • LuisM changed the title to Symprowire - PHP MVC Framework for ProcessWire 3.x // v0.4.0-rc1

Working Full-Time on the Module for this week after getting it running its just good old Symfony Development to make the Glue hold tight on ProcessWire. 
I plan to build a Blog with Symprowire next to see if everything works as expected. 

I added a small Project over at Github to keep you informed. Will continue to post release notes. For now, I edited the 1st Post as this would be my Base to develop the Blog.

  • Like 1
Link to comment
Share on other sites

On 7/13/2021 at 4:23 PM, LuisM said:

Right now I add a replace hook on TemplateFile render() and the used frontcontroller template will allow UrlSegments to be set.

I must admit, Routing is not something I have invested much tought into yet. Maybe you guys have some ideas what could work best here 

I can't say that I have a strong opinion here either. Also not sure if I grasp the whole context — when you say "routing" and mention URL segments, does that mean that you create routes automatically based on page structure (I assume so but...) or that there's a separate routing setup for front-end and page structure is only reflected in the data? Or do you mean something different with this? 🙂

This may or may not be related, but one thing to consider is whether you want Symprowire to be "all in", or rather something that can be used only for some parts of the site. Couple of examples from other MVC(ish) solutions:

  • Template Engine Factory hooks before Page::render and replaces the response, but also provides hookable method (TemplateEngineFactory::shouldRenderPage) for preventing it from rendering the page, in which case the site will fall back to the regular rendering flow (whatever that happens to be).
  • Wireframe takes an entirely different approach: instead of a hook ("enabled by default") you need to point templates that you want to render via it to the front controller file via Alternate Template Filename setting (more details in the docs). Essentially it's disabled by default.

Wireframe is my pet project and something we've used for our production sites for a while now, so that's what I'm mostly familiar with. I intentionally decided not to use hooks, since I felt it was best to let the developer decide if they want to use Wireframe for everything, just a small part of the site, or something in between. In fact it's possible to skip the MVC structure entirely, and just use Wireframe for its partials and/or components 🤷‍♂️

Template Engine Factory may be a bit closer to Symprowire feature wise, although Symprowire clearly has a much larger scope (and is more opinionated). So not sure if any of what I've said here applies as-is 🙂

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Thank you Teppo for that detailed answer. Really appriciate it. 

1 hour ago, teppo said:

I can't say that I have a strong opinion here either. Also not sure if I grasp the whole context — when you say "routing" and mention URL segments, does that mean that you create routes automatically based on page structure (I assume so but...) or that there's a separate routing setup for front-end and page structure is only reflected in the data? Or do you mean something different with this? 🙂

My first take was similiar to Wireframe. Adding a Template as alternate Template file and replace the render accordingly. But it didnt felt quite right, taking the tools Symfony provides into consideration. I now let Symprowire act as a drop-in solution to replace ProcessWire rendering completly. 

What this basically means is, ProcessWire will no longer be in charge about anything URL or rendering related. 
As of now Symprowire will intercept the Request and manage routing decoupled from ProcessWire. So ProcessWire will step back and act as a Data/Service Provider for Symprowire.

What I actually did here is separating into more or less 3 layers. 

  • ProcessWire as Data and Server Provider 
  • Symprowire as Businesslogic Backend MVC style powered by a Symfony Architecture
  • a separated Frontendlayer served by Twig Templates

ProcessWire Admin will be used as Data Editor / Content Management System and Symprowire will consume this data and do stuff with it before handing over to Twig.this

1 hour ago, teppo said:

... or that there's a separate routing setup for front-end and page structure is only reflected in the data ...

This would describe it best I guess.

 

1 hour ago, teppo said:

Wireframe is my pet project and something we've used for our production sites for a while now, so that's what I'm mostly familiar with.

I actually use Wireframe as Output Framework in the Project im working on 🙂

Quote

 I intentionally decided not to use hooks, since I felt it was best to let the developer decide if they want to use Wireframe for everything, just a small part of the site, or something in between. In fact it's possible to skip the MVC structure entirely, and just use Wireframe for its partials and/or components 🤷‍♂️

I am still not sure if this should be a possibility or an option in Symprowire. Its tempting to let the Developer decide, but on the other hand I mainly create Symprowire to give a somewhat strict structure and to have Phpunit tests in the not so far future. Which would be hard to integrate if just parts could be tested. Decisions decision decision... 😕 

 Another reason I am into this is the clear and concise way Symfony handles the Request/Response, it just makes so much sense for me to combine this both worlds. Take the very very strong parts CMS/CMF wise from ProcessWire and combine it with Symfony. I dunno 🙂 just feels to be like this 

 

1 hour ago, teppo said:

Template Engine Factory may be a bit closer to Symprowire feature wise, although Symprowire clearly has a much larger scope (and is more opinionated). So not sure if any of what I've said here applies as-is 🙂

Dont worry, I knew you would give great insights the moment I tagged you 😄 
Have to dig into TemplateEngineFacotry code now 😉

 

 

  • Like 1
Link to comment
Share on other sites

  • LuisM changed the title to Symprowire - PHP MVC Framework for ProcessWire 3.x // v0.5.0-rc1

Bump up to v0.5.0 

I added a tutorial for a simple Symprowire Blog Application.
You can find the tutorial here: https://github.com/Luis85/symprowire/wiki/Symprowire-Blog-Tutorial

To keep up with development and organize the project I added a GitHub Project and corresponding Issue Management. You can find it here: https://github.com/Luis85/symprowire/projects/1

  • Like 1
Link to comment
Share on other sites

  • LuisM changed the title to Symprowire - PHP MVC Framework for ProcessWire 3.x // v0.6.0-rc1

Bump up to v0.6.0

Breaking Changes

  • renamed AbstractRepository to AbstractPagesRepository
  • added new ProcessWireService / ProcessWireServiceInterface as wrapper to access ProcessWire in a centralized way and to reduce wire() function calls.
  • replaced all wire() function calls with using ProcessWireService
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

@LuisM This is really sweet. ProcessWire is awesome but for bigger projects, that go beyond a simple website, managing business logic and templates can get messy really quickly. I really like your attempt on integration with Symfony. I thought about a couple experiments to "professionalize" ProcessWire development too, e.g.

  • having the PW core and PW admin be independent packages
  • being able to load these packages through composer
  • having proper namespacing with autoloading
  • being able to use bundles for easier separation of business logic
  • going headless first (PW is so close to being there although not focusing on it at all)

 

One question: How would you manage to stay compatible with future PW version? Would that be possible without additional work in the future?

Link to comment
Share on other sites

  • 3 weeks later...

@MrSnoozles thanks for your kind words.

Yeah my main intent is to handle ProcessWire in a sane way with current "best-practices" in PHP Userland.

Which includes things like

  • Composer all the way
  • Dependency Injection 
  • Migrations!!!
  • Separation of concerns (hello Twig for example)
  • proper Headless Content distribution
On 9/28/2021 at 3:53 PM, MrSnoozles said:
  • having the PW core and PW admin be independent packages
  • being able to load these packages through composer
  • having proper namespacing with autoloading
  • being able to use bundles for easier separation of business logic
  • going headless first (PW is so close to being there although not focusing on it at all)

Nice, I had the exact same thoughts so far 🙂

I really like ProcessWire and it is my first go to whenever I need a MVP or an Prototype. But in the long run, or whenever I have more than 1 Developer working on the code the nightmare begins, atleast for me.

On 9/28/2021 at 3:53 PM, MrSnoozles said:

One question: How would you manage to stay compatible with future PW version? Would that be possible without additional work in the future?

I really dont know 🙂

The main problem is the way ProcessWire is organized, as it was never intended to be used as Dependency in another Project. So yeah, right now, whenever @ryan is in production mode and pushes new Versions I have to manually update the codebase. 

The thing is, I started to develop Symprowire because I had a Prototype in ProcessWire which acted as a Proof of Concept for some client presentations. To develop the concept and bring it to production ProcessWire just wasnt enough, I learned it the hard way 🙂 *cough* migrations *cough cough*

So in the course of 1 1/2 year I ported the PoC to Laravel with the intent to use Laravel Spark as our Product is a SaaS with fully fledged Multi-tenancy. Unfortunatly Laravel Spark wasnt that good of a solution back in the days as it was too opinionated and the general direction Laravel as a Framework is developed... mhhh I would say is not my cup of tea. 

So I started to port over to Symfony as we worked with Symfony some years ago to develop a Marketplace supporting 72 Languages and had ~ 350 active sellers from the beginning. I would say it was a fairly big project and I felt confident to work with the Framework, but I missed ProcessWire's CMS/CMF possibilites which ultimatly brings us to Symprowire.

As of today, we ditched ProcessWire completly from our Product and went full ham with Symfony as we are using

  • symfony/notifier for async notifications 
  • symfony/messenger for RabbitMQ 
  • api platform for our headless needs
  • and all the bits and pieces symfony brings

To give you an idea, I just published a basic Fullstack Template covering all our needs. You can find it here: https://github.com/Luis85/symfony-full-skeleton

Right now, I really dont know how to develop Symprowire or in which direction I would like to go with the Project. 
I have a lot of Ideas but every idea would be a complete refactor. I thought something like, yeah just copy the Data Modell ProcessWire uses and port it to Symfony to make a new CMS based on Symfony with the spirit of ProcessWire. I really dont know right now 🙂 What I know is, I want to contribute to ProcessWire.

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      PageMjmlToHtml
      Github: https://github.com/romaincazier/PageMjmlToHtml
      Modules directory: https://processwire.com/modules/page-mjml-to-html/
      A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.
      This is considered to be in alpha and as such needs some testing before being used in production!

      About
      Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.
      Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.
      Prerequisite
      For this module to work you will need to get an API key and paste it in the module’s configuration.
      Usage
      Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.
      From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.
      Features
      The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support
      Notes
      The code viewer is only shown to superusers. If there’s an error the page will display:
      Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
×
×
  • Create New...