Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objectification #7847

Merged

Conversation

Sesquipedalian
Copy link
Member

Refactors SMF to use the object oriented code paradigm.

@jdarwood007
Copy link
Member

I think the build job is failing because of this:

2023-11-04T20:56:41.2259237Z Could not locate SMF_SOFTWARE_YEAR

@jdarwood007 jdarwood007 added this to the 3.0 Alpha 1 milestone Nov 4, 2023
@frandominguezl
Copy link
Member

Oh, this is awesome. I have no words!

I will look into this further, but this was pretty much needed and I'm glad that you had time to do this. Out of curiosity, for how long have you been working on this?

@Sesquipedalian
Copy link
Member Author

Sesquipedalian commented Nov 4, 2023

Oh, this is awesome. I have no words!

Thanks! 😄

Out of curiosity, for how long have you been working on this?

Checks commit log...

Since Dec 22, 2022, at 20:21:21 UTC.

@jdarwood007
Copy link
Member

jdarwood007 commented Nov 4, 2023

( ! ) Fatal error: Uncaught Error: Typed static property SMF\Db\DatabaseApi::$db must not be accessed before initialization in /Sources/ErrorHandler.php on line 465
( ! ) Error: Typed static property SMF\Db\DatabaseApi::$db must not be accessed before initialization in //Sources/ErrorHandler.php on line 465
Call Stack
#	Time	Memory	Function	Location
1	0.0004	376416	{main}( )	.../index.php:0
2	0.0800	805696	SMF\Forum->__construct( )	.../index.php:130
3	0.0808	807496	SMF\Db\DatabaseApi::load( $options = ??? )	.../Forum.php:203
4	0.0884	873912	SMF\Db\APIs\MySQL->__construct( $options = [] )	.../DatabaseApi.php:360
5	0.0963	1020544	SMF\Db\APIs\MySQL->initiate( $user = '##########', $passwd = '######', $options = ['dont_select_db' => FALSE] )	.../MySQL.php:1917
6	0.0993	1027936	SMF\ErrorHandler::displayDbError( )	.../MySQL.php:1998

Looks like $db isn't there yet because of this:

		$class = __NAMESPACE__ . '\\APIs\\' . $class;
		self::$db = new $class($options);

Then when loading the database, we do so in the construct. Essentially we never can get a $db.

I debated if I should just fix this, but wanted to pass it through you, as its going to be a core issue and I'm still new to this code base. My idea was to have the API store the result of $class then have the Db hold a static error method which can call $db or if its not there, fall back to $class::error. Seems to fix it and provide a safe way to always just call Db::error and let it handle it.

Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
This eliminates a whole bunch of redundant code and variables.

Signed-off-by: Jon Stovell <[email protected]>
Done in a separate commit to preserve history.
Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
Signed-off-by: Jon Stovell <[email protected]>
Also adds SMF\Unicode\Utf8String::extractWords(), which does a much better job of finding words in non-ASCII strings than the old code did. There is still room for improvement, but that will have to wait until later.

Signed-off-by: Jon Stovell <[email protected]>
Also fixes truncate_array(), since it didn't actually work. Also removes useless $deep parameter.

Signed-off-by: Jon Stovell <[email protected]>
Like Load.php, Subs.php has been removed rather than turned into a backward compatibility stub file because every existing mod would assume that it had already been included and wouldn't try to include it themselves. The class_exists() calls in Subs-Compat.php are all we need to do now to maintain backward compatibility for those mods.

Signed-off-by: Jon Stovell <[email protected]>
@Sesquipedalian
Copy link
Member Author

My idea was to have the API store the result of $class then have the Db hold a static error method which can call $db or if its not there, fall back to $class::error. Seems to fix it and provide a safe way to always just call Db::error and let it handle it.

I did something simpler:

$db_error = isset(Db::$db) ? @Db::$db->error() : '';

@Sesquipedalian
Copy link
Member Author

I'm going to go ahead and merge this monster now. Bug fixes for any of it can be added in later PRs.

@Sesquipedalian Sesquipedalian merged commit 9eba82f into SimpleMachines:release-3.0 Nov 5, 2023
3 checks passed
@Sesquipedalian Sesquipedalian deleted the 3.0_objectification branch November 5, 2023 05:59
@jdarwood007
Copy link
Member

My idea was to have the API store the result of $class then have the Db hold a static error method which can call $db or if its not there, fall back to $class::error. Seems to fix it and provide a safe way to always just call Db::error and let it handle it.

I did something simpler:

$db_error = isset(Db::$db) ? @Db::$db->error() : '';

Only issue with that is now we have no error information. It should be possible to get the error info, even from a failed connection.

@Sesquipedalian
Copy link
Member Author

Good point. Feel free to submit a PR. 🙂

@shmax
Copy link

shmax commented Jan 7, 2024

Bravo, sir. This was long overdue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants