LPH
Well-known member
In my project, there are many files (located externally from XenForo) that use the following type of code:
I'd like to optimize the project by grouping common methods, repetitive code is eliminated, and the call to `getModelFromCache` is done properly. There is a XenWord_Forums class that I'm building but my understanding of OOP is very week. Therefore, I'm looking for help on the best way to organize and optimize the project.
Using this simple skeleton class, as an example, would it be best to take $forumModel and declare it at the top?
Thank you for any explanation and providing resources so that I may learn more about OOP.
PHP:
/** @var $threadModel XenForo_Model_Thread */
$forumModel = XenForo_Model::create( 'XenForo_Model_Forum' )->getModelFromCache( 'XenForo_Model_Forum' );
I'd like to optimize the project by grouping common methods, repetitive code is eliminated, and the call to `getModelFromCache` is done properly. There is a XenWord_Forums class that I'm building but my understanding of OOP is very week. Therefore, I'm looking for help on the best way to organize and optimize the project.
Using this simple skeleton class, as an example, would it be best to take $forumModel and declare it at the top?
Code:
$forumModel = XenForo_Model::create( 'XenForo_Model_Forum' );
PHP:
<?php
class XenWord_Forums extends XenWord {
public function __construct() {
}
/**
* @param $id
* @param array $fetchOptions
*
* @return mixed
* @throws XenForo_Exception
*/
public function getForumById( $id, $fetchOptions = array() ) {
/** @var $forumModel XenForo_Model_Forum getForumById */
$forumModel = XenForo_Model::create( 'XenForo_Model_Forum' );
return $forumModel->getForumById( $id, $fetchOptions );
}
/**
* @param $ids
* @param array $fetchOptions
*
* @return array
* @throws XenForo_Exception
*/
public function getForumsByIds( $ids, $fetchOptions = array() ) {
/** @var $forumModel XenForo_Model_Forum getForumByIds */
$forumModel = XenForo_Model::create( 'XenForo_Model_Forum' );
return $forumModel->getForumsByIds( $ids, $fetchOptions );
}
/**
* @param array $conditions
* @param array $fetchOptions
*
* @return array
* @throws XenForo_Exception
*/
public function getForums(array $conditions = array(), array $fetchOptions = array()) {
/** @var $forumModel XenForo_Model_Forum getForumByIds */
$forumModel = XenForo_Model::create( 'XenForo_Model_Forum' );
return $forumModel->getForums($conditions, $fetchOptions);
}
}
new XenWord_Forums();
Thank you for any explanation and providing resources so that I may learn more about OOP.