. namespace core\router\parameters; use core\exception\not_found_exception; use core\param; use core\user; use core\router\schema\example; use core\router\schema\parameters\mapped_property_parameter; use core\router\schema\referenced_object; use Psr\Http\Message\ServerRequestInterface; /** * A parameter representing a user. * * @package core * @copyright Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class path_user extends \core\router\schema\parameters\path_parameter implements mapped_property_parameter, referenced_object { /** * Create a new instance of the path_user. * * @param string $name The name of the parameter to use for the identifier * @param mixed ...$extra Additional arguments */ public function __construct( string $name = 'user', ...$extra, ) { $extra['name'] = $name; $extra['type'] = param::RAW; $extra['description'] = <<get_user_for_value($value); $request = $request->withAttribute($this->name, $user); if ($user->id) { $request = $request->withAttribute("{$this->name}context", \core\context\user::instance($user->id)); } return $request; } #[\Override] public function get_schema_from_type(param $type): \stdClass { $schema = parent::get_schema_from_type($type); $schema->pattern = "^("; $schema->pattern .= implode("|", [ 'current', '\d+', 'idnumber:.+', 'username:.+', ]); $schema->pattern .= ")$"; return $schema; } }