Php use case это

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

License

GCDTech/php-usecase-pattern

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

A UseCase is a single class, implementing one ‘use case’ of the application business logic. It co-ordinates the manipulation of application state to acheive it’s purpose.

By using only simple objects and primitive types as parameters and return types the use cases of your application are a permanent representation of your business logic and moving to a new language or framework should not require any significant recoding.

2. Integrate with framework as a plugin

Where use cases need to interact with external layers (for example to persist changes in state) this should always be acheived by wrapping the framework functionality as a service and injecting it as a dependancy. This ensures that the UseCases can always be moved to a new framework and the interop with the framework is easily assessed, rewritten and replaced with no changes to the UseCase code or tests.

Читайте также:  Html color dark to light

As UseCases only deal with pure and simple PHP classes they should be 100% testable and so TDD should be the favoured approach to development.

A UseCase should be focused on completing one business goal — for example creation of an invoice. Where the action requires a concert of other changes this can be acheived by calling other UserCases.

Generally a UseCase has a single method ‘execute’ which takes arguments and returns a response value. It may also have a constructor through which service dependancies are injected.

class DispatchOrderUseCase extends UseCase < private $emailProvider; public function __construct(EmailProvider $email) < $this->emailProvider = $email; > public function execute(Order $order) < // . Do something to despatch the order $this->emailProvider->send(new DispatchEmail($order)); > >

A UseCase should not be instantiated directly except in unit tests. In production code the static create() method ensure dependancies are injected using the DI container.

// Note no mention of the EmailProvider here. DispatchOrderUseCase::create()->execute($order);

An entity is a simple POPO (Plain Old PHP Object) with no frills that represents the data passed into and out of UseCases. Generally an entity can be regarded as a model for a business object.

This library defines a base Entity class only to allow for basic type recognition (e.g. $arg instanceof Entity)

ORMs generally support representing collections as iterable objects creating objects lazily as required. This is good practice to keep memory usage to the minimum possible. To represent a list we’ve provided an EntityEmittingIterator that extends the base Iterator PHP interface and can be used to classify parameter and return types.

About

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

Источник

Php use case это

The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

Note: Note that unlike some other languages, the continue statement applies to switch and acts similar to break . If you have a switch inside a loop and wish to continue to the next iteration of the outer loop, use continue 2 .

In the following example, each code block is equivalent. One uses a series of if and elseif statements, and the other a switch statement. In each case, the output is the same.

Читайте также:  Python процент схожести строк

Example #1 switch structure

switch ( $i ) case 0 :
echo «i equals 0» ;
break;
case 1 :
echo «i equals 1» ;
break;
case 2 :
echo «i equals 2» ;
break;
>

if ( $i == 0 ) echo «i equals 0» ;
> elseif ( $i == 1 ) echo «i equals 1» ;
> elseif ( $i == 2 ) echo «i equals 2» ;
>
?>

It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found whose expression evaluates to a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don’t write a break statement at the end of a case’s statement list, PHP will go on executing the statements of the following case. For example:

switch ( $i ) case 0 :
echo «i equals 0» ;
case 1 :
echo «i equals 1» ;
case 2 :
echo «i equals 2» ;
>
?>

Here, if $i is equal to 0, PHP would execute all of the echo statements! If $i is equal to 1, PHP would execute the last two echo statements. You would get the expected behavior (‘i equals 2’ would be displayed) only if $i is equal to 2. Thus, it is important not to forget break statements (even though you may want to avoid supplying them on purpose under certain circumstances).

In a switch statement, the condition is evaluated only once and the result is compared to each case statement. In an elseif statement, the condition is evaluated again. If your condition is more complicated than a simple compare and/or is in a tight loop, a switch may be faster.

The statement list for a case can also be empty, which simply passes control into the statement list for the next case.

Читайте также:  Configure error cannot find php config please use with php config path

switch ( $i ) case 0 :
case 1 :
case 2 :
echo «i is less than 3 but not negative» ;
break;
case 3 :
echo «i is 3» ;
>
?>

A special case is the default case. This case matches anything that wasn’t matched by the other cases. For example:

switch ( $i ) case 0 :
echo «i equals 0» ;
break;
case 1 :
echo «i equals 1» ;
break;
case 2 :
echo «i equals 2» ;
break;
default:
echo «i is not equal to 0, 1 or 2» ;
>
?>

Note: Multiple default cases will raise a E_COMPILE_ERROR error.

Note: Technically the default case may be listed in any order. It will only be used if no other case matches. However, by convention it is best to place it at the end as the last branch.

If no case branch matches, and there is no default branch, then no code will be executed, just as if no if statement was true.

A case value may be given as an expression. However, that expression will be evaluated on its own and then loosely compared with the switch value. That means it cannot be used for complex evaluations of the switch value. For example:

switch ( $target ) case $start — 1 :
print «A» ;
break;
case $start — 2 :
print «B» ;
break;
case $start — 3 :
print «C» ;
break;
case $start — 4 :
print «D» ;
break;
>

For more complex comparisons, the value true may be used as the switch value. Or, alternatively, if — else blocks instead of switch .

switch ( true ) case $start — $offset === 1 :
print «A» ;
break;
case $start — $offset === 2 :
print «B» ;
break;
case $start — $offset === 3 :
print «C» ;
break;
case $start — $offset === 4 :
print «D» ;
break;
>

The alternative syntax for control structures is supported with switches. For more information, see Alternative syntax for control structures.

switch ( $i ):
case 0 :
echo «i equals 0» ;
break;
case 1 :
echo «i equals 1» ;
break;
case 2 :
echo «i equals 2» ;
break;
default:
echo «i is not equal to 0, 1 or 2» ;
endswitch;
?>

It’s possible to use a semicolon instead of a colon after a case like:

switch( $beer )
case ‘tuborg’ ;
case ‘carlsberg’ ;
case ‘stella’ ;
case ‘heineken’ ;
echo ‘Good choice’ ;
break;
default;
echo ‘Please make a new selection. ‘ ;
break;
>
?>

Источник

Оцените статью