From ac7f5e753cdd4db2b6203bedbbb51cd5d0675960 Mon Sep 17 00:00:00 2001 From: visavi Date: Tue, 22 Oct 2019 13:15:58 +0300 Subject: [PATCH] 2.5 spec --- .gitignore | 4 + LICENSE | 675 ++++++++++++++ README.md | 36 + composer.json | 33 + phpunit.php | 7 + phpunit.xml | 11 + src/BidRequest/App.php | 457 +++++++++ src/BidRequest/Audio.php | 648 +++++++++++++ src/BidRequest/Banner.php | 575 ++++++++++++ src/BidRequest/BidRequest.php | 645 +++++++++++++ src/BidRequest/Content.php | 712 ++++++++++++++ src/BidRequest/Data.php | 140 +++ src/BidRequest/Deal.php | 226 +++++ src/BidRequest/Device.php | 857 +++++++++++++++++ src/BidRequest/Ext.php | 9 + src/BidRequest/Format.php | 161 ++++ src/BidRequest/Geo.php | 392 ++++++++ src/BidRequest/Imp.php | 546 +++++++++++ src/BidRequest/Metric.php | 100 ++ src/BidRequest/Native.php | 176 ++++ src/BidRequest/Pmp.php | 112 +++ src/BidRequest/Producer.php | 153 +++ src/BidRequest/Publisher.php | 156 ++++ src/BidRequest/Regs.php | 67 ++ src/BidRequest/Segment.php | 117 +++ src/BidRequest/Site.php | 454 +++++++++ src/BidRequest/Source.php | 112 +++ src/BidRequest/Specification/AdPosition.php | 20 + .../Specification/ApiFrameworks.php | 18 + src/BidRequest/Specification/AuctionType.php | 13 + .../Specification/BannerAdTypes.php | 20 + .../Specification/BannerMimeType.php | 14 + src/BidRequest/Specification/BitType.php | 13 + .../Specification/ConnectionType.php | 18 + .../Specification/ContentContext.php | 18 + .../Specification/ContentDeliveryMethods.php | 18 + .../Specification/CreativeAttributes.php | 34 + src/BidRequest/Specification/DeviceType.php | 18 + .../Specification/ExpandableDirection.php | 15 + src/BidRequest/Specification/FeedType.php | 18 + src/BidRequest/Specification/Gender.php | 16 + .../Specification/LocationService.php | 19 + src/BidRequest/Specification/LocationType.php | 14 + .../Specification/PlaybackCessationMode.php | 24 + .../Specification/ProductionQuality.php | 19 + .../Specification/QagMediaRatings.php | 14 + src/BidRequest/Specification/StartDelay.php | 13 + .../Specification/VastCompanionTypes.php | 14 + .../VideoBidResponseProtocols.php | 26 + .../Specification/VideoLinearity.php | 18 + .../Specification/VideoMimeType.php | 13 + .../Specification/VideoPlacementType.php | 45 + .../Specification/VideoPlaybackMethods.php | 27 + .../Specification/VolumeNormalizationMode.php | 20 + src/BidRequest/User.php | 255 +++++ src/BidRequest/Video.php | 874 ++++++++++++++++++ src/BidResponse/Bid.php | 816 ++++++++++++++++ src/BidResponse/BidResponse.php | 232 +++++ src/BidResponse/Ext.php | 9 + src/BidResponse/Seatbid.php | 140 +++ src/BidResponse/Specification/BitType.php | 13 + src/BidResponse/Specification/NoBidReason.php | 20 + src/Hydrator.php | 124 +++ src/Mapper/Map.php | 78 ++ src/Mapper/MapFactory.php | 101 ++ src/Mapper/MapItem.php | 134 +++ src/Mapper/Mapper.php | 139 +++ src/NativeAdRequest/Assets.php | 182 ++++ src/NativeAdRequest/Data.php | 89 ++ src/NativeAdRequest/Ext.php | 9 + src/NativeAdRequest/Image.php | 203 ++++ src/NativeAdRequest/NativeAdRequest.php | 226 +++++ src/NativeAdRequest/Specification/BitType.php | 13 + .../Specification/DataAssetType.php | 24 + .../Specification/ImageAssetType.php | 15 + .../Specification/ImageMimeType.php | 22 + .../Specification/NativeAdUnit.php | 25 + .../Specification/NativeLayout.php | 21 + .../Specification/VideoMimeType.php | 38 + src/NativeAdRequest/Title.php | 62 ++ src/NativeAdRequest/Video.php | 164 ++++ src/NativeAdResponse/Assets.php | 208 +++++ src/NativeAdResponse/Data.php | 89 ++ src/NativeAdResponse/Ext.php | 9 + src/NativeAdResponse/Image.php | 115 +++ src/NativeAdResponse/Link.php | 126 +++ src/NativeAdResponse/Native.php | 196 ++++ src/NativeAdResponse/NativeAdResponse.php | 37 + src/NativeAdResponse/Title.php | 63 ++ src/NativeAdResponse/Video.php | 40 + src/Tools/Classes/ArrayCollection.php | 262 ++++++ src/Tools/Classes/Ext.php | 51 + .../Exceptions/ExceptionInvalidValue.php | 29 + .../ExceptionMissingRequiredField.php | 9 + src/Tools/Interfaces/Arrayable.php | 11 + src/Tools/ObjectAnalyzer/AnnotationsBag.php | 84 ++ src/Tools/ObjectAnalyzer/Bag.php | 10 + src/Tools/ObjectAnalyzer/ObjectDescriber.php | 56 ++ .../ObjectAnalyzer/ObjectDescriberFactory.php | 88 ++ src/Tools/ObjectAnalyzer/ParametersBag.php | 95 ++ src/Tools/Traits/Cache.php | 40 + src/Tools/Traits/GetConstants.php | 31 + src/Tools/Traits/SetterValidation.php | 246 +++++ src/Tools/Traits/ToArray.php | 84 ++ tests/AccessProtectedMethod.php | 17 + tests/BidRequest/BidRequestTest.php | 24 + .../Specification/ApiFrameworksTest.php | 15 + tests/HydratorTest.php | 224 +++++ tests/Mapper/MapFactoryTest.php | 30 + tests/Mapper/MapperTest.php | 82 ++ tests/Tools/Classes/ArrayCollectionTest.php | 166 ++++ .../ObjectAnalyzer/ObjectDescriberTest.php | 39 + tests/Tools/Traits/GetConstantsTest.php | 27 + tests/Tools/Traits/SetterValidationTest.php | 289 ++++++ .../Traits/SetterValidationTracerTest.php | 22 + 115 files changed, 15042 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100755 composer.json create mode 100644 phpunit.php create mode 100644 phpunit.xml create mode 100644 src/BidRequest/App.php create mode 100644 src/BidRequest/Audio.php create mode 100644 src/BidRequest/Banner.php create mode 100644 src/BidRequest/BidRequest.php create mode 100644 src/BidRequest/Content.php create mode 100644 src/BidRequest/Data.php create mode 100644 src/BidRequest/Deal.php create mode 100644 src/BidRequest/Device.php create mode 100644 src/BidRequest/Ext.php create mode 100644 src/BidRequest/Format.php create mode 100644 src/BidRequest/Geo.php create mode 100644 src/BidRequest/Imp.php create mode 100644 src/BidRequest/Metric.php create mode 100644 src/BidRequest/Native.php create mode 100644 src/BidRequest/Pmp.php create mode 100644 src/BidRequest/Producer.php create mode 100644 src/BidRequest/Publisher.php create mode 100644 src/BidRequest/Regs.php create mode 100644 src/BidRequest/Segment.php create mode 100644 src/BidRequest/Site.php create mode 100644 src/BidRequest/Source.php create mode 100644 src/BidRequest/Specification/AdPosition.php create mode 100644 src/BidRequest/Specification/ApiFrameworks.php create mode 100644 src/BidRequest/Specification/AuctionType.php create mode 100644 src/BidRequest/Specification/BannerAdTypes.php create mode 100644 src/BidRequest/Specification/BannerMimeType.php create mode 100644 src/BidRequest/Specification/BitType.php create mode 100644 src/BidRequest/Specification/ConnectionType.php create mode 100644 src/BidRequest/Specification/ContentContext.php create mode 100644 src/BidRequest/Specification/ContentDeliveryMethods.php create mode 100644 src/BidRequest/Specification/CreativeAttributes.php create mode 100644 src/BidRequest/Specification/DeviceType.php create mode 100644 src/BidRequest/Specification/ExpandableDirection.php create mode 100644 src/BidRequest/Specification/FeedType.php create mode 100644 src/BidRequest/Specification/Gender.php create mode 100644 src/BidRequest/Specification/LocationService.php create mode 100644 src/BidRequest/Specification/LocationType.php create mode 100644 src/BidRequest/Specification/PlaybackCessationMode.php create mode 100644 src/BidRequest/Specification/ProductionQuality.php create mode 100644 src/BidRequest/Specification/QagMediaRatings.php create mode 100644 src/BidRequest/Specification/StartDelay.php create mode 100644 src/BidRequest/Specification/VastCompanionTypes.php create mode 100644 src/BidRequest/Specification/VideoBidResponseProtocols.php create mode 100644 src/BidRequest/Specification/VideoLinearity.php create mode 100644 src/BidRequest/Specification/VideoMimeType.php create mode 100644 src/BidRequest/Specification/VideoPlacementType.php create mode 100644 src/BidRequest/Specification/VideoPlaybackMethods.php create mode 100644 src/BidRequest/Specification/VolumeNormalizationMode.php create mode 100644 src/BidRequest/User.php create mode 100644 src/BidRequest/Video.php create mode 100644 src/BidResponse/Bid.php create mode 100644 src/BidResponse/BidResponse.php create mode 100644 src/BidResponse/Ext.php create mode 100644 src/BidResponse/Seatbid.php create mode 100644 src/BidResponse/Specification/BitType.php create mode 100644 src/BidResponse/Specification/NoBidReason.php create mode 100644 src/Hydrator.php create mode 100644 src/Mapper/Map.php create mode 100644 src/Mapper/MapFactory.php create mode 100644 src/Mapper/MapItem.php create mode 100644 src/Mapper/Mapper.php create mode 100644 src/NativeAdRequest/Assets.php create mode 100644 src/NativeAdRequest/Data.php create mode 100644 src/NativeAdRequest/Ext.php create mode 100644 src/NativeAdRequest/Image.php create mode 100644 src/NativeAdRequest/NativeAdRequest.php create mode 100644 src/NativeAdRequest/Specification/BitType.php create mode 100644 src/NativeAdRequest/Specification/DataAssetType.php create mode 100644 src/NativeAdRequest/Specification/ImageAssetType.php create mode 100644 src/NativeAdRequest/Specification/ImageMimeType.php create mode 100644 src/NativeAdRequest/Specification/NativeAdUnit.php create mode 100644 src/NativeAdRequest/Specification/NativeLayout.php create mode 100644 src/NativeAdRequest/Specification/VideoMimeType.php create mode 100644 src/NativeAdRequest/Title.php create mode 100644 src/NativeAdRequest/Video.php create mode 100644 src/NativeAdResponse/Assets.php create mode 100644 src/NativeAdResponse/Data.php create mode 100644 src/NativeAdResponse/Ext.php create mode 100644 src/NativeAdResponse/Image.php create mode 100644 src/NativeAdResponse/Link.php create mode 100644 src/NativeAdResponse/Native.php create mode 100644 src/NativeAdResponse/NativeAdResponse.php create mode 100644 src/NativeAdResponse/Title.php create mode 100644 src/NativeAdResponse/Video.php create mode 100644 src/Tools/Classes/ArrayCollection.php create mode 100644 src/Tools/Classes/Ext.php create mode 100644 src/Tools/Exceptions/ExceptionInvalidValue.php create mode 100644 src/Tools/Exceptions/ExceptionMissingRequiredField.php create mode 100644 src/Tools/Interfaces/Arrayable.php create mode 100644 src/Tools/ObjectAnalyzer/AnnotationsBag.php create mode 100644 src/Tools/ObjectAnalyzer/Bag.php create mode 100644 src/Tools/ObjectAnalyzer/ObjectDescriber.php create mode 100644 src/Tools/ObjectAnalyzer/ObjectDescriberFactory.php create mode 100644 src/Tools/ObjectAnalyzer/ParametersBag.php create mode 100644 src/Tools/Traits/Cache.php create mode 100644 src/Tools/Traits/GetConstants.php create mode 100644 src/Tools/Traits/SetterValidation.php create mode 100644 src/Tools/Traits/ToArray.php create mode 100644 tests/AccessProtectedMethod.php create mode 100644 tests/BidRequest/BidRequestTest.php create mode 100644 tests/BidRequest/Specification/ApiFrameworksTest.php create mode 100644 tests/HydratorTest.php create mode 100644 tests/Mapper/MapFactoryTest.php create mode 100644 tests/Mapper/MapperTest.php create mode 100644 tests/Tools/Classes/ArrayCollectionTest.php create mode 100644 tests/Tools/ObjectAnalyzer/ObjectDescriberTest.php create mode 100644 tests/Tools/Traits/GetConstantsTest.php create mode 100644 tests/Tools/Traits/SetterValidationTest.php create mode 100644 tests/Tools/Traits/SetterValidationTracerTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cea3189 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +vendor +composer.lock +!.gitkeep \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..733c072 --- /dev/null +++ b/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..da31843 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# OpenRTB +iab, RTB Project, OpenRTB Specification 2.5 + +## Example +``` +$imp = new Imp(); +$imp->setId('1'); + +$video = new Video(); +$video->setMimes( + [ + 'video/mp4', + 'application/x-shockwave-flash', + 'application/javascript', + 'video/webm', + 'video/mpg' + ] +) + ->setMinduration(1); + ->setMaxduration(120); + ->setProtocols([2, 3, 5, 6, 7, 8]); + ->setW(576); + ->setH(320); + ->setLinearity(2); + ->setSkip(1); + +$imp->setVideo($video); + +$bidRequest = new BidRequest(); +$bidRequest + ->setId('test-id') + ->addImp($imp); + + +$request = json_encode($bidRequest->toArray()); +``` diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..c18ee31 --- /dev/null +++ b/composer.json @@ -0,0 +1,33 @@ +{ + "name": "visavi/openrtb", + "type": "library", + "description": "OpenRTB specification", + "keywords": ["openrtb"], + "license": "GPL-2.0", + "authors": [ + { + "name": "Alexander Grigorev", + "email": "admin@visavi.net", + "homepage": "https://visavi.net" + } + ], + "require": { + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "phpunit/phpunit": "8.3.5" + }, + "autoload": { + "psr-4": { + "OpenRtb\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "OpenRtb\\Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/phpunit.php b/phpunit.php new file mode 100644 index 0000000..ac77551 --- /dev/null +++ b/phpunit.php @@ -0,0 +1,7 @@ + + + + tests + + + \ No newline at end of file diff --git a/src/BidRequest/App.php b/src/BidRequest/App.php new file mode 100644 index 0000000..71e8329 --- /dev/null +++ b/src/BidRequest/App.php @@ -0,0 +1,457 @@ +initialize(); + } + + public function initialize() + { + $this->setPublisher(new Publisher()); + $this->setContent(new Content()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getBundle() + { + return $this->bundle; + } + + /** + * @param string $bundle + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBundle($bundle) + { + $this->validateString($bundle); + $this->bundle = $bundle; + return $this; + } + + /** + * @return string + */ + public function getDomain() + { + return $this->domain; + } + + /** + * @param string $domain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDomain($domain) + { + $this->validateString($domain); + $this->domain = $domain; + return $this; + } + + /** + * @return string + */ + public function getStoreurl() + { + return $this->storeurl; + } + + /** + * @param string $storeurl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setStoreurl($storeurl) + { + $this->validateString($storeurl); + $this->storeurl = $storeurl; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param string $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat[] = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return array + */ + public function getSectioncat() + { + return $this->sectioncat; + } + + /** + * @param string $sectioncat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addSectioncat($sectioncat) + { + $this->validateString($sectioncat); + $this->sectioncat[] = $sectioncat; + return $this; + } + + /** + * @param array $sectioncat + * @return $this + */ + public function setSectioncat(array $sectioncat) + { + $this->sectioncat = $sectioncat; + return $this; + } + + /** + * @return array + */ + public function getPagecat() + { + return $this->pagecat; + } + + /** + * @param string $pagecat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addPagecat($pagecat) + { + $this->validateString($pagecat); + $this->pagecat[] = $pagecat; + return $this; + } + + /** + * @param array $pagecat + * @return $this + */ + public function setPagecat(array $pagecat) + { + $this->pagecat = $pagecat; + return $this; + } + + /** + * @return string + */ + public function getVer() + { + return $this->ver; + } + + /** + * @param string $ver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVer($ver) + { + $this->validateString($ver); + $this->ver = $ver; + return $this; + } + + /** + * @return int + */ + public function getPrivacypolicy() + { + return $this->privacypolicy; + } + + /** + * @param int $privacypolicy + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPrivacypolicy($privacypolicy) + { + $this->validateIn($privacypolicy, BitType::getAll()); + $this->privacypolicy = $privacypolicy; + return $this; + } + + /** + * @return int + */ + public function getPaid() + { + return $this->paid; + } + + /** + * @param int $paid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPaid($paid) + { + $this->validateIn($paid, BitType::getAll()); + $this->paid = $paid; + return $this; + } + + /** + * @return Publisher + */ + public function getPublisher() + { + return $this->publisher; + } + + /** + * @param Publisher $publisher + * @return $this + */ + public function setPublisher(Publisher $publisher) + { + $this->publisher = $publisher; + return $this; + } + + /** + * @return Content + */ + public function getContent() + { + return $this->content; + } + + /** + * @param Content $content + * @return $this + */ + public function setContent(Content $content) + { + $this->content = $content; + return $this; + } + + /** + * @return string + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param string $keywords + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setKeywords($keywords) + { + $this->validateString($keywords); + $this->keywords = $keywords; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + } +} diff --git a/src/BidRequest/Audio.php b/src/BidRequest/Audio.php new file mode 100644 index 0000000..e000234 --- /dev/null +++ b/src/BidRequest/Audio.php @@ -0,0 +1,648 @@ +initialize(); + } + + public function initialize() + { + $this->setCompanionad(new ArrayCollection()); + } + + /** + * @return array + */ + public function getMimes() + { + return $this->mimes; + } + + /** + * @param string $mimes + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addMimes($mimes) + { + $this->validateIn($mimes, VideoMimeType::getAll()); + $this->mimes[] = $mimes; + return $this; + } + + /** + * @param array $mimes + * @return $this + */ + public function setMimes(array $mimes) + { + $this->mimes = $mimes; + return $this; + } + + /** + * @return int + */ + public function getMinduration() + { + return $this->minduration; + } + + /** + * @param int $minduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMinduration($minduration) + { + $this->minduration = $this->validateInt($minduration); + return $this; + } + + /** + * @return int + */ + public function getMaxduration() + { + return $this->maxduration; + } + + /** + * @param int $maxduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxduration($maxduration) + { + $this->maxduration = $this->validateInt($maxduration); + return $this; + } + + /** + * @deprecated + * @return int + */ + public function getProtocol() + { + return $this->protocol; + } + + /** + * @deprecated + * @param $protocol + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setProtocol($protocol) + { + $this->protocol = $this->validateInt($protocol); + return $this; + } + + /** + * @return array + */ + public function getProtocols() + { + return $this->protocols; + } + + /** + * @param int $protocols + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addProtocols($protocols) + { + $this->validateIn($protocols, VideoBidResponseProtocols::getAll()); + $this->protocols[] = $protocols; + return $this; + } + + /** + * @param array $protocols + * @return $this + */ + public function setProtocols(array $protocols) + { + $this->protocols = $protocols; + return $this; + } + + /** + * @return int + */ + public function getStartdelay() + { + return $this->startdelay; + } + + /** + * @param int $startdelay + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setStartdelay($startdelay) + { + $this->startdelay = $this->validateInt($startdelay); + return $this; + } + + /** + * @return int + */ + public function getSequence() + { + return $this->sequence; + } + + /** + * @param int $sequence + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSequence($sequence) + { + $this->sequence = $this->validateInt($sequence); + return $this; + } + + /** + * @return array + */ + public function getBattr() + { + return $this->battr; + } + + /** + * @param int $battr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBattr($battr) + { + $this->validateIn($battr, CreativeAttributes::getAll()); + $this->battr[] = $battr; + return $this; + } + + /** + * @param array $battr + * @return $this + */ + public function setBattr(array $battr) + { + $this->battr = $battr; + return $this; + } + + /** + * @return int + */ + public function getMaxextended() + { + return $this->maxextended; + } + + /** + * @param int $maxextended + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxextended($maxextended) + { + $this->maxextended = $this->validateInt($maxextended); + return $this; + } + + /** + * @return int + */ + public function getMinbitrate() + { + return $this->minbitrate; + } + + /** + * @param int $minbitrate + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMinbitrate($minbitrate) + { + $this->minbitrate = $this->validateInt($minbitrate); + return $this; + } + + /** + * @return int + */ + public function getMaxbitrate() + { + return $this->maxbitrate; + } + + /** + * @param int $maxbitrate + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxbitrate($maxbitrate) + { + $this->maxbitrate = $this->validateInt($maxbitrate); + return $this; + } + + /** + * @return array + */ + public function getDelivery() + { + return $this->delivery; + } + + /** + * @param int $delivery + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addDelivery($delivery) + { + $this->validateIn($delivery, ContentDeliveryMethods::getAll()); + $this->delivery[] = $delivery; + return $this; + } + + /** + * @param array $delivery + * @return $this + */ + public function setDelivery(array $delivery) + { + $this->delivery = $delivery; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getCompanionad() + { + return $this->companionad; + } + + /** + * @param Banner $companionad + * @return $this + */ + public function addCompanionad(Banner $companionad) + { + $this->companionad->add($companionad); + return $this; + } + + /** + * @param ArrayCollection $companionad + * @return $this + */ + public function setCompanionad(ArrayCollection $companionad) + { + $this->companionad = $companionad; + return $this; + } + + /** + * @return array + */ + public function getApi() + { + return $this->api; + } + + /** + * @param int $api + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addApi($api) + { + $this->validateIn($api, ApiFrameworks::getAll()); + $this->api[] = $api; + return $this; + } + + /** + * @param array $api + * @return $this + */ + public function setApi(array $api) + { + $this->api = $api; + return $this; + } + + /** + * @return array + */ + public function getCompaniontype() + { + return $this->companiontype; + } + + /** + * @param $companiontype + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCompaniontype($companiontype) + { + $this->validateIn($companiontype, VastCompanionTypes::getAll()); + $this->companiontype[] = $companiontype; + return $this; + } + + /** + * @param array $companiontype + * @return $this + */ + public function setCompaniontype(array $companiontype) + { + $this->companiontype = $companiontype; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return int + */ + public function getMaxseq() + { + return $this->maxseq; + } + + /** + * @param $maxseq + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxseq($maxseq) + { + $this->validateInt($maxseq); + $this->maxseq = $maxseq; + + return $this; + } + + /** + * @return FeedType + */ + public function getFeed() + { + return $this->feed; + } + + /** + * @param $feed + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setFeed($feed) + { + $this->validateIn($feed, FeedType::getAll()); + $this->feed = $feed; + + return $this; + } + + /** + * @return int + */ + public function getStitched() + { + return $this->stitched; + } + + /** + * @param $stitched + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setStitched($stitched) + { + $this->validateIn($stitched, BitType::getAll()); + $this->stitched = $stitched; + + return $this; + } + + /** + * @return VolumeNormalizationMode + */ + public function getNvol() + { + return $this->nvol; + } + + /** + * @param $nvol + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setNvol($nvol) + { + $this->validateIn($nvol, VolumeNormalizationMode::getAll()); + $this->nvol = $nvol; + + return $this; + } + + +} diff --git a/src/BidRequest/Banner.php b/src/BidRequest/Banner.php new file mode 100644 index 0000000..95bbdad --- /dev/null +++ b/src/BidRequest/Banner.php @@ -0,0 +1,575 @@ +initialize(); + } + + public function initialize() + { + $this->setFormat(new ArrayCollection()); + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validatePositiveInt($w); + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validatePositiveInt($h); + return $this; + } + + /** + * @return int + */ + public function getWmax() + { + return $this->wmax; + } + + /** + * @param int $wmax + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWmax($wmax) + { + $this->wmax = $this->validatePositiveInt($wmax); + return $this; + } + + /** + * @return int + */ + public function getHmax() + { + return $this->hmax; + } + + /** + * @param int $hmax + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHmax($hmax) + { + $this->hmax = $this->validatePositiveInt($hmax); + return $this; + } + + /** + * @return int + */ + public function getWmin() + { + return $this->wmin; + } + + /** + * @param int $wmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWmin($wmin) + { + $this->wmin = $this->validatePositiveInt($wmin); + return $this; + } + + /** + * @return int + */ + public function getHmin() + { + return $this->hmin; + } + + /** + * @param int $hmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHmin($hmin) + { + $this->hmin = $this->validatePositiveInt($hmin); + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return array + */ + public function getBtype() + { + return $this->btype; + } + + /** + * @param int $btype + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBtype($btype) + { + $this->validateIn($btype, BannerAdTypes::getAll()); + $this->btype[] = $btype; + return $this; + } + + /** + * @param array $btype + * @return $this + */ + public function setBtype(array $btype) + { + $this->btype = $btype; + return $this; + } + + /** + * @return array + */ + public function getBattr() + { + return $this->battr; + } + + /** + * @param int $battr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBattr($battr) + { + $this->validateIn($battr, CreativeAttributes::getAll()); + $this->battr[] = $battr; + return $this; + } + + /** + * @param array $battr + * @return $this + */ + public function setBattr(array $battr) + { + $this->battr = $battr; + return $this; + } + + /** + * @return int + */ + public function getPos() + { + return $this->pos; + } + + /** + * @param int $pos + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPos($pos) + { + $this->pos = $this->validateIn($pos, AdPosition::getAll()); + return $this; + } + + /** + * @return array + */ + public function getMimes() + { + return $this->mimes; + } + + /** + * @param string $mimes + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addMimes($mimes) + { + $this->validateIn($mimes, BannerMimeType::getAll()); + $this->mimes[] = $mimes; + return $this; + } + + /** + * @param array $mimes + * @return $this + */ + public function setMimes(array $mimes) + { + $this->mimes = $mimes; + return $this; + } + + /** + * @return int + */ + public function getTopframe() + { + return $this->topframe; + } + + /** + * @param int $topframe + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTopframe($topframe) + { + $this->topframe = $this->validateInt($topframe); + return $this; + } + + /** + * @return array + */ + public function getExpdir() + { + return $this->expdir; + } + + /** + * @param int $expdir + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addExpdir($expdir) + { + $this->validateIn($expdir, ExpandableDirection::getAll()); + $this->expdir[] = $expdir; + return $this; + } + + /** + * @param array $expdir + * @return $this + */ + public function setExpdir(array $expdir) + { + $this->expdir = $expdir; + return $this; + } + + /** + * @return array + */ + public function getApi() + { + return $this->api; + } + + /** + * @param int $api + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addApi($api) + { + $this->validateIn($api, ApiFrameworks::getAll()); + $this->api[] = $api; + return $this; + } + + /** + * @param array $api + * @return $this + */ + public function setApi(array $api) + { + $this->api = $api; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + + /** + * @param ArrayCollection $format + * @return $this + */ + public function setFormat(ArrayCollection $format) + { + $this->format = $format; + return $this; + } + + /** + * @param Format $format + * @return $this + */ + public function addFormat(Format $format = null) + { + if (is_null($format)) { + $format = new Format(); + } + $this->format->add($format); + return $this; + } + + /** + * @return ArrayCollection + */ + public function getFormat() + { + return $this->format; + } + + /** + * @return int + */ + public function getVcm() + { + return $this->vcm; + } + + /** + * @param $vcm + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVcm($vcm) + { + $this->validateInt($vcm); + $this->vcm = $vcm; + + return $this; + } + + + +} diff --git a/src/BidRequest/BidRequest.php b/src/BidRequest/BidRequest.php new file mode 100644 index 0000000..a256614 --- /dev/null +++ b/src/BidRequest/BidRequest.php @@ -0,0 +1,645 @@ + 500. Default = SECOND_PRICE. + * Auction type, where 1 = First Price, 2 = Second Price Plus + * @default 2 + * @var int + */ + protected $at; + + /** + * Maximum time in milliseconds to submit a bid to avoid timeout + * @var int + */ + protected $tmax; + + /** + * Whitelist of buyer seats (e.g., advertisers, agencies) allowed to bid on this impression. + * IDs of seats and knowledge of the buyer's customers to which they refer must be coordinated between bidders and the exchange a priori. + * Omission implies no seat restrictions. + * + * @var string + */ + protected $wseat; + + /** + * Flag to indicate if Exchange can verify that the impressions offered represent all of the impressions available in context + * (e.g., all on the web page, all video spots such as pre/mid/post roll) to support road-blocking. + * 0 = no or unknown, 1 = yes, + * the impressions offered represent all that are available. + * @default 0 + * @var int + */ + protected $allimps; + + /** + * Array of allowed currencies for bids on this bid request using ISO-4217 alpha codes. + * Recommended only if the exchange accepts multiple currencies. + * Array of strings + * @var array + */ + protected $cur; + + /** + * Blocked advertiser categories using the IAB content categories. Refer to enum ContentCategory. + * Array of strings + * @var array + */ + protected $bcat; + + /** + * Block list of advertisers by their domains (e.g., "ford.com") + * Array of strings + * @var array + */ + protected $badv; + + /** + * Block list of applications by their platform-specific exchange-independent application identifiers. + * On Android, these should be bundle or package names (e.g., com.foo.mygame). On iOS, these are numeric IDs. + * Array of strings + * @var array + */ + protected $bapp; + + /** + * Specifies any industry, legal, or governmental regulations in force for this request. + * @var Regs + */ + protected $regs; + + /** + * Block list of buyer seats (e.g., advertisers, agencies) restricted from bidding on this impression. + * IDs of seats and knowledge of the buyer's customers to which they refer must be coordinated between bidders and the exchange a priori. + * At most, only one of wseat and bseat should be used in the same request. Omission of both implies no seat restrictions. + * + * @var string + */ + protected $bseat; + + /** + * Whitelist of languages for creatives using ISO-639-1-alpha-2. Omission implies no specific restrictions, + * but buyers would be advised to consider language attribute in the Device and/or Content objects if available. + * + * @var string + */ + protected $wlang; + + /** + * A Source object that provides data about the inventory source and which entity makes the final decision. + * @var Source + */ + protected $source; + + /** + * @var Ext + */ + protected $ext; + + public function __construct() + { + $this->initialize(); + } + + public function initialize() + { + $this->setImp(new ArrayCollection()); + $this->setSite(new Site()); + $this->setApp(new App()); + $this->setDevice(new Device()); + $this->setUser(new User()); + $this->setRegs(new Regs()); + $this->setSource(new Source()); + } + + /** + * @return false|string + * @throws \OpenRtb\Tools\Exceptions\ExceptionMissingRequiredField + */ + public function getBidRequest() + { + return json_encode($this->toArray()); + } + + /** + * @return false|string + * @throws \OpenRtb\Tools\Exceptions\ExceptionMissingRequiredField + */ + public function getRequest() + { + return $this->getBidRequest(); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @param ArrayCollection $imp + * @return $this + */ + public function setImp(ArrayCollection $imp) + { + $this->imp = $imp; + return $this; + } + + /** + * @param Imp $imp + * @return $this + */ + public function addImp(Imp $imp = null) + { + if (is_null($imp)) { + $imp = new Imp(); + } + $this->imp->add($imp); + return $this; + } + + /** + * @return ArrayCollection + */ + public function getImp() + { + return $this->imp; + } + + /** + * @return Site + */ + public function getSite() + { + return $this->site; + } + + /** + * @param Site $site + * @return $this + */ + public function setSite(Site $site) + { + $this->site = $site; + return $this; + } + + /** + * @return App + */ + public function getApp() + { + return $this->app; + } + + /** + * @param App $app + * @return $this + */ + public function setApp(App $app) + { + $this->app = $app; + return $this; + } + + /** + * @return Device + */ + public function getDevice() + { + return $this->device; + } + + /** + * @param Device $device + * @return $this + */ + public function setDevice(Device $device) + { + $this->device = $device; + return $this; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param User $user + * @return $this + */ + public function setUser(User $user) + { + $this->user = $user; + return $this; + } + + /** + * @return Regs + */ + public function getRegs() + { + return $this->regs; + } + + /** + * @param Regs $regs + * @return $this + */ + public function setRegs(Regs $regs) + { + $this->regs = $regs; + return $this; + } + + /** + * @return int + */ + public function getTest() + { + return $this->test; + } + + /** + * @param $test + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTest($test) + { + $this->validateIn($test, BitType::getAll()); + $this->test = $test; + return $this; + } + + /** + * @return int + */ + public function getAt() + { + return $this->at; + } + + /** + * @param $at + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAt($at) + { + $this->at = $this->validateInt($at); + return $this; + } + + /** + * @return int + */ + public function getTmax() + { + return $this->tmax; + } + + /** + * @param int $tmax + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTmax($tmax) + { + $this->tmax = $this->validatePositiveInt($tmax); + return $this; + } + + /** + * @return string + */ + public function getWseat() + { + return $this->wseat; + } + + /** + * @param string $wseat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addWseat($wseat) + { + $this->validateString($wseat); + $this->wseat = $wseat; + return $this; + } + + /** + * @param array $wseat + * @return $this + */ + public function setWseat(array $wseat) + { + $this->wseat = $wseat; + return $this; + } + + /** + * @return int + */ + public function getAllimps() + { + return $this->allimps; + } + + /** + * @param int $allimps + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAllimps($allimps) + { + $this->validateIn($allimps, BitType::getAll()); + $this->allimps = $allimps; + return $this; + } + + /** + * @return array + */ + public function getCur() + { + return $this->cur; + } + + /** + * @param string $cur + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCur($cur) + { + $this->validateString($cur); + $this->cur[] = $cur; + return $this; + } + + /** + * @param array $cur + * @return $this + */ + public function setCur(array $cur) + { + $this->cur = $cur; + return $this; + } + + /** + * @return array + */ + public function getBcat() + { + return $this->bcat; + } + + /** + * @param string $bcat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBcat($bcat) + { + $this->validateString($bcat); + $this->bcat[] = $bcat; + return $this; + } + + /** + * @param array $bcat + * @return $this + */ + public function setBcat(array $bcat) + { + $this->bcat = $bcat; + return $this; + } + + /** + * @return array + */ + public function getBadv() + { + return $this->badv; + } + + /** + * @param string $badv + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBadv($badv) + { + $this->validateString($badv); + $this->badv[] = $badv; + return $this; + } + + /** + * @param array $badv + * @return $this + */ + public function setBadv(array $badv) + { + $this->badv = $badv; + return $this; + } + + /** + * @param string $bapp + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBapp($bapp) + { + $this->validateString($bapp); + $this->bapp[] = $bapp; + return $this; + } + + /** + * @param array $bapp + * @return $this + */ + public function setBapp(array $bapp) + { + $this->bapp = $bapp; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + + /** + * @param string $bseat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBseat($bseat) + { + $this->validateString($bseat); + $this->bseat = $bseat; + return $this; + } + + /** + * @param array $bseat + * @return $this + */ + public function setBseat(array $bseat) + { + $this->bseat = $bseat; + return $this; + } + + /** + * @param string $wlang + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addWlang($wlang) + { + $this->validateString($wlang); + $this->wlang = $wlang; + return $this; + } + + /** + * @param array $wlang + * @return $this + */ + public function setWlang(array $wlang) + { + $this->wlang = $wlang; + return $this; + } + + + /** + * @return Source + */ + public function getSource() + { + return $this->source; + } + + /** + * @param Source $source + * @return $this + */ + public function setSource(Source $source) + { + $this->source = $source; + return $this; + } +} diff --git a/src/BidRequest/Content.php b/src/BidRequest/Content.php new file mode 100644 index 0000000..cc3b226 --- /dev/null +++ b/src/BidRequest/Content.php @@ -0,0 +1,712 @@ +initialize(); + } + + public function initialize() + { + $this->setProducer(new Producer()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getEpisode() + { + return $this->episode; + } + + /** + * @param $episode + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setEpisode($episode) + { + $this->episode = $this->validatePositiveInt($episode); + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param $title + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTitle($title) + { + $this->validateString($title); + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getSeries() + { + return $this->series; + } + + /** + * @param $series + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSeries($series) + { + $this->validateString($series); + $this->series = $series; + return $this; + } + + /** + * @return string + */ + public function getSeason() + { + return $this->season; + } + + /** + * @param $season + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSeason($season) + { + $this->validateString($season); + $this->season = $season; + return $this; + } + + /** + * @return Producer + */ + public function getProducer() + { + return $this->producer; + } + + /** + * @param Producer $producer + * @return $this + */ + public function setProducer(Producer $producer) + { + $this->producer = $producer; + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param $url + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUrl($url) + { + $this->validateString($url); + $this->url = $url; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat[] = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return int + */ + public function getContext() + { + return $this->context; + } + + /** + * @param $context + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setContext($context) + { + $this->validateIn($context, ContentContext::getAll()); + $this->context = $context; + return $this; + } + + /** + * @return string + */ + public function getContentrating() + { + return $this->contentrating; + } + + /** + * @param $contentrating + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setContentrating($contentrating) + { + $this->validateString($contentrating); + $this->contentrating = $contentrating; + return $this; + } + + /** + * @return string + */ + public function getUserrating() + { + return $this->userrating; + } + + /** + * @param $userrating + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUserrating($userrating) + { + $this->validateString($userrating); + $this->userrating = $userrating; + return $this; + } + + /** + * @return int + */ + public function getQagmediarating() + { + return $this->qagmediarating; + } + + /** + * @param $qagmediarating + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setQagmediarating($qagmediarating) + { + $this->validateIn($qagmediarating, QagMediaRatings::getAll()); + $this->qagmediarating = $qagmediarating; + return $this; + } + + /** + * @return string + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param $keywords + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setKeywords($keywords) + { + $this->validateString($keywords); + $this->keywords = $keywords; + return $this; + } + + /** + * @return int + */ + public function getLivestream() + { + return $this->livestream; + } + + /** + * @param $livestream + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLivestream($livestream) + { + $this->validateIn($livestream, BitType::getAll()); + $this->livestream = $livestream; + return $this; + } + + /** + * @return int + */ + public function getSourcerelationship() + { + return $this->sourcerelationship; + } + + /** + * @param $sourcerelationship + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSourcerelationship($sourcerelationship) + { + $this->validateIn($sourcerelationship, BitType::getAll()); + $this->sourcerelationship = $sourcerelationship; + return $this; + } + + /** + * @return int + */ + public function getLen() + { + return $this->len; + } + + /** + * @param $len + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLen($len) + { + $this->len = $this->validatePositiveInt($len); + return $this; + } + + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param $language + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLanguage($language) + { + $this->validateString($language); + $this->language = $language; + return $this; + } + + /** + * @return int + */ + public function getEmbeddable() + { + return $this->embeddable; + } + + /** + * @param $embeddable + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setEmbeddable($embeddable) + { + $this->validateIn($embeddable, BitType::getAll()); + $this->embeddable = $embeddable; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return string + */ + public function getArtist() + { + return $this->artist; + } + + /** + * @param $artist + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setArtist($artist) + { + $this->validateString($artist); + $this->artist = $artist; + + return $this; + } + + /** + * @return string + */ + public function getGenre() + { + return $this->genre; + } + + /** + * @param $genre + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setGenre($genre) + { + $this->validateString($genre); + $this->genre = $genre; + + return $this; + } + + /** + * @return string + */ + public function getAlbum() + { + return $this->album; + } + + /** + * @param $album + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAlbum($album) + { + $this->validateString($album); + $this->album = $album; + + return $this; + } + + /** + * @return string + */ + public function getIsrc() + { + return $this->isrc; + } + + /** + * @param $isrc + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIsrc($isrc) + { + $this->validateString($isrc); + $this->isrc = $isrc; + + return $this; + } + + /** + * @return ProductionQuality + */ + public function getProdq() + { + return $this->prodq; + } + + /** + * @param $prodq + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setProdq($prodq) + { + $this->validateIn($prodq, ProductionQuality::getAll()); + $this->prodq = $prodq; + + return $this; + } + + /** + * @return string + */ + public function getContext22() + { + return $this->context_22; + } + + /** + * @param $context_22 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setContext22($context_22) + { + $this->validateString($context_22); + $this->context_22 = $context_22; + + return $this; + } + + +} diff --git a/src/BidRequest/Data.php b/src/BidRequest/Data.php new file mode 100644 index 0000000..89b0094 --- /dev/null +++ b/src/BidRequest/Data.php @@ -0,0 +1,140 @@ +initialize(); + } + + public function initialize() + { + $this->setSegment(new ArrayCollection()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getSegment() + { + return $this->segment; + } + + /** + * @param Segment $segment + * @return $this + */ + public function addSegment(Segment $segment = null) + { + if (is_null($segment)) { + $segment = new Segment(); + } + $this->segment->add($segment); + return $this; + } + + /** + * @param ArrayCollection $segment + * @return $this + */ + public function setSegment(ArrayCollection $segment) + { + $this->segment = $segment; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Deal.php b/src/BidRequest/Deal.php new file mode 100644 index 0000000..5f772e5 --- /dev/null +++ b/src/BidRequest/Deal.php @@ -0,0 +1,226 @@ +id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return float + */ + public function getBidfloor() + { + return $this->bidfloor; + } + + /** + * @param float $bidfloor + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBidfloor($bidfloor) + { + $this->bidfloor = $this->validatePositiveFloat($bidfloor); + return $this; + } + + /** + * @return string + */ + public function getBidfloorcur() + { + return $this->bidfloorcur; + } + + /** + * @param string $bidfloorcur + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBidfloorcur($bidfloorcur) + { + $this->validateString($bidfloorcur); + $this->bidfloorcur = $bidfloorcur; + return $this; + } + + /** + * @return int + */ + public function getAt() + { + return $this->at; + } + + /** + * @param int $at + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAt($at) + { + $this->at = $this->validateInt($at); + return $this; + } + + /** + * @return array + */ + public function getWseat() + { + return $this->wseat; + } + + /** + * @param string $wseat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addWseat($wseat) + { + $this->validateString($wseat); + $this->wseat[] = $wseat; + return $this; + } + + /** + * @param array $wseat + * @return $this + */ + public function setWseat(array $wseat) + { + $this->wseat = $wseat; + return $this; + } + + /** + * @return array + */ + public function getWadomain() + { + return $this->wadomain; + } + + /** + * @param string $wadomain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addWadomain($wadomain) + { + $this->validateString($wadomain); + $this->wadomain[] = $wadomain; + return $this; + } + + /** + * @param array $wadomain + * @return $this + */ + public function setWadomain(array $wadomain) + { + $this->wadomain = $wadomain; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Device.php b/src/BidRequest/Device.php new file mode 100644 index 0000000..fdbe52a --- /dev/null +++ b/src/BidRequest/Device.php @@ -0,0 +1,857 @@ +initialize(); + } + + public function initialize() + { + $this->setGeo(new Geo()); + } + + /** + * @return string + */ + public function getUa() + { + return $this->ua; + } + + /** + * @param string $ua + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUa($ua) + { + $this->validateString($ua); + $this->ua = $ua; + return $this; + } + + /** + * @return Geo + */ + public function getGeo() + { + return $this->geo; + } + + /** + * @param Geo $geo + * @return $this + */ + public function setGeo(Geo $geo) + { + $this->geo = $geo; + return $this; + } + + /** + * @return int + */ + public function getDnt() + { + return $this->dnt; + } + + /** + * @param int $dnt + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDnt($dnt) + { + $this->validateIn($dnt, BitType::getAll()); + $this->dnt = $dnt; + return $this; + } + + /** + * @return int + */ + public function getLmt() + { + return $this->lmt; + } + + /** + * @param int $lmt + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLmt($lmt) + { + $this->validateIn($lmt, BitType::getAll()); + $this->lmt = $lmt; + return $this; + } + + /** + * @return string + */ + public function getIp() + { + return $this->ip; + } + + /** + * @param string $ip + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIp($ip) + { + $this->validateIp($ip); + $this->ip = $ip; + return $this; + } + + /** + * @return string + */ + public function getIpv6() + { + return $this->ipv6; + } + + /** + * @param string $ipv6 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIpv6($ipv6) + { + $this->validateString($ipv6); + $this->ipv6 = $ipv6; + return $this; + } + + /** + * @return int + */ + public function getDevicetype() + { + return $this->devicetype; + } + + /** + * @param int $devicetype + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDevicetype($devicetype) + { + $this->validateIn($devicetype, DeviceType::getAll()); + $this->devicetype = $devicetype; + return $this; + } + + /** + * @return string + */ + public function getMake() + { + return $this->make; + } + + /** + * @param string $make + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMake($make) + { + $this->validateString($make); + $this->make = $make; + return $this; + } + + /** + * @return string + */ + public function getModel() + { + return $this->model; + } + + /** + * @param string $model + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setModel($model) + { + $this->validateString($model); + $this->model = $model; + return $this; + } + + /** + * @return string + */ + public function getOs() + { + return $this->os; + } + + /** + * @param string $os + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setOs($os) + { + $this->validateString($os); + $this->os = $os; + return $this; + } + + /** + * @return string + */ + public function getOsv() + { + return $this->osv; + } + + /** + * @param string $osv + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setOsv($osv) + { + $this->validateString($osv); + $this->osv = $osv; + return $this; + } + + /** + * @return string + */ + public function getHwv() + { + return $this->hwv; + } + + /** + * @param string $hwv + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHwv($hwv) + { + $this->validateString($hwv); + $this->hwv = $hwv; + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validatePositiveInt($h); + return $this; + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validatePositiveInt($w); + return $this; + } + + /** + * @return int + */ + public function getPpi() + { + return $this->ppi; + } + + /** + * @param int $ppi + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPpi($ppi) + { + $this->ppi = $this->validatePositiveInt($ppi); + return $this; + } + + /** + * @return float + */ + public function getPxratio() + { + return $this->pxratio; + } + + /** + * @param float $pxratio + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPxratio($pxratio) + { + $this->pxratio = $this->validateNumericToFloat($pxratio); + return $this; + } + + /** + * @return int + */ + public function getJs() + { + return $this->js; + } + + /** + * @param int $js + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setJs($js) + { + $this->validateIn($js, BitType::getAll()); + $this->js = $js; + return $this; + } + + /** + * @return string + */ + public function getFlashver() + { + return $this->flashver; + } + + /** + * @param string $flashver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setFlashver($flashver) + { + $this->validateString($flashver); + $this->flashver = $flashver; + return $this; + } + + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param string $language + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLanguage($language) + { + $this->validateString($language); + $this->language = $language; + return $this; + } + + /** + * @return string + */ + public function getCarrier() + { + return $this->carrier; + } + + /** + * @param string $carrier + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCarrier($carrier) + { + $this->validateString($carrier); + $this->carrier = $carrier; + return $this; + } + + /** + * @return int + */ + public function getConnectiontype() + { + return $this->connectiontype; + } + + /** + * @param int $connectiontype + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setConnectiontype($connectiontype) + { + $this->validateIn($connectiontype, ConnectionType::getAll()); + $this->connectiontype = $connectiontype; + return $this; + } + + /** + * @return string + */ + public function getIfa() + { + return $this->ifa; + } + + /** + * @param string $ifa + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIfa($ifa) + { + $this->validateString($ifa); + $this->ifa = $ifa; + return $this; + } + + /** + * @return string + */ + public function getDidsha1() + { + return $this->didsha1; + } + + /** + * @param string $didsha1 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDidsha1($didsha1) + { + $this->validateString($didsha1); + $this->didsha1 = $didsha1; + return $this; + } + + /** + * @return string + */ + public function getDidmd5() + { + return $this->didmd5; + } + + /** + * @param string $didmd5 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDidmd5($didmd5) + { + $this->validateString($didmd5); + $this->didmd5 = $didmd5; + return $this; + } + + /** + * @return string + */ + public function getDpidsha1() + { + return $this->dpidsha1; + } + + /** + * @param string $dpidsha1 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDpidsha1($dpidsha1) + { + $this->validateString($dpidsha1); + $this->dpidsha1 = $dpidsha1; + return $this; + } + + /** + * @return string + */ + public function getDpidmd5() + { + return $this->dpidmd5; + } + + /** + * @param string $dpidmd5 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDpidmd5($dpidmd5) + { + $this->validateString($dpidmd5); + $this->dpidmd5 = $dpidmd5; + return $this; + } + + /** + * @return string + */ + public function getMacsha1() + { + return $this->macsha1; + } + + /** + * @param string $macsha1 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMacsha1($macsha1) + { + $this->validateString($macsha1); + $this->macsha1 = $macsha1; + return $this; + } + + /** + * @return string + */ + public function getMacmd5() + { + return $this->macmd5; + } + + /** + * @param string $macmd5 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMacmd5($macmd5) + { + $this->validateString($macmd5); + $this->macmd5 = $macmd5; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return int + */ + public function getGeofetch() + { + return $this->geofetch; + } + + /** + * @param $geofetch + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setGeofetch($geofetch) + { + $this->validateIn($geofetch, BitType::getAll()); + $this->geofetch = $geofetch; + + return $this; + } + + /** + * @return string + */ + public function getMccmnc() + { + return $this->mccmnc; + } + + /** + * @param $mccmnc + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMccmnc($mccmnc) + { + $this->validateString($mccmnc); + $this->mccmnc = $mccmnc; + + return $this; + } + + +} diff --git a/src/BidRequest/Ext.php b/src/BidRequest/Ext.php new file mode 100644 index 0000000..5b3cbf3 --- /dev/null +++ b/src/BidRequest/Ext.php @@ -0,0 +1,9 @@ +w; + } + + /** + * @param $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->validateInt($w); + $this->w = $w; + + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->validateInt($h); + $this->h = $h; + + return $this; + } + + /** + * @return int + */ + public function getWratio() + { + return $this->wratio; + } + + /** + * @param $wratio + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWratio($wratio) + { + $this->validateInt($wratio); + $this->wratio = $wratio; + + return $this; + } + + /** + * @return int + */ + public function getHratio() + { + return $this->hratio; + } + + /** + * @param $hratio + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHratio($hratio) + { + $this->validateInt($hratio); + $this->hratio = $hratio; + + return $this; + } + + /** + * @return int + */ + public function getWmin() + { + return $this->wmin; + } + + /** + * @param $wmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWmin($wmin) + { + $this->validateInt($wmin); + $this->wmin = $wmin; + + return $this; + } + +} diff --git a/src/BidRequest/Geo.php b/src/BidRequest/Geo.php new file mode 100644 index 0000000..0548e82 --- /dev/null +++ b/src/BidRequest/Geo.php @@ -0,0 +1,392 @@ +lat; + } + + /** + * @param float $lat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLat($lat) + { + $this->lat = $this->validateNumericToFloat($lat); + return $this; + } + + /** + * @return float + */ + public function getLon() + { + return $this->lon; + } + + /** + * @param float $lon + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLon($lon) + { + $this->lon = $this->validateNumericToFloat($lon); + return $this; + } + + /** + * @return int + */ + public function getType() + { + return $this->type; + } + + /** + * @param int $type + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setType($type) + { + $this->validateIn($type, LocationType::getAll()); + $this->type = $type; + return $this; + } + + /** + * @return string + */ + public function getCountry() + { + return $this->country; + } + + /** + * @param string $country + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCountry($country) + { + $this->validateString($country); + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getRegion() + { + return $this->region; + } + + /** + * @param string $region + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setRegion($region) + { + $this->validateString($region); + $this->region = $region; + return $this; + } + + /** + * @return string + */ + public function getRegionfips104() + { + return $this->regionfips104; + } + + /** + * @param string $regionfips104 + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setRegionfips104($regionfips104) + { + $this->validateString($regionfips104); + $this->regionfips104 = $regionfips104; + return $this; + } + + /** + * @return string + */ + public function getMetro() + { + return $this->metro; + } + + /** + * @param string $metro + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMetro($metro) + { + $this->validateString($metro); + $this->metro = $metro; + return $this; + } + + /** + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * @param string $city + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCity($city) + { + $this->validateString($city); + $this->city = $city; + return $this; + } + + /** + * @return string + */ + public function getZip() + { + return $this->zip; + } + + /** + * @param string $zip + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setZip($zip) + { + $this->validateString($zip); + $this->zip = $zip; + return $this; + } + + /** + * @return int + */ + public function getUtcoffset() + { + return $this->utcoffset; + } + + /** + * @param int $utcoffset + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUtcoffset($utcoffset) + { + $this->utcoffset = $this->validateInt($utcoffset); + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return int + */ + public function getAccuracy() + { + return $this->accuracy; + } + + /** + * @param $accuracy + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAccuracy($accuracy) + { + $this->validateInt($accuracy); + $this->accuracy = $accuracy; + + return $this; + } + + /** + * @return int + */ + public function getLastfix() + { + return $this->lastfix; + } + + /** + * @param $lastfix + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLastfix($lastfix) + { + $this->validateInt($lastfix); + $this->lastfix = $lastfix; + + return $this; + } + + /** + * @return LocationService + */ + public function getIpservice() + { + return $this->ipservice; + } + + /** + * @param $ipservice + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIpservice($ipservice) + { + $this->validateIn($ipservice, LocationService::getAll()); + $this->ipservice = $ipservice; + + return $this; + } + + +} diff --git a/src/BidRequest/Imp.php b/src/BidRequest/Imp.php new file mode 100644 index 0000000..9cd54bc --- /dev/null +++ b/src/BidRequest/Imp.php @@ -0,0 +1,546 @@ +initialize(); + } + + public function initialize() + { + $this->setPmp(new Pmp()); + $this->setMetric(new ArrayCollection()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return Banner + */ + public function getBanner() + { + return $this->banner; + } + + /** + * @param Banner $banner + * @return $this + */ + public function setBanner(Banner $banner) + { + $this->banner = $banner; + return $this; + } + + /** + * @return Video + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video $video + * @return $this + */ + public function setVideo(Video $video) + { + $this->video = $video; + return $this; + } + + /** + * @return Audio + */ + public function getAudio() + { + return $this->audio; + } + + /** + * @param Audio $audio + * @return $this + */ + public function setAudio(Audio $audio) + { + $this->audio = $audio; + return $this; + } + + /** + * @return Native + */ + public function getNative() + { + return $this->native; + } + + /** + * @param Native $native + * @return $this + */ + public function setNative(Native $native) + { + $this->native = $native; + return $this; + } + + /** + * @return string + */ + public function getDisplaymanager() + { + return $this->displaymanager; + } + + /** + * @param string $displaymanager + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDisplaymanager($displaymanager) + { + $this->validateString($displaymanager); + $this->displaymanager = $displaymanager; + return $this; + } + + /** + * @return string + */ + public function getDisplaymanagerver() + { + return $this->displaymanagerver; + } + + /** + * @param string $displaymanagerver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDisplaymanagerver($displaymanagerver) + { + $this->validateString($displaymanagerver); + $this->displaymanagerver = $displaymanagerver; + return $this; + } + + /** + * @return int + */ + public function getInstl() + { + return $this->instl; + } + + /** + * @param int $instl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setInstl($instl) + { + $this->validateIn($instl, BitType::getAll()); + $this->instl = (int) $instl; + return $this; + } + + /** + * @return string + */ + public function getTagid() + { + return $this->tagid; + } + + /** + * @param string $tagid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTagid($tagid) + { + $this->validateString($tagid); + $this->tagid = $tagid; + return $this; + } + + /** + * @return float + */ + public function getBidfloor() + { + return $this->bidfloor; + } + + /** + * @param float $bidfloor + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBidfloor($bidfloor) + { + $this->bidfloor = $this->validateNumericToFloat($bidfloor); + return $this; + } + + /** + * @return string + */ + public function getBidfloorcur() + { + return $this->bidfloorcur; + } + + /** + * @param string $bidfloorcur + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBidfloorcur($bidfloorcur) + { + $this->validateString($bidfloorcur); + $this->bidfloorcur = $bidfloorcur; + return $this; + } + + /** + * @return int + */ + public function getSecure() + { + return $this->secure; + } + + /** + * @param int $secure + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSecure($secure) + { + $this->validateIn($secure, BitType::getAll()); + $this->secure = (int) $secure; + return $this; + } + + /** + * @return array + */ + public function getIframebuster() + { + return $this->iframebuster; + } + + /** + * @param string $iframebuster + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addIframebuster($iframebuster) + { + $this->validateString($iframebuster); + $this->iframebuster[] = $iframebuster; + return $this; + } + + /** + * @param array $iframebuster + * @return $this + */ + public function setIframebuster(array $iframebuster) + { + $this->iframebuster = $iframebuster; + return $this; + } + + /** + * @return Pmp + */ + public function getPmp() + { + return $this->pmp; + } + + /** + * @param Pmp $pmp + * @return $this + */ + public function setPmp(Pmp $pmp) + { + $this->pmp = $pmp; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + + /** + * @return int + */ + public function getClickbrowser() + { + return $this->clickbrowser; + } + + /** + * @param int $clickbrowser + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setClickbrowser($clickbrowser) + { + $this->validateIn($clickbrowser, BitType::getAll()); + $this->clickbrowser = (int) $clickbrowser; + return $this; + } + + /** + * @return string + */ + public function getExp() + { + return $this->exp; + } + + /** + * @param string $exp + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setExp($exp) + { + $this->validateInt($exp); + $this->exp = $exp; + return $this; + } + + /** + * @param ArrayCollection $metric + * @return $this + */ + public function setMetric(ArrayCollection $metric) + { + $this->metric = $metric; + return $this; + } + + /** + * @param Metric $metric + * @return $this + */ + public function addMetric(Metric $metric = null) + { + if (is_null($metric)) { + $metric = new Metric(); + } + $this->metric->add($metric); + return $this; + } + + /** + * @return ArrayCollection + */ + public function getMetric() + { + return $this->metric; + } + + +} diff --git a/src/BidRequest/Metric.php b/src/BidRequest/Metric.php new file mode 100644 index 0000000..626984e --- /dev/null +++ b/src/BidRequest/Metric.php @@ -0,0 +1,100 @@ +type; + } + + /** + * @param $type + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setType($type) + { + $this->validateString($type); + $this->type = $type; + + return $this; + } + + /** + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * @param $value + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setValue($value) + { + $this->value = $this->validateNumericToFloat($value); + + return $this; + } + + /** + * @return string + */ + public function getVendor() + { + return $this->vendor; + } + + /** + * @param $vendor + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVendor($vendor) + { + $this->validateString($vendor); + $this->vendor = $vendor; + + return $this; + } + + +} diff --git a/src/BidRequest/Native.php b/src/BidRequest/Native.php new file mode 100644 index 0000000..d93a9d6 --- /dev/null +++ b/src/BidRequest/Native.php @@ -0,0 +1,176 @@ +request; + } + + public function setRequestViaNativeAdRequest(NativeAdRequest $nativeAdRequest) + { + $this->setRequest($nativeAdRequest->getRequest()); + } + + /** + * @param string $request + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setRequest($request) + { + $this->validateString($request); + $this->request = $request; + return $this; + } + + /** + * @return string + */ + public function getVer() + { + return $this->ver; + } + + /** + * @param string $ver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVer($ver) + { + $this->validateVersion($ver); + $this->ver = $ver; + return $this; + } + + /** + * @return array + */ + public function getApi() + { + return $this->api; + } + + /** + * @param int $api + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addApi($api) + { + $this->validateIn($api, ApiFrameworks::getAll()); + $this->api[] = $api; + return $this; + } + + /** + * @param array $api + * @return $this + */ + public function setApi(array $api) + { + $this->api = $api; + return $this; + } + + /** + * @return array + */ + public function getBattr() + { + return $this->battr; + } + + /** + * @param int $battr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBattr($battr) + { + $this->validateIn($battr, CreativeAttributes::getAll()); + $this->battr[] = $battr; + return $this; + } + + /** + * @param array $battr + * @return $this + */ + public function setBattr(array $battr) + { + $this->battr = $battr; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Pmp.php b/src/BidRequest/Pmp.php new file mode 100644 index 0000000..14ee028 --- /dev/null +++ b/src/BidRequest/Pmp.php @@ -0,0 +1,112 @@ +initialize(); + } + + public function initialize() + { + $this->setDeals(new ArrayCollection()); + } + + /** + * @return int + */ + public function getPrivate_auction() + { + return $this->private_auction; + } + + /** + * @param int $private_auction + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPrivate_auction($private_auction) + { + $this->validateIn($private_auction, BitType::getAll()); + $this->private_auction = $private_auction; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getDeals() + { + return $this->deals; + } + + /** + * @param Deal $deals + * @return $this + */ + public function addDeals(Deal $deals) + { + $this->deals->add($deals); + return $this; + } + + /** + * @param ArrayCollection $deals + * @return $this + */ + public function setDeals(ArrayCollection $deals) + { + $this->deals = $deals; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Producer.php b/src/BidRequest/Producer.php new file mode 100644 index 0000000..9b47f32 --- /dev/null +++ b/src/BidRequest/Producer.php @@ -0,0 +1,153 @@ +id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param $name + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param string $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat[] = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return string + */ + public function getDomain() + { + return $this->domain; + } + + /** + * @param string $domain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDomain($domain) + { + $this->validateString($domain); + $this->domain = $domain; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Publisher.php b/src/BidRequest/Publisher.php new file mode 100644 index 0000000..ad5d4d3 --- /dev/null +++ b/src/BidRequest/Publisher.php @@ -0,0 +1,156 @@ +id; + } + + /** + * @param $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param $name + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat[] = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return string + */ + public function getDomain() + { + return $this->domain; + } + + /** + * @param $domain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDomain($domain) + { + $this->validateString($domain); + $this->domain = $domain; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Regs.php b/src/BidRequest/Regs.php new file mode 100644 index 0000000..3b72d6f --- /dev/null +++ b/src/BidRequest/Regs.php @@ -0,0 +1,67 @@ +coppa; + } + + /** + * @param int $coppa + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCoppa($coppa) + { + $this->validateIn($coppa, BitType::getAll()); + $this->coppa = $coppa; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + +} diff --git a/src/BidRequest/Segment.php b/src/BidRequest/Segment.php new file mode 100644 index 0000000..cdbcf8b --- /dev/null +++ b/src/BidRequest/Segment.php @@ -0,0 +1,117 @@ +id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * @param string $value + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setValue($value) + { + $this->validateString($value); + $this->value = $value; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Site.php b/src/BidRequest/Site.php new file mode 100644 index 0000000..a5f0e71 --- /dev/null +++ b/src/BidRequest/Site.php @@ -0,0 +1,454 @@ +initialize(); + } + + public function initialize() + { + $this->setPublisher(new Publisher()); + $this->setContent(new Content()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->validateString($name); + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getDomain() + { + return $this->domain; + } + + /** + * @param string $domain + * @return $this + */ + public function setDomain($domain) + { + $this->validateString($domain); + $this->domain = $domain; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param string $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat[] = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return array + */ + public function getSectioncat() + { + return $this->sectioncat; + } + + /** + * @param string $sectioncat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addSectioncat($sectioncat) + { + $this->validateString($sectioncat); + $this->sectioncat[] = $sectioncat; + return $this; + } + + /** + * @param array $sectioncat + * @return $this + */ + public function setSectioncat(array $sectioncat) + { + $this->sectioncat = $sectioncat; + return $this; + } + + /** + * @return array + */ + public function getPagecat() + { + return $this->pagecat; + } + + /** + * @param string $pagecat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addPagecat($pagecat) + { + $this->validateString($pagecat); + $this->pagecat[] = $pagecat; + return $this; + } + + /** + * @param array $pagecat + * @return $this + */ + public function setPagecat(array $pagecat) + { + $this->pagecat = $pagecat; + return $this; + } + + /** + * @return string + */ + public function getPage() + { + return $this->page; + } + + /** + * @param string $page + * @return $this + */ + public function setPage($page) + { + $this->validateString($page); + $this->page = $page; + return $this; + } + + /** + * @return string + */ + public function getRef() + { + return $this->ref; + } + + /** + * @param $ref + * @return $this + */ + public function setRef($ref) + { + $this->ref = $ref; + return $this; + } + + /** + * @return string + */ + public function getSearch() + { + return $this->search; + } + + /** + * @param string $search + * @return $this + */ + public function setSearch($search) + { + $this->validateString($search); + $this->search = $search; + return $this; + } + + /** + * @return int + */ + public function getMobile() + { + return $this->mobile; + } + + /** + * @param int $mobile + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMobile($mobile) + { + $this->validateIn($mobile, BitType::getAll()); + $this->mobile = $mobile; + return $this; + } + + /** + * @return int + */ + public function getPrivacypolicy() + { + return $this->privacypolicy; + } + + /** + * @param $privacypolicy + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPrivacypolicy($privacypolicy) + { + $this->validateIn($privacypolicy, BitType::getAll()); + $this->privacypolicy = $privacypolicy; + return $this; + } + + /** + * @return Publisher + */ + public function getPublisher() + { + return $this->publisher; + } + + /** + * @param Publisher $publisher + * @return $this + */ + public function setPublisher(Publisher $publisher) + { + $this->publisher = $publisher; + return $this; + } + + /** + * @return Content + */ + public function getContent() + { + return $this->content; + } + + /** + * @param Content $content + * @return $this + */ + public function setContent(Content $content) + { + $this->content = $content; + return $this; + } + + /** + * @return string + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param string $keywords + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setKeywords($keywords) + { + $this->validateString($keywords); + $this->keywords = $keywords; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidRequest/Source.php b/src/BidRequest/Source.php new file mode 100644 index 0000000..1bda31e --- /dev/null +++ b/src/BidRequest/Source.php @@ -0,0 +1,112 @@ +fd; + } + + /** + * @param $fd + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setFd($fd) + { + $this->validateIn($allimps, BitType::getAll()); + $this->fd = $fd; + + return $this; + } + + /** + * @return string + */ + public function getTid() + { + return $this->tid; + } + + /** + * @param $tid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTid($tid) + { + $this->validateString($tid); + $this->tid = $tid; + + return $this; + } + + /** + * @return string + */ + public function getPchain() + { + return $this->pchain; + } + + /** + * @param $pchain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPchain($pchain) + { + $this->validateSha1($pchain); + $this->pchain = $pchain; + + return $this; + } + + + +} diff --git a/src/BidRequest/Specification/AdPosition.php b/src/BidRequest/Specification/AdPosition.php new file mode 100644 index 0000000..26b4983 --- /dev/null +++ b/src/BidRequest/Specification/AdPosition.php @@ -0,0 +1,20 @@ +initialize(); + } + + public function initialize() + { + $this->setGeo(new Geo()); + $this->setData(new ArrayCollection()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getBuyerid() + { + return $this->buyerid; + } + + /** + * @param string $buyerid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBuyerid($buyerid) + { + $this->validateString($buyerid); + $this->buyerid = $buyerid; + return $this; + } + + /** + * @return string + */ + public function getGender() + { + return $this->gender; + } + + /** + * @param string $gender + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setGender($gender) + { + $this->validateIn($gender, Gender::getAll()); + $this->gender = $gender; + return $this; + } + + /** + * @return string + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param string $keywords + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setKeywords($keywords) + { + $this->validateString($keywords); + $this->keywords = $keywords; + return $this; + } + + /** + * @return string + */ + public function getCustomdata() + { + return $this->customdata; + } + + /** + * @param string $customdata + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCustomdata($customdata) + { + $this->validateString($customdata); + $this->customdata = $customdata; + return $this; + } + + /** + * @return Geo + */ + public function getGeo() + { + return $this->geo; + } + + /** + * @param Geo $geo + * @return $this + */ + public function setGeo(Geo $geo) + { + $this->geo = $geo; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getData() + { + return $this->data; + } + + /** + * @param Data $data + * @return $this + */ + public function addData(Data $data = null) + { + if (is_null($data)) { + $data = new Data(); + } + $this->data->add($data); + return $this; + } + + /** + * @param ArrayCollection $data + * @return $this + */ + public function setData(ArrayCollection $data) + { + $this->data = $data; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + +} diff --git a/src/BidRequest/Video.php b/src/BidRequest/Video.php new file mode 100644 index 0000000..ed14948 --- /dev/null +++ b/src/BidRequest/Video.php @@ -0,0 +1,874 @@ +initialize(); + } + + public function initialize() + { + $this->setCompanionad(new ArrayCollection()); + } + + /** + * @return array + */ + public function getMimes() + { + return $this->mimes; + } + + /** + * @param string $mimes + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addMimes($mimes) + { + $this->validateIn($mimes, VideoMimeType::getAll()); + $this->mimes[] = $mimes; + return $this; + } + + /** + * @param array $mimes + * @return $this + */ + public function setMimes(array $mimes) + { + $this->mimes = $mimes; + return $this; + } + + /** + * @return int + */ + public function getMinduration() + { + return $this->minduration; + } + + /** + * @param int $minduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMinduration($minduration) + { + $this->minduration = $this->validateInt($minduration); + return $this; + } + + /** + * @return int + */ + public function getMaxduration() + { + return $this->maxduration; + } + + /** + * @param int $maxduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxduration($maxduration) + { + $this->maxduration = $this->validateInt($maxduration); + return $this; + } + + /** + * @deprecated + * @return int + */ + public function getProtocol() + { + return $this->protocol; + } + + /** + * @param $protocol + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setProtocol($protocol) + { + $this->protocol = $this->validateInt($protocol); + return $this; + } + + /** + * @return array + */ + public function getProtocols() + { + return $this->protocols; + } + + /** + * @param int $protocols + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addProtocols($protocols) + { + $this->validateIn($protocols, VideoBidResponseProtocols::getAll()); + $this->protocols[] = $protocols; + return $this; + } + + /** + * @param array $protocols + * @return $this + */ + public function setProtocols(array $protocols) + { + $this->protocols = $protocols; + return $this; + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validateInt($w); + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validateInt($h); + return $this; + } + + /** + * @return int + */ + public function getStartdelay() + { + return $this->startdelay; + } + + /** + * @param int $startdelay + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setStartdelay($startdelay) + { + $this->startdelay = $this->validateInt($startdelay); + return $this; + } + + /** + * @return int + */ + public function getLinearity() + { + return $this->linearity; + } + + /** + * @param int $linearity + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLinearity($linearity) + { + $this->validateIn($linearity, VideoLinearity::getAll()); + $this->linearity = $linearity; + return $this; + } + + /** + * @return int + */ + public function getSequence() + { + return $this->sequence; + } + + /** + * @param int $sequence + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSequence($sequence) + { + $this->sequence = $this->validateInt($sequence); + return $this; + } + + /** + * @return array + */ + public function getBattr() + { + return $this->battr; + } + + /** + * @param int $battr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addBattr($battr) + { + $this->validateIn($battr, CreativeAttributes::getAll()); + $this->battr[] = $battr; + return $this; + } + + /** + * @param array $battr + * @return $this + */ + public function setBattr(array $battr) + { + $this->battr = $battr; + return $this; + } + + /** + * @return int + */ + public function getMaxextended() + { + return $this->maxextended; + } + + /** + * @param int $maxextended + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxextended($maxextended) + { + $this->maxextended = $this->validateInt($maxextended); + return $this; + } + + /** + * @return int + */ + public function getMinbitrate() + { + return $this->minbitrate; + } + + /** + * @param int $minbitrate + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMinbitrate($minbitrate) + { + $this->minbitrate = $this->validateInt($minbitrate); + return $this; + } + + /** + * @return int + */ + public function getMaxbitrate() + { + return $this->maxbitrate; + } + + /** + * @param int $maxbitrate + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxbitrate($maxbitrate) + { + $this->maxbitrate = $this->validateInt($maxbitrate); + return $this; + } + + /** + * @return int + */ + public function getBoxingallowed() + { + return $this->boxingallowed; + } + + /** + * @param int $boxingallowed + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBoxingallowed($boxingallowed) + { + $this->validateIn($boxingallowed, BitType::getAll()); + $this->boxingallowed = $boxingallowed; + return $this; + } + + /** + * @return array + */ + public function getPlaybackmethod() + { + return $this->playbackmethod; + } + + /** + * @param int $playbackmethod + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addPlaybackmethod($playbackmethod) + { + $this->validateIn($playbackmethod, VideoPlaybackMethods::getAll()); + $this->playbackmethod[] = $playbackmethod; + return $this; + } + + /** + * @param array $playbackmethod + * @return $this + */ + public function setPlaybackmethod(array $playbackmethod) + { + $this->playbackmethod = $playbackmethod; + return $this; + } + + /** + * @return array + */ + public function getDelivery() + { + return $this->delivery; + } + + /** + * @param int $delivery + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addDelivery($delivery) + { + $this->validateIn($delivery, ContentDeliveryMethods::getAll()); + $this->delivery[] = $delivery; + return $this; + } + + /** + * @param array $delivery + * @return $this + */ + public function setDelivery(array $delivery) + { + $this->delivery = $delivery; + return $this; + } + + /** + * @return int + */ + public function getPos() + { + return $this->pos; + } + + /** + * @param int $pos + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPos($pos) + { + $this->validateIn($pos, AdPosition::getAll()); + $this->pos = $pos; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getCompanionad() + { + return $this->companionad; + } + + /** + * @param Banner $companionad + * @return $this + */ + public function addCompanionad(Banner $companionad) + { + $this->companionad->add($companionad); + return $this; + } + + /** + * @param ArrayCollection $companionad + * @return $this + */ + public function setCompanionad(ArrayCollection $companionad) + { + $this->companionad = $companionad; + return $this; + } + + /** + * @return array + */ + public function getApi() + { + return $this->api; + } + + /** + * @param int $api + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addApi($api) + { + $this->validateIn($api, ApiFrameworks::getAll()); + $this->api[] = $api; + return $this; + } + + /** + * @param array $api + * @return $this + */ + public function setApi(array $api) + { + $this->api = $api; + return $this; + } + + /** + * @return array + */ + public function getCompaniontype() + { + return $this->companiontype; + } + + /** + * @param $companiontype + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCompaniontype($companiontype) + { + $this->validateIn($companiontype, VastCompanionTypes::getAll()); + $this->companiontype[] = $companiontype; + return $this; + } + + /** + * @param array $companiontype + * @return $this + */ + public function setCompaniontype(array $companiontype) + { + $this->companiontype = $companiontype; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return int + */ + public function getSkip() + { + return $this->skip; + } + + /** + * @param $skip + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSkip($skip) + { + $this->validateIn($skip, BitType::getAll()); + $this->skip = $skip; + + return $this; + } + + /** + * @return int + */ + public function getSkipmin() + { + return $this->skipmin; + } + + /** + * @param $skipmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSkipmin($skipmin) + { + $this->validateInt($skipmin); + $this->skipmin = $skipmin; + + return $this; + } + + /** + * @return int + */ + public function getSkipafter() + { + return $this->skipafter; + } + + /** + * @param $skipafter + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSkipafter($skipafter) + { + $this->validateInt($skipafter); + $this->skipafter = $skipafter; + + return $this; + } + + /** + * @return VideoPlacementType + */ + public function getPlacement() + { + return $this->placement; + } + + /** + * @param $placement + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPlacement($placement) + { + $this->validateIn($placement, VideoPlacementType::getAll()); + $this->placement = $placement; + + return $this; + } + + /** + * @return PlaybackCessationMode + */ + public function getPlaybackend() + { + return $this->playbackend; + } + + /** + * @param $playbackend + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPlaybackend($playbackend) + { + $this->validateIn($playbackend, PlaybackCessationMode::getAll()); + $this->playbackend = $playbackend; + + return $this; + } + +} diff --git a/src/BidResponse/Bid.php b/src/BidResponse/Bid.php new file mode 100644 index 0000000..c78afb5 --- /dev/null +++ b/src/BidResponse/Bid.php @@ -0,0 +1,816 @@ +id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getImpid() + { + return $this->impid; + } + + /** + * @param string $impid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setImpid($impid) + { + $this->validateString($impid); + $this->impid = $impid; + return $this; + } + + /** + * @return float + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param float $price + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPrice($price) + { + $this->price = $this->validateNumericToFloat($price); + return $this; + } + + /** + * @return string + */ + public function getAdid() + { + return $this->adid; + } + + /** + * @param string $adid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAdid($adid) + { + $this->validateString($adid); + $this->adid = $adid; + return $this; + } + + /** + * @return string + */ + public function getNurl() + { + return $this->nurl; + } + + /** + * @param string $nurl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setNurl($nurl) + { + $this->validateString($nurl); + $this->nurl = $nurl; + return $this; + } + + /** + * @return string + */ + public function getAdm() + { + return $this->adm; + } + + /** + * @param string $adm + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAdm($adm) + { + $this->validateString($adm); + $this->adm = $adm; + return $this; + } + + /** + * @return array + */ + public function getAdomain() + { + return $this->adomain; + } + + /** + * @param string $adomain + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addAdomain($adomain) + { + $this->validateString($adomain); + $this->adomain[] = $adomain; + return $this; + } + + /** + * @param array $adomain + * @return $this + */ + public function setAdomain(array $adomain) + { + $this->adomain = $adomain; + return $this; + } + + /** + * @return string + */ + public function getBundle() + { + return $this->bundle; + } + + /** + * @param string $bundle + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBundle($bundle) + { + $this->validateString($bundle); + $this->bundle = $bundle; + return $this; + } + + /** + * @return string + */ + public function getIurl() + { + return $this->iurl; + } + + /** + * @param string $iurl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setIurl($iurl) + { + $this->validateString($iurl); + $this->iurl = $iurl; + return $this; + } + + /** + * @return string + */ + public function getCid() + { + return $this->cid; + } + + /** + * @param string $cid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCid($cid) + { + $this->validateString($cid); + $this->cid = $cid; + return $this; + } + + /** + * @return string + */ + public function getCrid() + { + return $this->crid; + } + + /** + * @param string $crid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCrid($crid) + { + $this->validateString($crid); + $this->crid = $crid; + return $this; + } + + /** + * @return array + */ + public function getCat() + { + return $this->cat; + } + + /** + * @param string $cat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addCat($cat) + { + $this->validateString($cat); + $this->cat = $cat; + return $this; + } + + /** + * @param array $cat + * @return $this + */ + public function setCat(array $cat) + { + $this->cat = $cat; + return $this; + } + + /** + * @return array + */ + public function getAttr() + { + return $this->attr; + } + + /** + * @param int $attr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addAttr($attr) + { + $this->validateIn($attr, CreativeAttributes::getAll()); + $this->attr = $attr; + return $this; + } + + /** + * @param array $attr + * @return $this + */ + public function setAttr(array $attr) + { + $this->attr = $attr; + return $this; + } + + /** + * @return string + */ + public function getDealid() + { + return $this->dealid; + } + + /** + * @param string $dealid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setDealid($dealid) + { + $this->validateString($dealid); + $this->dealid = $dealid; + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validateInt($h); + return $this; + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validateInt($w); + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } + + /** + * @return NativeAdResponse + */ + public function getAdmNative() + { + return $this->adm_native; + } + + /** + * @param NativeAdResponse $adm_native + * @return $this + */ + public function setAdmNative(NativeAdResponse $adm_native) + { + $this->adm_native = $adm_native; + return $this; + } + + /** + * @return int + */ + public function getApi() + { + return $this->api; + } + + /** + * @param $api + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setApi($api) + { + $this->validateIn($api, ApiFrameworks::getAll()); + $this->api = $api; + return $this; + } + + /** + * @return int + */ + public function getProtocol() + { + return $this->protocol; + } + + /** + * @param $protocol + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setProtocol($protocol) + { + $this->validateIn($protocol, VideoBidResponseProtocols::getAll()); + $this->protocol = $protocol; + return $this; + } + + /** + * @return int + */ + public function getQagmediarating() + { + return $this->qagmediarating; + } + + /** + * @param $qagmediarating + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setQagmediarating($qagmediarating) + { + $this->validateIn($qagmediarating, QagMediaRatings::getAll()); + $this->qagmediarating = $qagmediarating; + return $this; + } + + /** + * @return int + */ + public function getExp() + { + return $this->exp; + } + + /** + * @param $exp + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setExp($exp) + { + $this->validateInt($exp); + $this->exp = $exp; + return $this; + } + + /** + * @return string + */ + public function getBurl() + { + return $this->burl; + } + + /** + * @param $burl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBurl($burl) + { + $this->validateString($burl); + $this->burl = $burl; + return $this; + } + + /** + * @return string + */ + public function getLurl() + { + return $this->lurl; + } + + /** + * @param $lurl + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLurl($lurl) + { + $this->validateString($lurl); + $this->lurl = $lurl; + return $this; + } + + /** + * @return string + */ + public function getTactic() + { + return $this->tactic; + } + + /** + * @param $tactic + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setTactic($tactic) + { + $this->validateString($tactic); + $this->tactic = $tactic; + + return $this; + } + + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param $language + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLanguage($language) + { + $this->validateString($language); + $this->language = $language; + return $this; + } + + /** + * @return int + */ + public function getWratio() + { + return $this->wratio; + } + + /** + * @param $wratio + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWratio($wratio) + { + $this->validateInt($wratio); + $this->wratio = $wratio; + return $this; + } + + /** + * @return int + */ + public function getHratio() + { + return $this->hratio; + } + + /** + * @param $hratio + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHratio($hratio) + { + $this->validateInt($hratio); + $this->hratio = $hratio; + return $this; + } + + + +} diff --git a/src/BidResponse/BidResponse.php b/src/BidResponse/BidResponse.php new file mode 100644 index 0000000..c5388cb --- /dev/null +++ b/src/BidResponse/BidResponse.php @@ -0,0 +1,232 @@ +initialize(); + } + + public function initialize() + { + $this->setSeatbid(new ArrayCollection()); + } + + /** + * @return false|string + * @throws \OpenRtb\Tools\Exceptions\ExceptionMissingRequiredField + */ + public function getBidResponse() + { + return json_encode($this->toArray()); + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->validateString($id); + $this->id = $id; + return $this; + } + + /** + * @return ArrayCollection + */ + public function getSeatbid() + { + return $this->seatbid; + } + + /** + * @param Seatbid $seatbid + * @return $this + */ + public function addSeatbid(Seatbid $seatbid) + { + $this->seatbid->add($seatbid); + return $this; + } + + /** + * @param ArrayCollection $seatbid + * @return $this + */ + public function setSeatbid(ArrayCollection $seatbid) + { + $this->seatbid = $seatbid; + return $this; + } + + /** + * @return string + */ + public function getBidid() + { + return $this->bidid; + } + + /** + * @param string $bidid + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setBidid($bidid) + { + $this->validateString($bidid); + $this->bidid = $bidid; + return $this; + } + + /** + * @return string + */ + public function getCur() + { + return $this->cur; + } + + /** + * @param string $cur + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCur($cur) + { + $this->validateString($cur); + $this->cur = $cur; + return $this; + } + + /** + * @return string + */ + public function getCustomdata() + { + return $this->customdata; + } + + /** + * @param string $customdata + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setCustomdata($customdata) + { + $this->validateString($customdata); + $this->customdata = $customdata; + return $this; + } + + /** + * @return int + */ + public function getNbr() + { + return $this->nbr; + } + + /** + * @param int $nbr + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setNbr($nbr) + { + $this->validateIn($nbr, NoBidReason::getAll()); + $this->nbr = $nbr; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidResponse/Ext.php b/src/BidResponse/Ext.php new file mode 100644 index 0000000..d7bcb56 --- /dev/null +++ b/src/BidResponse/Ext.php @@ -0,0 +1,9 @@ +initialize(); + } + + public function initialize() + { + $this->setBid(new ArrayCollection()); + } + + /** + * @return ArrayCollection + */ + public function getBid() + { + return $this->bid; + } + + /** + * @param Bid $bid + * @return $this + */ + public function addBid(Bid $bid) + { + $this->bid->add($bid); + return $this; + } + + /** + * @param ArrayCollection $bid + * @return $this + */ + public function setBid(ArrayCollection $bid) + { + $this->bid = $bid; + return $this; + } + + /** + * @return string + */ + public function getSeat() + { + return $this->seat; + } + + /** + * @param string $seat + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSeat($seat) + { + $this->validateString($seat); + $this->seat = $seat; + return $this; + } + + /** + * @return int + */ + public function getGroup() + { + return $this->group; + } + + /** + * @param int $group + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setGroup($group) + { + $this->validateIn($group, BitType::getAll()); + $this->group = $group; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/BidResponse/Specification/BitType.php b/src/BidResponse/Specification/BitType.php new file mode 100644 index 0000000..c223b77 --- /dev/null +++ b/src/BidResponse/Specification/BitType.php @@ -0,0 +1,13 @@ + $value) { + if ( + is_array($value) && + $objectDescriptor->properties->has($key) && + $objectDescriptor->properties->get($key)->isObject() && + $objectDescriptor->properties->get($key)->get('var') == 'ArrayCollection' + ) { + self::set($object, $key, self::getDependencyObject($objectDescriptor, $key)); + $method = 'add'.ucfirst($key); + if ( ! $objectDescriptor->methods->has($method) || ! $objectDescriptor->methods->get($method)) { + throw new \Exception(sprintf('Method %s does not exist', $method)); + } + foreach ($value as $item) { + $object->$method(self::hydrate($item, self::getDependencyObject($objectDescriptor, ucfirst($key), false))); + } + } elseif ( + is_array($value) && + $objectDescriptor->properties->has($key) && + $objectDescriptor->properties->get($key)->isObject() + ) { + self::set($object, $key, self::hydrate($value, self::getDependencyObject($objectDescriptor, $key))); + } elseif ($objectDescriptor->properties->has($key)) { + self::set($object, $key, $value); + } elseif ($object instanceof \OpenRtb\Tools\Classes\Ext) { + $object->set($key, $value); + } + } + return $object; + } + + /** + * @param array $data + * @param ObjectDescriber $objectDescriber + * @return array + */ + protected static function checkFirstArrayKey(array $data, ObjectDescriber $objectDescriber) + { + if (strtolower(current(array_keys($data))) == strtolower($objectDescriber->getClassNameWithoutNamespace())) { + return current($data); + } + return $data; + } + + /** + * @param ObjectDescriber $objectDescriber + * @param string $key + * @param bool $getClassNameFromAnnotation + * @return mixed + * @throws \Exception + */ + protected static function getDependencyObject(ObjectDescriber $objectDescriber, $key, $getClassNameFromAnnotation = true) + { + $newClassName = self::getDependencyClassName($objectDescriber, $key, $getClassNameFromAnnotation); + if ( ! class_exists($newClassName)) { + $newClassName = self::tryPluralDependencyObject($newClassName); + } + return new $newClassName; + } + + /** + * @param $newClassName + * @return string + * @throws \Exception + */ + protected static function tryPluralDependencyObject($newClassName) + { + if ( ! substr($newClassName, -1) === 's' || ! class_exists($pluralClassName = substr($newClassName, 0, -1))) { + throw new \Exception(sprintf('Class %s does not exist', $newClassName)); + } + return $pluralClassName; + } + + /** + * @param ObjectDescriber $objectDescriber + * @param string $key + * @param bool $getClassNameFromAnnotation + * @return string + */ + protected static function getDependencyClassName(ObjectDescriber $objectDescriber, $key, $getClassNameFromAnnotation = true) + { + if ($getClassNameFromAnnotation) { + $key = $objectDescriber->properties->get($key)->get('var'); + } + if ($key == 'ArrayCollection') { + return 'OpenRtb\Tools\Classes\ArrayCollection'; + } + return $objectDescriber->getNamespace().'\\'.$key; + } + + /** + * @param object $object + * @param string $key + * @param mixed $value + * @throws \Exception + */ + protected static function set($object, $key, $value) + { + $method = 'set'.ucfirst($key); + if ( ! method_exists($object, $method)) { + throw new \Exception(sprintf('Method %s does not exist', $method)); + } + $object->$method($value); + } +} diff --git a/src/Mapper/Map.php b/src/Mapper/Map.php new file mode 100644 index 0000000..16ea7b3 --- /dev/null +++ b/src/Mapper/Map.php @@ -0,0 +1,78 @@ +map[$mapItem->getObjectPath()] = $mapItem; + } + + /** + * @return array + */ + public function getObjectPaths() + { + return array_keys($this->map); + } + + /** + * @param string $objectPath + * @return bool + */ + public function containsObjectPath($objectPath) + { + return isset($this->map[$objectPath]) || array_key_exists($objectPath, $this->map); + } + + /** + * @param string $objectPath + * @return MapItem/null + */ + public function get($objectPath) + { + return isset($this->map[$objectPath]) ? $this->map[$objectPath] : null; + } + + /** + * @param string $objectPath + * @return bool + */ + public function removeObjectPath($objectPath) + { + if ( ! $this->containsObjectPath($objectPath)) { + return false; + } + unset($this->map[$objectPath]); + return true; + } + + /** + * @return int + */ + public function count() + { + return count($this->map); + } + + /** + * @return ArrayIterator + */ + public function getIterator() + { + return new ArrayIterator($this->map); + } +} diff --git a/src/Mapper/MapFactory.php b/src/Mapper/MapFactory.php new file mode 100644 index 0000000..fe2d89a --- /dev/null +++ b/src/Mapper/MapFactory.php @@ -0,0 +1,101 @@ + $value) { + $tags = []; + if (strpos($key, ':') !== false) { + list($key, $tags) = explode(':', $key); + $tags = self::normaliseTags($tags); + } + $map->add(new MapItem($key, $value, $tags)); + } + return $map; + } + + /** + * @param string/array $tags + * @return array + * @throws \Exception + */ + protected static function normaliseTags($tags) + { + if (is_string($tags)) { + $tags = self::tagsFromString($tags); + } + if ( ! is_array($tags)) { + throw new \Exception('Invalid tags'); + } + return self::validateTags($tags); + } + + /** + * @param array $tags + * @return array + */ + protected static function validateTags(array $tags) + { + $result = []; + if (empty($tags)) { + return $result; + } + foreach ($tags as $tag => $value) { + if ( ! self::isValidTag($tag)) { + continue; + } + $result[$tag] = $value; + } + return $result; + } + + /** + * @param string $tags + * @return array + */ + protected static function tagsFromString($tags) + { + $result = []; + $tags = explode('@', $tags); + foreach ($tags as $tag) { + if (empty($tag)) { + continue; + } + if (strpos($tag, ' ') !== false) { + list($tag, $value) = explode(' ', $tag); + } + $result[$tag] = isset($value) ? $value : true; + } + return $result; + } + + /** + * @param $tag + * @return bool + */ + protected static function isValidTag($tag) + { + if ( ! in_array($tag, self::$allowedTags)) { + return false; + } + return true; + } +} diff --git a/src/Mapper/MapItem.php b/src/Mapper/MapItem.php new file mode 100644 index 0000000..30aac06 --- /dev/null +++ b/src/Mapper/MapItem.php @@ -0,0 +1,134 @@ + false, + 'uuid' => false, + 'default' => null + ]; + + /** + * @param $objectPath + * @param $value + * @param $tags + */ + public function __construct($objectPath, $value, $tags = []) + { + $this->objectPath = $objectPath; + $this->value = $value; + $this->setTags($tags); + } + + /** + * @return mixed + */ + public function getObjectPath() + { + return $this->objectPath; + } + + /** + * @param string $objectPath + * @return $this + */ + public function setObjectPath($objectPath) + { + $this->objectPath = $objectPath; + return $this; + } + + /** + * @return mixed + */ + public function getValue() + { + return $this->value; + } + + /** + * @param mixed $value + * @return $this + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * @return array + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param $tags + * @return $this + */ + public function setTags(array $tags) + { + $this->tags = array_replace($this->tags, $tags); + return $this; + } + + public function setTag($tag, $value) + { + if ( ! in_array($tag, array_keys($this->tags))) { + return false; + } + $this->tags[$tag] = $value; + return $this; + } + + /** + * @return bool + */ + public function isRequired() + { + return (bool) $this->tags['required']; + } + + /** + * @return bool + */ + public function isUuid() + { + return (bool) $this->tags['uuid']; + } + + /** + * @return mixed + */ + public function getDefaultValue() + { + return $this->tags['default']; + } + + /** + * @return bool + */ + public function isDefaultValueNull() + { + return is_null($this->tags['default']); + } + +} diff --git a/src/Mapper/Mapper.php b/src/Mapper/Mapper.php new file mode 100644 index 0000000..7249f71 --- /dev/null +++ b/src/Mapper/Mapper.php @@ -0,0 +1,139 @@ +processPath($item->getObjectPath(), $this->getValueFromObject($object, $item->getValue())) + ); + } + return $result; + } + + /** + * @param Map $map + * @param array $source + * @return array + */ + public function mapFromArray(Map $map, array $source) + { + $result = []; + foreach ($map as $item) { + $result = array_merge_recursive( + $result, + $this->processPath($item->getObjectPath(), $source[$item->getValue()]) + ); + } + return $result; + } + + /** + * @param Map $map + * @return array + */ + public function mapFromValues(Map $map) + { + $result = []; + foreach ($map as $item) { + $result = array_merge_recursive( + $result, + $this->processPath($item->getObjectPath(), $item->getValue()) + ); + } + return $result; + } + + protected function getValueFromObject($object, $path) + { + $result = $object; + $path = explode('.', $path); + foreach ($path as $node) { + $matches = $this->parseNode($node); + $get = 'get'.$matches['key']; + if (isset($matches['array'])) { + $result = $result->{$get}()->current(); + } else { + $result = $result->{$get}(); + } + } + return $result; + } + + /** + * @param string $path + * @param mixed $value + * @return array + */ + protected function processPath($path, $value) + { + $result = []; + $path = array_reverse(explode('.', $path)); + foreach ($path as $node) { + $matches = $this->parseNode($node); + if (empty($result)) { + $result[strtolower($matches['key'])] = $value; + continue; + } + $result = $this->createNode($node, $result); + } + return $result; + } + + /** + * @param string $node + * @param mixed $value + * @return array + */ + protected function createNode($node, $value) + { + $matches = $this->parseNode($node); + $result = []; + if (isset($matches['array'])) { + if (isset($matches['arrayKey'])) { + $result[strtolower($matches['key'])] = [$this->getValidArrayKey($matches['arrayKey']) => $value]; + } else { + $result[strtolower($matches['key'])] = [$value]; + } + } else { + $result[strtolower($matches['key'])] = $value; + } + + return $result; + } + + /** + * @param mixed $arrayKey + * @return string + */ + protected function getValidArrayKey($arrayKey) + { + if (is_numeric($arrayKey)) { + $arrayKey = 'id'.$arrayKey; + } + return strtolower($arrayKey); + } + + /** + * @param string $node + * @return array + */ + public function parseNode($node) + { + $regex = "/(?[\\w]+)(?\\[(?.*)\\])?/i"; + preg_match($regex, $node, $matches); + return $matches; + } + + +} diff --git a/src/NativeAdRequest/Assets.php b/src/NativeAdRequest/Assets.php new file mode 100644 index 0000000..e36f56c --- /dev/null +++ b/src/NativeAdRequest/Assets.php @@ -0,0 +1,182 @@ +id; + } + + /** + * @param int $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->id = $this->validateInt($id); + return $this; + } + + /** + * @return int + */ + public function getRequired() + { + return $this->required; + } + + /** + * @param int $required + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setRequired($required) + { + $this->validateIn($required, BitType::getAll()); + $this->required = $required; + return $this; + } + + /** + * @return Title + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param Title $title + * @return $this + */ + public function setTitle(Title $title) + { + $this->title = $title; + return $this; + } + + /** + * @return Image + */ + public function getImg() + { + return $this->img; + } + + /** + * @param Image $img + * @return $this + */ + public function setImg(Image $img) + { + $this->img = $img; + return $this; + } + + /** + * @return Video + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video $video + * @return $this + */ + public function setVideo(Video $video) + { + $this->video = $video; + return $this; + } + + /** + * @return Data + */ + public function getData() + { + return $this->data; + } + + /** + * @param Data $data + * @return $this + */ + public function setData(Data $data) + { + $this->data = $data; + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdRequest/Data.php b/src/NativeAdRequest/Data.php new file mode 100644 index 0000000..9b349c8 --- /dev/null +++ b/src/NativeAdRequest/Data.php @@ -0,0 +1,89 @@ +type; + } + + /** + * @param int $type + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setType($type) + { + $this->validateInWithCustom500Values($type, DataAssetType::getAll()); + $this->type = $type; + return $this; + } + + /** + * @return int + */ + public function getLen() + { + return $this->len; + } + + /** + * @param int $len + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLen($len) + { + $this->len = $this->validatePositiveInt($len); + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdRequest/Ext.php b/src/NativeAdRequest/Ext.php new file mode 100644 index 0000000..6a7b2cf --- /dev/null +++ b/src/NativeAdRequest/Ext.php @@ -0,0 +1,9 @@ +type; + } + + /** + * @param int $type + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setType($type) + { + $this->validateInWithCustom500Values($type, ImageAssetType::getAll()); + $this->type = $type; + return $this; + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validateInt($w); + return $this; + } + + /** + * @return int + */ + public function getWmin() + { + return $this->wmin; + } + + /** + * @param int $wmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setWmin($wmin) + { + $this->wmin = $this->validateInt($wmin); + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validateInt($h); + return $this; + } + + /** + * @return int + */ + public function getHmin() + { + return $this->hmin; + } + + /** + * @param int $hmin + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setHmin($hmin) + { + $this->hmin = $this->validateInt($hmin); + return $this; + } + + /** + * @return array + */ + public function getMimes() + { + return $this->mimes; + } + + /** + * @param string $mimes + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addMimes($mimes) + { + $this->validateIn($mimes, ImageMimeType::getAll()); + $this->mimes[] = $mimes; + return $this; + } + + /** + * @param array $mimes + * @return $this + */ + public function setMimes(array $mimes) + { + $this->mimes = $mimes; + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdRequest/NativeAdRequest.php b/src/NativeAdRequest/NativeAdRequest.php new file mode 100644 index 0000000..09e9322 --- /dev/null +++ b/src/NativeAdRequest/NativeAdRequest.php @@ -0,0 +1,226 @@ +initialize(); + } + + public function initialize() + { + $this->setAssets(new ArrayCollection()); + } + + /** + * @return string + */ + public function getRequest() + { + return json_encode(['native' => $this->toArray()]); + } + + /** + * @return string + */ + public function getVer() + { + return $this->ver; + } + + /** + * @param string $ver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVer($ver) + { + $this->ver = $this->validateVersion($ver); + return $this; + } + + /** + * @return int + */ + public function getLayout() + { + return $this->layout; + } + + /** + * @param int $layout + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLayout($layout) + { + $this->validateIn($layout, NativeLayout::getAll()); + $this->layout = $layout; + return $this; + } + + /** + * @return mixed + */ + public function getAdunit() + { + return $this->adunit; + } + + /** + * @param int $adunit + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setAdunit($adunit) + { + $this->validateIn($adunit, NativeAdUnit::getAll()); + $this->adunit = $adunit; + return $this; + } + + /** + * @return int + */ + public function getPlcmtcnt() + { + return $this->plcmtcnt; + } + + /** + * @param int $plcmtcnt + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setPlcmtcnt($plcmtcnt) + { + $this->plcmtcnt = $this->validateInt($plcmtcnt); + return $this; + } + + /** + * @return int + */ + public function getSeq() + { + return $this->seq; + } + + /** + * @param int $seq + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setSeq($seq) + { + $this->seq = $this->validateInt($seq); + return $this; + } + + /** + * @return ArrayCollection + */ + public function getAssets() + { + return $this->assets; + } + + /** + * @param Assets $assets + * @return $this + */ + public function addAssets(Assets $assets) + { + $this->assets->add($assets); + return $this; + } + + /** + * @param ArrayCollection $assets + * @return $this + */ + public function setAssets(ArrayCollection $assets) + { + $this->assets = $assets; + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdRequest/Specification/BitType.php b/src/NativeAdRequest/Specification/BitType.php new file mode 100644 index 0000000..d9ff2af --- /dev/null +++ b/src/NativeAdRequest/Specification/BitType.php @@ -0,0 +1,13 @@ +len; + } + + /** + * @param int $len + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLen($len) + { + $this->len = $this->validatePositiveInt($len); + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdRequest/Video.php b/src/NativeAdRequest/Video.php new file mode 100644 index 0000000..678da4b --- /dev/null +++ b/src/NativeAdRequest/Video.php @@ -0,0 +1,164 @@ +mimes; + } + + /** + * @param string $mimes + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addMimes($mimes) + { + $this->validateIn($mimes, VideoMimeType::getAll()); + $this->mimes = $mimes; + return $this; + } + + /** + * @param array $mimes + * @return $this + */ + public function setMimes(array $mimes) + { + $this->mimes = $mimes; + return $this; + } + + /** + * @return int + */ + public function getMinduration() + { + return $this->minduration; + } + + /** + * @param int $minduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMinduration($minduration) + { + $this->minduration = $this->validateInt($minduration); + return $this; + } + + /** + * @return int + */ + public function getMaxduration() + { + return $this->maxduration; + } + + /** + * @param int $maxduration + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setMaxduration($maxduration) + { + $this->maxduration = $this->validateInt($maxduration); + return $this; + } + + /** + * @return array + */ + public function getProtocols() + { + return $this->protocols; + } + + /** + * @param int $protocols + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addProtocols($protocols) + { + $this->validateIn($protocols, VideoBidResponseProtocols::getAll()); + $this->protocols[] = $protocols; + return $this; + } + + /** + * @param array $protocols + * @return $this + */ + public function setProtocols(array $protocols) + { + $this->protocols = $protocols; + return $this; + } + + /** + * @return mixed + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt($ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Assets.php b/src/NativeAdResponse/Assets.php new file mode 100644 index 0000000..b34c256 --- /dev/null +++ b/src/NativeAdResponse/Assets.php @@ -0,0 +1,208 @@ +id; + } + + /** + * @param int $id + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setId($id) + { + $this->id = $this->validateInt($id); + return $this; + } + + /** + * @return int + */ + public function getRequired() + { + return $this->required; + } + + /** + * @param int $required + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setRequired($required) + { + $this->required = $this->validateInt($required); + return $this; + } + + /** + * @return Title + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param Title $title + * @return $this + */ + public function setTitle(Title $title) + { + $this->title = $title; + return $this; + } + + /** + * @return Image + */ + public function getImg() + { + return $this->img; + } + + /** + * @param Image $img + * @return $this + */ + public function setImg(Image $img) + { + $this->img = $img; + return $this; + } + + /** + * @return Video + */ + public function getVideo() + { + return $this->video; + } + + /** + * @param Video $video + * @return $this + */ + public function setVideo(Video $video) + { + $this->video = $video; + return $this; + } + + /** + * @return Data + */ + public function getData() + { + return $this->data; + } + + /** + * @param Data $data + * @return $this + */ + public function setData(Data $data) + { + $this->data = $data; + return $this; + } + + /** + * @return Link + */ + public function getLink() + { + return $this->link; + } + + /** + * @param Link $link + * @return $this + */ + public function setLink(Link $link) + { + $this->link = $link; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Data.php b/src/NativeAdResponse/Data.php new file mode 100644 index 0000000..d38146a --- /dev/null +++ b/src/NativeAdResponse/Data.php @@ -0,0 +1,89 @@ +label; + } + + /** + * @param string $label + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setLabel($label) + { + $this->validateString($label); + $this->label = $label; + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * @param string $value + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setValue($value) + { + $this->validateString($value); + $this->value = $value; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Ext.php b/src/NativeAdResponse/Ext.php new file mode 100644 index 0000000..28bdad8 --- /dev/null +++ b/src/NativeAdResponse/Ext.php @@ -0,0 +1,9 @@ +url; + } + + /** + * @param string $url + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUrl($url) + { + $this->validateString($url); + $this->url = $url; + return $this; + } + + /** + * @return int + */ + public function getW() + { + return $this->w; + } + + /** + * @param int $w + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setW($w) + { + $this->w = $this->validateInt($w); + return $this; + } + + /** + * @return int + */ + public function getH() + { + return $this->h; + } + + /** + * @param int $h + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setH($h) + { + $this->h = $this->validateInt($h); + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Link.php b/src/NativeAdResponse/Link.php new file mode 100644 index 0000000..7149634 --- /dev/null +++ b/src/NativeAdResponse/Link.php @@ -0,0 +1,126 @@ +url; + } + + /** + * @param string $url + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setUrl($url) + { + $this->validateString($url); + $this->url = $url; + return $this; + } + + /** + * @return array + */ + public function getClicktrackers() + { + return $this->clicktrackers; + } + + /** + * @param string $clicktrackers + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addClicktrackers($clicktrackers) + { + $this->validateString($clicktrackers); + $this->clicktrackers[] = $clicktrackers; + return $this; + } + + /** + * @param array $clicktrackers + * @return $this + */ + public function setClicktrackers(array $clicktrackers) + { + $this->clicktrackers = $clicktrackers; + return $this; + } + + /** + * @return string + */ + public function getFallback() + { + return $this->fallback; + } + + /** + * @param string $fallback + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setFallback($fallback) + { + $this->validateString($fallback); + $this->fallback = $fallback; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Native.php b/src/NativeAdResponse/Native.php new file mode 100644 index 0000000..ac24b96 --- /dev/null +++ b/src/NativeAdResponse/Native.php @@ -0,0 +1,196 @@ +initialize(); + } + + public function initialize() + { + $this->setAssets(new ArrayCollection()); + } + + /** + * @return int + */ + public function getVer() + { + return $this->ver; + } + + /** + * @param int $ver + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVer($ver) + { + $this->ver = $this->validateInt($ver); + return $this; + } + + /** + * @return ArrayCollection + */ + public function getAssets() + { + return $this->assets; + } + + /** + * @param Assets $assets + * @return $this + */ + public function addAssets(Assets $assets) + { + $this->assets->add($assets); + return $this; + } + + /** + * @param ArrayCollection $assets + * @return $this + */ + public function setAssets(ArrayCollection $assets) + { + $this->assets = $assets; + return $this; + } + + /** + * @return Link + */ + public function getLink() + { + return $this->link; + } + + /** + * @param Link $link + * @return $this + */ + public function setLink(Link $link) + { + $this->link = $link; + return $this; + } + + /** + * @return array + */ + public function getImptrackers() + { + return $this->imptrackers; + } + + /** + * @param string $imptrackers + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function addImptrackers($imptrackers) + { + $this->validateString($imptrackers); + $this->imptrackers[] = $imptrackers; + return $this; + } + + /** + * @param array $imptrackers + * @return $this + */ + public function setImptrackers(array $imptrackers) + { + $this->imptrackers = $imptrackers; + return $this; + } + + /** + * @return string + */ + public function getJstracker() + { + return $this->jstracker; + } + + /** + * @param string $jstracker + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setJstracker($jstracker) + { + $this->validateString($jstracker); + $this->jstracker = $jstracker; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param Ext $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/NativeAdResponse.php b/src/NativeAdResponse/NativeAdResponse.php new file mode 100644 index 0000000..8be7547 --- /dev/null +++ b/src/NativeAdResponse/NativeAdResponse.php @@ -0,0 +1,37 @@ +native; + } + + /** + * @param Native $native + * @return $this + */ + public function setNative(Native $native) + { + $this->native = $native; + return $this; + } +} diff --git a/src/NativeAdResponse/Title.php b/src/NativeAdResponse/Title.php new file mode 100644 index 0000000..2137a97 --- /dev/null +++ b/src/NativeAdResponse/Title.php @@ -0,0 +1,63 @@ +text; + } + + /** + * @param string $text + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setText($text) + { + $this->validateString($text); + $this->text = $text; + return $this; + } + + /** + * @return Ext + */ + public function getExt() + { + return $this->ext; + } + + /** + * @param $ext + * @return $this + */ + public function setExt(Ext $ext) + { + $this->ext = $ext; + return $this; + } +} diff --git a/src/NativeAdResponse/Video.php b/src/NativeAdResponse/Video.php new file mode 100644 index 0000000..602174b --- /dev/null +++ b/src/NativeAdResponse/Video.php @@ -0,0 +1,40 @@ +vasttag; + } + + /** + * @param string $vasttag + * @return $this + * @throws \OpenRtb\Tools\Exceptions\ExceptionInvalidValue + */ + public function setVasttag($vasttag) + { + $this->validateString($vasttag); + $this->vasttag = $vasttag; + return $this; + } +} diff --git a/src/Tools/Classes/ArrayCollection.php b/src/Tools/Classes/ArrayCollection.php new file mode 100644 index 0000000..8e570d9 --- /dev/null +++ b/src/Tools/Classes/ArrayCollection.php @@ -0,0 +1,262 @@ +elements = $elements; + } + + /** + * {@inheritDoc} + */ + public function toArray() + { + return $this->elements; + } + + /** + * {@inheritDoc} + */ + public function first() + { + return reset($this->elements); + } + + /** + * {@inheritDoc} + */ + public function last() + { + return end($this->elements); + } + + /** + * {@inheritDoc} + */ + public function key() + { + return key($this->elements); + } + + /** + * {@inheritDoc} + */ + public function next() + { + return next($this->elements); + } + + /** + * {@inheritDoc} + */ + public function current() + { + return current($this->elements); + } + + /** + * {@inheritDoc} + */ + public function remove($key) + { + if ( ! isset($this->elements[$key]) && ! array_key_exists($key, $this->elements)) { + return null; + } + $removed = $this->elements[$key]; + unset($this->elements[$key]); + return $removed; + } + + /** + * {@inheritDoc} + */ + public function removeElement($element) + { + $key = array_search($element, $this->elements, true); + if ($key === false) { + return false; + } + unset($this->elements[$key]); + return true; + } + + /** + * Required by interface ArrayAccess. + * + * {@inheritDoc} + */ + public function offsetExists($offset) + { + return $this->containsKey($offset); + } + + /** + * Required by interface ArrayAccess. + * + * {@inheritDoc} + */ + public function offsetGet($offset) + { + return $this->get($offset); + } + + /** + * Required by interface ArrayAccess. + * + * {@inheritDoc} + */ + public function offsetSet($offset, $value) + { + if ( ! isset($offset)) { + return $this->add($value); + } + $this->set($offset, $value); + } + + /** + * Required by interface ArrayAccess. + * + * {@inheritDoc} + */ + public function offsetUnset($offset) + { + return $this->remove($offset); + } + + /** + * {@inheritDoc} + */ + public function containsKey($key) + { + return isset($this->elements[$key]) || array_key_exists($key, $this->elements); + } + + /** + * {@inheritDoc} + */ + public function contains($element) + { + return in_array($element, $this->elements, true); + } + + /** + * {@inheritDoc} + */ + public function indexOf($element) + { + return array_search($element, $this->elements, true); + } + + /** + * {@inheritDoc} + */ + public function get($key) + { + return isset($this->elements[$key]) ? $this->elements[$key] : null; + } + + /** + * {@inheritDoc} + */ + public function getKeys() + { + return array_keys($this->elements); + } + + /** + * {@inheritDoc} + */ + public function getValues() + { + return array_values($this->elements); + } + + /** + * {@inheritDoc} + */ + public function count() + { + return count($this->elements); + } + + /** + * {@inheritDoc} + */ + public function set($key, $value) + { + $this->elements[$key] = $value; + } + + /** + * {@inheritDoc} + */ + public function add($value) + { + $this->elements[] = $value; + return true; + } + + /** + * {@inheritDoc} + */ + public function isEmpty() + { + return empty($this->elements); + } + + /** + * Required by interface IteratorAggregate. + * + * {@inheritDoc} + */ + public function getIterator() + { + return new ArrayIterator($this->elements); + } + + /** + * Returns a string representation of this object. + * + * @return string + */ + public function __toString() + { + return __CLASS__ . '@' . spl_object_hash($this); + } + + /** + * {@inheritDoc} + */ + public function clear() + { + $this->elements = array(); + } + + /** + * {@inheritDoc} + */ + public function slice($offset, $length = null) + { + return array_slice($this->elements, $offset, $length, true); + } +} diff --git a/src/Tools/Classes/Ext.php b/src/Tools/Classes/Ext.php new file mode 100644 index 0000000..91cd6f3 --- /dev/null +++ b/src/Tools/Classes/Ext.php @@ -0,0 +1,51 @@ +parameters = array_replace($this->parameters, $parameters); + return $this; + } + + /** + * @param $key + * @param $value + * @return $this + */ + public function set($key, $value) + { + $this->parameters[$key] = $value; + return $this; + } + + /** + * @param $key + * @return mixed + */ + public function get($key) + { + return isset($this->parameters[$key]) ? $this->parameters[$key] : null; + } + + /** + * @return array + */ + public function toArray() + { + return $this->parameters; + } +} diff --git a/src/Tools/Exceptions/ExceptionInvalidValue.php b/src/Tools/Exceptions/ExceptionInvalidValue.php new file mode 100644 index 0000000..eff6b69 --- /dev/null +++ b/src/Tools/Exceptions/ExceptionInvalidValue.php @@ -0,0 +1,29 @@ +message = $message.' - '.$this->formatTrace(); + } + + private function formatTrace() + { + return + $this->retriveValue(1,'class').'::'. + $this->retriveValue(1, 'function').'::'. + $this->retriveValue(0, 'line'). + '['.$this->retriveValue(0, 'function').']'; + } + + private function retriveValue($index, $subIndex) + { + $trace = $this->getTrace(); + return isset($trace[$index][$subIndex]) ? $trace[$index][$subIndex] : 'null'; + } +} diff --git a/src/Tools/Exceptions/ExceptionMissingRequiredField.php b/src/Tools/Exceptions/ExceptionMissingRequiredField.php new file mode 100644 index 0000000..43e90cc --- /dev/null +++ b/src/Tools/Exceptions/ExceptionMissingRequiredField.php @@ -0,0 +1,9 @@ +set($annotation, true); + } else { + list($key, $value) = explode(' ', $annotation); + $this->set($key, $value); + } + } + return $this; + } + + /** + * @return bool + */ + public function isRequired() + { + if ( ! $this->has('required')) { + return false; + } + return $this->parameters['required']; + } + + /** + * @return bool + */ + public function isRecommended() + { + if ( ! $this->has('recommended')) { + return false; + } + return $this->parameters['recommended']; + } + + /** + * @return bool + */ + public function isOptional() + { + if ( ! $this->has('recommended') && ! $this->has('required')) { + return false; + } + return true; + } + + public function isObject() + { + if ( ! $this->has('var')) { + throw new \Exception('Impossible to identify the type'); + } + if (in_array($this->get('var'), $this->noObjectTypes)) { + return false; + } + return true; + } +} diff --git a/src/Tools/ObjectAnalyzer/Bag.php b/src/Tools/ObjectAnalyzer/Bag.php new file mode 100644 index 0000000..89fa45b --- /dev/null +++ b/src/Tools/ObjectAnalyzer/Bag.php @@ -0,0 +1,10 @@ +properties = new ParametersBag(); + $this->methods = new ParametersBag(); + } + + /** + * @return string + */ + public function getNamespace() + { + $nameSpaceExploded = explode('\\', $this->name); + array_pop($nameSpaceExploded); + return implode('\\', $nameSpaceExploded); + } + + /** + * @return string + */ + public function getClassName() + { + return $this->name; + } + + /** + * @return string + */ + public function getClassNameWithoutNamespace() + { + return current(array_reverse(explode('\\', $this->name))); + } +} diff --git a/src/Tools/ObjectAnalyzer/ObjectDescriberFactory.php b/src/Tools/ObjectAnalyzer/ObjectDescriberFactory.php new file mode 100644 index 0000000..65103ed --- /dev/null +++ b/src/Tools/ObjectAnalyzer/ObjectDescriberFactory.php @@ -0,0 +1,88 @@ +name = $reflectionClass->getName(); + $objectDescriber->properties->add(self::createPropertiesBag($reflectionClass)); + $objectDescriber->methods->add(self::createMethodsBag($reflectionClass)); + + self::cacheStore($className, $objectDescriber); + return $objectDescriber; + } + + /** + * @param $className + * @return string + * @throws \Exception + */ + private static function checkClassName($className) + { + if (is_object($className)) { + $className = get_class($className); + } + if ( ! class_exists($className)) { + throw new \Exception('Class does not exist'); + } + return $className; + } + + /** + * @param ReflectionClass $reflectionClass + * @return ParametersBag + */ + private static function createPropertiesBag(ReflectionClass $reflectionClass) + { + $result = []; + foreach ($reflectionClass->getProperties() as $property) { + $result[$property->getName()] = self::createPropertyAnnotationsBag($property); + } + return $result; + } + + /** + * @param ReflectionClass $reflectionClass + * @return ParametersBag + */ + private static function createMethodsBag(ReflectionClass $reflectionClass) + { + $result = []; + foreach ($reflectionClass->getMethods() as $method) { + $result[$method->getName()] = $method->isPublic(); + } + return $result; + } + + /** + * @param ReflectionProperty $reflectionProperty + * @return AnnotationsBag + */ + private static function createPropertyAnnotationsBag(ReflectionProperty $reflectionProperty) + { + $annotationsBag = new AnnotationsBag(); + return $annotationsBag + ->set('name', $reflectionProperty->getName()) + ->initializeDoc($reflectionProperty->getDocComment()); + } +} diff --git a/src/Tools/ObjectAnalyzer/ParametersBag.php b/src/Tools/ObjectAnalyzer/ParametersBag.php new file mode 100644 index 0000000..f60ba26 --- /dev/null +++ b/src/Tools/ObjectAnalyzer/ParametersBag.php @@ -0,0 +1,95 @@ +parameters = $parameters; + } + + /** + * @param $key + * @param $value + * @return $this + */ + public function set($key, $value) + { + $this->parameters[$key] = $value; + return $this; + } + + /** + * @param array $parameters + * @return $this + */ + public function add(array $parameters = array()) + { + $this->parameters = array_replace($this->parameters, $parameters); + return $this; + } + + /** + * @param $key + * @return bool + */ + public function has($key) + { + return array_key_exists($key, $this->parameters); + } + + /** + * @return mixed + */ + public function all() + { + return $this->parameters; + } + + /** + * @return array + */ + public function keys() + { + return array_keys($this->parameters); + } + + /** + * @param $key + * @return mixed + * @throws \InvalidArgumentException + */ + public function get($key) + { + if ( ! $this->has($key)) { + throw new InvalidArgumentException('The key does not exist'); + } + return $this->parameters[$key]; + } + + /** + * @return ArrayIterator + */ + public function getIterator() + { + return new ArrayIterator($this->parameters); + } + + /** + * @return int + */ + public function count() + { + return count($this->parameters); + } + +} diff --git a/src/Tools/Traits/Cache.php b/src/Tools/Traits/Cache.php new file mode 100644 index 0000000..009d090 --- /dev/null +++ b/src/Tools/Traits/Cache.php @@ -0,0 +1,40 @@ +getConstants(); + } +} diff --git a/src/Tools/Traits/SetterValidation.php b/src/Tools/Traits/SetterValidation.php new file mode 100644 index 0000000..b39bbf5 --- /dev/null +++ b/src/Tools/Traits/SetterValidation.php @@ -0,0 +1,246 @@ +argumentsForError($string) + ) + ); + } + return $string; + } + + /** + * @param string $string + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateString($string) + { + if ( ! is_string($string)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not a string', + $this->argumentsForError($string) + ) + ); + } + return true; + } + + /** + * @param int $int + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateInt($int) + { + if (is_numeric($int) && ! is_float($int)) { + $int = (int) $int; + } + + if ( ! is_int($int)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not an integer', + $this->argumentsForError($int) + ) + ); + } + return $int; + } + + /** + * @param int $int + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validatePositiveInt($int) + { + if (is_numeric($int) && ! is_float($int)) { + $int = (int) $int; + } + + if ( ! is_int($int) || $int < 0) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not a valid integer', + $this->argumentsForError($int) + ) + ); + } + return $int; + } + + /** + * @param float|int $float + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateNumericToFloat($float) + { + if (is_numeric($float)) { + $float = (float) $float; + } + + if ( ! is_float($float)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not a float', + $this->argumentsForError($float) + ) + ); + } + return $float; + } + + /** + * @param float $float + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validatePositiveFloat($float) + { + if (is_numeric($float)) { + $float = (float) $float; + } + + if ( ! is_float($float) || $float < 0) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not a positive float', + $this->argumentsForError($float) + ) + ); + } + return $float; + } + + /** + * @param mixed $value + * @param array $values + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateIn($value, array $values) + { + if ( ! in_array($value, $values)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not allowed', + $this->argumentsForError($value) + ) + ); + } + return true; + } + + /** + * @param mixed $value + * @param array $values + * @return bool + * @throws ExceptionInvalidValue + * Taking into account custom 500+ values, which are legal according to the spec, though + * we may not have a representation of them + */ + protected function validateInWithCustom500Values($value, array $values) + { + if ( ! in_array($value, $values) && ! (is_numeric($value) && $value >= 500) ) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not allowed', + $this->argumentsForError($value) + ) + ); + } + return true; + } + + /** + * @param string $md5 + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateMd5($md5) + { + if ( ! is_string($md5) || ! (bool) preg_match('/^[0-9a-f]{32}$/i', $md5)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not MD5', + $this->argumentsForError($md5) + ) + ); + } + return true; + } + + /** + * @param string $sha1 + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateSha1($sha1) + { + if ( ! is_string($sha1) || ! (bool) preg_match('/^[0-9a-f]{40}$/i', $sha1)) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not SHA1', + $this->argumentsForError($sha1) + ) + ); + } + return true; + } + + /** + * @param string $ip + * @return bool + * @throws ExceptionInvalidValue + */ + protected function validateIp($ip) + { + /** + * TODO According to the spec, if the regs.coppa field is set to 1, then the IP's last octet should be + * truncated. So we may receive a valid IP like 192.168.1. Handle this edge case. + */ + if (filter_var($ip, FILTER_VALIDATE_IP) === false) { + throw new ExceptionInvalidValue( + vsprintf( + 'Argument\'s value (%s of type %s) is not a valid IP', + $this->argumentsForError($ip) + ) + ); + } + return true; + } + + /** + * @param mixed $variable + * @return array + */ + private function argumentsForError($variable) + { + return [ + is_scalar($variable) ? $variable : get_class($variable), + gettype($variable) + ]; + } +} diff --git a/src/Tools/Traits/ToArray.php b/src/Tools/Traits/ToArray.php new file mode 100644 index 0000000..e0f9501 --- /dev/null +++ b/src/Tools/Traits/ToArray.php @@ -0,0 +1,84 @@ +getProperties(); + foreach ($properties as $propertyName => $property) { + if (is_object($this->$propertyName)) { + $this->addResult( + $result, + $propertyName, + $this->getArrayFromObject($this->$propertyName), + $property->isRequired() + ); + continue; + } + $this->addResult( + $result, + $propertyName, + $this->$propertyName, + $property->isRequired() + ); + } + return $result; + } + + /** + * @return \OpenRtb\Tools\ObjectAnalyzer\ParametersBag + * @throws \Exception + */ + private function getProperties() + { + $objectDescriptor = ObjectDescriberFactory::create(__CLASS__); + return $objectDescriptor->properties; + } + + /** + * @param object $object + * @return array + */ + private function getArrayFromObject($object) + { + $result = []; + if ($object instanceof \OpenRtb\Tools\Classes\ArrayCollection && ! $object->isEmpty()) { + foreach ($object as $item) { + $result[] = $item->toArray(); + } + } else { + $result = $object->toArray(); + } + return $result; + } + + /** + * @param array $result + * @param string $key + * @param mixed $value + * @param bool $required + * @throws ExceptionMissingRequiredField + */ + private function addResult(&$result, $key, $value, $required) + { + if (is_array($value) && ! empty($value)) { + $result[$key] = $value; + } elseif ( ! is_array($value) && ! is_null($value)) { + $result[$key] = $value; + } + + if ($required && ! isset($result[$key])) { + throw new ExceptionMissingRequiredField(sprintf('%s property is required in class: %s', $key, __CLASS__)); + } + } +} diff --git a/tests/AccessProtectedMethod.php b/tests/AccessProtectedMethod.php new file mode 100644 index 0000000..811cccb --- /dev/null +++ b/tests/AccessProtectedMethod.php @@ -0,0 +1,17 @@ +getMethod($methodName); + $method->setAccessible(true); + + return $method->invokeArgs($object, $parameters); + } +} diff --git a/tests/BidRequest/BidRequestTest.php b/tests/BidRequest/BidRequestTest.php new file mode 100644 index 0000000..f1c2251 --- /dev/null +++ b/tests/BidRequest/BidRequestTest.php @@ -0,0 +1,24 @@ +setId('bbb'); + + $bidRequest = new BidRequest(); + $bidRequest + ->setId('aaa') + ->addImp($imp) + ; + + $this->assertTrue(is_array($bidRequest->toArray())); + } +} diff --git a/tests/BidRequest/Specification/ApiFrameworksTest.php b/tests/BidRequest/Specification/ApiFrameworksTest.php new file mode 100644 index 0000000..c951549 --- /dev/null +++ b/tests/BidRequest/Specification/ApiFrameworksTest.php @@ -0,0 +1,15 @@ +assertTrue(is_array($result)); + } +} diff --git a/tests/HydratorTest.php b/tests/HydratorTest.php new file mode 100644 index 0000000..588045f --- /dev/null +++ b/tests/HydratorTest.php @@ -0,0 +1,224 @@ + [ + "buyeruid" => "y4O57Y16t5p449R94e7VQKs35fg7T87F", + "data" => [ + [ + "name" => "DoubleClick", + "segment" => [ + [ + "id" => "936", + "value" => "0.3" + ], + [ + "id" => "539", + "value" => "0.2" + ] + ], + "id" => "DetectedVerticals" + ] + ], + "id" => "R798U54QA3V0l3F9pmWo695f9e7", + "customdata" => "24vX66224qs416S8rza8FN137g7db8wc6cD8lRu1x94R46FA" + ], + "imp" => [ + [ + "tagid" => "2998080533", + "bidfloor" => 0.13, + "id" => "1", + "displaymanager" => "GOOGLE", + "banner" => [ + "format" => [ + [ + "w" => 300, + "h" => 250 + ], + [ + "w" => 250, + "h" => 250 + ] + ], + "expdir" => [ + 1, + 2, + 3, + 4 + ], + "w" => 300, + "h" => 250, + "pos" => 6 + ], + "metric" => [ + [ + "type" => "click_through_rate", + "value" => 0, + "vendor" => "EXCHANGE" + ], + [ + "type" => "viewability", + "value" => 0.6, + "vendor" => "EXCHANGE" + ] + ], + "ext" => [ + "billing_id" => [ + 20268073976 + ], + "ampad" => 3, + "dfp_ad_unit_code" => "/6280916/google/test" + ], + "secure" => 1, + "bidfloorcur" => "USD" + ] + ], + "device" => [ + "pxratio" => 1, + "ua" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36", + "devicetype" => 2, + "ip" => "192.168.1.0", + "geo" => [ + "lon" => 121.05069732666016, + "lat" => 0.0, + "country" => "USA", + "region" => "US-NY", + "utcoffset" => 480 + ], + "os" => "Windows" + ], + "site" => [ + "publisher" => [ + "ext" => [ + "country" => "US" + ], + "id" => "pub-6741497946274132" + ], + "ext" => [ + "amp" => 0 + ], + "content" => [ + "language" => "en", + "contentrating" => "DV-G" + ], + "page" => "https://www.google.com" + ], + "ext" => [ + "google_query_id" => "ANy-z451HD-99Nii3Jf66a7b9a06z9goBxiID357xnyi4j1Q9Rl8OEv657fppSeU147L66b6" + ], + "tmax" => 162, + "cur" => [ + "USD" + ], + "id" => "G9r0Di158163lk5p7718XG" + ]; + + $object = new BidRequest(); + + $result = Hydrator::hydrate($array, $object); + + $this->assertSame($object, $result); + $this->assertEquals('G9r0Di158163lk5p7718XG', $object->getId()); + $this->assertEquals('https://www.google.com', $object->getSite()->getPage()); + $this->assertInstanceOf('OpenRtb\Tools\Classes\ArrayCollection', $object->getImp()); + $this->assertInstanceOf('OpenRtb\BidRequest\Imp', $object->getImp()->current()); + $this->assertEquals('1', $object->getImp()->current()->getId()); +// $this->assertEquals('y4O57Y16t5p449R94e7VQKs35fg7T87F', $object->getUser()->getBuyerid()); + } + + public function testHydrateBidRequest() + { + $json = '{"badv":[],"tmax":200,"site":{"publisher":{"id":"267","name":"disqus"},"domain":"sozcu.com.tr","page":"http:\/\/www.sozcu.com.tr\/2015\/dunya\/turkiyeden-suriyeye-yuklu-miktarda-silah-sevkiyati-912385\/","id":"3763","sectioncat":["IAB12"]},"imp":[{"tagid":"","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":300},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.48,"id":"1"}],"device":{"os":"Windows 7","ip":"212.156.124.250","osv":"","geo":{"country":"TUR"},"dnt":0,"devicetype":2,"model":"Other","ua":"Mozilla\/5.0 (Windows NT 6.1; WOW64; Trident\/7.0; rv:11.0) like Gecko"},"at":2,"test":0,"id":"9c2e6ec2-99bd-4473-b4eb-b38e1ddea6d3","user":{"id":"fe3e4791fe2335ff9e786e7ef0a108d2d3d1b216"}}'; + + $object = new BidRequest(); + + Hydrator::hydrate(json_decode($json, true), $object); + + $this->assertEquals(200, $object->getTmax()); + $this->assertEquals('267', $object->getSite()->getPublisher()->getId()); + } + + public function testHydrateBidRequestOk() + { + $json = '{"id":"[ID]","imp":[{"id":"[IMP-ID]","native":{"request":"{\"native\":{\"layout\":7,\"adunit\":2,\"plcmtcnt\":6,\"seq\":0,\"assets\":[{\"id\":1,\"title\":{\"len\":50}},{\"id\":2,\"required\":1,\"img\":{\"w\":100,\"h\":70}}]}}"},"bidfloor":0.0,"ext":{"bidmodel":"CPC"}}],"site":{"cat":["IAB3"],"page":"http://asdf.com/","keywords":"tech"},"device":{"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36","ip":"24.193.27.157"},"at":1,"ext":{"pmodel":"cpc"}}'; + + $object = new BidRequest(); + + Hydrator::hydrate(json_decode($json, true), $object); + + $this->assertEquals('[ID]', $object->getId()); + $this->assertEquals('cpc', $object->getExt()->get('pmodel')); + $this->assertTrue(is_string($object->getImp()->current()->getNative()->getRequest())); + + $native = Hydrator::hydrate(json_decode($object->getImp()->current()->getNative()->getRequest(), true)['native'], new NativeAdRequest()); + $this->assertEquals($object->getImp()->current()->getNative()->getRequest(), $native->getRequest()); + } + + public function testHydrateWithExtraFakeFields() + { + $native = [ + 'request' => '{}', + 'ver' => '1.1', + 'api' => [], + 'battr' => [], + 'ext' => [], + // fields that don't exist + 'plcmtcnt' => 'fake', + 'assets' => 'fake', + 'adunit' => 3, + 'layout' => 'fake' + ]; + $object = new Native(); + + Hydrator::hydrate($native, $object); + + $this->assertEquals('1.1', $object->getVer()); + $this->assertEquals('{}', $object->getRequest()); + } + + public function jsonProvider() + { + return [ + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"267","name":"disqus"},"domain":"philstar.com","page":"http:\/\/www.philstar.com\/opinion\/2015\/08\/18\/1489348\/public-now-irrelevant-nomination-process","id":"1865","sectioncat":["IAB12"]},"imp":[{"tagid":"","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":300},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.48,"id":"1"}],"device":{"os":"iOS","ip":"49.144.161.68","osv":"8.4","geo":{"country":"PHL"},"dnt":0,"devicetype":1,"model":"iPad","ua":"Mozilla\/5.0 (iPad; CPU OS 8_4 like Mac OS X) AppleWebKit\/537.51.1 (KHTML, like Gecko) GSA\/4.0.1.31280 Mobile\/12H143 Safari\/9537.53"},"at":2,"test":0,"id":"3cbc1beb-56b2-4d1e-8335-beebc8d5c5cb","user":{"id":"dbabea9e54777949741bf96a0ac09aa53fbbc5ec"}}'], + ['{"id":"5A8A217D-7375-494E-93BB-602642C5A624","imp":[{"id":"1","tagid":"272646","banner":{"w":0,"h":0},"ext":{"native":{"layout":3,"adunit":3,"assets":[{"id":1,"required":1,"title":{"len":150}},{"id":2,"required":1,"img":{"type":3,"wmin":100,"hmin":100}},{"id":6,"required":1,"data":{"type":2,"len":200}},{"id":15,"required":0,"data":{"type":11}},{"id":5,"required":0,"data":{"type":1}}]}}}],"site":{"id":"90689","domain":"http://floor6.com/MobWeb","page":"http://boredomtherapy.com/hidden-german-bunker/18/?as=6030080037884&pas=2","ref":"http://boredomtherapy.com/hidden-german-bunker/17/?as=6030080037884&pas=2","publisher":{"id":"50758"}},"device":{"ip":"24.19.196.154","ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 [FBAN/FBIOS;FBAV/36.1.0.43.231;FBBV/13557860;FBDV/iPhone5,3;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.0;FBSS/2; FBCR/Sprint;FBID/phone;FBLC/en_US;FBOP/5]","carrier":"Comcast Cable","language":"en-US,en;q=0.5","make":"Apple","model":"iPhone","os":"iOS","Osv":"8","osv":"8","devicetype":1,"geo":{"country":"US","region":"WA","city":"Bellingham","metro":"819","zip":"98225"},"ext":{"res":"320x568","pf":2}},"user":{"keywords":"twitter,friends,facebook,inbox,terrifying,stories,bunker,omg,subscribe,guys","geo":{"country":"US","region":"WA","city":"Bellingham","zip":"98226","metro":"819"}}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"267","name":"disqus"},"domain":"bootsnipp.com","page":"http:\/\/bootsnipp.com\/snippets\/featured\/responsive-navbar-brand-centered","id":"4365","sectioncat":["IAB19"]},"imp":[{"tagid":"ARF04O5JJfT0xtT3scb7fVRO9OUF6oJPz9-wQ4u7","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":300},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.48,"id":"1"}],"device":{"os":"Windows 7","ip":"120.96.34.19","osv":"","geo":{"country":"TWN"},"dnt":0,"devicetype":2,"model":"Other","ua":"Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/44.0.2403.155 Safari\/537.36"},"at":2,"test":0,"id":"26128d00-3cf0-4b33-ad73-1b1af83d9b2b","user":{"id":"de10da4a53e497a3dd6735724be56266031b3861"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"267","name":"disqus"},"domain":"sozcu.com.tr","page":"http:\/\/www.sozcu.com.tr\/2015\/gundem\/demirtastan-koalisyon-aciklamasi-3-912438\/","id":"3763","sectioncat":["IAB12"]},"imp":[{"tagid":"","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":300},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.48,"id":"1"}],"device":{"os":"Windows 7","ip":"78.170.254.250","osv":"","geo":{"country":"TUR"},"dnt":0,"devicetype":2,"model":"Other","ua":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko\/20100101 Firefox\/40.0"},"at":2,"test":0,"id":"ac3c44c3-ecca-47bd-83b6-70be06ff2b66","user":{"id":"5f2c0bde10a67b534f84193d132097dd3837dcca"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"428","name":"epom"},"domain":"4shared.com","page":"http:\/\/search.4shared.com\/q\/CCAD\/1\/sims 1 rar","id":"1816","sectioncat":["IAB9","IAB12","IAB24"]},"imp":[{"tagid":"T1NNBiRhocoJlc-Y4N3EeCHmSLDs-jUPMsTNSEan","bidfloorcur":"USD","native":{"request":"{\"adunit\":5,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":200},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":0,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.5,"id":"1"}],"device":{"os":"BlackBerry OS","language":"en","geo":{"country":"GBR"},"osv":"7.1","dnt":0,"devicetype":1,"ip":"93.186.31.98","model":"BlackBerry 9380","ua":"Mozilla\/5.0 (BlackBerry; U; BlackBerry 9380; en) AppleWebKit\/534.11+ (KHTML, like Gecko) Version\/7.1.0.336 Mobile Safari\/534.11+"},"at":2,"test":0,"id":"a6f26a36-6e9e-40fe-a98b-5c304f1e5044","user":{"id":"47f3ceb7897045726e1254c5fb5744f1e6b90a7a"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"316","name":"adsparc"},"domain":"webdunia.com","page":"http:\/\/hindi.webdunia.com\/sanatan-dharma-mahapurush\/12-shiva-mystery-114072300014_2.html","id":"1567","sectioncat":["IAB1","IAB12","IAB17"]},"imp":[{"tagid":"Me1iEROb6rAntyWoj6YAfC8mHBrSiw3j1K6T33jH","bidfloorcur":"USD","native":{"request":"{\"adunit\":5,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":200},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":1.5,"id":"1"}],"device":{"os":"Android","language":"en","geo":{"country":"IND"},"osv":"","dnt":0,"devicetype":1,"ip":"106.79.147.202","model":"Other","ua":"Opera\/9.80 (Android; Opera Mini\/7.6.40234\/37.6283; U; en) Presto\/2.12.423 Version\/12.16"},"at":2,"test":0,"id":"c576a6a4-80a1-409f-942f-5ce96d709fef","user":{"id":"8fc32951d3d7b8291bc2ce21b05e2115f5c25e78"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"428","name":"epom"},"domain":"4shared.com","page":"http:\/\/search.4shared.com\/q\/CCAD\/020\/rude","id":"1816","sectioncat":["IAB9","IAB12","IAB24"]},"imp":[{"tagid":"T1NNBiRhocoJlc-Y4N3EeCHmSLDs-jUPMsTNSEan","bidfloorcur":"USD","native":{"request":"{\"adunit\":5,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":200},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":0,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.5,"id":"1"}],"device":{"os":"Android","language":"id","geo":{"country":"IDN"},"osv":"4.4.2","dnt":0,"devicetype":1,"ip":"202.67.40.31","model":"Lenovo A536","ua":"Mozilla\/5.0(Linux\/3.4.5; U; Android 4.4.2; zh-cn; Lenovo A536 Build\/KOT49H)AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.4.2 Mobile Safari\/534.30 Release\/01.17.2014"},"at":2,"test":0,"id":"22218b48-b537-4169-bc7c-71524da2caa2","user":{"id":"e8b1fd15d9116653e8231f8b5e3261b37a615a11"}}'], + ['{"id":"23B19D2D-4BDF-425D-95E3-3FD55134F5B7","imp":[{"id":"1","tagid":"272646","banner":{"w":0,"h":0},"ext":{"native":{"layout":3,"adunit":3,"assets":[{"id":1,"required":1,"title":{"len":150}},{"id":2,"required":1,"img":{"type":3,"wmin":100,"hmin":100}},{"id":6,"required":1,"data":{"type":2,"len":200}},{"id":15,"required":0,"data":{"type":11}},{"id":5,"required":0,"data":{"type":1}}]}}}],"site":{"id":"90689","domain":"http://floor6.com/MobWeb","page":"http://tvtropes.org/pmwiki/pmwiki.php/Main/TheComputerIsACheatingBastard","ref":"http://tvtropes.org/pmwiki/pmwiki.php/Main/NoFairCheating","publisher":{"id":"50758"}},"device":{"ip":"67.243.24.67","ua":"Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53","carrier":"Road Runner","language":"en-US,en;q=0.5","make":"Apple","model":"iPad","os":"iOS","Osv":"7","osv":"7","devicetype":5,"geo":{"country":"US","region":"NY","city":"New York","metro":"501","zip":"10023"},"ext":{"res":"768x1024","pf":2}},"user":{"keywords":"vanish,shotgun,sleeping,armies,stretch,shots,auto,ram,dogs,ogre mage","geo":{"country":"US","region":"NY","city":"Kingston","zip":"12401","metro":"501"}}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"267","name":"disqus"},"domain":"sozcu.com.tr","page":"http:\/\/www.sozcu.com.tr\/2015\/dunya\/malikiden-turkiyeye-sok-suclamalar-912393\/","id":"3763","sectioncat":["IAB12"]},"imp":[{"tagid":"","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":300},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":0.48,"id":"1"}],"device":{"os":"iOS","ip":"178.240.226.106","osv":"8.3","geo":{"country":"TUR"},"dnt":0,"devicetype":1,"model":"iPhone","ua":"Mozilla\/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit\/600.1.4 (KHTML, like Gecko) Version\/8.0 Mobile\/12F70 Safari\/600.1.4"},"at":2,"test":0,"id":"eb1f7194-334f-4bf3-a0cf-527cb634dd65","user":{"id":"55cf580d788236e72d7545e2171055e102836bec"}}'], + ['{"siteId":0,"adId":0,"operId":0,"adtype":0,"inIframe":0,"adVisibility":0,"ranreq":0,"id":"0ec4be31-7cbe-4efd-8700-7caa88a5fc69","imp":[{"id":"1","native":{"request":"{\"native\":{\"layout\":1,\"adunit\":4,\"plcmtcnt\":1,\"seq\":0,\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":100}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"w\":600,\"wmin\":0,\"h\":600,\"hmin\":0}},{\"id\":3,\"required\":1,\"data\":{\"type\":2,\"len\":200}},{\"id\":4,\"required\":0,\"data\":{\"type\":1,\"len\":200}}]}}"},"instl":0,"bidfloor":1.0,"secure":0}],"site":{"id":"11781","domain":"www.mobilelikez.com","cat":["IAB9","IAB2","IAB3","IAB5","IAB1","IAB22","IAB8","IAB7","IAB10","IAB14","IAB12","IAB6","IAB16","IAB17","IAB18","IAB19","IAB20","IAB4","IAB11","IAB13","IAB15","IAB21","IAB23"],"page":"http://www.mobilelikez.com/funny/10-signs-youre-dating-a-boy-not-a-man/page/4/?uid=303011935","privacypolicy":0,"publisher":{}},"device":{"dnt":0,"ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12H321 Twitter for iPhone","ip":"187.119.144.125","js":0,"connectiontype":0,"devicetype":4},"user":{"id":"9bb8a0fd-6e35-4f41-a03c-5e887e430306","yob":0},"at":2,"tmax":100,"allimps":0,"cur":["USD"]}'], + ['{"id":"[ID]","imp":[{"id":"[IMP-ID]","native":{"request":"{\"native\":{\"layout\":7,\"adunit\":2,\"plcmtcnt\":6,\"seq\":0,\"assets\":[{\"id\":1,\"title\":{\"len\":50}},{\"id\":2,\"required\":1,\"img\":{\"w\":100,\"h\":70}}]}}"},"bidfloor":0.0,"ext":{"bidmodel":"CPC"}}],"site":{"cat":["IAB3"],"page":"http://asdf.com/","keywords":"tech"},"device":{"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36","ip":"24.193.27.157"},"at":1,"ext":{"pmodel":"cpc"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"400","name":"pbh_network"},"domain":"runt-of-the-web.com","page":"http:\/\/runt-of-the-web.com\/george-costanza-quotes?utm_source=facebook&utm_medium=social&utm_campaign=whfbpd","id":"1639","sectioncat":["IAB1"]},"imp":[{"tagid":"4584Tb0cLcKCVtrQcRL6xMJI1QDkI0QFGYDSZyOe","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":200},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":2.0,"id":"1"}],"device":{"os":"iOS","language":"en","geo":{"country":"USA"},"osv":"8.4.1","dnt":0,"devicetype":1,"ip":"96.234.206.64","model":"iPhone","ua":"Mozilla\/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit\/600.1.4 (KHTML, like Gecko) Mobile\/12H321 [FBAN\/FBIOS;FBAV\/38.0.0.6.79;FBBV\/14316658;FBDV\/iPhone7,2;FBMD\/iPhone;FBSN\/iPhone OS;FBSV\/8.4.1;FBSS\/2; FBCR\/Verizon;FBID\/phone;FBLC\/en_US;FBOP\/5]"},"at":2,"test":0,"id":"36342d7b-3dba-4900-a5e2-5d2af37bc8b4","user":{"id":"9563ec6a0d5cb434e9bfe082a2cc98af9e9eb607"}}'], + ['{"badv":[],"tmax":200,"site":{"publisher":{"id":"400","name":"pbh_network"},"domain":"runt-of-the-web.com","page":"http:\/\/runt-of-the-web.com\/george-costanza-quotes?utm_source=facebook&utm_medium=social&utm_campaign=whfbpd","id":"1639","sectioncat":["IAB1"]},"imp":[{"pmp":{"deals":[{"id":"abc"}]},"tagid":"4584Tb0cLcKCVtrQcRL6xMJI1QDkI0QFGYDSZyOe","bidfloorcur":"USD","native":{"request":"{\"adunit\":502,\"ver\":1,\"assets\":[{\"required\":1,\"id\":0,\"title\":{\"len\":120}},{\"required\":0,\"data\":{\"type\":2,\"len\":200},\"id\":1},{\"required\":1,\"data\":{\"type\":1},\"id\":2},{\"required\":0,\"data\":{\"type\":12},\"id\":3},{\"required\":0,\"id\":4,\"img\":{\"hmin\":60,\"wmin\":60,\"type\":1}},{\"required\":1,\"id\":5,\"img\":{\"hmin\":200,\"h\":260,\"type\":3,\"w\":300,\"wmin\":200}},{\"required\":0,\"video\":{\"protocols\":[2,3],\"maxduration\":3600,\"mimes\":[\"video\\\/x-flv\",\"video\\\/mp4\",\"video\\\/ogg\",\"video\\\/webm\"],\"minduration\":1},\"id\":5}],\"seq\":0,\"plcmtcnt\":1}","ver":"1.0.0.1"},"bidfloor":2.0,"id":"1"}],"device":{"os":"iOS","language":"en","geo":{"country":"USA"},"osv":"8.4.1","dnt":0,"devicetype":1,"ip":"96.234.206.64","model":"iPhone","ua":"Mozilla\/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit\/600.1.4 (KHTML, like Gecko) Mobile\/12H321 [FBAN\/FBIOS;FBAV\/38.0.0.6.79;FBBV\/14316658;FBDV\/iPhone7,2;FBMD\/iPhone;FBSN\/iPhone OS;FBSV\/8.4.1;FBSS\/2; FBCR\/Verizon;FBID\/phone;FBLC\/en_US;FBOP\/5]"},"at":2,"test":0,"id":"36342d7b-3dba-4900-a5e2-5d2af37bc8b4","user":{"id":"9563ec6a0d5cb434e9bfe082a2cc98af9e9eb607"}}'] + ]; + } + + public function wrongJsonProvider() + { + return [ + ['{"app":{"name":"ABC News","bundle":"com.abcnews.ABCNews","id":"d4519606","publisher":{"id":"ae759c3e"},"cat":["IAB24","IAB13","IAB12","IAB3","IAB11"]},"device":{"connectiontype":0,"devicetype":4,"ip":"98.220.74.138","model":"iPhone","ua":"iPhone; iOS 8.3; ABC News; STR 2.2.4","geo":{"type":2,"metro":"527","country":"US"},"os":"iOS","ifa":"D247B3BB-F03F-426F-A8C8-4ED934EE9C53","osv":"unknown","make":"Apple","ext":{"idfasha1":"8f36739a173daeafc1bcbaeeb2869058aa1d553f"},"js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"a0aaf758-201a-4fd0-bfe0-a0ffae32c985"}'], + ['{"site":{"domain":"http://magiquiz.com","page":"http://magiquiz.com/quiz/where-should-you-live/?utm_source=facebook&utm_medium=ocpm&utm_term=Mobile-F25_34&utm_content=Nola&utm_campaign=MQ-Where_live","id":"160993bb","publisher":{"id":"3a7fddfa"},"cat":["IAB1","IAB24"]},"id":"410a4a19-b4d2-455e-a7e4-79db460aef27","imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"user":{"id":"uObIMwAK99OtaAAc"},"device":{"connectiontype":0,"devicetype":4,"ip":"76.187.75.89","model":"iPod Touch","ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4","geo":{"type":2,"metro":"623","country":"US"},"os":"iOS","osv":"8","make":"Apple","js":1,"dnt":0}}'], + ['{"app":{"name":"com.cheezburger.icanhas","bundle":"2.0.86","id":"c3d80edf","publisher":{"id":"172fc595"},"cat":["IAB1","IAB24","IAB16","IAB9"]},"device":{"connectiontype":0,"devicetype":4,"ip":"49.195.152.232","model":"SM-G900I","ua":"Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-G900I Build/KOT49H); STR cbc6090","geo":{"type":2,"metro":"200","country":"AU"},"os":"Android","osv":"","make":"Samsung","js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"dd119c13-c2e1-4359-80c6-5833a450f4e2"}'], + ['{"site":{"domain":"allday.com","page":"http://allday.com/post/5262-she-thought-it-was-just-a-normal-pimple-untilthe-smell/pages/2/","id":"dc4cabdc","publisher":{"id":"da3563b8"},"cat":["IAB1"]},"id":"39a2fb5d-3563-485b-ba27-1d35aa3f2083","imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"user":{"id":"lQFm4wAK99eHTe6b"},"device":{"connectiontype":0,"devicetype":4,"ip":"31.49.176.223","model":"A1549","ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70 [FBAN/FBIOS;FBAV/31.0.0.44.261;FBBV/10598108;FBDV/iPhone7,2;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.3;FBSS/2; FBCR/vodafoneUK;FBID/phone;FBLC/en_GB;FBOP/5]","geo":{"type":2,"metro":"300","country":"GB"},"os":"iOS","osv":"","make":"Apple","js":1,"dnt":0}}'], + ['{"app":{"name":"net.flixster.android","bundle":"7.4.3","id":"9e037903","publisher":{"id":"2fb9d1f3"},"cat":["IAB1"]},"device":{"connectiontype":0,"devicetype":4,"ip":"72.219.189.123","model":"SM-G900P","ua":"Dalvik/2.1.0 (Linux; U; Android 5.0; SM-G900P Build/LRX21T); STR 1.1.1","geo":{"type":2,"metro":"803","country":"US"},"os":"Android","osv":"","make":"Samsung","js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"2c3a3a73-3eb4-40ff-a65f-5a80f9ed48d7"}'], + ['{"id":"112fa29c-968c-4d3a-b295-3223fd7e4d46","seatbid":[{"seat":"C0","bid":[{"id":"imp-1-1","impid":"1","price":3.0212276506616,"nurl":"http:\/\/register.powerlinks.com\/win?a=%24%7BAUCTION_ID%7D&ab=%24%7BAUCTION_BID_ID%7D&ai=%24%7BAUCTION_IMP_ID%7D&as=%24%7BAUCTION_SEAT_ID%7D&aa=%24%7BAUCTION_AD_ID%7D&ap=%24%7BAUCTION_PRICE%7D&ac=%24%7BAUCTION_CURRENCY%7D&bidid=use-126fd272099e1afff1eb146a0c5fb04f&rid=612506d8-4582-11e5-9927-0ea06522b981","cid":"C0","crid":"-1","adm":"{\"native\":{\"assets\":[{\"title\":{\"text\":\"Home-Buying Basics: The Cash You Need to Close\"},\"id\":0,\"required\":1},{\"data\":{\"value\":\"Buying a home is a big deal, and there\\u2019s a lot to know. Get the basics, and...\"},\"id\":1,\"required\":0},{\"data\":{\"value\":\"Better Money Habits\"},\"id\":2,\"required\":1},{\"data\":{\"value\":\"CLICK HERE\"},\"id\":3,\"required\":0},{\"img\":{\"url\":\"http:\\\/\\\/cdn.bttrack.com\\\/a\\\/60\\\/60\\\/3071412\",\"w\":60,\"h\":60},\"id\":4,\"required\":0},{\"img\":{\"url\":\"http:\\\/\\\/cdn.bttrack.com\\\/a\\\/200\\\/200\\\/3071412\",\"w\":200,\"h\":200},\"id\":5,\"required\":1}],\"link\":{\"url\":\"http:\\\/\\\/register.powerlinks.com\\\/click?inventory_id=26790&domain_id=&creative_id=-1&exchange=1&campaign_id=0&format_id=3&bidid=use-126fd272099e1afff1eb146a0c5fb04f&rid=612506d8-4582-11e5-9927-0ea06522b981&ctype=cpm&third_party=17&dmd=iPhone&dos=iOS&dosv=8.4.1&redirect=http%3A%2F%2Fbttrack.com%2FClick%2FNative%3Fdata%3DOuJifVtEKZqw3CQ7Y5rtW7MSDuuHzuUgzKVD-5goSFVktbOBOorWHdosdAjAgNM88i-6yiBQW-qn1E-p-eI_lPaTqsmc0ACFdXaS0M1aff0EfrYS34MXYbPM6CWANAcTJFrEMsfv6pl64SH-n3o3VGhW7P_y0kL3zOpA6ahhajEZOy7ktE2yIK2b3CiGIfg90niupVvVU6yiZlkUT7r-1Ie_jd5yAe3rr2orSg_LR6mPWq_nww3TCnfvA5k1\"},\"imptrackers\":[\"http:\\\/\\\/register.powerlinks.com\\\/impression?inventory_id=26790&domain_id=&creative_id=-1&exchange=1&campaign_id=0&format_id=3&bidid=use-126fd272099e1afff1eb146a0c5fb04f&rid=612506d8-4582-11e5-9927-0ea06522b981&ctype=cpm&third_party=17&dmd=iPhone&dos=iOS&dosv=8.4.1&rtbap=%24%7BAUCTION_PRICE%7D&impu=http%3A%2F%2Fapi.bttrack.com%2Fwin%3Fts%3D1439886198%26id%3D94948b1f-8461-495e-9767-872a6901d55e%26cid%3D13585%26crid%3D344823%26pid%3D36341819%26data%3DOuJifVtEKZqw3Hw645qtW69SDiw62_-wHHOaNgtjqFMg-82yXiF1lVG3IeTgzlG5GdQkbNcAGK22RGXPQTOnMFj1LXHF9EJA0wVqNyR-boVKwxQrMAVZKAuBXXQjkDRl9Hd58-k7N_ujFBsbIat8FKJCw2VdeGe8Nw2%26price%3D4.0283035342154%26reqid%3D112fa29c-968c-4d3a-b295-3223fd7e4d46&otype=img\",\"http:\\\/\\\/bttrack.com\\\/Pixel\\\/Impression\\\/?data=OuJifVtEKZqw3Hw7af7tW7NSHotBj5mbLX7xPfTWCbsEXxUAgO3xUwNrJNwfLpiFP0ZQs9EiU3oIcza-aPwIaOH6-vmOXmLsljE1d5jSPc-CmYBu1owwzJjoInJPpkgWZZwhJr5e9DBBTGG_1lNnoov17HIcyxyyxnXOcIPr77-6pYFynFpyTvD648y-CJD0bABFZJO2acSb42jkb6ACPcGX7g6HQr1mf3a2UvdJdL3tbN-IvxmK-ce6bw1S9deZ9oo2zPUbYhCFvu7S71xdU-QtQOpYwnDqtu5tOoGOreWKC2JT5mTUgXEdFV4jHZ2o0&type=img\"]}}","adomain":["Better Money Habits"]}]}],"cur":"USD"}'], + ['{"app":{"name":"MyFitnessPal","bundle":"com.myfitnesspal.mfp","id":"51929922","publisher":{"id":"60f84bc0"},"cat":["IAB7","IAB17"]},"device":{"connectiontype":0,"devicetype":4,"ip":"66.87.98.93","model":"iPhone","ua":"iPhone; iOS 8.4; MyFitnessPal; STR 2.2.4","geo":{"type":2,"metro":"623","country":"US"},"os":"iOS","ifa":"CFE76C8D-8763-4D6D-9AB3-D6F9793DACFF","osv":"unknown","make":"Apple","ext":{"idfasha1":"ee8d886927f4d9627c67550864c6351b03a7b07f"},"js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"eb3763ae-7f81-4be0-98b7-c69d9184370a"}'], + ['{"app":{"name":"Flixster","bundle":"com.jeffreygrossman.moviesapp","id":"8360dd7e","publisher":{"id":"2fb9d1f3"},"cat":["IAB1"]},"device":{"connectiontype":0,"devicetype":4,"ip":"92.6.186.73","model":"iPhone","ua":"iPhone; iOS 8.4; Flixster; STR 2.2.8","geo":{"type":2,"metro":"300","country":"GB"},"os":"iOS","ifa":"6D7FC508-CDB4-4979-8814-D6600270F1EA","osv":"unknown","make":"Apple","ext":{"idfasha1":"c82ecd71bc26f43d7e76eaceb3369b1c65b53919"},"js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"d2b67b9d-2942-4f57-868d-850ebbfac81b"}'], + ['{"site":{"domain":"cracked.com","page":"http://ignored/","id":"a27da424","publisher":{"id":"a3875efb"},"cat":["IAB1","IAB9"]},"device":{"connectiontype":0,"devicetype":4,"ip":"172.56.16.3","model":"MS323","ua":"Mozilla/5.0 (Linux; Android 4.4.2; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36","geo":{"type":2,"metro":"803","country":"US"},"os":"Android","osv":"4","make":"LG","js":1,"dnt":0},"imp":[{"native":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":140}},{"id":4,"required":0,"img":{"hmin":750,"wmin":1000,"type":3}},{"id":3,"required":0,"img":{"hmin":48,"wmin":48,"type":2}},{"id":2,"required":1,"img":{"hmin":180,"wmin":320,"type":1}},{"id":6,"required":1,"data":{"len":140,"type":2}},{"id":5,"required":1,"data":{"len":140,"type":1}}],"adunit":2,"ver":1,"layout":3},"id":"1"}],"id":"3774af16-ab14-4a24-86c6-5ac7458841a3"}'], + ['{"id":"5CF396C9-F71D-4002-8FA2-793F2685628F","imp":[{"id":"1","tagid":"275677","banner":{"w":0,"h":0},"ext":{"native":{"ver":"1.0","assets":[{"id":1,"required":1,"img":{"w":150,"h":150,"type":1}},{"id":2,"required":0,"img":{"type":3}},{"id":3,"required":1,"title":{"len":25}},{"id":4,"required":1,"data":{"type":2,"len":67}},{"id":5,"required":1,"data":{"type":12,"len":15}},{"id":6,"required":0,"data":{"type":3}},{"id":7,"required":0,"img":{"type":2}}]}}}],"site":{"id":"91371","domain":"http://softonic.com","page":"http://m.en.softonic.com/","publisher":{"id":"54437"}},"device":{"ip":"168.235.197.204","ua":"UCWEB/2.0 (MIDP-2.0; U; Adr 4.4.2; en-US; A1 _Champ) U2/1.0.0 UCBrowser/10.2.0.584 U2/1.0.0 Mobile","language":"en-US","make":"Micromax","geo":{"country":"US","lat":34.1474991,"lon":-118.139999,"type":2},"ext":{"otherdeviceid":"8315142b26bdbaca972e398214d3d52a24afd076","hash":2,"res":"120x92","pf":2}},"user":{"keywords":"#global#"},"ext":{"bidguidefloor":1.2}}'], + ]; + } +} diff --git a/tests/Mapper/MapFactoryTest.php b/tests/Mapper/MapFactoryTest.php new file mode 100644 index 0000000..260ccde --- /dev/null +++ b/tests/Mapper/MapFactoryTest.php @@ -0,0 +1,30 @@ + 'native', + 'BidRequest.Imp[].Id' => 'id' + ]; + + $map = MapFactory::create($demoMap); + + $this->assertEquals(['BidRequest.Imp[].Native.Request', 'BidRequest.Imp[].Id'],$map->getObjectPaths()); + $this->assertEquals(2,$map->count()); + $this->assertTrue($map->get('BidRequest.Imp[].Native.Request')->isRequired()); + $this->assertFalse($map->get('BidRequest.Imp[].Native.Request')->isUuid()); + $this->assertEquals('native', $map->get('BidRequest.Imp[].Native.Request')->getValue()); + + foreach ($map as $item) { + $this->assertInstanceOf('OpenRtb\Mapper\MapItem', $item); + } + } + +} diff --git a/tests/Mapper/MapperTest.php b/tests/Mapper/MapperTest.php new file mode 100644 index 0000000..81b939c --- /dev/null +++ b/tests/Mapper/MapperTest.php @@ -0,0 +1,82 @@ + 'native', + 'BidRequest.Imp[].Id' => 'id' + ]; + + $map = MapFactory::create($demoMap); + + $mapper = new Mapper(); + $arrayMapped = $mapper->mapFromValues($map, new BidRequest()); + + $myObject = new BidRequest(); + Hydrator::hydrate($arrayMapped, $myObject); + + $this->assertEquals(1, $myObject->getImp()->count()); + $this->assertEquals('id', $myObject->getImp()->current()->getId()); + $this->assertEquals('native', $myObject->getImp()->current()->getNative()->getRequest()); + } + + public function testMapFromArray() + { + $demoMap = [ + 'BidRequest.Imp[].Native.Request:@required' => 'request', + 'BidRequest.Imp[].Id' => 'id' + ]; + $map = MapFactory::create($demoMap); + + $source = [ + 'request' => 'native', + 'id' => '123' + ]; + + $mapper = new Mapper(); + $arrayMapped = $mapper->mapFromArray($map, $source); + + $myObject = new BidRequest(); + Hydrator::hydrate($arrayMapped, $myObject); + + $this->assertEquals(1, $myObject->getImp()->count()); + $this->assertEquals('123', $myObject->getImp()->current()->getId()); + $this->assertEquals('native', $myObject->getImp()->current()->getNative()->getRequest()); + } + + public function testMapFromObject() + { + $demoMap = [ + 'Native.Request' => 'Id', + 'Id' => 'Imp[].Id' + ]; + $map = MapFactory::create($demoMap); + + $imp = new Imp(); + $imp->setId('impId'); + + $bidRequest = new BidRequest(); + $bidRequest + ->setId('bidRequestId') + ->addImp($imp) + ; + + $mapper = new Mapper(); + $arrayMapped = $mapper->mapFromObject($map, $bidRequest); + + $this->assertTrue(is_array($arrayMapped)); + $this->assertEquals('bidRequestId', $arrayMapped['native']['request']); + $this->assertEquals('impId', $arrayMapped['id']); + } +} diff --git a/tests/Tools/Classes/ArrayCollectionTest.php b/tests/Tools/Classes/ArrayCollectionTest.php new file mode 100644 index 0000000..fb865b8 --- /dev/null +++ b/tests/Tools/Classes/ArrayCollectionTest.php @@ -0,0 +1,166 @@ +collection = new ArrayCollection(); + } + + public function testIssetAndUnset() + { + $this->assertFalse(isset($this->collection[0])); + $this->collection->add('testing'); + $this->assertTrue(isset($this->collection[0])); + unset($this->collection[0]); + $this->assertFalse(isset($this->collection[0])); + } + + public function testToString() + { + $this->collection->add('testing'); + $this->assertTrue(is_string((string) $this->collection)); + } + + public function testRemovingNonExistentEntryReturnsNull() + { + $this->assertEquals(null, $this->collection->remove('testing_does_not_exist')); + } + + public function testFirstAndLast() + { + $this->collection->add('one'); + $this->collection->add('two'); + $this->assertEquals($this->collection->first(), 'one'); + $this->assertEquals($this->collection->last(), 'two'); + } + + public function testArrayAccess() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->assertEquals($this->collection[0], 'one'); + $this->assertEquals($this->collection[1], 'two'); + unset($this->collection[0]); + $this->assertEquals($this->collection->count(), 1); + } + + public function testContainsKey() + { + $this->collection[5] = 'five'; + $this->assertTrue($this->collection->containsKey(5)); + } + + public function testContains() + { + $this->collection[0] = 'test'; + $this->assertTrue($this->collection->contains('test')); + } + + public function testSearch() + { + $this->collection[0] = 'test'; + $this->assertEquals(0, $this->collection->indexOf('test')); + } + + public function testGet() + { + $this->collection[0] = 'test'; + $this->assertEquals('test', $this->collection->get(0)); + } + + public function testGetKeys() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->assertEquals(array(0, 1), $this->collection->getKeys()); + } + + public function testGetValues() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->assertEquals(array('one', 'two'), $this->collection->getValues()); + } + + public function testCount() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->assertEquals($this->collection->count(), 2); + $this->assertEquals(count($this->collection), 2); + } + + public function testClear() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->collection->clear(); + $this->assertEquals($this->collection->isEmpty(), true); + } + + public function testRemove() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $el = $this->collection->remove(0); + $this->assertEquals('one', $el); + $this->assertEquals($this->collection->contains('one'), false); + $this->assertNull($this->collection->remove(0)); + } + + public function testRemoveElement() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->assertTrue($this->collection->removeElement('two')); + $this->assertFalse($this->collection->contains('two')); + $this->assertFalse($this->collection->removeElement('two')); + } + + public function testSlice() + { + $this->collection[] = 'one'; + $this->collection[] = 'two'; + $this->collection[] = 'three'; + $slice = $this->collection->slice(0, 1); + $this->assertIsArray($slice); + $this->assertEquals(array('one'), $slice); + $slice = $this->collection->slice(1); + $this->assertEquals(array(1 => 'two', 2 => 'three'), $slice); + $slice = $this->collection->slice(1, 1); + $this->assertEquals(array(1 => 'two'), $slice); + } + + public function fillMatchingFixture() + { + $std1 = new \stdClass(); + $std1->foo = "bar"; + $this->collection[] = $std1; + $std2 = new \stdClass(); + $std2->foo = "baz"; + $this->collection[] = $std2; + } + + public function testCanRemoveNullValuesByKey() + { + $this->collection->add(null); + $this->collection->remove(0); + $this->assertTrue($this->collection->isEmpty()); + } + public function testCanVerifyExistingKeysWithNullValues() + { + $this->collection->set('key', null); + $this->assertTrue($this->collection->containsKey('key')); + } +} diff --git a/tests/Tools/ObjectAnalyzer/ObjectDescriberTest.php b/tests/Tools/ObjectAnalyzer/ObjectDescriberTest.php new file mode 100644 index 0000000..fc24ebb --- /dev/null +++ b/tests/Tools/ObjectAnalyzer/ObjectDescriberTest.php @@ -0,0 +1,39 @@ +assertEquals('OpenRtb\BidRequest\BidRequest', $descriptor->getClassName()); + $this->assertEquals('OpenRtb\BidRequest', $descriptor->getNamespace()); + + $this->assertEquals(20, $descriptor->properties->count()); + $this->assertInstanceOf('Traversable', $descriptor->properties); + + foreach ($descriptor->properties as $propertyName => $property) { + $this->assertTrue(is_string($propertyName)); + $this->assertEquals($propertyName, $property->get('name')); + $this->assertInstanceOf('OpenRtb\Tools\ObjectAnalyzer\AnnotationsBag', $property); + } + + $this->assertTrue($descriptor->properties->get('id')->isRequired()); + $this->assertFalse($descriptor->properties->get('id')->isObject()); + $this->assertEquals('string', $descriptor->properties->get('id')->get('var')); + + $this->assertInstanceOf('Traversable', $descriptor->methods); + $this->assertTrue($descriptor->methods->has('setId')); + $this->assertTrue($descriptor->methods->has('getId')); + $this->assertTrue($descriptor->methods->get('setId')); + $this->assertTrue($descriptor->methods->get('getId')); + + $this->assertTrue($descriptor->methods->has('getArrayFromObject')); + $this->assertFalse($descriptor->methods->get('getArrayFromObject')); + } +} diff --git a/tests/Tools/Traits/GetConstantsTest.php b/tests/Tools/Traits/GetConstantsTest.php new file mode 100644 index 0000000..2a7ce07 --- /dev/null +++ b/tests/Tools/Traits/GetConstantsTest.php @@ -0,0 +1,27 @@ + 1, + 'STRING_TEST' => 'test' + ]; + $this->assertEquals($expected, $result); + } +} diff --git a/tests/Tools/Traits/SetterValidationTest.php b/tests/Tools/Traits/SetterValidationTest.php new file mode 100644 index 0000000..c3afbb6 --- /dev/null +++ b/tests/Tools/Traits/SetterValidationTest.php @@ -0,0 +1,289 @@ +setterValidation = $this->getMockForTrait('OpenRtb\Tools\Traits\SetterValidation'); + } + + public function testValidateString() + { + $this->assertTrue(AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateString', ['test', 1])); + } + + /** + * @dataProvider validateStringExceptionProvider + */ + public function testValidateStringException($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateString', [$value]); + } + + public function validateStringExceptionProvider() + { + return [ + [1], + [1.234], + [new \stdClass] + ]; + } + + public function testValidateInt() + { + $this->assertEquals(1, AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateInt', [1])); + $this->assertEquals(-1, AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateInt', [-1])); + $this->assertEquals(0, AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateInt', [0])); + } + + /** + * @dataProvider validateIntExceptionProvider + */ + public function testValidateIntException($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateInt', [$value, 1]); + } + + public function validateIntExceptionProvider() + { + return [ + ['test'], + [1.234], + [new \stdClass] + ]; + } + + public function testValidatePositiveInt() + { + $this->assertEquals(1, AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveInt', [1, 1])); + $this->assertEquals(0, AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveInt', [0, 1])); + } + + /** + * @dataProvider validatePositiveIntExceptionProvider + */ + public function testValidatePositiveIntException($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveInt', [$value, 1]); + } + + public function validatePositiveIntExceptionProvider() + { + return [ + ['test'], + [1.234], + [-1], + [new \stdClass] + ]; + } + + public function testValidatePositiveFloat() + { + $this->assertEquals( + 0.0, + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveFloat', [0.0, 1]) + ); + $this->assertEquals( + 1.2, + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveFloat', [1.2, 1]) + ); + $this->assertEquals( + 0.0, + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveFloat', [0, 1]) + ); + $this->assertEquals( + 1.0, + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveFloat', [1, 1]) + ); + } + + /** + * @dataProvider validatePositiveFloatExceptionProvider + */ + public function testValidatePositiveFloatException($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validatePositiveFloat', [$value, 1]); + } + + public function validatePositiveFloatExceptionProvider() + { + return [ + ['test'], + [-1], + [-1.2], + [new \stdClass] + ]; + } + + public function testValidateIn() + { + $this->assertTrue( + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateIn', [1, [1 ,2, 3], 1]) + ); + $this->assertTrue( + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateIn', ['alpha', ['alpha', 'bravo'], 1]) + ); + } + + /** + * @dataProvider validateInExceptionProvider + */ + public function testValidateInException($value, $validValues) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateIn', [$value, $validValues, 1]); + } + + public function validateInExceptionProvider() + { + return [ + ['test', ['alpha', 'bravo']], + [1, [2, 3]] + ]; + } + + public function testValidateInWithCustom500Values() + { + $this->assertTrue( + AccessProtectedMethod::invokeMethod( + $this->setterValidation, + 'validateInWithCustom500Values', + [501, [1 ,2, 3], 1] + ) + ); + $this->assertTrue( + AccessProtectedMethod::invokeMethod( + $this->setterValidation, + 'validateInWithCustom500Values', + [599, [1 ,2, 3], 1] + ) + ); + } + + /** + * @dataProvider validateInWithCustom500ValuesExceptionProvider + */ + public function testValidateInWithCustom500ValuesException($value, $validValues) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod( + $this->setterValidation, + 'validateInWithCustom500Values', + [$value, $validValues, 1] + ); + } + + public function validateInWithCustom500ValuesExceptionProvider() + { + return [ + [99, [1, 2, 3]], + [499, [1, 2, 3]] + ]; + } + + public function testValidateMd5() + { + $this->assertTrue(AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateMd5', [md5(1), 1])); + } + + /** + * @dataProvider validateMd5ExceptionProvider + */ + public function testValidateMd5Exception($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateMd5', [$value, 1]); + } + + public function validateMd5ExceptionProvider() + { + return [ + ['g4ca4238a0b923820dcc509a6f75849b'], + ['cc4ca4238a0b923820dcc509a6f75849b'], + ['4ca4238a0b923820dcc509a6f75849b'], + [1], + [1.234], + [new \stdClass] + ]; + } + + public function testValidateSha1() + { + $this->assertTrue(AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateSha1', [sha1(1), 1])); + } + + /** + * @dataProvider validateSha1ExceptionProvider + */ + public function testValidateSha1Exception($value) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateSha1', [$value, 1]); + } + + public function validateSha1ExceptionProvider() + { + return [ + ['g4ca4238a0b923820dcc509a6f75849b509a6f75'], + ['cc4ca4238a0b923820dcc509a6f75849b509a6f75'], + ['4ca4238a0b923820dcc509a6f75849b509a6f75'], + [1], + [1.234], + [new \stdClass] + ]; + } + + /** + * @dataProvider validateIpProvider + */ + public function testValidateIp($ip) + { + $this->assertTrue(AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateIp', [$ip])); + } + + public function validateIpProvider() + { + return [ + ['2001:cdba:0000:0000:0000:0000:3257:9652'], + ['2001:cdba:0:0:0:0:3257:9652'], + ['2001:cdba::3257:9652'], + ['192.168.0.1'], + ['188.200.88.12'], + ['0.0.0.0'], + ['8.8.8.8'] + ]; + } + + /** + * @dataProvider validateIpExceptionProvider + */ + public function testValidateIpException($ip) + { + $this->expectException(\OpenRtb\Tools\Exceptions\ExceptionInvalidValue::class); + $this->assertTrue(AccessProtectedMethod::invokeMethod($this->setterValidation, 'validateIp', [$ip])); + } + + public function validateIpExceptionProvider() + { + return [ + ['zzzz:cdba:0000:0000:0000:0000:3257:9652'], + ['2001:cdba:0:0:0:0:zzzz:9652'], + ['2001:cdba3257:9652'], + ['192.168.0.256'], + ['188.200.88'], + ['0.0.0.1000'], + ['8.8.8.800'] + ]; + } +} diff --git a/tests/Tools/Traits/SetterValidationTracerTest.php b/tests/Tools/Traits/SetterValidationTracerTest.php new file mode 100644 index 0000000..733d908 --- /dev/null +++ b/tests/Tools/Traits/SetterValidationTracerTest.php @@ -0,0 +1,22 @@ +addCur(1); + } catch (\Exception $e) { + $this->assertStringContainsString( + 'OpenRtb\BidRequest\BidRequest::addCur::474[validateString]', + $e->getMessage() + ); + } + } +}