Code style used with Table::getInstance i Joomla4

Visto 106 veces
Saltar al primer mensaje no leído

Fros...@koonsoft.dk

no leída,
10 nov 2018, 10:25:3410/11/18
a Joomla! CMS Development

Looking at the code style used in the current code may well be a bit confused.

 

I'm trying to find the best style to copy to the future code.

I'm aware that Joomla4 should still be able to execute  Joomla 3.x code. (more or less)

 

We must remember that this style will be copied for the next 5 years or more.


You need to select the code style you want.

 

Example 1:

administrator\components\com_newsfeeds\Helper\AssociationsHelper.php(127):

                             $table = Table::getInstance('NewsfeedTable', 'Joomla\\Component\\Newsfeeds\\Administrator\\Table\\');

administrator\components\com_newsfeeds\Table\NewsfeedTable.php(185):

                             $table = Table::getInstance('NewsfeedTable', __NAMESPACE__ . '\\', array('dbo' => $this->_db));

 

Here you can see two different code styles

  1. Use __NAMESPACE__
  2. An array is used ('dbo' => $ this -> _ db)

Comment to 1)

I prefer not to use __NAMESPACE__, given the use of the JPATH_COMPONENT discussion. It does not take long before this style are copied.


Question to 2)

Usually you use the active database driver object ($db) or not?

 

 

Example 2:

plugins\sampledata\multilong\ multilang.php (1031):

$ category = Table :: getInstance ('CategoryTable', '\\ Joomla \\ Component \\ Categories \\ Administrator \\ Table \\');

administrator \ components \ com_associations \ Model \ AssociationsModel.php (393):

$ categoryTable = Table :: getInstance ('Category', 'JTable');

administrator \ components \ com_banners \ Model \ BannerModel.php (128):

$ categoryTable = Table :: getInstance ('Category');

 

Comment to Example 2:

Everything else et is a table "class" obejct that we need to have an instance of.

Personally, I personally like it from sample data, as it will look like the one that our components need

 

$ table = Table :: getInstance ('{name} Table', '\\ {vendor} \\ Component \\ {componenNeme} \\ Administrator \\ Table \\');

 

Example 3:

installation\src\Model\LanguagesModel.php(1333):

$tableItem = Table::getInstance('Menu', 'MenusTable');

libraries\src\Installer\Adapter\ComponentAdapter.php(1087):

$table = Table::getInstance('menu');


Comment to Example 3:

I think this code are  not done or it's a mistake.

 

Since my English is not a strong side, I would like to apologize in advance if my writing style strikes someone. It has nothing proven, but an error on my part

Yours sincerely
Karsten F.

Michael Babker

no leída,
10 nov 2018, 11:42:3510/11/18
a joomla-...@googlegroups.com
__NAMESPACE__ is a PHP "magic" constant, meaning its value is different based on the class/file it is used in (so for Joomla\CMS\Http\Http the __NAMESPACE__ constant would resolve to Joomla\CMS\Http, for Joomla\CMS\Table\Table it would be Joomla\CMS\Table).  This behavior is similar to __DIR__ or __FILE__ or __CLASS__.  It is nothing like the JPATH_COMPONENT constant which is in essence hardcoded to the active component for a given request.

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send email to joomla-...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/d/optout.

Fros...@koonsoft.dk

no leída,
10 nov 2018, 12:27:1710/11/18
a Joomla! CMS Development
 I'm aware that __NAMESPACE__ and more will be generated automatically.
What if I just copy the code into another method under another NAMESPACE, we reuse the code.

This is the part of the reuse or code that my post is about.

then there are still examples 2 and 3.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos