1To make the crust, in a bowl (or the bowl of a food processor) combine the flour and salt, then pulse or blend in the butter until almost combined - the mixture should resemble coarse meal. Add the water and stir until the dough comes together. Let it sit on the countertop for 20 minutes to rest - or stick it in the fridge if it's warm.
2On a lightly floured surface, roll the dough out to a 10-12-inch circle - just bigger than a 9 or 10 inch tart pan with a removable bottom. Fit it into the pan and fold the edges over inward, making a double-thick crust; trim to about 1/8-inch above the edge of the pan. (I used a larger pan and so didn't do this - just trimmed it to within 1/8 inch without folding it over.) Preheat oven to 375°F and chill the crust for 20-30 minutes.
3To make the filling, heat the oil and butter in a heavy skillet set over medium-high heat. Saute the onion and mushrooms until soft; add the rosemary, season with salt and pepper and continue cooking until all the liquid has cooked off and the mushrooms are starting to turn golden. If you like, add a shot of Cognac, sherry or brandy and cook until it evaporates. Stir in the ham.
4Line the crust with foil and fill with dried beans or pie weights; bake until golden, about 15 minutes. Sprinkle half the cheese over the bottom of the crust. Cover with the mushroom mixture. Whisk together the cream, yolks and egg - add a few extra snippets of thyme if you like - and pour the custard over the mushrooms. Scatter with the remaining cheese.
5Bake for 30 minutes, until set and golden. Serve warm, at room temperature, or cold.