/** * create metadata * * @throws InvalidOperationException * * @return NorthWindMetadata */ public static function create() { $db_name = ServiceConfig::GetServiceInfo('db_name'); DB::connect(ServiceConfig::GetServiceInfo('server'), $db_name, ServiceConfig::GetServiceInfo('user'), ServiceConfig::GetServiceInfo('password')); $metadata = new ServiceBaseMetadata('DefaultEntities', $db_name); $tables = DB::table("select `table_name`,`table_type` from information_schema.tables where `table_schema`='{$db_name}';"); foreach ($tables as $table) { $postsEntityType = $metadata->addEntityType(new ReflectionClass('EmptyEntity'), $table['table_name']); } return $metadata; }
/** * create metadata * * @return NorthWindMetadata */ public static function create() { $metadata = new ServiceBaseMetadata('NorthWindEntities', 'NorthWind'); //Register the entity (resource) type 'category' $categoryEntityType = $metadata->addEntityType(new ReflectionClass('category'), 'category', 'NorthWind'); $metadata->addKeyProperty($categoryEntityType, 'CategoryID', EdmPrimitiveType::BOOLEAN); $metadata->addPrimitiveProperty($categoryEntityType, 'CategoryName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($categoryEntityType, 'Description', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($categoryEntityType, 'Picture', EdmPrimitiveType::STRING); //Register the entity (resource) type 'customer' $customerEntityType = $metadata->addEntityType(new ReflectionClass('customer'), 'customer', 'NorthWind'); $metadata->addKeyProperty($customerEntityType, 'CustomerID', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'CompanyName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'ContactName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'ContactTitle', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'Address', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'City', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'Region', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'PostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'Country', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'Phone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customerEntityType, 'Fax', EdmPrimitiveType::STRING); //Register the entity (resource) type 'employee' $employeeEntityType = $metadata->addEntityType(new ReflectionClass('employee'), 'employee', 'NorthWind'); $metadata->addKeyProperty($employeeEntityType, 'EmployeeID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($employeeEntityType, 'LastName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'FirstName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Title', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'TitleOfCourtesy', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'BirthDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($employeeEntityType, 'HireDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($employeeEntityType, 'Address', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'City', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Region', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'PostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Country', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'HomePhone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Extension', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Photo', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Notes', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'ReportsTo', EdmPrimitiveType::INT32); //Register the entity (resource) type 'order_detail' $order_detailEntityType = $metadata->addEntityType(new ReflectionClass('order_detail'), 'order_detail', 'NorthWind'); $metadata->addKeyProperty($order_detailEntityType, 'ID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($order_detailEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($order_detailEntityType, 'ProductID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($order_detailEntityType, 'UnitPrice', EdmPrimitiveType::DOUBLE); $metadata->addPrimitiveProperty($order_detailEntityType, 'Quantity', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($order_detailEntityType, 'Discount', EdmPrimitiveType::DOUBLE); //Register the entity (resource) type 'order' $orderEntityType = $metadata->addEntityType(new ReflectionClass('order'), 'order', 'NorthWind'); $metadata->addKeyProperty($orderEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'CustomerID', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'EmployeeID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'OrderDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'RequiredDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'ShippedDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'ShipVia', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'Freight', EdmPrimitiveType::DOUBLE); $metadata->addPrimitiveProperty($orderEntityType, 'ShipName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipAddress', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipCity', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipRegion', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipPostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipCountry', EdmPrimitiveType::STRING); //Register the entity (resource) type 'product' $productEntityType = $metadata->addEntityType(new ReflectionClass('product'), 'product', 'NorthWind'); $metadata->addKeyProperty($productEntityType, 'ProductID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($productEntityType, 'ProductName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($productEntityType, 'SupplierID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($productEntityType, 'CategoryID', EdmPrimitiveType::BOOLEAN); $metadata->addPrimitiveProperty($productEntityType, 'QuantityPerUnit', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($productEntityType, 'UnitPrice', EdmPrimitiveType::DOUBLE); $metadata->addPrimitiveProperty($productEntityType, 'UnitsInStock', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($productEntityType, 'UnitsOnOrder', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($productEntityType, 'ReorderLevel', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($productEntityType, 'Discontinued', EdmPrimitiveType::STRING); //Register the entity (resource) type 'shipper' $shipperEntityType = $metadata->addEntityType(new ReflectionClass('shipper'), 'shipper', 'NorthWind'); $metadata->addKeyProperty($shipperEntityType, 'ShipperID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($shipperEntityType, 'CompanyName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($shipperEntityType, 'Phone', EdmPrimitiveType::STRING); //Register the entity (resource) type 'supplier' $supplierEntityType = $metadata->addEntityType(new ReflectionClass('supplier'), 'supplier', 'NorthWind'); $metadata->addKeyProperty($supplierEntityType, 'SupplierID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($supplierEntityType, 'CompanyName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'ContactName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'ContactTitle', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'Address', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'City', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'Region', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'PostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'Country', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'Phone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'Fax', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($supplierEntityType, 'HomePage', EdmPrimitiveType::STRING); $categoriesResourceSet = $metadata->addResourceSet('categories', $categoryEntityType); $customersResourceSet = $metadata->addResourceSet('customers', $customerEntityType); $employeesResourceSet = $metadata->addResourceSet('employees', $employeeEntityType); $order_detailsResourceSet = $metadata->addResourceSet('order_details', $order_detailEntityType); $ordersResourceSet = $metadata->addResourceSet('orders', $orderEntityType); $productsResourceSet = $metadata->addResourceSet('products', $productEntityType); $shippersResourceSet = $metadata->addResourceSet('shippers', $shipperEntityType); $suppliersResourceSet = $metadata->addResourceSet('suppliers', $supplierEntityType); //Register the assoications (navigations) $metadata->addResourceSetReferenceProperty($employeeEntityType, 'employees', $employeesResourceSet); $metadata->addResourceReferenceProperty($order_detailEntityType, 'order', $ordersResourceSet); $metadata->addResourceSetReferenceProperty($orderEntityType, 'order_details', $order_detailsResourceSet); $metadata->addResourceReferenceProperty($order_detailEntityType, 'product', $productsResourceSet); $metadata->addResourceSetReferenceProperty($productEntityType, 'order_details', $order_detailsResourceSet); $metadata->addResourceReferenceProperty($orderEntityType, 'customer', $customersResourceSet); $metadata->addResourceSetReferenceProperty($customerEntityType, 'orders', $ordersResourceSet); $metadata->addResourceReferenceProperty($orderEntityType, 'employee', $employeesResourceSet); $metadata->addResourceSetReferenceProperty($employeeEntityType, 'orders', $ordersResourceSet); $metadata->addResourceReferenceProperty($orderEntityType, 'shipper', $shippersResourceSet); $metadata->addResourceSetReferenceProperty($shipperEntityType, 'orders', $ordersResourceSet); $metadata->addResourceReferenceProperty($productEntityType, 'category', $categoriesResourceSet); $metadata->addResourceSetReferenceProperty($categoryEntityType, 'products', $productsResourceSet); $metadata->addResourceReferenceProperty($productEntityType, 'supplier', $suppliersResourceSet); $metadata->addResourceSetReferenceProperty($supplierEntityType, 'products', $productsResourceSet); return $metadata; }
/** * create metadata * * @throws InvalidOperationException * * @return NorthWindMetadata */ public static function create() { $metadata = new ServiceBaseMetadata('NorthWindEntities', 'NorthWind'); //Register the complex type 'Address' having a property of same type. $addressComplexType = $metadata->addComplexType(new ReflectionClass('Address'), 'Address', 'NorthWind', null); $metadata->addPrimitiveProperty($addressComplexType, 'StreetName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'City', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'Region', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'PostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'Country', EdmPrimitiveType::STRING); //A complex sub property to hold alternate address $metadata->addComplexProperty($addressComplexType, 'AltAddress', $addressComplexType); //Register the entity (resource) type 'Customer' $customersEntityType = $metadata->addEntityType(new ReflectionClass('Customer'), 'Customer', 'NorthWind'); $metadata->addKeyProperty($customersEntityType, 'CustomerID', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'CompanyName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'ContactName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'ContactTitle', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'Phone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'Fax', EdmPrimitiveType::STRING); $metadata->addComplexProperty($customersEntityType, 'Address', $addressComplexType); //Add a bag property (bag of complex type) to hold array of other addresses $metadata->addComplexProperty($customersEntityType, 'OtherAddresses', $addressComplexType, true); //Add a bag property (bag of primitve type) to hold array of email addresses $metadata->addPrimitiveProperty($customersEntityType, 'EmailAddresses', EdmPrimitiveType::STRING, true); //Register the entity (resource) type 'Order' $orderEntityType = $metadata->addEntityType(new ReflectionClass('Order'), 'Order', 'NorthWind'); $metadata->addKeyProperty($orderEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'CustomerID', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'EmployeeID', EdmPrimitiveType::INT32); //Adding an etag property $metadata->addETagProperty($orderEntityType, 'OrderDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'RequiredDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'ShippedDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'ShipVia', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'Freight', EdmPrimitiveType::DECIMAL); $metadata->addPrimitiveProperty($orderEntityType, 'ShipName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipAddress', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipCity', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipRegion', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipPostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ShipCountry', EdmPrimitiveType::STRING); //Register the entity (resource) type 'Order_Details' $orderDetailsEntityType = $metadata->addEntityType(new ReflectionClass('Order_Details'), 'Order_Details', 'NorthWind'); $metadata->addKeyProperty($orderDetailsEntityType, 'ProductID', EdmPrimitiveType::INT32); $metadata->addKeyProperty($orderDetailsEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'UnitPrice', EdmPrimitiveType::DECIMAL); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'Quantity', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'Discount', EdmPrimitiveType::SINGLE); //Register the entity (resource) type 'Employee' $employeeEntityType = $metadata->addEntityType(new ReflectionClass('Employee'), 'Employee', 'NorthWind'); $metadata->addKeyProperty($employeeEntityType, 'EmployeeID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($employeeEntityType, 'FirstName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'LastName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Title', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'TitleOfCourtesy', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'BirthDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($employeeEntityType, 'HireDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($employeeEntityType, 'Address', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'City', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Region', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'PostalCode', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Country', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'HomePhone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Extension', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'Notes', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'ReportsTo', EdmPrimitiveType::INT32); //$metadata->addPrimitiveProperty($employeeEntityType, 'Photo', EdmPrimitiveType::BINARY); $metadata->addPrimitiveProperty($employeeEntityType, 'Emails', EdmPrimitiveType::STRING, true); $metadata->addPrimitiveProperty($employeeEntityType, 'PhotoPath', EdmPrimitiveType::STRING); //Set Employee entity type as MLE thus the url http://host/NorthWind.svc/Employee(1875)/$value will give the stream associated with employee with id 1875 $employeeEntityType->setMediaLinkEntry(true); //Add a named stream property to the employee entity type //so the url http://host/NorthWind.svc/Employee(9831)/TumbNail_48X48 will give stream associated with employee's thumbnail (of size 48 x 48) image //$streamInfo = new ResourceStreamInfo('TumbNail_48X48'); //$employeeEntityType->addNamedStream($streamInfo); $customersResourceSet = $metadata->addResourceSet('Customers', $customersEntityType); $ordersResourceSet = $metadata->addResourceSet('Orders', $orderEntityType); $orderDetialsResourceSet = $metadata->addResourceSet('Order_Details', $orderDetailsEntityType); $employeeResourceSet = $metadata->addResourceSet('Employees', $employeeEntityType); //Register the assoications (navigations) //Customers (1) <==> Orders (0-*) $metadata->addResourceSetReferenceProperty($customersEntityType, 'Orders', $ordersResourceSet); $metadata->addResourceReferenceProperty($orderEntityType, 'Customer', $customersResourceSet); //Register the assoications (navigations) //Orders (1) <==> Orders_Details (0-*) $metadata->addResourceReferenceProperty($orderDetailsEntityType, 'Order', $ordersResourceSet); $metadata->addResourceSetReferenceProperty($orderEntityType, 'Order_Details', $orderDetialsResourceSet); return $metadata; }
/** * create metadata * * @throws InvalidOperationException * * @return NorthWindMetadata */ public static function create() { $metadata = new ServiceBaseMetadata('WordPressEntities', 'WordPress'); //Register the entity (resource) type 'Post' $postsEntityType = $metadata->addEntityType(new ReflectionClass('Post'), 'Post', 'WordPress'); $metadata->addKeyProperty($postsEntityType, 'PostID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($postsEntityType, 'Author', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($postsEntityType, 'Date', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($postsEntityType, 'DateGmt', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($postsEntityType, 'Content', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Title', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Excerpt', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Status', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'CommentStatus', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'PingStatus', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Password', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Name', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'ToPing', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'Pinged', EdmPrimitiveType::STRING); $metadata->addETagProperty($postsEntityType, 'Modified', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($postsEntityType, 'ModifiedGmt', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($postsEntityType, 'ContentFiltered', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'ParentID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($postsEntityType, 'Guid', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'MenuOrder', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($postsEntityType, 'Type', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'MimeType', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($postsEntityType, 'CommentCount', EdmPrimitiveType::INT32); //Register the entity (resource) type 'Tag' $tagsEntityType = $metadata->addEntityType(new ReflectionClass('Tag'), 'Tag', 'WordPress'); $metadata->addKeyProperty($tagsEntityType, 'TagID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($tagsEntityType, 'Name', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($tagsEntityType, 'Slug', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($tagsEntityType, 'Description', EdmPrimitiveType::STRING); //Register the entity (resource) type 'Category' $catsEntityType = $metadata->addEntityType(new ReflectionClass('Category'), 'Category', 'WordPress'); $metadata->addKeyProperty($catsEntityType, 'CategoryID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($catsEntityType, 'Name', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($catsEntityType, 'Slug', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($catsEntityType, 'Description', EdmPrimitiveType::STRING); //Register the entity (resource) type 'Comment' $commentsEntityType = $metadata->addEntityType(new ReflectionClass('Comment'), 'Comment', 'WordPress'); $metadata->addKeyProperty($commentsEntityType, 'CommentID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($commentsEntityType, 'PostID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($commentsEntityType, 'Author', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'AuthorEmail', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'AuthorUrl', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'AuthorIp', EdmPrimitiveType::STRING); $metadata->addETagProperty($commentsEntityType, 'Date', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($commentsEntityType, 'DateGmt', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($commentsEntityType, 'Content', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'Karma', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($commentsEntityType, 'Approved', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'Agent', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'Type', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($commentsEntityType, 'ParentID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($commentsEntityType, 'UserID', EdmPrimitiveType::INT32); //Register the entity (resource) type 'User' $usersEntityType = $metadata->addEntityType(new ReflectionClass('User'), 'User', 'WordPress'); $metadata->addKeyProperty($usersEntityType, 'UserID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($usersEntityType, 'Login', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($usersEntityType, 'Nicename', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($usersEntityType, 'Email', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($usersEntityType, 'Url', EdmPrimitiveType::STRING); $metadata->addETagProperty($usersEntityType, 'Registered', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($usersEntityType, 'Status', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($usersEntityType, 'DisplayName', EdmPrimitiveType::STRING); $postsResourceSet = $metadata->addResourceSet('Posts', $postsEntityType); $tagsResourceSet = $metadata->addResourceSet('Tags', $tagsEntityType); $catsResourceSet = $metadata->addResourceSet('Categories', $catsEntityType); $commentsResourceSet = $metadata->addResourceSet('Comments', $commentsEntityType); $usersResourceSet = $metadata->addResourceSet('Users', $usersEntityType); //associations of Post $metadata->addResourceReferenceProperty($postsEntityType, 'User', $usersResourceSet); $metadata->addResourceSetReferenceProperty($postsEntityType, 'Tags', $tagsResourceSet); $metadata->addResourceSetReferenceProperty($postsEntityType, 'Categories', $catsResourceSet); $metadata->addResourceSetReferenceProperty($postsEntityType, 'Comments', $commentsResourceSet); //associations of Tag $metadata->addResourceSetReferenceProperty($tagsEntityType, 'Posts', $postsResourceSet); //associations of Category $metadata->addResourceSetReferenceProperty($catsEntityType, 'Posts', $postsResourceSet); //associations of Comment $metadata->addResourceReferenceProperty($commentsEntityType, 'User', $usersResourceSet); $metadata->addResourceReferenceProperty($commentsEntityType, 'Post', $postsResourceSet); //associations of User $metadata->addResourceSetReferenceProperty($usersEntityType, 'Posts', $postsResourceSet); $metadata->addResourceSetReferenceProperty($usersEntityType, 'Comments', $commentsResourceSet); return $metadata; }
/** * * * @throws InvalidOperationException * @return NorthWindMetadata */ public static function Create() { $metadata = new ServiceBaseMetadata('NorthWindEntities', 'NorthWind'); //Register the complex type 'Address2' $address2ComplexType = $metadata->addComplexType(new ReflectionClass('Address2'), 'Address2'); $metadata->addPrimitiveProperty($address2ComplexType, 'IsPrimary', EdmPrimitiveType::BOOLEAN); //Register the complex type 'Address' with 'Address2' as base class $addressComplexType = $metadata->addComplexType(new ReflectionClass('Address4'), 'Address'); $metadata->addPrimitiveProperty($addressComplexType, 'HouseNumber', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'LineNumber', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($addressComplexType, 'LineNumber2', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($addressComplexType, 'StreetName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($addressComplexType, 'IsValid', EdmPrimitiveType::BOOLEAN); $metadata->addComplexProperty($addressComplexType, 'Address2', $address2ComplexType); //Register the entity (resource) type 'Customer' $customersEntityType = $metadata->addEntityType(new ReflectionClass('Customer2'), 'Customer'); $metadata->addKeyProperty($customersEntityType, 'CustomerID', EdmPrimitiveType::STRING); $metadata->addKeyProperty($customersEntityType, 'CustomerGuid', EdmPrimitiveType::GUID); $metadata->addPrimitiveProperty($customersEntityType, 'CustomerName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'Country', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($customersEntityType, 'Rating', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($customersEntityType, 'Photo', EdmPrimitiveType::BINARY); $metadata->addComplexProperty($customersEntityType, 'Address', $addressComplexType); //Register the entity (resource) type 'Order' $orderEntityType = $metadata->addEntityType(new ReflectionClass('Order2'), 'Order'); $metadata->addKeyProperty($orderEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'OrderDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'DeliveryDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($orderEntityType, 'ShipName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($orderEntityType, 'ItemCount', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'QualityRate', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderEntityType, 'Price', EdmPrimitiveType::DOUBLE); //Register the entity (resource) type 'Product2' $productEntityType = $metadata->addEntityType(new ReflectionClass('Product2'), 'Product'); $metadata->addKeyProperty($productEntityType, 'ProductID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($productEntityType, 'ProductName', EdmPrimitiveType::STRING); //Register the entity (resource) type 'Order_Details' $orderDetailsEntityType = $metadata->addEntityType(new ReflectionClass('Order_Details2'), 'Order_Details'); $metadata->addKeyProperty($orderDetailsEntityType, 'ProductID', EdmPrimitiveType::INT32); $metadata->addKeyProperty($orderDetailsEntityType, 'OrderID', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'UnitPrice', EdmPrimitiveType::DECIMAL); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'Quantity', EdmPrimitiveType::INT16); $metadata->addPrimitiveProperty($orderDetailsEntityType, 'Discount', EdmPrimitiveType::SINGLE); //Register the entity (resource) type 'Employee' $employeeEntityType = $metadata->addEntityType(new ReflectionClass('Employee2'), 'Employee'); $metadata->addKeyProperty($employeeEntityType, 'EmployeeID', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'FirstName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'LastName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($employeeEntityType, 'ReportsTo', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($employeeEntityType, 'Emails', EdmPrimitiveType::STRING, true); //Set Employee entity type as MLE thus the url http://host/NorthWind.svc/Employee(1875)/$value will give the stream associated with employee with id 1875 $employeeEntityType->setMediaLinkEntry(true); //Add a named stream property to the employee entity type //so the url http://host/NorthWind.svc/Employee(9831)/TumbNail_48X48 will give stream associated with employee's thumbnail (of size 48 x 48) image $streamInfo = new ResourceStreamInfo('TumbNail_48X48'); $employeeEntityType->addNamedStream($streamInfo); //Register the entity (resource) sets $customersResourceSet = $metadata->addResourceSet('Customers', $customersEntityType); $ordersResourceSet = $metadata->addResourceSet('Orders', $orderEntityType); $productResourceSet = $metadata->addResourceSet('Products', $productEntityType); $orderDetailsEntitySet = $metadata->addResourceSet('Order_Details', $orderDetailsEntityType); $employeeSet = $metadata->addResourceSet('Employees', $employeeEntityType); //Register the assoications (navigations) //Customers (1) <==> Orders (0-*) $metadata->addResourceSetReferenceProperty($customersEntityType, 'Orders', $ordersResourceSet); $metadata->addResourceReferenceProperty($orderEntityType, 'Customer', $customersResourceSet); //Orders (1) <==> Order_Details (0-*) //Products (1) <==> Order_Details (0-*) $metadata->addResourceReferenceProperty($orderDetailsEntityType, 'Order', $ordersResourceSet); $metadata->addResourceReferenceProperty($orderDetailsEntityType, 'Product', $productResourceSet); $metadata->addResourceSetReferenceProperty($productEntityType, 'Order_Details', $orderDetailsEntitySet); $metadata->addResourceSetReferenceProperty($orderEntityType, 'Order_Details', $orderDetailsEntitySet); //Employees (1) <==> Employees (1) 'Manager //Employees (1) <==> Employees (*) 'Subordinates $metadata->addResourceReferenceProperty($employeeEntityType, 'Manager', $employeeSet); $metadata->addResourceSetReferenceProperty($employeeEntityType, 'Subordinates', $employeeSet); return $metadata; }
/** * create metadata * * @return InventoryMetadata */ public static function create() { $metadata = new ServiceBaseMetadata('InventoryEntities', 'Inventory'); //Register the entity (resource) type 'event' $eventEntityType = $metadata->addEntityType(new ReflectionClass('event'), 'event', 'Inventory'); $metadata->addKeyProperty($eventEntityType, 'eventId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($eventEntityType, 'eventName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($eventEntityType, 'eventDescription', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($eventEntityType, 'location', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($eventEntityType, 'eventStartDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($eventEntityType, 'eventEndDate', EdmPrimitiveType::DATETIME); $metadata->addPrimitiveProperty($eventEntityType, 'userName', EdmPrimitiveType::STRING); //Register the entity (resource) type 'event_inventory' $event_inventoryEntityType = $metadata->addEntityType(new ReflectionClass('event_inventory'), 'event_inventory', 'Inventory'); $metadata->addKeyProperty($event_inventoryEntityType, 'eventInventoryId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($event_inventoryEntityType, 'itemId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($event_inventoryEntityType, 'eventId', EdmPrimitiveType::INT32); //Register the entity (resource) type 'event_user' $event_userEntityType = $metadata->addEntityType(new ReflectionClass('event_user'), 'event_user', 'Inventory'); $metadata->addKeyProperty($event_userEntityType, 'evetUserId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($event_userEntityType, 'userName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($event_userEntityType, 'eventId', EdmPrimitiveType::INT32); //Register the entity (resource) type 'inventory' $inventoryEntityType = $metadata->addEntityType(new ReflectionClass('inventory'), 'inventory', 'Inventory'); $metadata->addKeyProperty($inventoryEntityType, 'inventoryItemId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($inventoryEntityType, 'itemId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($inventoryEntityType, 'condition', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($inventoryEntityType, 'lastCheckedOutBy', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($inventoryEntityType, 'checkOutDate', EdmPrimitiveType::DATETIME); //Register the entity (resource) type 'item' $itemEntityType = $metadata->addEntityType(new ReflectionClass('item'), 'item', 'Inventory'); $metadata->addKeyProperty($itemEntityType, 'itemId', EdmPrimitiveType::INT32); $metadata->addPrimitiveProperty($itemEntityType, 'itemName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($itemEntityType, 'description', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($itemEntityType, 'pricing', EdmPrimitiveType::DOUBLE); $metadata->addPrimitiveProperty($itemEntityType, 'locationPurchased', EdmPrimitiveType::STRING); //Register the entity (resource) type 'user' $userEntityType = $metadata->addEntityType(new ReflectionClass('user'), 'user', 'Inventory'); $metadata->addKeyProperty($userEntityType, 'userName', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($userEntityType, 'authToken', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($userEntityType, 'name', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($userEntityType, 'address', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($userEntityType, 'phone', EdmPrimitiveType::STRING); $metadata->addPrimitiveProperty($userEntityType, 'email', EdmPrimitiveType::STRING); $eventsResourceSet = $metadata->addResourceSet('events', $eventEntityType); $event_inventoriesResourceSet = $metadata->addResourceSet('event_inventories', $event_inventoryEntityType); $event_usersResourceSet = $metadata->addResourceSet('event_users', $event_userEntityType); $inventoriesResourceSet = $metadata->addResourceSet('inventories', $inventoryEntityType); $itemsResourceSet = $metadata->addResourceSet('items', $itemEntityType); $usersResourceSet = $metadata->addResourceSet('users', $userEntityType); //Register the assoications (navigations) $metadata->addResourceReferenceProperty($eventEntityType, 'user', $usersResourceSet); $metadata->addResourceSetReferenceProperty($userEntityType, 'events', $eventsResourceSet); $metadata->addResourceReferenceProperty($event_inventoryEntityType, 'event', $eventsResourceSet); $metadata->addResourceSetReferenceProperty($eventEntityType, 'event_inventories', $event_inventoriesResourceSet); $metadata->addResourceReferenceProperty($event_inventoryEntityType, 'inventory', $inventoriesResourceSet); $metadata->addResourceSetReferenceProperty($inventoryEntityType, 'event_inventories', $event_inventoriesResourceSet); $metadata->addResourceReferenceProperty($event_userEntityType, 'event', $eventsResourceSet); $metadata->addResourceSetReferenceProperty($eventEntityType, 'event_users', $event_usersResourceSet); $metadata->addResourceReferenceProperty($event_userEntityType, 'user', $usersResourceSet); $metadata->addResourceSetReferenceProperty($userEntityType, 'event_users', $event_usersResourceSet); $metadata->addResourceReferenceProperty($inventoryEntityType, 'user', $usersResourceSet); $metadata->addResourceSetReferenceProperty($userEntityType, 'inventories', $inventoriesResourceSet); $metadata->addResourceReferenceProperty($inventoryEntityType, 'item', $itemsResourceSet); $metadata->addResourceSetReferenceProperty($itemEntityType, 'inventories', $inventoriesResourceSet); return $metadata; }