php - Defining class constants in facades -


I have some libraries that are set for my large application which reveal the constant.

For example, I

my class definition looks like this:

  & lt; Php? There is a class to calculate the holidays and work days, some reports are used to calculate the number of working days. Name Location MyApp \ libraries; / ** * Holig Calculation Helper Library * An Assistant Class to Calculate Vacations and Work Days * / Class Vacations {* ** Define EBS Vacations: New Year's Day * / Const New_IERS_AY = "New Year's Day"; / ** * Defined EBS Holidays: Independence Day * / Combined INDEPENDENCE_DAY = "Independence Day"; / ** * Defined EBS Holiday: Christmas Day * / Cut CHRISTMAS_DAY = "Christmas Day"; ...  

They are used by a date method (for example), which takes the leave constant value and one year and that holiday The date gives it in the year. I have a mask and a service provider, so this library can be used in Lorval Way and Trade . Everything works perfectly, I have a unit test for everything, and I'm happy with the code. / P>

The question I have is how to refer to these constants, if I am using the mask and calling the library from other parts of my code, then it seems:

< Pre> $ xmas = \ holidays: date (\ MyApp \ library \ holidays: CHRISTMAS_DAY, "2014");

It works, but I like to use the mask to do it, like:

  $ xmas = \ holidays: date (\ Holidays :: Christmas, "2014");  

I have thought of a solution that defines the constants in the mask it works, but then I am isolating values ​​continuously from the library - for obvious reasons, I I would prefer to keep those values ​​with those codes from which they are connected.

Then, I have another solution: Define the constants as above, then refer them to the mask like this:

   

Now I can mention the constant through a mask rather than a fully qualified library class, and I have to define only once for a static value (though I It is necessary to add any new constants to both the Library and the Mask), and this is what I want, but it seems a bit like a violation of the Drought (repeat theory itself).

So here's the question. What is the best way to do this?

You can use use your \ MyApp \ Library \ Holidays surname, but unfortunately, a serious error will be thrown by using leave , so I suggest aliasing it as holidays> which will give you future Can save some confusion in

Before you declare your class announcement and add your name after declaring location ...

  Use \ MyApp \ libraries for holidays vacations in the form of;  

Use inside your class like this ....

  $ xmas = \ holidays :: date (vacation :: CHRISTMAS_DAY, " 2014 ");  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -