We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I was thinking about the location of files for MODx service classes that are created by components -- i.e., inside or outside the core.

    You could make an argument for keeping the core limited to stuff that is put there by an official install. OTOH, if they’re all in /core/model/modx/service_name, it makes them easy to find.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 28215
      • 4,149 Posts
      Quote from: BobRay at Feb 10, 2009, 02:03 PM

      You could make an argument for keeping the core limited to stuff that is put there by an official install. OTOH, if they’re all in /core/model/modx/service_name, it makes them easy to find.

      Welcome to the Great Debate. Jason and I have been talking about separation vs. standardization for months, and we still can’t decide on anything. tongue

        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: BobRay at Feb 10, 2009, 02:03 PM

        You could make an argument for keeping the core limited to stuff that is put there by an official install. OTOH, if they’re all in /core/model/modx/service_name, it makes them easy to find.
        Technically, I would consider these things we’ve termed service classes to simply be classes that may be represented in another model or as a model by themselves. In any case, as long as they are in a model package, you can configure the base location of that specific package, so, ultimately it’s up to you. There is no issue with separation if you keep your packages separate from the modx package, so I would recommend using the core/model location and adding a subdirectory for your specific model outside of the modx/ directory, using a convention like core/model/developer-or-company/specific-component-package/ or core/model/custom-model-name/sub-component-package.

        The benefits of using the core/model/ location include:
        [*] Easier to find everything
        [*] Potentially faster class loading: the fewer package locations to search through, the better
        [*] Core deployments with multiple configurations can share the code
        [*] The core can (and really should) be deployed outside of the web server, so the code is generally more secure

        The problems of using core/model/ include:
        [*] Shared core deployments would require upgrades to be coordinated across all configurations
        [*] Requires more careful organization of code and installation workflow

        IMO, we should ultimately allow components that consist of more than just a snippet or plugin record in the db to allow the user to configure the location of such files interactively during installation and/or manually via appropriate system or context settings. The reason is, with more advanced configurations, especially multi-site, shared-core setups, some components make sense as shared across all site configurations, and some might be better in their own isolated locations (could also be outside the web server directories) for each specific site or a set of them.
          • 3749
          • 24,544 Posts
          IMO, we should ultimately allow components that consist of more than just a snippet or plugin record in the db to allow the user to configure the location of such files interactively during installation and/or manually via appropriate system or context settings. The reason is, with more advanced configurations, especially multi-site, shared-core setups, some components make sense as shared across all site configurations, and some might be better in their own isolated locations (could also be outside the web server directories) for each specific site or a set of them.

          I can see the value of setting the locations at install (presumably in a "custom" install versus a "standard" install), although it might be easier for everyone if the developer decides how the item is likely to be used and locates it appropriately, since most users won’t know what to do when faced with that question. Tools to relocate add-ons might be a part of a multi-sits config tool.

          Of course I’m wondering now if EZfaq, SPForm, and Captcha (not to mention Wayfinder and Ditto) should be moved inside the core since it would be efficient for them to be shared in a multiple-site environment.

          With respect to your comments about locations inside the core, I’ve been looking harder at the current configuration and it’s made me more confused.

          Class files for xmlrpc and xmlrss (and all their supporting files) are in

          core/model/modx/xmlrpc
          core/model/modx/xmlrss

          That seems to violate what you’re suggesing if I understand you.

          For Smarty, otoh, most of the Smarty files are in

          core/model/smarty

          but the smarty class file is in

          core/model/modx/smarty

          Let me ask something more concrete. For the Mollom package, if it were you, where would you put the mollom class file and where would you put the rest of the files (e.g. ixr_lib.inc, readme, etc.)?
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            Quote from: BobRay at Feb 10, 2009, 09:22 PM

            Let me ask something more concrete. For the Mollom package, if it were you, where would you put the mollom class file and where would you put the rest of the files (e.g. ixr_lib.inc, readme, etc.)?

            Bump . . . I’m leaning toward core/model/modx/mollom/ for Revo and /assets/snippet/mollom/ for Evo but could be convinced otherwise. wink
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 22303 MODX Staff
              • 10,725 Posts
              In regards to xmlrpc and jsonrpc, "Do as I say, not as I do" tongue

              I would say the package should be simply mollum (not modx.mollum, unless you have a custom class for integrating it with modx separate from a set of classes provided by mollum, then both packages may be necessary, as with Smarty).

              And core/model is just the base_path of a model package; that should always be configurable IMO.
                • 3749
                • 24,544 Posts
                So you’re saying /core/model/mollom/xml-rpc.lib, right, even though it becomes a service class instantiated with $modx->getService()?

                BTW, what are the advantages of using$modx-> getService() rather than just including the class file and using "new." ?
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: BobRay at Feb 14, 2009, 03:39 PM

                  So you’re saying /core/model/mollom/xml-rpc.lib, right, even though it becomes a service class instantiated with $modx->getService()?
                  Well, yes, but isn’t there going to be a modMollum class to integrate it? i.e. the mollum model contains the mollum files as is, then in modx.mollum you could create modMollum (like modSmarty), if that’s necessary. I don’t know anything about mollum, so I don’t know what is appropriate exactly. It always depends on how the code was constructed.

                  Quote from: BobRay at Feb 14, 2009, 03:39 PM

                  BTW, what are the advantages of using$modx-> getService() rather than just including the class file and using "new." ?
                  The object becomes a member variable of the $modx instance, and is then instantly available to any code where you have access to $modx. It also can be used multiple times in a request, and will just get the existing service instance if it was already instantiated. It also automatically passed a reference to $modx and an array of parameters to the class so that it can also have access back to $modx if need be. This prevents sloppy reliance on global variables.

                  Think of it as placeholders for object instances that might be reusable in multiple components on a page.
                    • 3749
                    • 24,544 Posts
                    Quote from: OpenGeek at Feb 15, 2009, 12:52 PM

                    Quote from: BobRay at Feb 14, 2009, 03:39 PM

                    So you’re saying /core/model/mollom/xml-rpc.lib, right, even though it becomes a service class instantiated with $modx->getService()?
                    Well, yes, but isn’t there going to be a modMollom class to integrate it? i.e. the mollom model contains the mollom files as is, then in modx.mollom you could create modMollom (like modSmarty), if that’s necessary. I don’t know anything about mollom, so I don’t know what is appropriate exactly. It always depends on how the code was constructed.
                    Yes, there is a modmollom.class.php and I could certainly do it like Smarty, but since there will then be a core/model/modx/mollom, is there a reason not to put all the files there and keep them together?-- it’s a very small package - one lib, the class file, an example.php andd a readme should do it.

                    Quote from: BobRay at Feb 14, 2009, 03:39 PM

                    BTW, what are the advantages of using$modx-> getService() rather than just including the class file and using "new." ?

                    The object becomes a member variable of the $modx instance, and is then instantly available to any code where you have access to $modx. It also can be used multiple times in a request, and will just get the existing service instance if it was already instantiated. It also automatically passed a reference to $modx and an array of parameters to the class so that it can also have access back to $modx if need be. This prevents sloppy reliance on global variables.

                    Think of it as placeholders for object instances that might be reusable in multiple components on a page.

                    Good to know. A page that uses Mollom would make a number of separate calls to the service.

                    Does the service object survive a page reload?
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Quote from: BobRay at Feb 15, 2009, 03:34 PM

                      Yes, there is a modmollom.class.php and I could certainly do it like Smarty, but since there will then be a core/model/modx/mollom, is there a reason not to put all the files there and keep them together?-- it’s a very small package - one lib, the class file, an example.php andd a readme should do it.
                      Just the reasons we have already discussed; mostly isolating the external third party artifacts from those that integrate it into MODx specifically. I am going to do this with the xml/jsonrpc as well, since you brought it up.

                      Quote from: BobRay at Feb 15, 2009, 03:34 PM

                      Does the service object survive a page reload?
                      Never; nothing in PHP ever survives a page load. To persist objects or data across page loads, you can use PHP sessions, files, a custom database table, or modRegistry.