idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
35,700 | public static function getAuditTables ( ) { $ connection = Yii :: $ app -> db ; $ schema = $ connection -> schema ; $ tables = $ schema -> getTableNames ( 'audits' ) ; $ map = [ ] ; $ map [ ] = Yii :: t ( 'app' , 'Choose' ) ; foreach ( $ tables as $ table ) { $ map [ $ table ] = $ table ; } return $ map ; } | Selects all table from audits schema |
35,701 | public function checkTableExists ( $ model ) { if ( ! in_array ( $ model -> table , $ this -> getAuditTables ( ) ) ) { $ model -> addError ( 'table' , Yii :: t ( 'app' , "You've entered an invalid table name." ) ) ; return false ; } return true ; } | Check if given table exists in audits schema |
35,702 | public static function renderControlGroup ( $ model , $ form , $ name , $ data ) { if ( isset ( $ data [ 'model' ] ) ) { $ model = $ data [ 'model' ] ; } $ field = $ form -> field ( $ model , $ name ) ; if ( isset ( $ data [ 'formMethod' ] ) ) { if ( is_string ( $ data [ 'formMethod' ] ) ) { echo call_user_func_array ( [ $ field , $ data [ 'formMethod' ] ] , $ data [ 'arguments' ] ) ; } else { echo call_user_func ( $ data [ 'formMethod' ] , $ field , $ data [ 'arguments' ] ) ; } return ; } if ( isset ( $ data [ 'options' ] [ 'label' ] ) ) { $ label = $ data [ 'options' ] [ 'label' ] ; unset ( $ data [ 'options' ] [ 'label' ] ) ; } else { $ label = $ model -> getAttributeLabel ( $ name ) ; } echo $ field -> label ( $ label , [ 'class' => 'control-label' ] ) -> error ( [ 'class' => 'help-block' ] ) -> widget ( $ data [ 'widgetClass' ] , $ data [ 'options' ] ) ; return ; } | Renders form field |
35,703 | public function getFormFields ( $ model , $ multiple = false ) { $ formFields [ ] = [ 'table' => [ 'attribute' => 'table' , 'formMethod' => 'dropDownList' , 'arguments' => [ 'items' => call_user_func ( [ 'nineinchnick\audit\models\AuditForm' , 'getAuditTables' ] ) ] , ] ] ; foreach ( Yii :: $ app -> controller -> module -> filters as $ propety => $ params ) { $ formFields [ ] = static :: addFormField ( $ model , $ propety , $ params ) ; } return $ formFields ; } | Retrieves form fields configuration . |
35,704 | public function findUserOrdersForCurrentMonth ( $ locale , UserInterface $ user ) { try { $ qb = $ this -> getOrderQuery ( $ locale ) -> andWhere ( 'status.id >= :statusId' ) -> andWhere ( 'o.changed >= :currentMonth' ) -> andWhere ( 'o.creator = :user' ) -> setParameter ( 'statusId' , OrderStatus :: STATUS_CONFIRMED ) -> setParameter ( 'currentMonth' , date ( 'Y-m-01 0:00:00' ) ) -> setParameter ( 'user' , $ user ) -> orderBy ( 'o.created' , 'ASC' ) ; return $ qb -> getQuery ( ) -> getResult ( ) ; } catch ( NoResultException $ exc ) { return null ; } } | Finds all orders of a user made this month . |
35,705 | public function findOrdersByStatusAndAccount ( $ locale , $ status , AccountInterface $ account ) { try { $ qb = $ this -> getOrderQuery ( $ locale ) -> leftJoin ( 'o.creator' , 'creator' ) -> leftJoin ( 'creator.contact' , 'contact' ) -> leftJoin ( 'contact.accountContacts' , 'accountContact' , 'WITH' , 'accountContact.main = true' ) -> leftJoin ( 'accountContact.account' , 'account' ) -> andWhere ( 'status.id = :statusId' ) -> andWhere ( 'account = :account' ) -> setParameter ( 'account' , $ account ) -> setParameter ( 'statusId' , $ status ) ; return $ qb -> getQuery ( ) -> getResult ( ) ; } catch ( NoResultException $ exc ) { return null ; } } | Find all orders of an account with a specific status . |
35,706 | public function findByStatusIdsAndUser ( $ locale , $ statusIds , UserInterface $ user , $ limit = null ) { try { $ qb = $ this -> getOrderQuery ( $ locale ) -> andWhere ( 'o.creator = :user' ) -> setParameter ( 'user' , $ user ) -> andWhere ( 'status.id IN (:statusId)' ) -> setParameter ( 'statusId' , $ statusIds ) -> orderBy ( 'o.created' , 'DESC' ) -> setMaxResults ( $ limit ) ; return $ qb -> getQuery ( ) -> getResult ( ) ; } catch ( NoResultException $ exc ) { return null ; } } | Finds orders by statusIds and user . |
35,707 | private function getOrderQuery ( $ locale ) { $ qb = $ this -> createQueryBuilder ( 'o' ) -> leftJoin ( 'o.deliveryAddress' , 'deliveryAddress' ) -> leftJoin ( 'o.invoiceAddress' , 'invoiceAddress' ) -> leftJoin ( 'o.status' , 'status' ) -> leftJoin ( 'status.translations' , 'statusTranslations' , 'WITH' , 'statusTranslations.locale = :locale' ) -> leftJoin ( 'o.items' , 'items' ) -> setParameter ( 'locale' , $ locale ) ; return $ qb ; } | Returns query for orders . |
35,708 | public function del ( $ prop ) { unset ( $ this -> $ prop , $ _GET [ $ prop ] , $ _POST [ $ prop ] , $ this -> deleteVars [ $ prop ] , $ this -> putVars [ $ prop ] ) ; } | Deletes a var . |
35,709 | public function setTraitClass ( $ traitClass ) { if ( $ this -> isObjectNameValid ( $ traitClass ) !== true ) { throw new InvalidArgumentException ( 'The name of the trait to use is not valid.' ) ; } $ this -> traitClass = $ traitClass ; return $ this ; } | Set the trait name to use . |
35,710 | public function setStatic ( $ static ) { if ( $ static === true ) { $ this -> addModifier ( Modifiers :: MODIFIER_STATIC ) ; } else { $ this -> removeModifier ( Modifiers :: MODIFIER_STATIC ) ; } } | Set the entity static . |
35,711 | public function setAbstract ( $ abstract ) { if ( $ abstract === true ) { $ this -> addModifier ( Modifiers :: MODIFIER_ABSTRACT ) ; } else { $ this -> removeModifier ( Modifiers :: MODIFIER_ABSTRACT ) ; } } | Set the entity abstract . |
35,712 | public function setBody ( $ body ) { $ this -> code = array ( new CodeLineGenerator ( $ body , $ this -> getIndentationLevel ( ) , $ this -> getIndentationString ( ) ) ) ; return $ this ; } | Set the body of the file . |
35,713 | final public function fromArray ( Array $ data ) : self { foreach ( $ data as $ key => $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ value ) ; } } return $ this ; } | Fills attributes from array |
35,714 | public static function fromReflection ( ReflectionClass $ reflectionClass ) { if ( $ reflectionClass -> isInterface ( ) === true || $ reflectionClass -> isTrait ( ) === true ) { throw new InvalidArgumentException ( 'The reflected class can not be a trait or interface.' ) ; } $ cg = new static ( $ reflectionClass -> getShortName ( ) , $ reflectionClass -> getNamespaceName ( ) ) ; $ cg -> setFinal ( $ reflectionClass -> isFinal ( ) ) ; $ cg -> setAbstract ( $ reflectionClass -> isAbstract ( ) ) ; $ parentClass = $ reflectionClass -> getParentClass ( ) ; if ( $ parentClass !== false ) { if ( $ parentClass -> getNamespaceName ( ) === $ cg -> getNamespace ( ) ) { $ extends = $ parentClass -> getShortName ( ) ; } else { $ extends = '\\' . $ parentClass -> getName ( ) ; } $ cg -> setExtends ( $ extends ) ; } $ interfaces = array ( ) ; foreach ( $ reflectionClass -> getOwnInterfaces ( ) as $ interface ) { if ( $ interface -> getNamespaceName ( ) === $ cg -> getNamespace ( ) ) { $ interfaces [ ] = $ interface -> getShortName ( ) ; } else { $ interfaces [ ] = '\\' . $ interface -> getName ( ) ; } } $ cg -> setImplements ( $ interfaces ) ; if ( $ reflectionClass -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ cg -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionClass -> getReflectionDocComment ( ) ) ) ; } foreach ( $ reflectionClass -> getUses ( ) as $ use ) { $ use = UseTraitGenerator :: fromReflection ( $ use ) ; if ( $ cg -> getNamespace ( ) !== null && strpos ( $ use -> getTraitClass ( ) , $ cg -> getNamespace ( ) ) === 0 ) { $ use -> setTraitClass ( substr ( $ use -> getTraitClass ( ) , strlen ( $ cg -> getNamespace ( ) ) + 1 ) ) ; } $ cg -> addTraitUse ( $ use ) ; } foreach ( $ reflectionClass -> getOwnConstants ( ) as $ constant ) { $ cg -> addConstant ( ClassConstantGenerator :: fromReflection ( $ constant ) ) ; } foreach ( $ reflectionClass -> getOwnProperties ( ) as $ property ) { $ cg -> addProperty ( PropertyGenerator :: fromReflection ( $ property ) ) ; } foreach ( $ reflectionClass -> getOwnMethods ( ) as $ method ) { $ cg -> addMethod ( MethodGenerator :: fromReflection ( $ method ) ) ; } return $ cg ; } | Create a new class from reflection . |
35,715 | public function addImplement ( $ interfaceName ) { if ( $ this -> isObjectNameValid ( $ interfaceName ) !== true ) { throw new InvalidArgumentException ( 'The name of the interface is not valid.' ) ; } $ this -> implements [ $ interfaceName ] = $ interfaceName ; return $ this ; } | Add an interface that this class implements . |
35,716 | public function loadPlugins ( $ _ ) { $ arguments = func_get_args ( ) ; foreach ( $ arguments as $ possiblePackage ) { if ( FALSE === is_array ( $ possiblePackage ) ) { $ this -> plugins += $ this -> loadPluginsFromPackage ( $ possiblePackage ) ; } else { foreach ( $ possiblePackage as $ package ) { $ this -> plugins += $ this -> loadPluginsFromPackage ( $ package ) ; } } } return $ this ; } | Wrapper method to load plugins from an arbitrary source definition - either a string package name or an array of string package names . |
35,717 | protected function loadPluginsFromPackage ( $ package ) { $ plugins = array ( ) ; $ settings = $ this -> loadSettings ( ) ; $ expectedListerClassName = '\\' . $ package . '\\GizzlePlugins\\PluginList' ; if ( TRUE === class_exists ( $ expectedListerClassName ) ) { $ packageSettings = ( array ) TRUE === isset ( $ settings [ $ package ] ) ? $ settings [ $ package ] : array ( ) ; $ lister = new $ expectedListerClassName ( ) ; $ lister -> initialize ( $ packageSettings ) ; $ pluginClassNames = $ lister -> getPluginClassNames ( ) ; $ pluginClassNames = array_combine ( $ pluginClassNames , array_fill ( 0 , count ( $ pluginClassNames ) , array ( ) ) ) ; $ pluginSettings = ( array ) ( TRUE === isset ( $ settings [ $ package ] ) ? $ settings [ $ package ] : $ pluginClassNames ) ; $ packagePlugins = $ this -> loadPluginInstances ( $ pluginSettings ) ; $ plugins = array_merge ( $ plugins , $ packagePlugins ) ; } return $ plugins ; } | Create and initialize all plugin classes from the package specified in the input argument . Similar to loading a list of plugin classes but uses the special PluginList class from that package in order to determine which plugins should be activated and to deliver default settings values for those plugins . |
35,718 | protected function loadPluginInstances ( array $ pluginClassNamesAndSettings ) { $ plugins = array ( ) ; foreach ( $ pluginClassNamesAndSettings as $ class => $ settings ) { $ plugins [ ] = $ this -> loadPluginInstance ( $ class , ( array ) $ settings ) ; } return $ plugins ; } | Create and initialize all plugin classes based on an input array in which the keys are the class names of plugins and the values are an array of settings for that particular plugin instance . |
35,719 | protected function loadPluginInstance ( $ pluginClassName , array $ settings ) { $ pluginClassName = '\\' . ltrim ( $ pluginClassName , '\\' ) ; $ plugin = new $ pluginClassName ( ) ; $ plugin -> initialize ( $ settings ) ; return $ plugin ; } | Create and initialize a single plugin instance based on class name and settings . |
35,720 | protected function loadSettings ( ) { $ folder = realpath ( __DIR__ ) ; $ segments = explode ( '/' , $ folder ) ; $ file = NULL ; while ( NULL === $ file && 0 < count ( $ segments ) && ( $ segment = array_pop ( $ segments ) ) ) { $ base = '/' . implode ( '/' , $ segments ) . '/' . $ segment . '/' ; $ expectedFile = $ base . $ this -> settingsFile ; $ expectedFile = FALSE === file_exists ( $ expectedFile ) ? $ base . 'Settings.yml' : $ expectedFile ; $ file = TRUE === file_exists ( $ expectedFile ) ? $ expectedFile : NULL ; } return ( array ) ( TRUE === file_exists ( $ file ) ? Yaml :: parse ( file_get_contents ( $ file ) ) : array ( ) ) ; } | Loads the settings specified in the . yml file that this Gizzle instance was instructed to use . If the file does not exist no settings are loaded and no error message given . |
35,721 | public function process ( ) { if ( 0 === count ( $ this -> plugins ) ) { $ settings = $ this -> loadSettings ( ) ; $ packages = array_keys ( $ settings ) ; $ this -> loadPlugins ( $ packages ) ; } $ this -> executePlugins ( $ this -> plugins ) ; return $ this -> response ; } | Run Gizzle plugins specified in configuration or input arguments . Return a Response object containing feedback from all plugins . |
35,722 | public function storePullRequestComment ( PullRequest $ pullRequest , $ message ) { $ url = $ pullRequest -> resolveApiUrl ( PullRequest :: API_URL_COMMENTS ) ; $ parameters = array ( 'body' => $ message , ) ; $ this -> getApi ( ) -> post ( $ url , json_encode ( $ parameters ) ) ; } | Store a message about the pull request identified in the argument . |
35,723 | public function storeCommitComment ( Commit $ commit , $ message ) { $ url = $ this -> getRepository ( ) -> resolveApiUrl ( Repository :: API_URL_COMMITS ) ; $ url = str_replace ( '{/sha}' , '/' . $ commit -> getId ( ) , $ url ) ; $ url .= '/comments' ; $ parameters = array ( 'body' => $ message ) ; $ this -> getApi ( ) -> post ( $ url , json_encode ( $ parameters ) ) ; } | Store a standard GitHub comment about a commit be it part of a pull request or not . Any commit including merge commits can be commented . |
35,724 | public function storeCommitValidation ( PullRequest $ pullRequest , Commit $ commit , $ message , $ file , $ line ) { $ url = $ pullRequest -> resolveApiUrl ( PullRequest :: API_URL_REVIEW_COMMENTS ) ; $ parameters = array ( 'commit_id' => $ commit -> getId ( ) , 'body' => $ message , 'path' => $ file , 'position' => $ line ) ; $ this -> getApi ( ) -> post ( $ url , json_encode ( $ parameters ) ) ; } | Store a pull request specific validation of a single line in a commit . |
35,725 | public function sideMenu ( ) { $ menu = $ this -> factory -> createItem ( 'root' ) ; $ this -> dispatcher -> dispatch ( ConfigureMenuEvent :: CONFIGURE , new ConfigureMenuEvent ( $ this -> factory , $ menu ) ) ; return $ menu ; } | Build main menu . |
35,726 | public function check ( $ data = null , & $ failed = null ) { $ failed = null ; $ valid = $ this -> checkType ( $ data , $ failed ) && $ this -> checkValueSet ( $ data , $ failed ) ; if ( ! $ valid ) Structure :: $ lastFail = $ failed ; return $ valid ; } | Runs type and value set tests |
35,727 | public function take ( $ limit = null ) { if ( $ limit !== null ) { $ this -> limit ( $ limit ) ; } $ this -> executeSql ( ) ; $ cn = $ this -> model_name ; return $ cn :: createModelsFromQuery ( $ this ) ; } | Excecutes the query . Returns all records . |
35,728 | public function pluck ( $ column ) { $ columns = func_get_args ( ) ; $ argv_count = func_num_args ( ) ; $ collection = $ this -> take ( ) ; $ values = [ ] ; if ( $ collection -> any ( ) ) { if ( $ argv_count == 1 ) { foreach ( $ collection as $ model ) $ values [ ] = $ model -> $ column ; } else { foreach ( $ collection as $ model ) { $ row_values = [ ] ; foreach ( $ columns as $ column ) { $ row_values [ ] = $ model -> $ column ; } $ values [ ] = $ row_values ; } } } return $ values ; } | Accepts more than 1 argument . |
35,729 | public function exists ( $ group , $ namespace = null ) { $ key = $ group . $ namespace ; if ( isset ( $ this -> exists [ $ key ] ) ) { return $ this -> exists [ $ key ] ; } $ path = $ this -> getPath ( $ namespace ) ; if ( is_null ( $ path ) ) { return $ this -> exists [ $ key ] = false ; } $ file = "{$path}/{$group}.php" ; $ exists = $ this -> files -> exists ( $ file ) ; return $ this -> exists [ $ key ] = $ exists ; } | Determine if the given group exists . |
35,730 | public static function fromReflection ( ReflectionParameter $ reflectionParameter ) { $ param = new static ( $ reflectionParameter -> getName ( ) ) ; if ( $ reflectionParameter -> isArray ( ) === true ) { $ param -> setType ( 'array' ) ; } else { $ typeClass = $ reflectionParameter -> getClass ( ) ; if ( $ typeClass !== null ) { $ param -> setType ( '\\' . $ typeClass -> getName ( ) ) ; } } if ( $ reflectionParameter -> isOptional ( ) === true ) { $ param -> setDefaultValue ( $ reflectionParameter -> getDefaultValue ( ) ) ; if ( $ reflectionParameter -> isDefaultValueConstant ( ) === true ) { $ defaultValueConstantName = $ reflectionParameter -> getDefaultValueConstantName ( ) ; $ declaringFunction = $ reflectionParameter -> getDeclaringFunction ( ) ; if ( $ declaringFunction instanceof \ ReflectionMethod ) { $ ns = $ declaringFunction -> getDeclaringClass ( ) -> getNamespaceName ( ) ; } else { $ ns = $ declaringFunction -> getNamespaceName ( ) ; } if ( $ ns !== '' && strpos ( $ defaultValueConstantName , $ ns ) === 0 ) { $ defaultValueConstantName = substr ( $ defaultValueConstantName , strlen ( $ ns ) + 1 ) ; } elseif ( strpos ( $ defaultValueConstantName , '\\' ) !== false ) { $ defaultValueConstantName = '\\' . $ defaultValueConstantName ; } $ param -> setDefaultValueConstantName ( $ defaultValueConstantName ) ; } } $ param -> setPassByReference ( $ reflectionParameter -> isPassedByReference ( ) ) ; return $ param ; } | Create a new parameter from reflection . |
35,731 | public function setDefaultValue ( $ value ) { if ( ( $ value instanceof ValueGenerator ) === false ) { $ value = new ValueGenerator ( $ value ) ; } if ( $ this -> isValidParameterDefaultValue ( $ value ) !== true ) { throw new InvalidArgumentException ( 'Parameter default value is not valid.' ) ; } $ this -> defaultValue = $ value ; return $ this ; } | Set the default value of the parameter . |
35,732 | public function setDefaultValueConstantName ( $ name ) { if ( is_string ( $ name ) !== true || strlen ( $ name ) === 0 || preg_match ( '/\s/' , $ name ) > 0 ) { throw new InvalidArgumentException ( 'Constant name is not valid.' ) ; } $ this -> defaultValueConstantName = $ name ; return $ this ; } | Set the name of the constant of the default value . |
35,733 | public function setType ( $ type ) { if ( $ type === null || $ type === 'array' ) { $ this -> type = $ type ; return $ this ; } if ( $ this -> isObjectNameValid ( $ type ) !== true ) { throw new InvalidArgumentException ( 'Parameter type is not valid.' ) ; } $ this -> type = $ type ; return $ this ; } | Set the type of the parameter . |
35,734 | protected function detectParameterType ( ) { $ this -> setType ( null ) ; if ( $ this -> defaultValue !== null ) { $ value = $ this -> defaultValue -> getValue ( ) ; if ( is_array ( $ value ) === true ) { $ this -> setType ( 'array' ) ; } } return $ this ; } | Get the data type of the parameter from a value . |
35,735 | protected function getSchema ( $ connectionName = null ) { $ connectionName = $ connectionName === null ? $ this -> connectionName : $ connectionName ; $ schema = app ( 'db' ) -> connection ( $ connectionName ) -> getDoctrineSchemaManager ( ) ; $ schema -> getDatabasePlatform ( ) -> registerDoctrineTypeMapping ( 'enum' , 'string' ) ; $ schema -> getDatabasePlatform ( ) -> registerDoctrineTypeMapping ( 'long' , 'integer' ) ; $ schema -> getDatabasePlatform ( ) -> registerDoctrineTypeMapping ( 'bit' , 'boolean' ) ; return $ schema ; } | Get pdo instance for database connection |
35,736 | public static function fromReflection ( ReflectionClass $ reflectionClass ) { if ( $ reflectionClass -> isInterface ( ) !== true ) { throw new InvalidArgumentException ( 'The reflected class must be an interface.' ) ; } $ ig = new static ( $ reflectionClass -> getShortName ( ) , $ reflectionClass -> getNamespaceName ( ) ) ; if ( $ reflectionClass -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ ig -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionClass -> getReflectionDocComment ( ) ) ) ; } $ extends = array ( ) ; foreach ( $ reflectionClass -> getOwnInterfaces ( ) as $ interface ) { if ( $ interface -> getNamespaceName ( ) === $ ig -> getNamespace ( ) ) { $ extends [ ] = $ interface -> getShortName ( ) ; } else { $ extends [ ] = '\\' . $ interface -> getName ( ) ; } } $ ig -> setExtends ( $ extends ) ; foreach ( $ reflectionClass -> getOwnConstants ( ) as $ constant ) { $ ig -> addConstant ( ClassConstantGenerator :: fromReflection ( $ constant ) ) ; } foreach ( $ reflectionClass -> getOwnMethods ( ) as $ method ) { $ method = MethodGenerator :: fromReflection ( $ method ) ; $ method -> setAbstract ( false ) ; $ ig -> addMethod ( $ method ) ; } return $ ig ; } | Create a new interface from reflection . |
35,737 | public function addExtend ( $ interfaceName ) { if ( $ this -> isObjectNameValid ( $ interfaceName ) !== true ) { throw new InvalidArgumentException ( 'The name of the extended interface is not valid.' ) ; } $ this -> extends [ $ interfaceName ] = $ interfaceName ; return $ this ; } | Add an extended interface . |
35,738 | public static function addExtension ( string $ file , string $ extension ) { if ( substr ( $ file , strlen ( $ extension ) * - 1 ) !== $ extension ) { $ file .= $ extension ; } return $ file ; } | Checks if there is an extension and adds it if does not |
35,739 | public static function padNumber ( int $ val , int $ len , bool $ trim = false ) { $ result = sprintf ( "%0${len}d" , $ val ) ; if ( strlen ( $ result ) > $ len ) { if ( $ trim ) { return substr ( $ result , - $ len ) ; } else { throw new \ LengthException ( 'Value overflows maximum length' ) ; } } return $ result ; } | Adds leading zeroes to a value |
35,740 | public function getModel ( $ model = null ) { if ( $ model === null ) { $ model = $ this -> crudApi -> model ; } if ( $ model === null ) { return false ; } $ model = ucfirst ( $ model ) ; if ( $ this -> crudApi -> namespace === null ) { $ this -> crudApi -> setNamespace ( 'App\\' ) ; } $ conventions = [ $ this -> crudApi -> namespace . $ model , $ this -> crudApi -> namespace . 'Models\\' . $ model ] ; foreach ( $ conventions as $ fqModel ) { if ( class_exists ( $ fqModel ) ) { return $ fqModel ; } } try { $ additionalNamespaces = $ this -> getAdditionalNamespaces ( ) ; if ( ! empty ( $ additionalNamespaces ) ) { foreach ( $ additionalNamespaces as $ ns ) { $ fqModel = $ ns . $ model ; if ( class_exists ( $ fqModel ) ) { return $ fqModel ; } } } } catch ( \ Exception $ e ) { return false ; } return false ; } | Get a model from the currently set namespace and model . |
35,741 | public function instance ( ) { if ( $ this -> crudApi -> instance === null ) { $ fq = $ this -> getModel ( ) ; $ instance = new $ fq ( ) ; $ this -> crudApi -> setInstance ( $ instance ) ; } return $ this -> crudApi -> instance ; } | Return the crudapi model instance . |
35,742 | public function setJsonFormat ( $ format ) { if ( ! is_string ( $ format ) ) throw new \ Exception ( "JsonFormat must be a valid json string or a path to a file" ) ; if ( file_exists ( $ format ) ) { $ handler = fopen ( $ format , 'r' ) ; $ contents = fread ( $ handler , filesize ( $ format ) ) ; fclose ( $ handler ) ; $ format = $ contents ; } $ format = trim ( $ format ) ; $ arrayFormatCandidate = json_decode ( $ format , true , 1024 ) ; $ error = json_last_error ( ) ; if ( $ error === JSON_ERROR_NONE ) { $ this -> setFormat ( $ arrayFormatCandidate ) ; return true ; } throw new \ Exception ( "Invalid Json format or file" ) ; } | Takes a string argument that can be either a valid JSON string or a path to a file containing a valid JSON string . If the syntax is invalid or the file can t be accessed an \ Exception will be thrown |
35,743 | final public function output ( string $ name = null ) { $ result = implode ( static :: EOL , $ this -> registries ) . static :: EOL . static :: EOF ; if ( $ name === null ) { return $ result ; } Utils :: checkOutput ( pathinfo ( $ name ) [ 'extension' ] ?? '' ) ; header ( 'Content-Type: text/plain' ) ; header ( 'Content-Length: ' . strlen ( $ result ) ) ; header ( 'Content-Disposition: attachment; filename="' . $ name . '"' ) ; echo $ result ; } | Outputs the file contents in a multiline string |
35,744 | protected static function filter ( $ field ) { $ field = preg_replace ( '/[\.\/\\:;,?$*!#_-]/' , '' , $ field ) ; $ field = preg_replace ( '/\s+/' , ' ' , trim ( $ field ) ) ; return $ field ; } | Remove unwanted characters |
35,745 | protected static function mask ( $ subject , $ mask ) { if ( $ mask === null ) { return $ subject ; } elseif ( $ mask === '' ) { return '' ; } $ result = str_split ( $ subject ) ; foreach ( $ result as $ id => $ value ) { $ char = $ mask [ $ id ] ; if ( $ char !== static :: MOVEMENT_MASK_CHAR ) { $ result [ $ id ] = $ char ; } } return implode ( '' , $ result ) ; } | Applies a mask in a string |
35,746 | protected static function normalize ( $ data ) { foreach ( $ data as $ id => $ value ) { $ data [ $ id ] = strtoupper ( NoDiacritic :: filter ( $ value ) ) ; } return $ data ; } | Removes diacritics and convert to upper case |
35,747 | public function getErrors ( ) : array { $ error = [ ] ; foreach ( $ this -> list as $ r ) { $ error [ $ r -> getPropertyPath ( ) ] = $ r -> getMessage ( ) ; } return $ error ; } | Gets the list of errors |
35,748 | public function visitAndType ( AndType $ type ) { $ subTypes = array ( ) ; foreach ( $ type -> types ( ) as $ subType ) { $ subTypes [ ] = $ subType -> accept ( $ this ) ; } return implode ( '+' , $ subTypes ) ; } | Visit an and type . |
35,749 | public function visitOrType ( OrType $ type ) { $ subTypes = array ( ) ; foreach ( $ type -> types ( ) as $ subType ) { $ subTypes [ ] = $ subType -> accept ( $ this ) ; } return implode ( '|' , $ subTypes ) ; } | Visit an or type . |
35,750 | public function delete ( $ id ) { $ shipping = $ this -> getShippingRepository ( ) -> findById ( $ id ) ; if ( ! $ shipping ) { throw new ShippingNotFoundException ( $ id ) ; } $ this -> em -> remove ( $ shipping ) ; $ this -> em -> flush ( ) ; } | Delete a shipping |
35,751 | private function convertItemStatus ( Shipping $ shipping , $ shippingStatusId ) { foreach ( $ shipping -> getItems ( ) as $ shippingItem ) { $ item = $ shippingItem -> getItem ( ) ; switch ( $ shippingStatusId ) { case ShippingStatusEntity :: STATUS_CREATED : $ this -> itemManager -> addStatus ( $ item , Item :: STATUS_CREATED ) ; break ; case ShippingStatusEntity :: STATUS_DELIVERY_NOTE : if ( $ this -> isPartiallyItem ( $ shippingItem , true ) ) { $ itemStatus = Item :: STATUS_SHIPPING_NOTE_PARTIALLY ; } else { $ itemStatus = Item :: STATUS_SHIPPING_NOTE ; } $ this -> itemManager -> addStatus ( $ item , $ itemStatus ) ; break ; case ShippingStatusEntity :: STATUS_SHIPPED : if ( $ this -> isPartiallyItem ( $ shippingItem , false ) ) { $ itemStatus = Item :: STATUS_SHIPPED_PARTIALLY ; } else { $ itemStatus = Item :: STATUS_SHIPPED ; } $ this -> itemManager -> addStatus ( $ item , $ itemStatus ) ; break ; case ShippingStatusEntity :: STATUS_CANCELED : $ this -> itemManager -> removeStatus ( $ item , Item :: STATUS_SHIPPED ) ; break ; } } } | converts the status of an item |
35,752 | private function isPartiallyItem ( $ shippingItem , $ includeDeliveryNoteStatus = false ) { $ item = $ shippingItem -> getItem ( ) ; $ sumShipped = $ this -> getSumOfShippedItemsByItemId ( $ item -> getId ( ) , $ includeDeliveryNoteStatus ) ; $ orderItem = $ shippingItem -> getShipping ( ) -> getOrder ( ) -> getItem ( $ item -> getId ( ) ) ; if ( $ sumShipped == $ orderItem -> getQuantity ( ) - $ shippingItem -> getQuantity ( ) ) { return false ; } return true ; } | checks if an item is fully shipped or still open |
35,753 | public function getFieldDescriptor ( $ key ) { if ( array_key_exists ( $ key , $ this -> fieldDescriptors ) ) { return $ this -> fieldDescriptors [ $ key ] ; } else if ( array_key_exists ( $ key , $ this -> orderFieldDescriptors ) ) { return $ this -> orderFieldDescriptors [ $ key ] ; } else { throw new ShippingException ( 'field descriptor with key ' . $ key . ' could not be found' ) ; } } | returns a specific field descriptor by key |
35,754 | public function findByOrderId ( $ orderId , $ locale ) { $ result = array ( ) ; $ items = $ this -> getShippingRepository ( ) -> findByOrderId ( $ orderId , $ locale ) ; foreach ( $ items as $ item ) { $ result [ ] = $ this -> shippingFactory -> createApiEntity ( $ item , $ locale ) ; } return $ result ; } | Returns shippings by order id |
35,755 | private function initializeFieldDescriptors ( $ locale ) { $ this -> initializeOrderFieldDescriptors ( $ locale ) ; $ this -> fieldDescriptors [ 'id' ] = new DoctrineFieldDescriptor ( 'id' , 'id' , self :: $ shippingEntityName , 'public.id' , array ( ) , true ) ; $ this -> fieldDescriptors [ 'number' ] = new DoctrineFieldDescriptor ( 'number' , 'number' , self :: $ shippingEntityName , 'salesshipping.shippings.number' , array ( ) , false , true ) ; $ contactJoin = array ( self :: $ orderAddressEntityName => new DoctrineJoinDescriptor ( self :: $ orderAddressEntityName , self :: $ shippingEntityName . '.deliveryAddress' ) ) ; $ this -> fieldDescriptors [ 'account' ] = new DoctrineConcatenationFieldDescriptor ( array ( new DoctrineFieldDescriptor ( 'accountName' , 'account' , self :: $ orderAddressEntityName , 'contact.contacts.contact' , $ contactJoin ) ) , 'account' , 'salescore.account' , ' ' , false , false , '' , '' , '160px' ) ; $ this -> fieldDescriptors [ 'contact' ] = new DoctrineConcatenationFieldDescriptor ( array ( new DoctrineFieldDescriptor ( 'firstName' , 'contact' , self :: $ orderAddressEntityName , 'contact.contacts.contact' , $ contactJoin ) , new DoctrineFieldDescriptor ( 'lastName' , 'contact' , self :: $ orderAddressEntityName , 'contact.contacts.contact' , $ contactJoin ) ) , 'contact' , 'salescore.contact' , ' ' , false , false , '' , '' , '160px' , false ) ; $ this -> fieldDescriptors [ 'status' ] = new DoctrineFieldDescriptor ( 'name' , 'status' , self :: $ shippingStatusTranslationEntityName , 'salescore.status' , array ( self :: $ shippingStatusEntityName => new DoctrineJoinDescriptor ( self :: $ shippingStatusEntityName , self :: $ shippingEntityName . '.status' ) , self :: $ shippingStatusTranslationEntityName => new DoctrineJoinDescriptor ( self :: $ shippingStatusTranslationEntityName , self :: $ shippingStatusEntityName . '.translations' , self :: $ shippingStatusTranslationEntityName . ".locale = '" . $ locale . "'" ) ) ) ; $ this -> fieldDescriptors [ 'orderNumber' ] = $ this -> orderFieldDescriptors [ 'orderNumber' ] ; } | initializes field descriptors |
35,756 | private function checkRequiredData ( $ data , $ isNew ) { $ this -> checkDataSet ( $ data , 'order' , $ isNew ) && $ this -> checkDataSet ( $ data [ 'order' ] , 'id' , $ isNew ) ; $ this -> checkDataSet ( $ data , 'deliveryAddress' , $ isNew ) ; } | check if necessary data is set |
35,757 | private function checkDataSet ( array $ data , $ key , $ isNew ) { $ keyExists = array_key_exists ( $ key , $ data ) ; if ( ( $ isNew && ! ( $ keyExists && $ data [ $ key ] !== null ) ) || ( ! $ keyExists || $ data [ $ key ] === null ) ) { throw new MissingShippingAttributeException ( $ key ) ; } return $ keyExists ; } | checks data for attributes |
35,758 | private function getProperty ( array $ data , $ key , $ default = null ) { return array_key_exists ( $ key , $ data ) && $ data [ $ key ] !== null ? $ data [ $ key ] : $ default ; } | Returns the entry from the data with the given key or the given default value if the key does not exist |
35,759 | private function processItems ( $ data , Shipping $ shipping , $ locale , $ userId ) { $ result = true ; try { if ( $ this -> checkDataSet ( $ data , 'items' , false ) ) { if ( ! is_array ( $ data [ 'items' ] ) ) { throw new MissingShippingAttributeException ( 'items array' ) ; } $ items = $ data [ 'items' ] ; $ get = function ( $ item ) { return $ item -> getId ( ) ; } ; $ delete = function ( $ item ) use ( $ shipping ) { $ entity = $ item -> getEntity ( ) ; $ shipping -> removeShippingItem ( $ entity ) ; $ this -> em -> remove ( $ entity ) ; } ; $ update = function ( $ item , $ matchedEntry ) use ( $ locale ) { $ shippingItem = $ this -> saveShippingItem ( $ matchedEntry , $ item -> getEntity ( ) ) ; return $ shippingItem ? true : false ; } ; $ add = function ( $ itemData ) use ( $ locale , $ shipping ) { $ shippingItem = $ this -> saveShippingItem ( $ itemData ) ; $ shippingItem -> setShipping ( $ shipping -> getEntity ( ) ) ; return $ shipping -> addShippingItem ( $ shippingItem , null , $ locale ) ; } ; $ result = $ this -> restHelper -> processSubEntities ( $ shipping -> getItems ( ) , $ items , $ get , $ add , $ update , $ delete ) ; } } catch ( Exception $ e ) { throw new OrderException ( 'Error while creating items: ' . $ e -> getMessage ( ) ) ; } return $ result ; } | process shipping items |
35,760 | public static function attributes ( array $ attributes = array ( ) ) { $ formattedAttributes = array ( ) ; foreach ( $ attributes as $ name => $ value ) { if ( is_null ( $ value ) ) { continue ; } $ name = is_string ( $ name ) ? $ name : $ value ; $ formattedAttributes [ $ name ] = $ name . '="' . self :: escape ( $ value ) . '"' ; } return $ formattedAttributes ? ' ' . implode ( ' ' , $ formattedAttributes ) : '' ; } | Converts the array of attribute names and values into a valid HTML string . |
35,761 | public static function script ( $ src , $ type = 'text/javascript' , array $ attributes = array ( ) ) { $ attributes = array_merge ( $ attributes , compact ( 'src' , 'type' ) ) ; return '<script' . self :: attributes ( $ attributes ) . '></script>' . PHP_EOL ; } | Generates a script tag . |
35,762 | public function filter ( $ pattern , $ subject , $ limit = - 1 , $ flags = 0 ) { return $ this -> sandbox -> run ( 'preg_filter' , func_get_args ( ) , $ this -> throw ) ; } | Same as \ preg_filter but throws exception when an invalid pcre string is given |
35,763 | public function match ( $ pattern , $ subject , & $ matches = null , $ flags = 0 , $ offset = 0 ) { return $ this -> sandbox -> run ( 'preg_match' , [ $ pattern , $ subject , & $ matches , $ flags , $ offset ] , $ this -> throw ) ; } | Same as \ preg_match but throws exception when an invalid pcre string is given |
35,764 | public function matchAll ( $ pattern , $ subject , & $ matches = null , $ flags = PREG_PATTERN_ORDER , $ offset = 0 ) { return $ this -> sandbox -> run ( 'preg_match_all' , [ $ pattern , $ subject , & $ matches , $ flags , $ offset ] , $ this -> throw ) ; } | Same as \ preg_match_all but throws exception when an invalid pcre string is given |
35,765 | public function replace ( $ pattern , $ replacement , $ subject , $ limit = - 1 , & $ count = null ) { return $ this -> sandbox -> run ( 'preg_replace' , func_get_args ( ) , $ this -> throw ) ; } | Same as \ preg_replace but throws exception when an invalid pcre string is given |
35,766 | public function edit ( $ area , $ provider ) { $ provider = Provider :: query ( ) -> findOrFail ( $ provider ) ; $ area = ( ! $ area instanceof AreaContract ) ? app ( AreaManagerContract :: class ) -> getById ( $ area ) : $ area ; return $ this -> processor -> edit ( $ this , $ area , $ provider ) ; } | Request for edit provider on selected area . |
35,767 | public function update ( Request $ request ) { $ data = array_get ( $ request -> input ( ) , '2fa' , [ ] ) ; return $ this -> processor -> update ( $ this , $ data ) ; } | Request for update provider on selected area . |
35,768 | public function getCache ( $ cache ) { $ cache = self :: encodeCache ( $ cache ) ; $ url = "projects/{$this->project_id}/caches/$cache" ; $ this -> setJsonHeaders ( ) ; return self :: json_decode ( $ this -> apiCall ( self :: GET , $ url ) ) ; } | Get information about cache . Also returns cache size . |
35,769 | public function putItem ( $ cache , $ key , $ item ) { $ cache = self :: encodeCache ( $ cache ) ; $ key = self :: encodeKey ( $ key ) ; $ itm = new IronCache_Item ( $ item ) ; $ req = $ itm -> asArray ( ) ; $ url = "projects/{$this->project_id}/caches/$cache/items/$key" ; $ this -> setJsonHeaders ( ) ; $ res = $ this -> apiCall ( self :: PUT , $ url , $ req ) ; return self :: json_decode ( $ res ) ; } | Push a item on the cache at key |
35,770 | public function getItem ( $ cache , $ key ) { $ cache = self :: encodeCache ( $ cache ) ; $ key = self :: encodeKey ( $ key ) ; $ url = "projects/{$this->project_id}/caches/$cache/items/$key" ; $ this -> setJsonHeaders ( ) ; try { $ res = $ this -> apiCall ( self :: GET , $ url ) ; } catch ( Http_Exception $ e ) { if ( $ e -> getCode ( ) == Http_Exception :: NOT_FOUND ) { return null ; } else { throw $ e ; } } return self :: json_decode ( $ res ) ; } | Get item from cache by key |
35,771 | public function incrementItem ( $ cache , $ key , $ amount = 1 ) { $ cache = self :: encodeCache ( $ cache ) ; $ key = self :: encodeKey ( $ key ) ; $ url = "projects/{$this->project_id}/caches/$cache/items/$key/increment" ; $ params = array ( 'amount' => $ amount , ) ; $ this -> setJsonHeaders ( ) ; return self :: json_decode ( $ this -> apiCall ( self :: POST , $ url , $ params ) ) ; } | Atomically increments the value for key by amount . Can be used for both increment and decrement by passing a negative value . The value must exist and must be an integer . The number is treated as an unsigned 64 - bit integer . The usual overflow rules apply when adding but subtracting from 0 always yields 0 . |
35,772 | public function clear ( $ cache = null ) { if ( $ cache === null ) { $ cache = $ this -> cache_name ; } $ cache = self :: encodeCache ( $ cache ) ; $ url = "projects/{$this->project_id}/caches/$cache/clear" ; $ params = array ( ) ; $ this -> setJsonHeaders ( ) ; return self :: json_decode ( $ this -> apiCall ( self :: POST , $ url , $ params ) ) ; } | Clear a Cache Delete all items in a cache . This cannot be undone . |
35,773 | public function set_as_session_store ( $ session_expire_time = null ) { if ( $ session_expire_time != null ) { $ this -> session_expire_time = $ session_expire_time ; } session_set_save_handler ( array ( $ this , 'session_open' ) , array ( $ this , 'session_close' ) , array ( $ this , 'session_read' ) , array ( $ this , 'session_write' ) , array ( $ this , 'session_destroy' ) , array ( $ this , 'session_gc' ) ) ; } | Set IronCache as session store handler |
35,774 | public function configure ( UserConfigurationListener $ listener , AreaContract $ area ) { $ provider = $ this -> twoFactorProvidersService -> getEnabledInArea ( $ area ) ; $ userConfig = $ this -> userConfigService -> saveConfig ( $ provider ) ; $ form = $ this -> presenter -> configure ( $ userConfig , $ area , $ provider ) ; $ this -> dispatcher -> fire ( 'antares.form: two_factor_auth' , [ $ provider , $ form ] ) ; return $ listener -> showConfiguration ( $ provider , $ form ) ; } | Show configuration form for given area . |
35,775 | public function markAsConfigured ( UserConfigurationListener $ listener , AreaContract $ area ) { $ service = app ( TwoFactorProvidersService :: class ) ; $ service -> bind ( ) ; $ provider = $ service -> getEnabledInArea ( $ area ) ; $ userConfig = $ this -> userConfigService -> getSettingsByArea ( $ area ) ; $ secretKey = $ userConfig -> settings [ 'secret_key' ] ; $ form = app ( \ Antares \ Modules \ TwoFactorAuth \ Http \ Presenters \ AuthPresenter :: class ) -> verify ( $ userConfig , $ area , $ provider , $ secretKey ) ; return $ listener -> afterConfiguration ( $ form ) ; } | Mark given area as configured . |
35,776 | public function enable ( UserConfigurationListener $ listener , User $ user , AreaContract $ area ) { try { $ userConfig = $ this -> getUserConfig ( $ user , $ area ) ; $ this -> userConfigRepository -> markAsEnabledById ( $ userConfig -> id ) ; if ( $ this -> isConfigured ( $ area ) ) { $ msg = trans ( 'antares/two_factor_auth::configuration.responses.enable.success' , [ 'area' => $ area -> getLabel ( ) ] ) ; return $ listener -> afterConfiguration ( $ area , $ msg ) ; } return $ this -> configure ( $ listener , $ area ) ; } catch ( Exception $ e ) { Log :: emergency ( $ e ) ; $ msg = trans ( 'antares/two_factor_auth::configuration.responses.enable.fail' , [ 'area' => $ area -> getLabel ( ) ] ) ; return $ listener -> enableFailed ( $ msg ) ; } } | Enable the provider for the user in the selected area . |
35,777 | public function disable ( UserConfigurationListener $ listener , User $ user , AreaContract $ area ) { try { $ userConfig = $ this -> getUserConfig ( $ user , $ area ) ; $ this -> userConfigRepository -> markAsDisabledById ( $ userConfig -> id ) ; $ msg = trans ( 'antares/two_factor_auth::configuration.responses.disable.success' , [ 'area' => $ area -> getLabel ( ) ] ) ; return $ listener -> disableSuccess ( $ msg ) ; } catch ( Exception $ e ) { Log :: emergency ( $ e ) ; $ msg = trans ( 'antares/two_factor_auth::configuration.responses.disable.fail' , [ 'area' => $ area -> getLabel ( ) ] ) ; return $ listener -> disableFailed ( $ msg ) ; } } | Disable the provider for the user in the selected area . |
35,778 | protected function getUserConfig ( User $ user , AreaContract $ area ) { $ provider = $ this -> twoFactorProvidersService -> getEnabledInArea ( $ area ) ; $ userConfig = $ this -> userConfigRepository -> findByUserIdAndProviderId ( $ user -> id , $ provider -> getId ( ) ) ; if ( $ userConfig ) { return $ userConfig ; } $ data = [ 'user_id' => $ user -> id , 'provider_id' => $ provider -> getId ( ) , ] ; return $ this -> userConfigRepository -> save ( $ data ) ; } | Returns user configuration from the repository . It will be stored in repository if it has not been stored yet . |
35,779 | public function addKey ( $ table , $ hash , $ range = null ) { if ( $ this -> count ( ) >= 100 ) { throw new \ Riverline \ DynamoDB \ Exception \ AttributesException ( "Can't request more than 100 items" ) ; } if ( ! isset ( $ this -> keysByTable [ $ table ] ) ) { $ this -> keysByTable [ $ table ] = array ( ) ; } $ this -> keysByTable [ $ table ] [ ] = array ( $ hash , $ range ) ; return $ this ; } | Add an item key |
35,780 | public function optionsFromEnumColumn ( $ model_name , $ column_name , array $ extra_options = [ ] ) { $ options = [ ] ; foreach ( $ model_name :: table ( ) -> enumValues ( $ column_name ) as $ val ) { $ options [ $ this -> humanize ( $ val ) ] = $ val ; } if ( $ extra_options ) { $ options = array_merge ( $ extra_options , $ options ) ; } return $ options ; } | This method could go somewhere else . |
35,781 | public function getElementInstance ( $ type ) { $ class = $ this -> elementNamespace . ucfirst ( $ type ) ; if ( array_key_exists ( $ type , $ this -> customTypes ) ) { $ class = $ this -> customTypes [ $ type ] ; } return new $ class ; } | Gets a new instance of the given input type |
35,782 | public function schemaTemplate ( $ schemaName ) { return [ 'exists' => ( new Query ( ) ) -> select ( 'nspname' ) -> from ( 'pg_namespace' ) -> where ( 'nspname = :value' , [ ':value' => $ schemaName ] ) -> exists ( $ this -> db ) , 'up' => "CREATE SCHEMA $schemaName" , 'down' => "DROP SCHEMA $schemaName" , ] ; } | Returns two queries to create and destroy the audits schema . |
35,783 | public function actionTypeTemplate ( $ schemaName = null ) { if ( $ schemaName === null ) { $ schemaName = 'public' ; } return [ 'exists' => ( new Query ( ) ) -> select ( 'typname' ) -> from ( 'pg_type' ) -> where ( 'typname=:value' , [ ':value' => 'action_type' ] ) -> exists ( $ this -> db ) , 'up' => "CREATE TYPE $schemaName.action_type AS ENUM ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE')" , 'down' => "DROP TYPE $schemaName.action_type" , ] ; } | Returns two queries to create and destroy the action db type . |
35,784 | public function triggerTemplate ( $ tableName , $ schemaName ) { if ( $ schemaName === null ) { $ schemaName = 'public' ; } $ rowTriggerTemplate = <<<SQLCREATE TRIGGER log_action_row_trigger AFTER INSERT OR UPDATE OR DELETE ON {$tableName} FOR EACH ROW EXECUTE PROCEDURE {$schemaName}.log_action();SQL ; $ stmtTriggerTemplate = <<<SQLCREATE TRIGGER log_action_stmt_trigger AFTER INSERT OR UPDATE OR DELETE ON {$tableName} FOR EACH STATEMENT EXECUTE PROCEDURE {$schemaName}.log_action(true);SQL ; return [ 'exists' => ( new Query ( ) ) -> select ( 'tgname' ) -> from ( 'pg_trigger t' ) -> innerJoin ( 'pg_class c' , 'c.oid = t.tgrelid' ) -> innerJoin ( 'pg_namespace n' , 'n.oid = c.relnamespace' ) -> where ( 'n.nspname || \'.\' || c.relname = :table AND tgname=:value' , [ ':table' => $ tableName , ':value' => 'log_action_row_trigger' ] ) -> exists ( $ this -> db ) && ( new Query ( ) ) -> select ( 'tgname' ) -> from ( 'pg_trigger t' ) -> innerJoin ( 'pg_class c' , 'c.oid = t.tgrelid' ) -> innerJoin ( 'pg_namespace n' , 'n.oid = c.relnamespace' ) -> where ( 'n.nspname || \'.\' || c.relname = :table AND tgname=:value' , [ ':table' => $ tableName , ':value' => 'log_action_stmt_trigger' ] ) -> exists ( $ this -> db ) , 'up' => [ 'log_action_row_trigger' => $ rowTriggerTemplate , 'log_action_stmt_trigger' => $ stmtTriggerTemplate , ] , 'down' => [ 'log_action_stmt_trigger' => "DROP TRIGGER log_action_stmt_trigger ON {$tableName}" , 'log_action_row_trigger' => "DROP TRIGGER log_action_row_trigger ON {$tableName}" , ] , ] ; } | Returns two queries to create and destroy the db trigger . |
35,785 | public function tableTemplate ( $ auditTableName , $ changesetTableName = null , $ schemaName = null ) { if ( $ schemaName === null ) { $ schemaName = 'public' ; } $ result = [ ] ; $ auditColumns = [ 'action_id' => 'bigserial NOT NULL PRIMARY KEY' , 'schema_name' => 'text NOT NULL' , 'table_name' => 'text NOT NULL' , 'relation_id' => 'oid NOT NULL' , 'transaction_date' => 'timestamp with time zone NOT NULL' , 'statement_date' => 'timestamp with time zone NOT NULL' , 'action_date' => 'timestamp with time zone NOT NULL' , 'transaction_id' => 'bigint' , 'session_user_name' => 'text' , 'application_name' => 'text' , 'client_addr' => 'inet' , 'client_port' => 'integer' , 'query' => 'text' , 'action_type' => "$schemaName.action_type NOT NULL" , 'row_data' => 'jsonb' , 'changed_fields' => 'jsonb' , 'statement_only' => 'boolean NOT NULL DEFAULT FALSE' , 'key_type' => "char(1) NOT NULL CHECK (key_type IN ('t', 'a'))" , ] ; if ( $ changesetTableName !== null ) { $ auditColumns [ 'key_type' ] = "char(1) NOT NULL CHECK (key_type IN ('c', 't', 'a'))" ; $ auditColumns [ 'changeset_id' ] = "integer REFERENCES $schemaName.$changesetTableName (id) ON UPDATE CASCADE ON DELETE CASCADE" ; $ metaColumns = [ 'id' => 'serial NOT NULL PRIMARY KEY' , 'transaction_id' => 'bigint' , 'user_id' => 'integer' , 'session_id' => 'text' , 'request_date' => 'timestamp with time zone NOT NULL' , 'request_url' => 'text' , 'request_addr' => 'inet' , ] ; $ result [ ] = [ 'name' => "$schemaName.$changesetTableName" , 'exists' => $ this -> db -> schema -> getTableSchema ( "$schemaName.$changesetTableName" ) !== null , 'columns' => $ metaColumns , 'indexes' => [ 'transaction_id' , 'User_id' , 'session_id' , 'request_url' , 'request_addr' , ] , ] ; } $ result [ ] = [ 'name' => "$schemaName.$auditTableName" , 'exists' => $ this -> db -> schema -> getTableSchema ( "$schemaName.$auditTableName" ) !== null , 'columns' => $ auditColumns , 'indexes' => array_merge ( [ 'schema_name, table_name' , 'relation_id' , 'statement_date' , 'action_type' , 'key_type' , 'statement_only' , 'row_data' => 'USING GIN (row_data jsonb_path_ops)' , ] , $ changesetTableName === null ? [ "key_type, (CASE key_type WHEN 'c' THEN changeset_id WHEN 't' THEN transaction_id ELSE action_id END))" , ] : [ "key_type, (CASE key_type WHEN 't' THEN transaction_id ELSE action_id END))" , 'changeset_id' , ] ) , ] ; return $ result ; } | Returns an array with columns list for the audit table that stores row version . If the table already exists also returns current columns for comparison . |
35,786 | public function checkModel ( ActiveRecord $ model ) { if ( ( $ behavior = $ this -> getBehavior ( $ model ) ) === null ) { return null ; } $ auditTableName = $ behavior -> auditTableName ; if ( ( $ pos = strpos ( $ auditTableName , '.' ) ) !== false ) { $ auditSchema = substr ( $ auditTableName , 0 , $ pos ) ; } else { $ auditSchema = null ; } $ triggerTemplate = $ this -> triggerTemplate ( $ model -> getTableSchema ( ) -> name , $ auditSchema ) ; return [ 'enabled' => true , 'valid' => $ triggerTemplate [ 'exists' ] , ] ; } | Checks if audit objects for specified model exist and are valid . |
35,787 | public function onKernelRequest ( GetResponseEvent $ event ) { if ( ! $ event -> isMasterRequest ( ) ) { return ; } if ( ! $ this -> csrfTokenManager instanceof CsrfTokenManagerInterface ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ request -> isMethodCacheable ( ) ) { return ; } if ( $ request -> attributes -> get ( '_route' ) !== $ this -> routeName ) { return ; } $ session = $ event -> getRequest ( ) -> getSession ( ) ; if ( ! $ session -> isStarted ( ) ) { return ; } if ( $ request -> headers -> get ( 'X-CSRF-Token' ) !== null ) { return ; } $ csrfToken = $ this -> csrfTokenManager -> getToken ( $ this -> csrfTokenId ) -> getValue ( ) ; $ request -> headers -> set ( 'X-CSRF-Token' , $ csrfToken ) ; } | Resolves the layout to be used for the current request . |
35,788 | public function renderData ( ) { $ columns = $ this -> table -> getTableColumns ( ) ; $ types = [ ] ; $ structure = [ ] ; foreach ( $ columns as $ column ) { $ structure [ ] = snake_case ( str_replace ( 'ID' , 'Id' , $ column -> getName ( ) ) ) ; $ type = $ column -> getType ( ) -> getName ( ) ; switch ( $ type ) { case Type :: INTEGER : case Type :: SMALLINT : case Type :: BIGINT : $ types [ $ column -> getName ( ) ] = 'int' ; break ; case Type :: FLOAT : $ types [ $ column -> getName ( ) ] = 'float' ; break ; case Type :: DECIMAL : $ types [ $ column -> getName ( ) ] = 'decimal' ; break ; case Type :: BOOLEAN : $ types [ $ column -> getName ( ) ] = 'boolean' ; break ; default : $ types [ $ column -> getName ( ) ] = 'string' ; break ; } } $ data = $ this -> table -> getData ( ) ; $ tableData = [ ] ; foreach ( $ data as $ row ) { $ modelData = [ ] ; foreach ( $ row as $ column => $ value ) { switch ( $ types [ $ column ] ) { case 'int' : $ value = ( int ) $ value ; break ; case 'float' : $ value = ( float ) $ value ; break ; case 'decimal' : $ value = ( double ) $ value ; break ; case 'boolean' : $ value = ( int ) $ value ; break ; case 'string' : $ value = ( string ) $ value ; break ; } $ modelData [ ] = var_export ( $ value , true ) ; } $ tableData [ ] = '[' . implode ( ',' , $ modelData ) . ']' ; } return [ $ structure , '[' . implode ( ',' , $ tableData ) . ']' , count ( $ data ) ] ; } | Get database table data rendered in model create |
35,789 | public function getModelClass ( ) { $ map = config ( 'db-exporter.model.map' ) ; $ namespace = config ( 'db-exporter.model.namespace' ) ; $ class = snake_case ( $ this -> getTable ( ) -> getTableName ( ) ) ; foreach ( $ map as $ item ) { $ tablePattern = '/' . str_replace ( '/' , '\/' , $ item [ 'tablePattern' ] ) . '/' ; if ( preg_match ( $ tablePattern , $ this -> table -> getTableName ( ) ) === 1 ) { $ namespace = $ item [ 'namespace' ] ; if ( $ item [ 'className' ] !== null ) { $ pattern = '/' . str_replace ( '/' , '\/' , $ item [ 'className' ] [ 'pattern' ] ) . '/' ; $ replacement = $ item [ 'className' ] [ 'replacement' ] ; echo $ replacement ; $ class = preg_replace ( $ pattern , $ replacement , $ class ) ; } break ; } } return $ namespace . '\\' . studly_case ( str_singular ( $ class ) ) ; } | Get class model |
35,790 | public function writeSeedOut ( OutputInterface $ output , $ force ) { $ class = $ this -> getClass ( ) ; $ modelClass = $ this -> getModelClass ( ) ; $ fileName = $ class . '.php' ; list ( $ structure , $ data , $ count ) = $ this -> renderData ( ) ; if ( $ count > 0 ) { $ this -> writeToFileFromTemplate ( $ this -> path . '/' . $ fileName , 'seeder' , $ output , [ 'use' => $ modelClass , 'className' => $ this -> getClass ( ) , 'tableName' => snake_case ( $ this -> table -> getTableName ( ) ) , 'model' => class_basename ( $ modelClass ) , 'structure' => var_export ( $ structure , true ) , 'count' => $ count , ] , $ force ) ; $ this -> writeToFileFromTemplate ( $ this -> path . '/data/' . snake_case ( $ this -> table -> getTableName ( ) ) . '_table_data.php' , 'seederData' , $ output , [ 'data' => $ data , ] , $ force ) ; } } | Render seed class and write out to file |
35,791 | public static function fromReflection ( ReflectionConstant $ reflectionConstant ) { $ cc = new static ( $ reflectionConstant -> getName ( ) , $ reflectionConstant -> getValue ( ) ) ; if ( $ reflectionConstant -> getReflectionDocComment ( ) -> isEmpty ( ) !== true ) { $ cc -> setDocumentation ( DocCommentGenerator :: fromReflection ( $ reflectionConstant -> getReflectionDocComment ( ) ) ) ; } return $ cc ; } | Create a new class constant generator from reflection . |
35,792 | public function setValue ( $ value ) { if ( ( $ value instanceof ValueGenerator ) !== true ) { $ value = new ValueGenerator ( $ value ) ; } if ( $ value -> isValidConstantType ( ) !== true ) { throw new InvalidArgumentException ( 'Constant value is not valid (' . gettype ( $ value -> getValue ( ) ) . ' type given).' ) ; } $ this -> value = $ value ; return $ this ; } | Set the value for the constant . |
35,793 | public function generate ( ) { $ code = array ( ) ; $ doc = $ this -> generateDocumentation ( ) ; if ( $ doc !== null ) { $ code [ ] = $ doc ; } $ code [ ] = $ this -> getIndentation ( ) . 'const ' . $ this -> name . ' = ' . $ this -> value -> generate ( ) . ';' ; return implode ( $ this -> getLineFeed ( ) , $ code ) ; } | Generate the class constant code . |
35,794 | public function allowCancel ( $ order ) { if ( $ this -> shippingManager -> countByOrderId ( $ order -> getId ( ) , array ( ShippingStatus :: STATUS_SHIPPED ) ) > 0 ) { return false ; } return true ; } | returns the identifying name |
35,795 | private function cleanHost ( $ host ) { if ( strpos ( $ host , 'http://' ) === false || strpos ( $ host , 'https://' ) ) { $ host = 'http://' . $ host ; } $ host = rtrim ( $ host , '/' ) ; return $ host ; } | Helper method to clean the host url |
35,796 | public function map ( Registrar $ router ) { foreach ( $ this -> getRoutes ( ) as $ binder ) { $ binder -> addRoutes ( $ router ) ; } } | Register routes on boot . |
35,797 | public function getRoute ( AdminInterface $ admin , $ action , $ params = [ ] , $ isIndex = false ) { $ defaults = [ ] ; $ path = '/' . $ admin -> getAlias ( ) ; if ( ! $ isIndex ) { $ path .= '/' . $ action ; } foreach ( $ params as $ paramKey => $ paramValue ) { if ( is_int ( $ paramKey ) ) { $ paramName = $ paramValue ; } else { $ paramName = $ paramKey ; $ defaults [ $ paramName ] = $ paramValue ; } $ path .= '/{' . $ paramName . '}' ; } $ controller = 'ShuweeAdminBundle:Content:' . $ action ; $ defaults = array_merge ( [ '_controller' => $ controller , 'alias' => $ admin -> getAlias ( ) , ] , $ defaults ) ; return new Route ( $ path , $ defaults ) ; } | Build a route for a given admin and action . |
35,798 | public static function nameByType ( $ type ) { switch ( $ type ) { case self :: TOKEN_BOOLEAN_FALSE : return 'BOOLEAN_FALSE' ; case self :: TOKEN_BOOLEAN_TRUE : return 'BOOLEAN_TRUE' ; case self :: TOKEN_BRACE_CLOSE : return 'BRACE_CLOSE' ; case self :: TOKEN_BRACE_OPEN : return 'BRACE_OPEN' ; case self :: TOKEN_COLON : return 'COLON' ; case self :: TOKEN_COMMA : return 'COMMA' ; case self :: TOKEN_FLOAT : return 'FLOAT' ; case self :: TOKEN_GREATER_THAN : return 'GREATER_THAN' ; case self :: TOKEN_INTEGER : return 'INTEGER' ; case self :: TOKEN_LESS_THAN : return 'LESS_THAN' ; case self :: TOKEN_NULL : return 'NULL' ; case self :: TOKEN_PIPE : return 'PIPE' ; case self :: TOKEN_PLUS : return 'PLUS' ; case self :: TOKEN_SQUARE_BRACKET_CLOSE : return 'SQUARE_BRACKET_CLOSE' ; case self :: TOKEN_SQUARE_BRACKET_OPEN : return 'SQUARE_BRACKET_OPEN' ; case self :: TOKEN_STRING : return 'STRING' ; case self :: TOKEN_STRING_QUOTED : return 'STRING_QUOTED' ; case self :: TOKEN_TYPE_NAME : return 'TYPE_NAME' ; case self :: TOKEN_WHITESPACE : return 'WHITESPACE' ; } return null ; } | Get the token name from a token type . |
35,799 | public static function namesByType ( array $ types ) { $ names = array ( ) ; foreach ( $ types as $ type ) { $ names [ ] = self :: nameByType ( $ type ) ; } return $ names ; } | Get token names from an array of token types . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.