1 | <?php |
||
23 | class Taxonomy extends Component |
||
24 | { |
||
25 | /* @var Connection The db connection component */ |
||
26 | public $db = 'db'; |
||
27 | public $table = 'taxonomy'; |
||
28 | //cache array of initialized terms |
||
29 | private $_taxonomy = []; |
||
30 | // |
||
31 | public $definitions = []; |
||
32 | |||
33 | public function isTermInstalled($termName) |
||
38 | |||
39 | public function addTerm($term, $object_id, $params) |
||
44 | |||
45 | public function removeTerm($term, $object_id, $params = []) |
||
50 | |||
51 | public function getTerms($term, $object_id, $name = null) |
||
56 | |||
57 | /** |
||
58 | * @param $termName |
||
59 | * @return BaseTerm |
||
60 | * @throws InvalidConfigException |
||
61 | * @throws TermNotDefinedException |
||
62 | */ |
||
63 | public function getTerm($termName, $reload = false) |
||
64 | { |
||
65 | if(!isset($this->_taxonomy[$termName]) or $reload) { |
||
|
|||
66 | $tax = TaxonomyDef::findOne(['name' => $termName]); |
||
67 | \Yii::getLogger()->log("Initialising term $termName", Logger::LEVEL_INFO, 'nkostadinov.taxonomy.terms'); |
||
68 | $this->_taxonomy[$termName] = \Yii::createObject($tax->attributes); |
||
69 | } |
||
70 | return $this->_taxonomy[$termName]; |
||
71 | } |
||
72 | |||
73 | public function isInstalled() |
||
77 | |||
78 | /** |
||
79 | * @return array |
||
80 | */ |
||
81 | public function getDefinitions() |
||
88 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.