M
M
Mitya ToDaSyo2019-06-14 18:03:57
PHP
Mitya ToDaSyo, 2019-06-14 18:03:57

Classes, objects, templates - how right!?

So I came to the study of OOP, swam a little ...
For example, I have an array that can consist of a number, a string, or contain array attachments.

demo array
(он больше, но структура такая...)
$cfg  =  array ( 
     
    'sett'	=>		array (				
      'agent'		=>		11,								
      'search'		=>		90,							
      'check'		=>		3,											
       'crypt'		=>		array (	
        'key'		=>		'XXXXXXXXXXXXXXXXXXX',
        'secret'	=>	        'XXXXXXXXXXXXXXXXXXX'
      )		
    ),
     
    'cargo'		=>		array (
      'JDE'		=>		array (	
        'name'			=>		'XXXXXXXXXXXXXXXXXXX',		
        'user'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'token'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'login'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'pass'			=>		'XXXXXXXXXXXXXXXXXXX'	
      ),	
       
      'DL'			=>		array (
        'name'			=>		'XXXXXXXXXXXXXXXXXXX',		
        'user'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'token'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'login'			=>		'XXXXXXXXXXXXXXXXXXX',	
        'pass'			=>		'XXXXXXXXXXXXXXXXXXX'							
      )
    )
   );
var_dump
int(90)
["check"] =>
 int(3)
["crypt"] =>
 array(2) {
  ["key"] =>
  string(19) "XXXXXXXXXXXXXXXXXXX"
  ["secret"] =>
  string(19) "XXXXXXXXXXXXXXXXXXX"
}
}
["cargo"] =>
 array(2) {
  ["JDE"] =>
  array(5) {
    ["name"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["user"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["token"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["login"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["pass"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
  }
  ["DL"] =>
  array(5) {
    ["name"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["user"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["token"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["login"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
    ["pass"] =>
    string(19) "XXXXXXXXXXXXXXXXXXX"
  }
}                                                                                                                                                                                  
}


These are settings for connecting to different APIs to get information.
I have two ready-made client classes for these APIs, one provided by the developers, the second I made by analogy.
I want to use the class to connect one or another client, which in turn must use the data from the config + receive additional properties when called.
I'm confused, I don't understand:
  • How exactly should I store the config data?!
  • Do I need to do this through a class with a visibility constraint or something else?
  • If it will be a class, is it necessary to use a constructor in this case?

I read about patterns , it got even worse!
  • Should I use a singleton?
  • If this is an object with attachments, then you need to make a pool?

Those. I just got it all mixed up now and I don’t understand how it’s right ... I want to do it as it should, and not as I want))) So now everything works on arrays mixed with objects and separately living two client API classes... So I want to put everything together and make it read)) I don’t ask you to write for me, I ask you to explain where and what in my case is more correct to use, and I already read how they eat it%)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konata Izumi, 2019-06-14
@dimastik1986

How exactly should I store the config data?!

You can do this in a separate file:
return [
   //тут конфиг
]

Then connect this file to where the config is required.
No, because the config contains critical data that is not entered under the git.
Ps instead of array() use []

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question