findout:api-dev
Différences
Ci-dessous, les différences entre deux révisions de la page.
| findout:api-dev [2023/08/09 19:35] – created 85.169.126.26 | findout:api-dev [2023/10/13 09:58] (Version actuelle) – supprimée admin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | **hierarchie** | ||
| - | |||
| - | < | ||
| - | classes/< | ||
| - | classes/< | ||
| - | </ | ||
| - | |||
| - | chaque classe inclut | ||
| - | < | ||
| - | set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__)); | ||
| - | </ | ||
| - | |||
| - | **apiPath.php** | ||
| - | |||
| - | < | ||
| - | <?php | ||
| - | |||
| - | $sApiPaths = '[ | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | { " | ||
| - | ]' ; | ||
| - | |||
| - | spl_autoload_register(function($className) { | ||
| - | $fileName = stream_resolve_include_path(' | ||
| - | if ($fileName !== false) { | ||
| - | include $fileName; | ||
| - | } | ||
| - | }); | ||
| - | spl_autoload_register(function($traitName) { | ||
| - | $fileName = stream_resolve_include_path(' | ||
| - | if ($fileName !== false) { | ||
| - | include $fileName; | ||
| - | } | ||
| - | }); | ||
| - | |||
| - | function apiPathMatch ( $method, $path ) { | ||
| - | $aPath = explode ( '/', | ||
| - | $iParts = count ( $aPath ) ; | ||
| - | $sFirst = $aPath [ 0 ] ; | ||
| - | $sMethod = $method ; | ||
| - | |||
| - | $aCompare = sortPaths () ; | ||
| - | foreach ( $aCompare as $iKey => $aValue ) { | ||
| - | if ( $method != $aValue [ ' | ||
| - | if ( $sFirst != $aValue [ ' | ||
| - | if ( $iParts < $aValue [ ' | ||
| - | if ( $iParts > $aValue [ ' | ||
| - | |||
| - | if ( $iParts == 1 ) { | ||
| - | doThings ( $aValue [ ' | ||
| - | return ; | ||
| - | } | ||
| - | |||
| - | $iCount = 0 ; | ||
| - | foreach ( explode ( '/', | ||
| - | $iCount++ ; | ||
| - | if ( preg_match ( '/ | ||
| - | if ( $sPath != $aPath [ $iKey2 ] ) break ; | ||
| - | } | ||
| - | if ( $iCount == $iParts ) { | ||
| - | doThings ( $aValue [ ' | ||
| - | return ; | ||
| - | } | ||
| - | } | ||
| - | echo "No match" ; | ||
| - | } | ||
| - | |||
| - | function sortPaths () { | ||
| - | global $sApiPaths ; | ||
| - | |||
| - | $aPaths = json_decode ( $sApiPaths, true ) ; | ||
| - | |||
| - | foreach ( $aPaths as $iKey => $aPath ) { | ||
| - | $sLocalPath = $aPath [' | ||
| - | $sLocalGo = $aPath [' | ||
| - | $aLocalPath = explode ('/', | ||
| - | $iLocalPart = count ( $aLocalPath ) ; | ||
| - | $sLocalFirst = $aLocalPath [0] ; | ||
| - | $sLocalMethod = $aPath [ ' | ||
| - | |||
| - | $aLocalResult [ $iKey ] [ ' | ||
| - | $aLocalResult [ $iKey ] [ ' | ||
| - | $aLocalResult [ $iKey ] [ ' | ||
| - | $aLocalResult [ $iKey ] [ ' | ||
| - | $aLocalResult [ $iKey ] [ ' | ||
| - | |||
| - | $aSort1 [ $iKey ] = $sLocalFirst ; | ||
| - | $aSort2 [ $iKey ] = $iLocalPart ; | ||
| - | } | ||
| - | |||
| - | array_multisort($aSort1, | ||
| - | |||
| - | return $aLocalResult ; | ||
| - | } | ||
| - | |||
| - | function doThings( $class, $method, $path) | ||
| - | { | ||
| - | $o = new $class () ; | ||
| - | $a = explode ( ';', | ||
| - | $m = $a [ 0 ] ; | ||
| - | $p = explode ( ',', | ||
| - | $pa = explode ( '/', | ||
| - | $pl = [] ; | ||
| - | foreach ( $p as $k => $pn ) { | ||
| - | echo "avec le param : " . $pa [ $pn ] . " | ||
| - | $pl [] = $pa [ $pn ] ; | ||
| - | } | ||
| - | |||
| - | $o -> {$m} ( $pl ) ; | ||
| - | } | ||
| - | |||
| - | apiPathMatch ( ' | ||
| - | |||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | **Classe : obj2** | ||
| - | * classes/ | ||
| - | |||
| - | < | ||
| - | <?php | ||
| - | |||
| - | set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__)); | ||
| - | |||
| - | class obj1 { | ||
| - | use obj1Get ; | ||
| - | use obj1GetAll ; | ||
| - | use obj1Patch ; | ||
| - | |||
| - | private $text; | ||
| - | |||
| - | function __construct () { | ||
| - | $this -> text = 'Je suis OBJ1' ; | ||
| - | } | ||
| - | |||
| - | public function getText () { | ||
| - | return ( $this -> text ) ; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | **Trait : obj2GetDetail** | ||
| - | * classes/ | ||
| - | * paramètre : tableau de valeurs * | ||
| - | |||
| - | < | ||
| - | <?php | ||
| - | |||
| - | trait obj2GetDetail { | ||
| - | function getDetail ( $p ) { | ||
| - | echo $this -> text () . " | ||
| - | echo "- dans getDetails" | ||
| - | echo "- params : " . $p [0] . ", " . $p [1] . " | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
findout/api-dev.1691602522.txt.gz · Dernière modification : 2023/08/09 19:35 de 85.169.126.26