<?php
declare(strict_types=1);$lane=getenv('COMMENT_LANE');$dm=getenv('POC_DIALECT')==='dm';$db=new PDO($dm?'dm:host=127.0.0.1;port=5238;schema=AIZHCT_APP':'mysql:host='.getenv('POC_AI_HOST').';port='.getenv('POC_AI_PORT').';dbname='.getenv('POC_AI_SCHEMA').';charset='.getenv('POC_AI_CHARSET'),getenv('POC_AI_USER'),getenv('POC_AI_PASSWORD'),[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_CASE=>PDO::CASE_LOWER]);$rows=$db->query('SELECT api_id,url FROM yoshop_store_api ORDER BY api_id LIMIT 2000')->fetchAll(PDO::FETCH_ASSOC);$counts=[];$other=[];foreach($rows as $row){$u=$row['url'];$kind=$u===null?'null':($u===''?'empty':(strpos($u,'://')!==false?'absolute':(strpos($u,'?')!==false?'query':(preg_match('#^/?[A-Za-z0-9_.*:/-]+$#D',$u)?'relative_or_route':'other'))));$counts[$kind]=($counts[$kind]??0)+1;if(in_array($kind,['absolute','query','other'],true))$other[]=['api_id'=>(int)$row['api_id'],'sha256'=>hash('sha256',$u),'length'=>strlen($u),'first_char_code'=>ord(substr($u,0,1))];}$out=['lane'=>$lane,'business_dml'=>0,'shape_counts'=>$counts,'exception_hash_only'=>$other];file_put_contents(__DIR__.'/url-shapes-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode($out),"\n";
