idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
36,800 | public function getServiceDescription ( $ service ) { if ( $ this -> serviceIsObject ( $ service ) ) { return get_class ( $ service ) ; } return $ this -> formatServiceDescription ( $ service , is_scalar ( $ service ) ) ; } | Retrieve a string representation of a service . |
36,801 | public function formatServiceDescription ( $ service , $ scalar = true ) { return sprintf ( $ scalar ? self :: SCALAR_FORMAT : self :: NON_SCALAR_FORMAT , gettype ( $ service ) , $ scalar ? ( string ) $ service : null ) ; } | Retrieve a suitable formatted service description . |
36,802 | private function parseNamespace ( $ tokens ) { $ namespace = null ; $ tokenCount = count ( $ tokens ) ; for ( $ offset = 0 ; $ offset < $ tokenCount ; $ offset ++ ) { if ( ! is_array ( $ tokens [ $ offset ] ) ) { continue ; } if ( T_NAMESPACE === $ tokens [ $ offset ] [ 0 ] ) { $ offset ++ ; return $ this -> parseNamespaceString ( $ tokens , $ offset ) ; } } return $ namespace ; } | Extracts the namespace from tokenized file |
36,803 | public function sync ( array $ ids , $ detaching = true ) { $ current = $ this -> newPivotQuery ( ) -> lists ( $ this -> otherKey ) ; $ records = $ this -> formatSyncList ( $ ids ) ; $ detach = array_diff ( $ current , array_keys ( $ records ) ) ; if ( $ detaching && count ( $ detach ) > 0 ) { $ this -> detach ( $ detach ) ; } $ this -> attachNew ( $ records , $ current , false ) ; $ this -> touchIfTouching ( ) ; } | Sync the intermediate tables with a list of IDs . |
36,804 | protected function setTimestampsOnAttach ( array $ record , $ exists = false ) { $ fresh = $ this -> parent -> freshTimestamp ( ) ; if ( ! $ exists ) $ record [ $ this -> createdAt ( ) ] = $ fresh ; $ record [ $ this -> updatedAt ( ) ] = $ fresh ; return $ record ; } | Set the creation and update timstamps on an attach record . |
36,805 | public function addError ( Exception $ error ) { $ errorNode = $ this -> addElement ( "error" , $ error -> getMessage ( ) ) ; if ( ! $ error instanceof NoRecordsMatchException ) { $ this -> status = '400' ; } if ( $ error -> getErrorName ( ) ) { $ errorNode -> setAttribute ( "code" , $ error -> getErrorName ( ) ) ; } else { $ errorNode -> setAttribute ( "code" , "badArgument" ) ; } } | adds an error node base on a Exception |
36,806 | public function minifyHTML ( ) { $ buffer = $ this -> response -> getContent ( ) ; if ( strpos ( $ buffer , '<pre>' ) !== false ) { $ replace = array ( '/<!--[^\[](.*?)[^\]] => '' , "/<\?php/" => '<?php ' , "/\r/" => '' , "/>\n</" => '><' , "/>\s+\n</" => '><' , "/>\n\s+</" => '><' , ) ; } else { $ replace = array ( '/<!--[^\[](.*?)[^\]] => '' , "/<\?php/" => '<?php ' , "/\n([\S])/" => '$1' , "/\r/" => '' , "/\n/" => '' , "/\t/" => '' , "/ +/" => ' ' , '#^\s*//.+$#m' => '' , ) ; } $ buffer = preg_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ buffer ) ; $ this -> response -> setContent ( $ buffer ) ; } | Minify the HTML Output |
36,807 | public function get ( $ name , $ options = null ) { if ( $ this -> has ( $ name ) ) { return $ this -> resolve ( $ name , $ options ) ; } else { $ this -> throwNotFound ( $ name ) ; return false ; } } | Resolves the service of widget based on its configuration |
36,808 | public function set ( $ name , $ definition , $ shared = false ) { $ widget = $ this -> getDI ( ) -> get ( '\Phalcon\DI\Service' , [ $ name , $ definition , $ shared ] ) ; $ this -> _widgets [ $ name ] = $ widget ; return $ this ; } | Registers a widget in the container |
36,809 | public function getService ( $ name ) { if ( $ this -> has ( $ name ) ) { return $ this -> _widgets [ $ name ] ; } else { $ this -> throwNotFound ( $ name ) ; return false ; } } | Returns the corresponding Phalcon \ Di \ Service instance for a widget |
36,810 | protected function resolve ( $ name , $ options = null ) { $ widget = $ this -> getService ( $ name ) ; $ wDefinition = $ widget -> getDefinition ( ) ; if ( is_array ( $ wDefinition ) && ! $ widget -> isResolved ( ) ) { if ( isset ( $ wDefinition [ 'path' ] ) && ! class_exists ( $ wDefinition [ 'className' ] , false ) ) { include_once $ wDefinition [ 'path' ] ; } if ( isset ( $ wDefinition [ 'options' ] ) ) { $ options = array_merge ( $ wDefinition [ 'options' ] , $ options ) ; } } $ instance = $ widget -> resolve ( [ $ options ] , $ this -> getDI ( ) ) ; if ( $ instance instanceof InjectionAwareInterface ) { $ instance -> setDI ( $ this -> getDI ( ) ) ; } return $ instance ; } | Resolves the widget |
36,811 | protected function translateCipher ( int $ nscaName ) : string { switch ( $ nscaName ) { case self :: ENCRYPT_DES : return MCRYPT_DES ; case self :: ENCRYPT_3DES : return MCRYPT_3DES ; case self :: ENCRYPT_CAST128 : return MCRYPT_CAST_128 ; case self :: ENCRYPT_CAST256 : return MCRYPT_CAST_256 ; case self :: ENCRYPT_XTEA : return MCRYPT_XTEA ; case self :: ENCRYPT_3WAY : return MCRYPT_THREEWAY ; case self :: ENCRYPT_BLOWFISH : return MCRYPT_BLOWFISH ; case self :: ENCRYPT_TWOFISH : return MCRYPT_TWOFISH ; case self :: ENCRYPT_LOKI97 : return MCRYPT_LOKI97 ; case self :: ENCRYPT_RC2 : return MCRYPT_RC2 ; case self :: ENCRYPT_ARCFOUR : return MCRYPT_ARCFOUR ; case self :: ENCRYPT_RIJNDAEL128 : return MCRYPT_RIJNDAEL_128 ; case self :: ENCRYPT_RIJNDAEL192 : return MCRYPT_RIJNDAEL_192 ; case self :: ENCRYPT_RIJNDAEL256 : return MCRYPT_RIJNDAEL_256 ; case self :: ENCRYPT_WAKE : return MCRYPT_WAKE ; case self :: ENCRYPT_SERPENT : return MCRYPT_SERPENT ; case self :: ENCRYPT_ENIGMA : return MCRYPT_ENIGNA ; case self :: ENCRYPT_GOST : return MCRYPT_GOST ; case self :: ENCRYPT_SAFER64 : return MCRYPT_SAFER64 ; case self :: ENCRYPT_SAFER128 : return MCRYPT_SAFER128 ; case self :: ENCRYPT_SAFERPLUS : return MCRYPT_SAFERPLUS ; } throw new EncryptionException ( 'Unknown Cipher: ' . $ nscaName ) ; } | Translates the EncryptorInterfaces class constants to the legacy mcrypt constants |
36,812 | static function cache_namespace ( $ user_perms = true ) { $ ns_parts = array ( ) ; if ( empty ( $ _SERVER [ 'HTTP_HOST' ] ) ) $ ns_parts [ ] = 'cli' ; elseif ( ! preg_match ( '/^\d+\.\d+\.\d+\.\d+$/' , $ _SERVER [ 'HTTP_HOST' ] ) ) $ ns_parts [ ] = str_replace ( ':' , '=' , strtolower ( $ _SERVER [ 'HTTP_HOST' ] ) ) ; elseif ( $ _SERVER [ 'HTTP_HOST' ] != gethostbyname ( gethostname ( ) ) ) $ ns_parts [ ] = 'unknown' ; $ ns_parts [ ] = Cfg :: get ( 'project.name' ) ; if ( $ user_perms && ! empty ( $ _SERVER [ 'USER' ] ) ) $ ns_parts [ ] = strtolower ( $ _SERVER [ 'USER' ] ) ; if ( ( $ cs = Cfg :: get ( 'internal_charset' ) ) && $ cs != 'utf-8' ) $ ns_parts [ ] = 'i' . $ cs ; if ( ( $ cs = Cfg :: get ( 'output_charset' ) ) && $ cs != 'utf-8' ) $ ns_parts [ ] = 'o' . $ cs ; if ( ! empty ( $ _SERVER [ 'BORS_INSTANCE' ] ) ) $ ns_parts [ ] = $ _SERVER [ 'BORS_INSTANCE' ] ; return array_filter ( $ ns_parts ) ; } | BORS process namespace |
36,813 | public function make ( $ model , $ method , $ element ) { $ this -> tableInfo = $ this -> getTableInfo ( $ model ) ; $ type = 'generic' ; if ( preg_match ( '/^ul|li|ol$/i' , $ element ) ) { $ element = 'li' ; $ type = 'list' ; } $ output = $ this -> render ( $ type , $ method , $ model , $ element ) ; $ this -> printOutput ( $ output ) ; } | Create the form |
36,814 | public function getTableInfo ( $ model ) { $ table = $ this -> getTableName ( $ model ) ; return \ DB :: getDoctrineSchemaManager ( ) -> listTableDetails ( $ table ) -> getColumns ( ) ; } | Fetch Doctrine table info |
36,815 | public function getInputType ( $ name ) { $ dataType = $ this -> tableInfo [ $ name ] -> getType ( ) -> getName ( ) ; $ lookup = array ( 'string' => 'text' , 'float' => 'text' , 'date' => 'text' , 'text' => 'textarea' , 'boolean' => 'checkbox' ) ; return array_key_exists ( $ dataType , $ lookup ) ? $ lookup [ $ dataType ] : 'text' ; } | Calculate correct Formbuilder method |
36,816 | protected function getFormElements ( $ type = 'list' , $ element ) { $ form = array ( ) ; $ template = $ this -> getTemplate ( "{$type}-block" ) ; $ attributes = $ this -> getModelAttributes ( $ this -> tableInfo ) ; foreach ( $ attributes as $ name ) { $ form [ ] = $ this -> renderElement ( $ template , $ element , $ name ) ; } return implode ( PHP_EOL . PHP_EOL , $ form ) ; } | Dynamically create form elements |
36,817 | protected function renderElement ( $ block , $ element , $ name ) { return $ this -> mustache -> render ( $ block , array ( 'element' => $ element , 'name' => $ name , 'type' => $ this -> getInputType ( $ name ) , 'label' => str_replace ( '_' , ' ' , ucwords ( $ name ) ) . ':' ) ) ; } | Render a single element block |
36,818 | protected function decrypt ( Request $ request ) { foreach ( $ request -> cookies as $ key => $ c ) { try { $ request -> cookies -> set ( $ key , $ this -> decryptCookie ( $ c ) ) ; } catch ( DecryptException $ e ) { $ request -> cookies -> set ( $ key , null ) ; } } return $ request ; } | Decrypt the cookies on the request . |
36,819 | private function getControllerClassName ( ) : string { $ tableName = App :: shortName ( get_class ( $ this -> table ) , 'Model/Table' , 'Table' ) ; return ( string ) App :: className ( $ tableName . 'Controller' , 'Controller' ) ; } | Controller class name getter . |
36,820 | private function isFilterable ( ) : bool { if ( empty ( $ this -> user ) ) { return false ; } if ( ! array_key_exists ( 'id' , $ this -> user ) ) { return false ; } if ( $ this -> isSuperuser ( ) ) { return false ; } if ( $ this -> isSkipTable ( ) ) { return false ; } $ controllerName = $ this -> getControllerClassName ( ) ; if ( ! $ controllerName ) { return false ; } if ( 'Cake\Controller\Controller' === $ controllerName ) { return false ; } return true ; } | Validates if Query is filterable . |
36,821 | private function isSkipTable ( ) : bool { $ config = ( array ) Configure :: read ( 'RolesCapabilities.ownerCheck.skipTables.byInstance' ) ; if ( in_array ( get_class ( $ this -> table ) , $ config ) ) { return true ; } $ config = ( array ) Configure :: read ( 'RolesCapabilities.ownerCheck.skipTables.byRegistryAlias' ) ; if ( in_array ( $ this -> table -> getRegistryAlias ( ) , $ config ) ) { return true ; } $ config = ( array ) Configure :: read ( 'RolesCapabilities.ownerCheck.skipTables.byTableName' ) ; if ( in_array ( $ this -> table -> getTable ( ) , $ config ) ) { return true ; } return false ; } | Validates if provided table must be skipped from access checks . |
36,822 | public function execute ( ) : Query { if ( ! $ this -> filterable ) { return $ this -> query ; } if ( $ this -> hasFullAccess ( ) ) { return $ this -> query ; } $ where = $ this -> getWhereClause ( ) ; if ( ! empty ( $ where ) ) { $ where = [ 'OR' => $ where ] ; } if ( empty ( $ where ) ) { $ primaryKey = $ this -> table -> getPrimaryKey ( ) ; Assert :: string ( $ primaryKey ) ; $ where = [ $ this -> table -> aliasField ( $ primaryKey ) => null ] ; } $ this -> query -> where ( $ where ) ; return $ this -> query ; } | Executes Query filtering functionality . |
36,823 | private function getWhereClause ( ) : array { $ result = array_merge ( $ this -> getOwnerFields ( ) , $ this -> getBelongTo ( ) , $ this -> getPermissions ( ) ) ; $ result = array_merge ( $ result , $ this -> getParentPermissions ( ) , $ this -> getParentJoinsWhereClause ( ) ) ; $ result = array_merge_recursive ( $ result , $ this -> getSupervisorWhereClause ( ) ) ; return $ result ; } | Generates conditions for where clause . |
36,824 | private function getParentPermissions ( ) : array { $ result = [ ] ; foreach ( $ this -> table -> associations ( ) as $ association ) { if ( ! $ this -> isSupportedJoinAssociation ( $ association ) ) { continue ; } if ( ! $ this -> isParentModuleAssociation ( $ association ) ) { continue ; } $ foreignKey = $ association -> getForeignKey ( ) ; Assert :: string ( $ foreignKey ) ; $ field = sprintf ( '%s IN' , $ foreignKey ) ; $ result [ $ field ] = $ this -> getPermissionsByModel ( $ this -> getModelByAssociation ( $ association ) ) ; } return $ result ; } | User permissions getter by parent module . |
36,825 | private function getParentJoinsWhereClause ( ) : array { $ result = [ ] ; foreach ( $ this -> getParentJoins ( ) as $ name => $ conditions ) { $ result = array_merge ( $ result , $ conditions ) ; $ this -> query -> leftJoinWith ( $ name , function ( $ q ) { return $ q -> applyOptions ( [ 'accessCheck' => false ] ) ; } ) ; } return $ result ; } | Generates parent joins conditions for where clause . |
36,826 | private function getSupervisorWhereClause ( ) : array { if ( ! $ this -> isSupervisor ( ) ) { return [ ] ; } $ result = [ ] ; foreach ( Utils :: getReportToUsers ( $ this -> user [ 'id' ] ) as $ subordinate ) { $ result = array_merge_recursive ( $ result , ( new FilterQuery ( $ this -> query , $ this -> table , $ subordinate -> toArray ( ) ) ) -> getWhereClause ( ) ) ; } return $ result ; } | Generates supervisor conditions for where clause . |
36,827 | private function hasFullAccess ( ) : bool { if ( ! isset ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeFull ( ) ] ) ) { return false ; } foreach ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeFull ( ) ] as $ capability ) { if ( in_array ( $ capability -> getName ( ) , $ this -> capabilities [ 'user' ] ) ) { return true ; } } return false ; } | Check if user has full access . |
36,828 | private function getOwnerFields ( ) : array { if ( ! isset ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeOwner ( ) ] ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeOwner ( ) ] as $ capability ) { if ( in_array ( $ capability -> getName ( ) , $ this -> capabilities [ 'user' ] ) ) { $ result [ $ this -> table -> aliasField ( $ capability -> getField ( ) ) . ' IN' ] = $ this -> user [ 'id' ] ; } } return $ result ; } | Return owner fields and value . |
36,829 | private function getPermissions ( ) : array { $ model = App :: shortName ( get_class ( $ this -> table ) , 'Model/Table' , 'Table' ) ; $ values = $ this -> getPermissionsByModel ( $ model ) ; if ( empty ( $ values ) ) { return [ ] ; } $ primaryKey = $ this -> table -> getPrimaryKey ( ) ; Assert :: string ( $ primaryKey ) ; return [ $ this -> table -> aliasField ( $ primaryKey ) . ' IN' => array_unique ( $ values ) ] ; } | User permissions getter . |
36,830 | private function getPermissionsByModel ( string $ model ) : array { $ table = TableRegistry :: getTableLocator ( ) -> get ( 'RolesCapabilities.Capabilities' ) ; Assert :: isInstanceOf ( $ table , CapabilitiesTable :: class ) ; $ groups = $ table -> getUserGroups ( $ this -> user [ 'id' ] ) ; $ query = TableRegistry :: getTableLocator ( ) -> get ( 'RolesCapabilities.Permissions' ) -> find ( 'all' ) -> select ( 'foreign_key' ) -> where ( [ 'model' => $ model , 'type IN ' => [ 'view' ] , 'OR' => [ [ 'owner_foreign_key IN ' => array_keys ( $ groups ) , 'owner_model' => 'Groups' ] , [ 'owner_foreign_key' => $ this -> user [ 'id' ] , 'owner_model' => 'Users' ] ] ] ) -> applyOptions ( [ 'accessCheck' => false ] ) ; $ result = [ ] ; foreach ( $ query -> all ( ) as $ permission ) { $ result [ ] = $ permission -> get ( 'foreign_key' ) ; } return $ result ; } | User permissions getter by model . |
36,831 | private function getParentJoins ( ) : array { if ( empty ( $ this -> getParentModules ( ) ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ this -> table -> associations ( ) as $ association ) { if ( ! $ this -> isSupportedJoinAssociation ( $ association ) ) { continue ; } if ( ! $ this -> isParentModuleAssociation ( $ association ) ) { continue ; } $ conditions = $ this -> getParentJoin ( $ association ) ; if ( empty ( $ conditions ) ) { continue ; } $ result [ $ association -> getName ( ) ] = $ conditions ; } return $ result ; } | Return parent association joins . |
36,832 | private function getParentModules ( ) : array { if ( ! isset ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeParent ( ) ] ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeParent ( ) ] as $ capability ) { if ( in_array ( $ capability -> getName ( ) , $ this -> capabilities [ 'user' ] ) ) { $ result = $ capability -> getParentModules ( ) ; } } return $ result ; } | Parent modules getter . |
36,833 | private function getParentJoin ( Association $ association ) : array { $ table = $ association -> getTarget ( ) ; $ result = [ ] ; foreach ( Utils :: getTableAssignationFields ( $ table ) as $ field ) { $ result [ $ table -> aliasField ( $ field ) . ' IN' ] = $ this -> user [ 'id' ] ; } return $ result ; } | Return parent association join . |
36,834 | private function isSupportedJoinAssociation ( Association $ association ) : bool { return in_array ( $ association -> type ( ) , [ Association :: MANY_TO_MANY , Association :: MANY_TO_ONE ] ) ; } | Supported JOIN assocation validator . |
36,835 | private function isParentModuleAssociation ( Association $ association ) : bool { return in_array ( $ this -> getModelByAssociation ( $ association ) , $ this -> getParentModules ( ) ) ; } | Parent module assocation validator . |
36,836 | private function getBelongTo ( ) : array { $ result = [ ] ; if ( ! isset ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeBelongs ( ) ] ) ) { return $ result ; } $ table = TableRegistry :: getTableLocator ( ) -> get ( 'RolesCapabilities.Capabilities' ) ; Assert :: isInstanceOf ( $ table , CapabilitiesTable :: class ) ; $ groups = $ table -> getUserGroups ( $ this -> user [ 'id' ] ) ; foreach ( $ this -> capabilities [ 'action' ] [ Utils :: getTypeBelongs ( ) ] as $ capability ) { if ( in_array ( $ capability -> getName ( ) , $ this -> capabilities [ 'user' ] ) ) { $ result [ $ this -> table -> aliasField ( $ capability -> getField ( ) ) . ' IN' ] = array_keys ( $ groups ) ; } } return $ result ; } | Return belong to statement . |
36,837 | public function validate ( array $ unexpectedArtifacts ) { $ foundUnexpectedArtifacts = $ this -> archive -> getUnexpectedArchiveArtifacts ( $ unexpectedArtifacts ) ; $ this -> ranValidate = true ; if ( $ foundUnexpectedArtifacts !== [ ] ) { return false ; } return true ; } | Validate archive against unexpected artifacts . |
36,838 | public function getFoundUnexpectedArchiveArtifacts ( ) { if ( $ this -> ranValidate === false ) { $ message = 'Git archive ' . $ this -> archive -> getFilename ( ) . ' not validated. Run validate first.' ; throw new GitArchiveNotValidatedYet ( $ message ) ; } return $ this -> archive -> getFoundUnexpectedArtifacts ( ) ; } | Accessor for found unexpected archive artifacts . |
36,839 | public function containsClassAnnotation ( $ annotationName ) { foreach ( $ this -> getClassAnnotations ( ) as $ annotation ) { if ( $ annotation instanceof $ annotationName ) { return true ; } } return false ; } | Returns TRUE if the class is annotated with the given annotationName |
36,840 | public function containsMethodAnnotation ( $ annotationName ) { foreach ( $ this -> getMethodAnnotations ( ) as $ annotations ) { foreach ( $ annotations as $ annotation ) { if ( $ annotation instanceof $ annotationName ) { return true ; } } } return false ; } | Returns TRUE if any of the class - methods is annotated with the given annotationName |
36,841 | public function toArray ( ) { return [ 'prefix' => $ this -> prefix , 'entity' => $ this -> entity , 'lower_entities' => $ this -> getLowerEntities ( ) , 'lower_singular_entity' => $ this -> getLowerSingularEntity ( ) , 'studly_entity' => $ this -> getStudlyEntity ( ) , 'studly_plural_entity' => $ this -> getStudlyPluralEntity ( ) , 'prefix_dot' => $ this -> getPrefixDot ( ) , 'prefix_slash' => $ this -> getPrefixSlash ( ) , ] ; } | Array of replacements . |
36,842 | public function settings ( ) { if ( is_file ( $ this -> path . '/.markdb' ) ) { $ attributes = \ Symfony \ Component \ Yaml \ Yaml :: parse ( file_get_contents ( $ this -> path . '/.markdb' ) ) ; $ this -> attributes = $ attributes ; foreach ( $ attributes as $ key => $ value ) { if ( empty ( $ this -> { $ key } ) ) { $ this -> { $ key } = $ value ; } } } if ( ! isset ( $ this -> slug ) ) { $ this -> slug = $ this -> name ; } $ this -> base = empty ( $ this -> base ) ? ( $ this -> parent ( ) ? $ this -> parent ( ) -> base : false ) : $ this -> base ; $ this -> slug = new Slug ( MarkDb :: sluggify ( implode ( '/' , array_filter ( [ ( $ this -> parent ? $ this -> parent -> slug : null ) , $ this -> slug ] ) ) ) , $ this -> base ) ; if ( ! empty ( $ this -> date ) ) { $ this -> date = \ Carbon \ Carbon :: createFromTimestamp ( strtotime ( $ this -> date ) ) ; } } | Set library settings based on path or existance of . markdb in directory |
36,843 | public function update ( UserPolicy $ user , Category $ category ) { if ( $ user -> canDo ( 'blog.category.edit' ) && $ user -> isAdmin ( ) ) { return true ; } return $ category -> user_id == user_id ( ) && $ category -> user_type == user_type ( ) ; } | Determine if the given user can update the given category . |
36,844 | public function html ( $ path = null , $ pos = 0 ) { if ( $ path === null ) return $ this -> code ; return $ this -> item ( $ path , $ pos ) -> html ( ) ; } | Returns the html code for a specific children |
36,845 | public function text ( $ path = null , $ pos = 0 ) { if ( $ path === null ) { $ res = '' ; foreach ( $ this -> items ( '/*' ) as $ i ) $ res .= $ i -> text ( ) ; return $ res ; } else return $ this -> item ( $ path , $ pos ) -> text ( ) ; } | Returns text for a specific children . |
36,846 | public function getExcerptAttribute ( ) { $ value = $ this -> getAttribute ( 'content' ) ; $ format = $ this -> attributes [ 'format' ] ; list ( $ excerpt , ) = explode ( '<!--more , $ value , 2 ) ; return StoryFormat :: driver ( $ format ) -> parse ( $ excerpt ) ; } | Accessor for parsed excerpt . |
36,847 | public function getBodyAttribute ( ) { $ value = $ this -> getAttribute ( 'content' ) ; $ format = $ this -> attributes [ 'format' ] ; return StoryFormat :: driver ( $ format ) -> parse ( $ value ) ; } | Accessor for parsed content . |
36,848 | protected function getFlyConsole ( ) { if ( ! is_null ( $ this -> flyconsole ) ) return $ this -> flyconsole ; $ this -> app -> loadDeferredProviders ( ) ; $ this -> flyconsole = ConsoleApplication :: make ( $ this -> app ) ; return $ this -> flyconsole -> boot ( ) ; } | Get the FlyConsole console instance . |
36,849 | public static function create ( array $ attributes ) { $ model = new PaymentTransaction ; $ model -> attributes = $ attributes ; $ model -> userIdentifier = isset ( $ attributes [ 'userIdentifier' ] ) ? $ attributes [ 'userIdentifier' ] : Yii :: app ( ) -> user -> id ; $ model -> locale = isset ( $ attributes [ 'locale' ] ) ? $ attributes [ 'locale' ] : Yii :: app ( ) -> language ; if ( ! $ model -> save ( ) ) { throw new CException ( 'Failed to save payment transaction.' ) ; } return $ model ; } | Creates a new payment transaction . |
36,850 | static function optionsframework_uploader ( $ _id , $ _value , $ _desc = '' , $ _name = '' ) { $ optionsframework_settings = get_option ( 'optionsframework' ) ; $ option_name = $ optionsframework_settings [ 'id' ] ; $ output = '' ; $ id = '' ; $ class = '' ; $ int = '' ; $ value = '' ; $ name = '' ; $ id = strip_tags ( strtolower ( $ _id ) ) ; if ( $ _value != '' && $ value == '' ) { $ value = $ _value ; } if ( $ _name != '' ) { $ name = $ _name ; } else { $ name = $ option_name . '[' . $ id . ']' ; } if ( $ value ) { $ class = ' has-file' ; } $ output .= '<input id="' . $ id . '" class="upload' . $ class . '" type="text" name="' . $ name . '" value="' . $ value . '" placeholder="' . __ ( 'No file chosen' , 'options-framework' ) . '" />' . "\n" ; if ( function_exists ( 'wp_enqueue_media' ) ) { if ( ( $ value == '' ) ) { $ output .= '<input id="upload-' . $ id . '" class="upload-button button" type="button" value="' . __ ( 'Upload' , 'options-framework' ) . '" />' . "\n" ; } else { $ output .= '<input id="remove-' . $ id . '" class="remove-file button" type="button" value="' . __ ( 'Remove' , 'options-framework' ) . '" />' . "\n" ; } } else { $ output .= '<p><i>' . __ ( 'Upgrade your version of WordPress for full media support.' , 'options-framework' ) . '</i></p>' ; } if ( $ _desc != '' ) { $ output .= '<span class="of-metabox-desc">' . $ _desc . '</span>' . "\n" ; } $ output .= '<div class="screenshot" id="' . $ id . '-image">' . "\n" ; if ( $ value != '' ) { $ remove = '<a class="remove-image">Remove</a>' ; $ image = preg_match ( '/(^.*\.jpg|jpeg|png|gif|ico*)/i' , $ value ) ; if ( $ image ) { $ output .= '<img src="' . $ value . '" alt="" />' . $ remove ; } else { $ parts = explode ( "/" , $ value ) ; for ( $ i = 0 ; $ i < sizeof ( $ parts ) ; ++ $ i ) { $ title = $ parts [ $ i ] ; } $ output .= '' ; $ title = __ ( 'View File' , 'options-framework' ) ; $ output .= '<div class="no-image"><span class="file_link"><a href="' . $ value . '" target="_blank" rel="external">' . $ title . '</a></span></div>' ; } } $ output .= '</div>' . "\n" ; return $ output ; } | Media Uploader Using the WordPress Media Library . |
36,851 | function optionsframework_media_scripts ( $ hook ) { $ menu = Options_Framework_Admin :: menu_settings ( ) ; if ( substr ( $ hook , - strlen ( $ menu [ 'menu_slug' ] ) ) !== $ menu [ 'menu_slug' ] ) return ; if ( function_exists ( 'wp_enqueue_media' ) ) wp_enqueue_media ( ) ; wp_register_script ( 'of-media-uploader' , plugin_dir_url ( dirname ( __FILE__ ) ) . 'js/media-uploader.js' , array ( 'jquery' ) , Options_Framework :: VERSION ) ; wp_enqueue_script ( 'of-media-uploader' ) ; wp_localize_script ( 'of-media-uploader' , 'optionsframework_l10n' , array ( 'upload' => __ ( 'Upload' , 'options-framework' ) , 'remove' => __ ( 'Remove' , 'options-framework' ) ) ) ; } | Enqueue scripts for file uploader |
36,852 | public function handle ( SpecificationInterface $ specification ) : Generator { foreach ( $ this -> yieldFilesInPath ( $ specification , '' ) as $ path ) { if ( isset ( $ path [ 'type' ] ) && $ path [ 'type' ] === 'file' ) { yield $ path ; } } } | Find the specified files |
36,853 | private function yieldFilesInPath ( SpecificationInterface $ specification , string $ path ) : Generator { $ listContents = $ this -> filesystem -> listContents ( $ path ) ; foreach ( $ listContents as $ location ) { if ( $ specification -> isSatisfiedBy ( $ location ) ) { yield $ location ; } if ( $ location [ 'type' ] === 'dir' ) { foreach ( $ this -> yieldFilesInPath ( $ specification , $ location [ 'path' ] ) as $ returnedLocation ) { yield $ returnedLocation ; } } } } | Recursively yield files that meet the specification |
36,854 | protected function _makeApiRequest ( $ params , $ photos = array ( ) ) { $ token = array ( 'access_token' => $ this -> _getAccessToken ( ) ) ; $ params = array_merge ( $ params , $ token ) ; return $ this -> _makeRequest ( $ this -> _baseEndPoint , $ params , $ photos ) ; } | Wrapper method to make an api request |
36,855 | protected function _makeRequest ( $ url , $ params = array ( ) , $ photos = array ( ) ) { if ( count ( $ photos ) ) { $ params = array_merge ( $ params , $ photos ) ; } foreach ( $ params as $ key => $ value ) { if ( is_array ( $ value ) ) { $ flattened = $ this -> _flattenMultiDimensionalParams ( $ params ) ; $ params = $ flattened ; } } $ headers = array ( 'X-WRAPPER: ' . $ this -> _version ) ; $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_URL , $ url ) ; curl_setopt ( $ curl , CURLOPT_CONNECTTIMEOUT , 5 ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ curl , CURLOPT_POST , true ) ; curl_setopt ( $ curl , CURLOPT_POSTFIELDS , $ params ) ; curl_setopt ( $ curl , CURLOPT_HTTPHEADER , $ headers ) ; $ response = curl_exec ( $ curl ) ; $ info = curl_getinfo ( $ curl ) ; $ error = curl_error ( $ curl ) ; $ errno = curl_errno ( $ curl ) ; if ( $ error ) { throw new Sp_CurlException ( $ error , $ errno ) ; } if ( ! $ response ) { throw new Sp_NoResponseException ( 'The API did not return any response. Error #' . $ info [ 'http_code' ] ) ; } $ json = json_decode ( $ response , true ) ; if ( $ json [ 'stat' ] != 'ok' ) { throw new Sp_Exception ( 'The API did not return an OK response. ' . $ json [ 'msg' ] , 0 , $ response ) ; } return $ json ; } | Method to make the request to the API |
36,856 | public function build ( $ pathTemplate , Restriction $ restriction ) { $ matches = [ ] ; preg_match_all ( "/\\{(.*?)\\}/" , $ pathTemplate , $ matches ) ; $ matchedParameters = end ( $ matches ) ; $ required = [ ] ; $ parameters = [ ] ; foreach ( $ matchedParameters as $ parameter ) { if ( substr ( $ parameter , 0 , 1 ) == '?' ) { $ parameters = explode ( ',' , str_replace ( '?' , '' , $ parameter ) ) ; } else { if ( ( $ p = $ restriction -> getParameter ( $ parameter ) ) === NULL ) { $ required [ ] = $ parameter ; } else { $ pathTemplate = str_replace ( '{' . $ parameter . '}' , $ p , $ pathTemplate ) ; } } } if ( ! empty ( $ required ) ) { $ message = 'Empty required parameters: ' . implode ( ', ' , $ required ) ; throw new InvalidArgumentException ( $ message ) ; } if ( ( $ pos = strpos ( $ pathTemplate , '{?' ) ) !== FALSE ) { $ pathTemplate = substr ( $ pathTemplate , 0 , $ pos ) ; $ first = TRUE ; foreach ( $ parameters as $ qParameter ) { $ p = $ restriction -> getParameter ( $ qParameter ) ; if ( $ p !== NULL ) { $ pathTemplate .= ( $ first ? '?' : '&' ) . $ qParameter . '=' . rawurlencode ( $ p ) ; $ first = FALSE ; } } } return $ pathTemplate ; } | Replaces parameters in path template with their values from restriction . |
36,857 | public static function generateSlug ( $ string ) { $ string = strtolower ( $ string ) ; $ string = preg_replace ( '/([^a-z0-9]+)/' , '-' , $ string ) ; $ string = str_replace ( '--' , '-' , $ string ) ; if ( substr ( $ string , 0 , 1 ) == '-' ) { $ string = substr ( $ string , 1 ) ; } if ( substr ( $ string , - 1 ) == '-' ) { $ string = substr ( $ string , 0 , - 1 ) ; } return $ string ; } | Generate a slug from a string |
36,858 | public function getPage ( int $ page , array $ options = null ) { $ params = $ this -> preparePageParams ( $ page , $ options ?? [ ] ) ; $ this -> flow -> getLogger ( ) -> debug ( "Retrieving Resource List: $this->endpoint, $page, $this->id" ) ; $ response = $ this -> flow -> send ( 'get' , $ this -> endpoint . '/' . ( $ options [ 'method' ] ?? $ this -> paginationMethod ?? 'list' ) , $ params ) ; $ items = [ ] ; foreach ( $ response [ 'data' ] ?? [ ] as $ item ) { $ items [ ] = $ this -> make ( $ item ) ; } $ response [ 'items' ] = $ items ; unset ( $ response [ 'data' ] ) ; return ( new PagedResponse ( $ response ) ) -> page ( $ page ) ; } | Gets a Page of Resources from the Service |
36,859 | public function getSessionId ( ) { if ( $ this -> startSession && ! $ this -> session -> isStarted ( ) ) { $ this -> session -> start ( ) ; } if ( $ this -> session -> isStarted ( ) ) { return sha1 ( $ this -> secret . $ this -> session -> getId ( ) ) ; } return null ; } | Returns the session id . If there is not session id yet NULL has to be returned . |
36,860 | public function getDefaultMessage ( ) { switch ( $ this -> type ) { case self :: LESS_THAN : $ message = _t ( __CLASS__ . '.DEFAULTMESSAGELESSTHAN' , 'This value should be less than the value of the %s field.' ) ; break ; case self :: LESS_THAN_OR_EQUAL : $ message = _t ( __CLASS__ . '.DEFAULTMESSAGELESSTHANOREQUAL' , 'This value should be less than or equal to the value of the %s field.' ) ; break ; case self :: GREATER_THAN : $ message = _t ( __CLASS__ . '.DEFAULTMESSAGEGREATERTHAN' , 'This value should be greater than the value of the %s field.' ) ; break ; case self :: GREATER_THAN_OR_EQUAL : $ message = _t ( __CLASS__ . '.DEFAULTMESSAGEGREATERTHANOREQUAL' , 'This value should be greater than or equal to the value of the %s field.' ) ; break ; } return sprintf ( $ message , $ this -> getTargetTitle ( ) ) ; } | Answers the default message for the rule . |
36,861 | public function getPaginator ( ) { if ( $ this -> paginator instanceof Closure ) { $ this -> paginator = call_user_func ( $ this -> paginator ) ; } return $ this -> paginator ; } | Get the paginator environment instance . |
36,862 | public static function & getRegistry ( $ load = false ) { $ orm = static :: getInstance ( ) ; if ( $ load ) { $ orm -> loadRegistry ( ) ; } return $ orm -> getRegistryCache ( ) ; } | Returns the application registry . This method populates the registry the first time its invoked and caches it since its a very expensive method . subsequent calls get the cached registry . |
36,863 | private function registerModelChecks ( ) { $ models = $ this -> getRegistryCache ( ) -> getModels ( ) ; foreach ( $ models as $ name => $ modelObj ) { if ( ! $ modelObj -> hasMethod ( 'checks' ) ) { continue ; } self :: getCheckRegistry ( ) -> register ( [ $ modelObj , 'checks' ] , [ Tags :: Model ] ) ; } } | Runs checks on the application models . |
36,864 | private function loadRegistry ( ) { $ this -> registryCache -> setOrm ( $ this ) ; try { $ this -> registryCache -> isAppReady ( ) ; } catch ( AppRegistryNotReady $ e ) { $ this -> registryCache -> populate ( ) ; } } | Populate the registray . |
36,865 | private function loadComponents ( ) { if ( ! $ this -> componentsloaded ) { foreach ( $ this -> getSettings ( ) -> getComponents ( ) as $ componentClass ) { $ component = new $ componentClass ( ) ; if ( $ component instanceof ComponentInterface ) { $ this -> addComponent ( $ component ) ; } } $ this -> componentsloaded = true ; } } | Load the components to the orm . |
36,866 | private function componentsReady ( ) { $ this -> getRegistryCache ( ) -> isAppReady ( ) ; if ( $ this -> componentsloaded ) { foreach ( $ this -> components as $ component ) { $ component -> ready ( $ this ) ; } } } | Run the ready method on each of the components . |
36,867 | public function index ( CommentRequest $ request ) { $ view = $ this -> response -> theme -> listView ( ) ; if ( $ this -> response -> typeIs ( 'json' ) ) { $ function = camel_case ( 'get-' . $ view ) ; return $ this -> repository -> setPresenter ( \ Litecms \ Blog \ Repositories \ Presenter \ CommentPresenter :: class ) -> $ function ( ) ; } $ comments = $ this -> repository -> paginate ( ) ; return $ this -> response -> title ( trans ( 'blog::comment.names' ) ) -> view ( 'blog::comment.index' , true ) -> data ( compact ( 'comments' ) ) -> output ( ) ; } | Display a list of comment . |
36,868 | public function show ( CommentRequest $ request , Comment $ comment ) { if ( $ comment -> exists ) { $ view = 'blog::comment.show' ; } else { $ view = 'blog::comment.new' ; } return $ this -> response -> title ( trans ( 'app.view' ) . ' ' . trans ( 'blog::comment.name' ) ) -> data ( compact ( 'comment' ) ) -> view ( $ view , true ) -> output ( ) ; } | Display comment . |
36,869 | public function destroy ( CommentRequest $ request , Comment $ comment ) { try { $ comment -> delete ( ) ; return $ this -> response -> message ( trans ( 'messages.success.deleted' , [ 'Module' => trans ( 'blog::comment.name' ) ] ) ) -> code ( 202 ) -> status ( 'success' ) -> url ( guard_url ( 'blog/comment/0' ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'blog/comment/' . $ comment -> getRouteKey ( ) ) ) -> redirect ( ) ; } } | Remove the comment . |
36,870 | public function import ( array $ data ) : void { if ( ! $ this -> isDataSetProperly ( $ data ) ) { return ; } $ wakeup = function ( array $ array ) : EncapsulatedEdge { return EncapsulatedEdge :: fromArray ( $ array ) ; } ; $ this -> out = array_map ( $ wakeup , $ data [ "out" ] ) ; $ this -> in = array_map ( $ wakeup , $ data [ "in" ] ) ; foreach ( $ data [ "from" ] as $ from => $ frozen ) { $ this -> from [ $ from ] = array_map ( $ wakeup , $ frozen ) ; } foreach ( $ data [ "to" ] as $ to => $ frozen ) { $ this -> to [ $ to ] = array_map ( $ wakeup , $ frozen ) ; } } | Imports data from given array source |
36,871 | private function isDataSetProperly ( array $ data ) : bool { return ( isset ( $ data [ "in" ] ) && isset ( $ data [ "out" ] ) && isset ( $ data [ "from" ] ) && isset ( $ data [ "to" ] ) ) ; } | Checks if the data source for import is valid . |
36,872 | public function toArray ( ) : array { $ to_array = function ( EncapsulatedEdge $ encapsulated ) : array { return $ encapsulated -> toArray ( ) ; } ; $ array = [ ] ; $ array [ "to" ] = [ ] ; foreach ( $ this -> to as $ to => $ encapsulated ) { $ array [ "to" ] [ $ to ] = array_map ( $ to_array , $ encapsulated ) ; } $ array [ "from" ] = [ ] ; foreach ( $ this -> from as $ from => $ encapsulated ) { $ array [ "from" ] [ $ from ] = array_map ( $ to_array , $ encapsulated ) ; } $ array [ "in" ] = array_map ( $ to_array , $ this -> in ) ; $ array [ "out" ] = array_map ( $ to_array , $ this -> out ) ; return $ array ; } | Retrieves this object in array format |
36,873 | public function addIncoming ( EdgeInterface $ edge ) : void { $ edge_encapsulated = EncapsulatedEdge :: fromEdge ( $ edge ) ; $ this -> from [ ( string ) $ edge -> tail ( ) -> id ( ) ] [ ( string ) $ edge -> id ( ) ] = $ edge_encapsulated ; $ this -> in [ ( string ) $ edge -> id ( ) ] = $ edge_encapsulated ; $ this -> master -> emit ( "modified" ) ; } | Adds an incoming edge to the list . |
36,874 | public function addOutgoing ( EdgeInterface $ edge ) : void { $ edge_encapsulated = EncapsulatedEdge :: fromEdge ( $ edge ) ; $ this -> to [ ( string ) $ edge -> head ( ) -> id ( ) ] [ ( string ) $ edge -> id ( ) ] = $ edge_encapsulated ; $ this -> out [ ( string ) $ edge -> id ( ) ] = $ edge_encapsulated ; $ this -> master -> emit ( "modified" ) ; } | Adds an outgoing edge to the list . |
36,875 | protected function retrieve ( Direction $ direction , string $ class ) : \ ArrayIterator { $ d = ( string ) $ direction ; $ hydrate = function ( EncapsulatedEdge $ encapsulated ) : EdgeInterface { if ( ! $ encapsulated -> hydrated ( ) ) return $ this -> master -> edge ( $ encapsulated -> id ( ) ) ; return $ encapsulated -> edge ( ) ; } ; $ filter_classes = function ( EncapsulatedEdge $ encapsulated ) use ( $ class ) : bool { return in_array ( $ class , $ encapsulated -> classes ( ) ) ; } ; if ( empty ( $ class ) ) { return new \ ArrayIterator ( array_map ( $ hydrate , $ this -> $ d ) ) ; } return new \ ArrayIterator ( array_map ( $ hydrate , array_filter ( $ this -> $ d , $ filter_classes ) ) ) ; } | A helper method to retrieve edges . |
36,876 | public function to ( ID $ node_id , string $ class = "" ) : \ ArrayIterator { return $ this -> retrieveDirected ( Direction :: out ( ) , $ node_id , $ class ) ; } | Retrieves a list of edges from the list s owner node to the given target node . |
36,877 | public function from ( ID $ node_id , string $ class = "" ) : \ ArrayIterator { return $ this -> retrieveDirected ( Direction :: in ( ) , $ node_id , $ class ) ; } | Retrieves a list of edges to the list s owner node from the given source node . |
36,878 | public function between ( ID $ node_id , string $ class = "" ) : \ ArrayIterator { return new \ ArrayIterator ( array_merge ( $ this -> from ( $ node_id , $ class ) -> getArrayCopy ( ) , $ this -> to ( $ node_id , $ class ) -> getArrayCopy ( ) ) ) ; } | Retrieves a list of edges between the list s owner node and the given node . |
36,879 | protected function retrieveDirected ( Direction $ direction , ID $ node_id , string $ class ) : \ ArrayIterator { $ key = $ direction -> equals ( Direction :: in ( ) ) ? "from" : "to" ; $ direction = ( string ) $ direction ; $ hydrate = function ( EncapsulatedEdge $ encapsulated ) : EdgeInterface { if ( ! $ encapsulated -> hydrated ( ) ) return $ this -> master -> edge ( $ encapsulated -> id ( ) ) ; return $ encapsulated -> edge ( ) ; } ; $ filter_classes = function ( EncapsulatedEdge $ encapsulated ) use ( $ class ) : bool { return in_array ( $ class , $ encapsulated -> classes ( ) ) ; } ; if ( ! isset ( $ this -> $ key [ ( string ) $ node_id ] ) ) { return new \ ArrayIterator ( ) ; } if ( empty ( $ class ) ) { return new \ ArrayIterator ( array_map ( $ hydrate , $ this -> $ key [ ( string ) $ node_id ] ) ) ; } return new \ ArrayIterator ( array_map ( $ hydrate , array_filter ( $ this -> $ key [ ( string ) $ node_id ] , $ filter_classes ) ) ) ; } | A helper method to retrieve directed edges . |
36,880 | public function make ( $ path , $ template ) { $ this -> name = basename ( $ path , '.php' ) ; $ this -> path = $ this -> getPath ( $ path ) ; $ template = $ this -> getTemplate ( $ template , $ this -> name ) ; if ( ! $ this -> file -> exists ( $ this -> path ) ) { return $ this -> file -> put ( $ this -> path , $ template ) !== false ; } return false ; } | Compile template and generate |
36,881 | public function addLogHandler ( $ type , $ options ) { if ( $ options == [ ] ) { throw new \ Exception ( 'Missing handler configuration!' , 1 ) ; } if ( ! array_key_exists ( 'log_level' , $ options ) ) { $ options [ 'log_level' ] = $ this -> defaultLogLevel ; } if ( ! array_key_exists ( 'bubble' , $ options ) ) { $ options [ 'bubble' ] = true ; } switch ( $ type ) { case 'file' : $ this -> pushHandler ( new StreamHandler ( $ options [ 'log_location' ] , $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ) ; break ; case 'firebug' : $ this -> pushHandler ( new FirePHPHandler ( $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ) ; break ; case 'syslog' : $ syslog = new SyslogHandler ( $ options [ 'facility' ] , $ options [ 'syslogLevel' ] , $ options [ 'bubble' ] ) ; $ formatter = new LineFormatter ( '%channel%.%level_name%: %message% %context% %extra%' ) ; $ syslog -> setFormatter ( $ formatter ) ; $ this -> pushHandler ( $ syslog ) ; break ; case 'mail' : $ transport = Swift_SmtpTransport :: newInstance ( $ options [ 'host' ] , $ options [ 'port' ] , 'ssl' ) -> setUsername ( $ options [ 'username' ] ) -> setPassword ( $ options [ 'password' ] ) ; $ mailer = Swift_Mailer :: newInstance ( $ transport ) ; $ message = Swift_Message :: newInstance ( $ options [ 'subject' ] ) -> setFrom ( $ options [ 'from' ] ) -> setTo ( $ options [ 'to' ] ) -> setBody ( '' , 'text/html' ) ; $ htmlFormatter = new HtmlFormatter ( ) ; $ mailStream = new SwiftMailerHandler ( $ mailer , $ message , $ this -> loggerLevel ( $ options [ 'log_level' ] ) , $ options [ 'bubble' ] ) ; $ mailStream -> setFormatter ( $ htmlFormatter ) ; $ this -> pushHandler ( $ mailStream ) ; break ; case 'sms' : $ twilio = new TwilioHandler ( $ options [ 'account_sid' ] , $ options [ 'auth_token' ] , $ options [ 'from_numbers' ] , $ options [ 'to_numbers' ] , $ options [ 'log_level' ] , $ options [ 'bubble' ] ) ; $ formatter = new LineFormatter ( '%channel%.%level_name%: %message% %context%' ) ; $ twilio -> setFormatter ( $ formatter ) ; $ this -> pushHandler ( $ twilio ) ; break ; default : throw new \ Exception ( 'Unknown Log Handler' , 1 ) ; break ; } } | Wraps the creation of log handlers so they can be created in a standard way . |
36,882 | public function addLogProcessor ( $ type ) { switch ( $ type ) { case 'web' : $ this -> pushProcessor ( new WebProcessor ( ) ) ; break ; case 'intro' : case 'introspection' : $ this -> pushProcessor ( new IntrospectionProcessor ( ) ) ; break ; default : throw new \ Exception ( 'Unknown Log Processor' , 1 ) ; break ; } } | Wraps the creation of log processors so they can be created in a standard way . |
36,883 | private function loggerLevel ( $ level ) { switch ( $ level ) { case 'trace' : case 'debug' : return Logger :: DEBUG ; break ; case 'info' : return Logger :: INFO ; break ; case 'notice' : return Logger :: NOTICE ; break ; case 'warn' : case 'warning' : return Logger :: WARNING ; break ; case 'error' : return Logger :: ERROR ; break ; case 'crit' : case 'critical' : return Logger :: CRITICAL ; break ; case 'alert' : return Logger :: ALERT ; break ; case 'emergency' : return Logger :: EMERGENCY ; break ; default : throw new \ Exception ( 'Unknown Log Level' , 1 ) ; break ; } } | Get the Monolog constants for log levels . |
36,884 | private function getChangeExtent ( $ fromLine , $ toLine ) { $ start = 0 ; $ limit = min ( strlen ( $ fromLine ) , strlen ( $ toLine ) ) ; while ( $ start < $ limit && $ fromLine { $ start } == $ toLine { $ start } ) { ++ $ start ; } $ end = - 1 ; $ limit = $ limit - $ start ; while ( - $ end <= $ limit && substr ( $ fromLine , $ end , 1 ) == substr ( $ toLine , $ end , 1 ) ) { -- $ end ; } return array ( $ start , $ end + 1 ) ; } | Given two strings determine where the changes in the two strings begin and where the changes in the two strings end . |
36,885 | function fixSpaces ( $ spaces = '' ) { $ count = strlen ( $ spaces ) ; if ( $ count == 0 ) { return '' ; } $ div = floor ( $ count / 2 ) ; $ mod = $ count % 2 ; return str_repeat ( ' ' , $ div ) . str_repeat ( ' ' , $ mod ) ; } | Replace a string containing spaces with a HTML representation using   ; . |
36,886 | public function request ( $ slug , $ params = [ ] ) { $ headers = array ( 'Accept' => 'application/json' , 'Accept-Encoding' => 'gzip, deflate' ) ; $ uri = $ this -> uriConstruct ( $ slug , $ params ) ; $ response = Requests :: get ( $ uri , $ headers , $ this -> options ) ; return $ response -> body ; } | Make API request to Intrino . |
36,887 | private function uriConstruct ( $ slug , $ params ) { $ uri = self :: API_HOST . '/' . $ slug ; if ( $ params ) { $ queryData = http_build_query ( $ params ) ; $ uri .= '?' . $ queryData ; } return $ uri ; } | Construct full request URI |
36,888 | public function hasManyThroughTwo ( $ related , $ through , $ throughSecond , $ firstKey = null , $ secondKey = null , $ thirdKey = null , $ localKey = null , $ secondLocalKey = null , $ thirdLocalKey = null , $ distinct = true , $ where = [ ] ) { $ instance = $ this -> newRelatedInstance ( $ related ) ; $ throughSecond = new $ throughSecond ( ) ; $ through = new $ through ( ) ; $ firstKey = $ firstKey ? : $ this -> getForeignKey ( ) ; $ secondKey = $ secondKey ? : $ throughSecond -> getForeignKey ( ) ; $ thirdKey = $ thirdKey ? : ( $ through -> getTable ( ) . '.' . $ instance -> getForeignKey ( ) ) ; $ localKey = $ localKey ? : $ this -> getKeyName ( ) ; $ secondLocalKey = $ secondLocalKey ? : $ throughSecond -> getKeyName ( ) ; $ thirdLocalKey = $ thirdLocalKey ? : ( $ instance -> getTable ( ) . '.' . $ instance -> getKeyName ( ) ) ; $ query = $ instance -> newQuery ( ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } if ( ! empty ( $ where ) ) { $ query -> where ( $ where ) ; } $ query -> join ( $ through -> getTable ( ) , $ thirdKey , '=' , $ thirdLocalKey ) ; return new HasManyThroughTwo ( $ query , $ this , $ throughSecond , $ through , $ firstKey , $ secondKey , $ localKey , $ secondLocalKey ) ; } | Define a has - many - through - two relationship . |
36,889 | public function hasManyThroughSeveral ( array $ relations , $ foreignKey = null , $ localKey = null ) { $ helpers = new Helpers ( $ this ) ; $ currentRelation = current ( $ relations ) ; $ related = $ helpers -> getClassNameFromCurrent ( $ currentRelation , $ relations ) ; $ firstRelation = new $ related ( ) ; $ instance = $ this -> newRelatedInstance ( $ related ) ; $ query = $ instance -> newQuery ( ) -> distinct ( ) -> select ( $ firstRelation -> getTable ( ) . '.*' ) ; $ joins = $ helpers -> getReverseJoinsRelations ( $ relations , $ localKey ) ; foreach ( $ joins as $ join ) { $ query -> join ( $ join [ 'table' ] , $ join [ 'key' ] , '=' , $ join [ 'foreign_key' ] ) ; } $ query -> addSelect ( $ join [ 'select_key' ] ) ; $ key = $ localKey ?? $ this -> getTable ( ) . '.' . $ this -> getKeyName ( ) ; $ value = $ this -> { $ this -> getKeyName ( ) } ; $ foreignKey = $ foreignKey ?? $ join [ 'foreign_key' ] ; $ localKey = $ localKey ?? $ this -> getKeyName ( ) ; $ query -> where ( $ key , $ value ) ; return new HasMany ( $ query , $ this , $ foreignKey , $ localKey ) ; } | Define a one - to - many - through - several relationship . |
36,890 | public function hasOneThroughSeveral ( array $ relations , $ foreignKey = null , $ localKey = null ) { $ helpers = new Helpers ( $ this ) ; $ currentRelation = current ( $ relations ) ; $ related = $ helpers -> getClassNameFromCurrent ( $ currentRelation , $ relations ) ; $ firstRelation = new $ related ( ) ; $ instance = $ this -> newRelatedInstance ( $ related ) ; $ query = $ instance -> newQuery ( ) -> select ( $ firstRelation -> getTable ( ) . '.*' ) ; $ joins = $ helpers -> getJoinsRelations ( $ relations , $ localKey ) ; foreach ( $ joins as $ join ) { $ query -> join ( $ join [ 'table' ] , $ join [ 'key' ] , '=' , $ join [ 'foreign_key' ] ) ; } $ key = $ localKey ?? $ this -> getKeyName ( ) ; $ foreignKey = $ foreignKey ?? $ this -> getTable ( ) . '.' . $ firstRelation -> getKeyName ( ) ; $ localKey = $ localKey ?? $ firstRelation -> getKeyName ( ) ; return new HasOneThroughSeveral ( $ query , $ this , $ foreignKey , $ localKey ) ; } | Define a one - to - one - through - several relationship . |
36,891 | public static function fromString ( string $ direction ) : Direction { if ( $ direction == self :: IN ) { return self :: in ( ) ; } else if ( $ direction == self :: OUT ) { return self :: out ( ) ; } else { throw new Exceptions \ InvalidDirectionException ( $ direction ) ; } } | Reproduces Direction object from string representation . |
36,892 | public function getResponse ( ) { $ this -> response = new ResponseDocument ( ) ; $ this -> response -> addElement ( "responseDate" , $ this -> toUtcDateTime ( new \ DateTime ( ) ) ) ; $ requestNode = $ this -> response -> createElement ( "request" , $ this -> repository -> getBaseUrl ( ) ) ; $ this -> response -> getDocument ( ) -> documentElement -> appendChild ( $ requestNode ) ; try { $ this -> checkVerb ( ) ; $ verbOutput = $ this -> doVerb ( ) ; foreach ( $ this -> params as $ k => $ v ) { $ requestNode -> setAttribute ( $ k , $ v ) ; } $ this -> response -> getDocument ( ) -> documentElement -> appendChild ( $ verbOutput ) ; foreach ( $ this -> response -> getDocument ( ) -> getElementsByTagName ( 'metadata' ) as $ item ) { $ record = array_shift ( $ this -> records ) ; $ node = $ this -> response -> getDocument ( ) -> importNode ( $ record -> documentElement , true ) ; $ item -> appendChild ( $ node ) ; } } catch ( MultipleExceptions $ errors ) { foreach ( $ errors as $ error ) { $ this -> response -> addError ( $ error ) ; } } catch ( \ Exception $ error ) { if ( $ error instanceof Exception ) { $ this -> response -> addError ( $ error ) ; } else { $ this -> response -> addError ( new Exception ( $ error -> getMessage ( ) ) ) ; } } return $ this -> response -> getResponse ( ) ; } | handles the current request |
36,893 | private function doVerb ( ) { switch ( $ this -> verb ) { case "Identify" : return $ this -> identify ( ) ; break ; case "ListMetadataFormats" : return $ this -> listMetadataFormats ( ) ; break ; case "ListSets" : return $ this -> listSets ( ) ; break ; case "ListRecords" : return $ this -> listRecords ( ) ; break ; case "ListIdentifiers" : return $ this -> listIdentifiers ( ) ; break ; case "GetRecord" : return $ this -> getRecord ( ) ; break ; default : throw new BadVerbException ( "$this->verb is not a valid verb" ) ; } } | executes the right function for the current verb |
36,894 | private function getRecord ( ) { $ checks = [ function ( ) { if ( ! isset ( $ this -> params [ 'identifier' ] ) ) { throw new BadArgumentException ( "Missing required argument identifier" ) ; } } , function ( ) { if ( ! isset ( $ this -> params [ 'metadataPrefix' ] ) ) { throw new BadArgumentException ( "Missing required argument metadataPrefix" ) ; } $ this -> checkMetadataPrefix ( $ this -> params [ 'metadataPrefix' ] , isset ( $ this -> params [ 'identifier' ] ) ? $ this -> params [ 'identifier' ] : null ) ; } ] ; $ this -> doChecks ( $ checks ) ; $ record = $ this -> repository -> getRecord ( $ this -> params [ 'metadataPrefix' ] , $ this -> params [ 'identifier' ] ) ; $ recordNode = $ this -> response -> createElement ( 'record' ) ; $ header = $ record -> getHeader ( ) ; $ recordNode -> appendChild ( $ this -> getRecordHeaderNode ( $ header ) ) ; if ( ! $ header -> isDeleted ( ) ) { $ recordNode -> appendChild ( $ this -> response -> createElement ( 'metadata' ) ) ; array_push ( $ this -> records , $ record -> getMetadata ( ) ) ; $ about = $ record -> getAbout ( ) ; if ( $ about !== null ) { $ recordNode -> appendChild ( $ this -> response -> createElement ( 'about' , $ about ) ) ; } } $ getRecordNode = $ this -> response -> createElement ( 'GetRecord' ) ; $ getRecordNode -> appendChild ( $ recordNode ) ; return $ getRecordNode ; } | handles GetRecord requests |
36,895 | private function identify ( ) { $ identity = $ this -> repository -> identify ( ) ; $ identityNode = $ this -> response -> createElement ( 'Identify' ) ; $ identityNode -> appendChild ( $ this -> response -> createElement ( 'repositoryName' , $ identity -> getRepositoryName ( ) ) ) ; $ identityNode -> appendChild ( $ this -> response -> createElement ( 'baseURL' , $ this -> repository -> getBaseUrl ( ) ) ) ; $ identityNode -> appendChild ( $ this -> response -> createElement ( 'protocolVersion' , '2.0' ) ) ; foreach ( $ identity -> getAdminEmails ( ) as $ email ) { $ identityNode -> appendChild ( $ this -> response -> createElement ( 'adminEmail' , $ email ) ) ; } $ identityNode -> appendChild ( $ this -> response -> createElement ( 'earliestDatestamp' , $ this -> toUtcDateTime ( $ identity -> getEarliestDatestamp ( ) ) ) ) ; $ identityNode -> appendChild ( $ this -> response -> createElement ( 'deletedRecord' , $ identity -> getDeletedRecord ( ) ) ) ; $ identityNode -> appendChild ( $ this -> response -> createElement ( 'granularity' , $ identity -> getGranularity ( ) ) ) ; if ( $ identity -> getCompression ( ) ) { $ identityNode -> appendChild ( $ this -> response -> createElement ( 'compression' , $ identity -> getCompression ( ) ) ) ; } if ( $ identity -> getDescription ( ) ) { $ identityNode -> appendChild ( $ this -> response -> createElement ( 'description' , $ identity -> getDescription ( ) ) ) ; } return $ identityNode ; } | handles Identify requests |
36,896 | private function listMetadataFormats ( ) { $ listNode = $ this -> response -> createElement ( 'ListMetadataFormats' ) ; $ identifier = isset ( $ this -> params [ 'identifier' ] ) ? $ this -> params [ 'identifier' ] : null ; $ formats = $ this -> repository -> listMetadataFormats ( $ identifier ) ; if ( ! count ( $ formats ) ) { throw new NoMetadataFormatsException ( "There are no metadata formats available for the specified item." ) ; } foreach ( $ formats as $ format ) { $ formatNode = $ this -> response -> createElement ( 'metadataFormat' ) ; $ formatNode -> appendChild ( $ this -> response -> createElement ( "metadataPrefix" , $ format -> getPrefix ( ) ) ) ; $ formatNode -> appendChild ( $ this -> response -> createElement ( "schema" , $ format -> getSchema ( ) ) ) ; $ formatNode -> appendChild ( $ this -> response -> createElement ( "metadataNamespace" , $ format -> getNamespace ( ) ) ) ; $ listNode -> appendChild ( $ formatNode ) ; } return $ listNode ; } | handles ListMetadataFormats requests |
36,897 | private function checkVerb ( ) { if ( ! isset ( $ this -> params [ 'verb' ] ) ) { throw new BadVerbException ( "Verb is missing" ) ; } $ this -> verb = $ this -> params [ 'verb' ] ; if ( is_array ( $ this -> verb ) ) { throw new BadVerbException ( "Only 1 verb allowed, multiple given" ) ; } if ( ! array_key_exists ( $ this -> verb , self :: $ verbs ) ) { throw new BadVerbException ( "$this->verb is not a valid verb" ) ; } $ requestParams = $ this -> params ; unset ( $ requestParams [ 'verb' ] ) ; $ errors = [ ] ; foreach ( array_diff_key ( $ requestParams , array_flip ( self :: $ verbs [ $ this -> verb ] ) ) as $ key => $ value ) { $ errors [ ] = new BadArgumentException ( "Argument {$key} is not allowed for verb $this->verb. " . "Allowed arguments are: " . implode ( ", " , self :: $ verbs [ $ this -> verb ] ) ) ; } if ( count ( $ errors ) ) { throw ( new MultipleExceptions ( ) ) -> setExceptions ( $ errors ) ; } if ( isset ( $ requestParams [ 'resumptionToken' ] ) && count ( $ requestParams ) > 1 ) { throw new BadArgumentException ( "resumptionToken can not be used together with other arguments" ) ; } } | checks if the provided verb is correct and if the arguments supplied are allowed for this verb |
36,898 | private function listSets ( ) { $ listNode = $ this -> response -> createElement ( 'ListSets' ) ; if ( isset ( $ this -> params [ 'resumptionToken' ] ) ) { $ sets = $ this -> repository -> listSetsByToken ( $ this -> params [ 'resumptionToken' ] ) ; } else { $ sets = $ this -> repository -> listSets ( ) ; if ( ! count ( $ sets -> getItems ( ) ) ) { throw new NoSetHierarchyException ( "The repository does not support sets." ) ; } } foreach ( $ sets -> getItems ( ) as $ set ) { $ setNode = $ this -> response -> createElement ( 'set' ) ; $ setNode -> appendChild ( $ this -> response -> createElement ( 'setSpec' , $ set -> getSpec ( ) ) ) ; $ setNode -> appendChild ( $ this -> response -> createElement ( 'setName' , $ set -> getName ( ) ) ) ; if ( $ set -> getDescription ( ) ) { $ setNode -> appendChild ( $ this -> response -> createElement ( 'setDescription' , $ set -> getDescription ( ) ) ) ; } $ listNode -> appendChild ( $ setNode ) ; } $ this -> addResumptionToken ( $ sets , $ listNode ) ; return $ listNode ; } | handles ListSets requests |
36,899 | private function listRecords ( ) { $ listNode = $ this -> response -> createElement ( 'ListRecords' ) ; if ( isset ( $ this -> params [ 'resumptionToken' ] ) ) { $ records = $ this -> repository -> listRecordsByToken ( $ this -> params [ 'resumptionToken' ] ) ; } else { list ( $ metadataPrefix , $ from , $ until , $ set ) = $ this -> getRecordListParams ( ) ; $ records = $ this -> repository -> listRecords ( $ metadataPrefix , $ from , $ until , $ set ) ; if ( ! count ( $ records -> getItems ( ) ) ) { if ( $ set && ! count ( $ this -> repository -> listSets ( ) -> getItems ( ) ) ) { throw new NoSetHierarchyException ( "The repository does not support sets." ) ; } throw new NoRecordsMatchException ( "The combination of the values of the from, until, set and metadataPrefix arguments " . "results in an empty list." ) ; } } foreach ( $ records -> getItems ( ) as $ record ) { $ recordNode = $ this -> response -> createElement ( 'record' ) ; $ header = $ record -> getHeader ( ) ; $ recordNode -> appendChild ( $ this -> getRecordHeaderNode ( $ header ) ) ; if ( ! $ header -> isDeleted ( ) ) { $ recordNode -> appendChild ( $ this -> response -> createElement ( 'metadata' ) ) ; array_push ( $ this -> records , $ record -> getMetadata ( ) ) ; $ about = $ record -> getAbout ( ) ; if ( $ about !== null ) { $ recordNode -> appendChild ( $ this -> response -> createElement ( 'about' , $ about ) ) ; } } $ listNode -> appendChild ( $ recordNode ) ; } $ this -> addResumptionToken ( $ records , $ listNode ) ; return $ listNode ; } | handles ListSets Records |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.