idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
41,800 | public function cost ( $ to , $ text ) { $ url = self :: HOST . self :: COST ; $ this -> id = null ; $ params = $ this -> get_default_params ( ) ; $ params [ 'to' ] = $ to ; $ params [ 'text' ] = $ text ; $ result = $ this -> request ( $ url , $ params ) ; $ result = explode ( "\n" , $ result ) ; return array ( 'code' => $ result [ 0 ] , 'price' => $ result [ 1 ] , 'number' => $ result [ 2 ] ) ; } | Get message cost |
41,801 | public function senders ( ) { $ url = self :: HOST . self :: SENDERS ; $ params = $ this -> get_default_params ( ) ; $ result = $ this -> request ( $ url , $ params ) ; $ result = explode ( "\n" , rtrim ( $ result ) ) ; $ response = array ( 'code' => $ result [ 0 ] , 'senders' => $ result ) ; unset ( $ response [ 'senders' ] [ 0 ] ) ; $ response [ 'senders' ] = array_values ( $ response [ 'senders' ] ) ; return $ response ; } | Get my senders list |
41,802 | public function check ( ) { $ url = self :: HOST . self :: CHECK ; $ params = $ this -> get_default_params ( ) ; $ result = $ this -> request ( $ url , $ params ) ; return $ result ; } | Check user auth |
41,803 | public function trashed ( Request $ request ) { $ request -> user ( ) -> authorizeRoles ( [ 'admin' , 'editor' ] ) ; $ pages = Page :: onlyTrashed ( ) -> orderBy ( 'updated_at' , 'desc' ) -> orderBy ( 'created_at' , 'desc' ) -> with ( 'pagetype' ) -> paginate ( self :: PAGINATION_ITEMS ) ; return view ( 'page::pages.trashed' , [ 'pages' => $ pages ] ) ; } | Display a listing of trashed resources . |
41,804 | public function select ( Request $ request ) { $ request -> user ( ) -> authorizeRoles ( [ 'admin' , 'editor' ] ) ; $ pagetypes = PageType :: all ( ) ; return view ( 'page::pages.select' , [ 'pagetypes' => $ pagetypes ] ) ; } | Show the form for selecting a new resource . |
41,805 | public function delete ( Request $ request , $ page ) { $ request -> user ( ) -> authorizeRoles ( [ 'admin' , 'editor' ] ) ; $ page = Page :: withTrashed ( ) -> findOrFail ( $ page ) ; return view ( 'page::pages.delete' , [ 'page' => $ page ] ) ; } | Display a delete page . |
41,806 | public static function splitPath ( string $ path , bool $ safe = null ) : array { if ( $ path === '' ) { return [ ] ; } $ safe = ( $ safe === null ? self :: $ safeSeparationMode : $ safe ) ; if ( $ safe ) { $ segments = preg_split ( '~\\\\' . self :: $ separator . '(*SKIP)(*F)|\.~s' , $ path , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( $ segments === false ) { trigger_error ( 'Path splitting failed, received path: ' . $ path ) ; $ segments = [ ] ; } foreach ( $ segments as & $ segment ) { $ segment = stripslashes ( $ segment ) ; } return $ segments ; } return explode ( self :: $ separator , $ path ) ; } | Split given string to it s segments according to dot notation . Empty segments will be ignored . Supports escaping . |
41,807 | public static function set ( array $ array , ... $ args ) : array { if ( empty ( $ args ) ) { throw new \ ArgumentCountError ( 'Too few arguments to function xobotyi\A::set(), 1 passed, at least 2 expected' ) ; } if ( is_string ( $ args [ 0 ] ) || is_numeric ( $ args [ 0 ] ) ) { if ( ! isset ( $ args [ 1 ] ) && ! \ array_key_exists ( 1 , $ args ) ) { throw new \ ArgumentCountError ( 'Too few arguments to function xobotyi\A::set(), 2 passed, at least 3 expected when second is string' ) ; } $ args = [ $ args [ 0 ] => $ args [ 1 ] ] ; } else if ( \ is_array ( $ args [ 0 ] ) ) { $ args = $ args [ 0 ] ; } else { throw new \ TypeError ( "Argument 2 passed to xobotyi\A::set() must be of the type array or string, " . gettype ( $ args [ 0 ] ) . " given" ) ; } foreach ( $ args as $ path => & $ value ) { if ( $ path === '' ) { continue ; } $ path = self :: splitPath ( $ path ) ; if ( empty ( $ path ) ) { continue ; } $ scope = & $ array ; for ( $ i = 0 ; $ i < count ( $ path ) - 1 ; $ i ++ ) { if ( ! isset ( $ scope [ $ path [ $ i ] ] ) || ! \ is_array ( $ scope [ $ path [ $ i ] ] ) ) { $ scope [ $ path [ $ i ] ] = [ ] ; } $ scope = & $ scope [ $ path [ $ i ] ] ; } $ scope [ $ path [ $ i ] ] = $ value ; } return $ array ; } | Set the value passed with 3 rd argument on the path passed with 2 nd argument . If 2 nd argument is array it s keys will be used as paths and items as values . Empty paths will be processed as non - existent . |
41,808 | public function updateDb ( ) { $ this -> createUpdateTableIfNotExists ( ) ; $ this -> getProcessedFiles ( ) ; $ path = leedch_resourceMysqlUpdateFolder ; $ files = $ this -> findNewFiles ( $ path ) ; $ this -> processNewFiles ( $ files ) ; } | This method is triggered in Bash to process DB Update Files |
41,809 | protected function processNewFiles ( array $ files ) { foreach ( $ files as $ file ) { if ( ! file_exists ( $ file ) ) { throw new Exception ( 'Cant find File: ' . $ file ) ; } include $ file ; if ( ! isset ( $ arrUpdate ) ) { throw new Exception ( 'Array $arrUpdate does not exist in ' . $ file ) ; } try { $ this -> processArray ( $ arrUpdate ) ; $ this -> addFileToProcessedList ( $ file ) ; } catch ( Exception $ ex ) { echo $ ex -> getMessage ( ) ; } unset ( $ arrUpdate ) ; } } | Reads the Update Files and triggers the Update |
41,810 | protected function addFileToProcessedList ( string $ filePath ) { $ arrFile = explode ( DIRECTORY_SEPARATOR , $ filePath ) ; $ fileName = array_pop ( $ arrFile ) ; $ folder = implode ( DIRECTORY_SEPARATOR , $ arrFile ) . DIRECTORY_SEPARATOR ; $ tmp = new Update ( ) ; $ tmp -> name = $ fileName ; $ tmp -> folder = $ folder ; $ tmp -> createDate = strftime ( "%Y-%m-%d %H:%M:%S" ) ; $ tmp -> save ( ) ; echo "Processed: " . $ fileName . "\n" ; unset ( $ tmp ) ; } | Puts the Filename into the update table |
41,811 | protected function getProcessedFiles ( ) { $ sql = "SELECT * FROM `" . $ this -> tableName . "` ORDER BY `id` ASC;" ; try { $ arrResult = $ this -> getAllRows ( ) ; } catch ( PDOException $ ex ) { echo $ ex -> getMessage ( ) . PHP_EOL ; return ; } foreach ( $ arrResult as $ row ) { $ this -> knownUpdateFiles [ $ row [ 'id' ] ] = $ row [ 'folder' ] . $ row [ 'name' ] ; } } | Get List of processed files catches exception if db_update does not exist |
41,812 | protected function findNewFiles ( string $ path ) : array { $ arrReturn = [ ] ; $ arrFolders = scandir ( $ path ) ; $ arrSkip = [ '.' , '..' , ] ; foreach ( $ arrFolders as $ file ) { if ( in_array ( $ file , $ arrSkip ) ) { continue ; } if ( is_dir ( $ path . $ file ) ) { $ arrSubFolderFiles = $ this -> findNewFiles ( $ path . $ file . "/" ) ; $ arrReturn = $ this -> addArrayToNewFiles ( $ arrSubFolderFiles , $ arrReturn ) ; continue ; } $ arrReturn [ ] = $ path . $ file ; } foreach ( $ arrReturn as $ key => $ file ) { if ( in_array ( $ file , $ this -> knownUpdateFiles ) ) { unset ( $ arrReturn [ $ key ] ) ; } } return $ arrReturn ; } | Creates an array of Update Files that were not yet processed |
41,813 | public function addHeader ( $ string , $ prepend = false ) { if ( $ prepend ) { $ this -> prependHeader ( $ string ) ; } else { $ this -> headers [ ] = $ string ; } } | addHeader function . |
41,814 | public function addMeta ( $ name , $ content , $ attributes = array ( ) ) { $ html = '<meta name="' . $ this -> sanitize ( $ name ) . '" content="' . $ this -> sanitize ( $ content ) . '"' ; foreach ( $ attributes as $ key => $ value ) { $ html .= ' ' . $ this -> sanitize ( $ key ) . '="' . $ this -> sanitize ( $ value ) . '"' ; } $ html .= ' />' ; $ this -> addHeader ( $ html ) ; } | addMeta function . |
41,815 | public function addScript ( $ src , $ prepend = false ) { if ( $ prepend ) { array_unshift ( $ this -> scriptUrls , $ src ) ; } else { $ this -> scriptUrls [ ] = $ src ; } $ html = '<script type="text/javascript" src="' . $ this -> sanitize ( $ src ) . '"></script>' ; $ this -> addHeader ( $ html , $ prepend ) ; } | addScript function . |
41,816 | public function addStylesheet ( $ src , $ prepend = false ) { if ( $ prepend ) { array_unshift ( $ this -> stylesheetUrls , $ src ) ; } else { $ this -> stylesheetUrls [ ] = $ src ; } $ html = '<link rel="stylesheet" type="text/css" href="' . $ this -> sanitize ( $ src ) . '" />' ; $ this -> addHeader ( $ html , $ prepend ) ; } | addStylesheet function . |
41,817 | public function historyAction ( $ reportUri = null ) { $ hideHome = $ this -> container -> get ( 'request' ) -> query -> get ( 'hideHome' ) ? : 'false' ; $ response = new Response ( $ this -> container -> get ( 'templating' ) -> render ( 'MesdJasperReportViewerBundle:ReportViewer:reportHistory.html.twig' , array ( 'reportUri' => $ reportUri , 'hideHome' => $ hideHome ) ) ) ; return $ response ; } | Display information and history for a given report |
41,818 | protected function loadPage ( $ requestId , $ page ) { $ response = array ( 'success' => true , 'output' => '' ) ; $ rl = $ this -> container -> get ( 'mesd.jasper.report.loader' ) -> getReportLoader ( ) ; try { $ report = $ rl -> getCachedReport ( $ requestId , 'html' , array ( 'page' => $ page ) ) ; } catch ( \ Exception $ e ) { $ response [ 'success' ] = false ; $ response [ 'output' ] = 'An error occured trying to load the report' ; $ response [ 'totalPages' ] = 0 ; $ response [ 'page' ] = 0 ; } if ( $ response [ 'success' ] ) { $ response [ 'success' ] = ! $ report -> getError ( ) ; $ response [ 'output' ] = $ report -> getOutput ( ) ; $ response [ 'totalPages' ] = $ report -> getTotalPages ( ) ; $ response [ 'page' ] = $ report -> getPage ( ) ; } return $ response ; } | Loads a page from the report store |
41,819 | public function executeAction ( $ reportUri , Request $ request ) { $ decodedReportUri = urldecode ( $ reportUri ) ; $ form = $ this -> container -> get ( 'mesd.jasper.report.client' ) -> buildReportInputForm ( $ decodedReportUri , null , array ( 'data' => $ request -> request -> get ( 'form' ) ) ) ; $ form -> handleRequest ( $ request ) ; if ( ! $ form -> isValid ( ) ) { $ errors = FormErrorConverter :: convertToArray ( $ form ) ; return new JsonResponse ( array ( 'success' => false , 'errors' => $ errors ) ) ; } $ rb = $ this -> container -> get ( 'mesd.jasper.report.client' ) -> createReportBuilder ( $ decodedReportUri ) ; $ rb -> setInputParametersArray ( $ form -> getData ( ) ) ; $ rb -> setFormat ( 'html' ) ; $ rb -> setPage ( 1 ) ; $ requestId = $ rb -> runReport ( ) ; $ response = $ this -> loadPage ( $ requestId , 1 ) ; $ response [ 'toolbar' ] = $ this -> container -> get ( 'mesd.jasper.reportviewer.linkhelper' ) -> generateToolbarLinks ( $ requestId , $ response [ 'page' ] , $ response [ 'totalPages' ] ) ; return new JsonResponse ( $ response ) ; } | Runs a report |
41,820 | public function listJsonAction ( ) { $ folderUri = $ this -> container -> get ( 'request' ) -> query -> get ( 'id' ) ; if ( '#' === $ folderUri ) { $ folder = null ; } else { $ folder = $ folderUri ; } $ resources = $ this -> container -> get ( 'mesd.jasper.report.client' ) -> getResourceList ( $ folder , false ) ; $ response = array ( ) ; foreach ( $ resources as $ resource ) { $ data = array ( ) ; $ data [ 'id' ] = $ resource -> getUriString ( ) ; $ data [ 'parent' ] = $ folderUri ; $ data [ 'icon' ] = false ; if ( 'reportUnit' === $ resource -> getWsType ( ) ) { $ data [ 'text' ] = '<i id="' . $ data [ 'id' ] . '-icon" class="icon-file"></i> ' . $ resource -> getLabel ( ) ; $ data [ 'children' ] = false ; $ data [ 'a_attr' ] = array ( 'href' => $ this -> container -> get ( 'router' ) -> generate ( 'MesdJasperReportViewerBundle_display_report_viewer' , array ( 'reportUri' => rawurlencode ( $ resource -> getUriString ( ) ) ) ) ) ; $ data [ 'dump' ] = $ resource -> getUriString ( ) ; } elseif ( 'folder' === $ resource -> getWsType ( ) ) { $ data [ 'text' ] = '<i id="' . $ data [ 'id' ] . '-icon" class="icon-folder-close"></i> ' . $ resource -> getLabel ( ) ; $ data [ 'children' ] = true ; } $ response [ ] = $ data ; } return new JsonResponse ( $ response ) ; } | Gets the resources contained in the requested folder |
41,821 | public function reportHistoryJsonAction ( $ reportUri = null ) { $ limit = $ this -> container -> get ( 'request' ) -> query -> get ( 'length' ) ; $ offset = $ this -> container -> get ( 'request' ) -> query -> get ( 'start' ) ; $ response = array ( ) ; $ records = $ this -> container -> get ( 'mesd.jasper.report.history' ) -> getReportHistoryDisplay ( urldecode ( $ reportUri ) , true , array ( 'limit' => $ limit , 'offset' => $ offset ) ) ; if ( $ reportUri ) { $ count = $ this -> container -> get ( 'mesd.jasper.report.history' ) -> loadHistoryForReport ( urldecode ( $ reportUri ) , true , array ( 'count' => true ) ) ; } else { $ count = $ this -> container -> get ( 'mesd.jasper.report.history' ) -> loadRecentHistory ( true , array ( 'count' => true ) ) ; } $ response [ 'recordsTotal' ] = $ count ; $ response [ 'recordsFiltered' ] = $ count ; $ response [ 'data' ] = array ( ) ; foreach ( $ records as $ record ) { $ links = array ( ) ; foreach ( json_decode ( $ record [ 'formats' ] ) as $ format ) { if ( 'html' === $ format ) { $ href = $ this -> container -> get ( 'router' ) -> generate ( 'MesdJasperReportViewerBundle_display_history_report_viewer' , array ( 'reportUri' => urlencode ( $ record [ 'report' ] ) , 'existing' => $ record [ 'requestId' ] ) ) ; } else { $ href = $ this -> container -> get ( 'router' ) -> generate ( 'MesdJasperReportBundle_export_cached_report' , array ( 'requestId' => $ record [ 'requestId' ] , 'format' => $ format ) ) ; } $ links [ ] = '<a href="' . $ href . '">' . $ format . '</a>' ; } $ response [ 'data' ] [ ] = array ( $ record [ 'report' ] , $ record [ 'date' ] -> format ( 'Y-m-d H:i:s' ) , $ record [ 'parameters' ] , implode ( ' ' , $ links ) ) ; } return new JsonResponse ( $ response ) ; } | Returns the json of a |
41,822 | public function onKernelControllerArguments ( FilterControllerArgumentsEvent $ event ) : void { $ arguments = $ event -> getArguments ( ) ; foreach ( $ arguments as $ argument ) { if ( $ argument instanceof ResourceInterface ) { $ violationList = $ this -> validator -> validate ( $ argument ) ; if ( count ( $ violationList ) ) { throw ViolationListException :: create ( $ violationList ) ; } } } } | Listen kernel . controller_arguments event for validate input resources |
41,823 | public function addPath ( $ path , $ namespace = '' , $ prepend = FALSE ) { if ( $ prepend === TRUE ) { return $ this -> prependPath ( $ path , $ namespace ) ; } else { if ( ! empty ( $ namespace ) ) { $ path = array ( $ path , str_replace ( '_' , '/' , $ namespace ) ) ; } $ this -> paths [ ] = $ path ; } return $ this ; } | Adds a path to the search path array |
41,824 | public function SetRoute ( $ Route , $ Destination , $ Type , $ Save = TRUE ) { $ Key = $ this -> _EncodeRouteKey ( $ Route ) ; SaveToConfig ( 'Routes.' . $ Key , array ( $ Destination , $ Type ) , $ Save ) ; $ this -> _LoadRoutes ( ) ; } | Update or add a route to the config table |
41,825 | public function getForFrontend ( $ pageId ) { return $ this -> find ( ) -> contain ( [ 'Current' , 'Attributes' ] ) -> formatResults ( [ $ this , 'formatAttributes' ] ) -> where ( [ $ this -> aliasField ( 'id' ) => $ pageId ] ) -> first ( ) ; } | Find a single page including content and attributes for output in the frontend . |
41,826 | public static function encode ( String $ string ) : String { $ secBadChars = Properties :: $ injectionBadChars ; if ( ! empty ( $ secBadChars ) ) { foreach ( $ secBadChars as $ badChar => $ changeChar ) { if ( is_numeric ( $ badChar ) ) { $ badChar = $ changeChar ; $ changeChar = '' ; } $ badChar = trim ( $ badChar , '/' ) ; $ string = preg_replace ( '/' . $ badChar . '/xi' , $ changeChar , $ string ) ; } } return addslashes ( trim ( $ string ) ) ; } | Encode Injection Chars |
41,827 | public static function nailEncode ( String $ str ) : String { $ str = str_replace ( array_keys ( self :: $ nailChars ) , array_values ( self :: $ nailChars ) , $ str ) ; return $ str ; } | Encode Nail Chars |
41,828 | public static function nailDecode ( String $ str ) : String { $ str = str_replace ( array_values ( self :: $ nailChars ) , array_keys ( self :: $ nailChars ) , $ str ) ; return $ str ; } | Decode Nail Chars |
41,829 | protected function parseProxyData ( & $ data ) { if ( empty ( $ data ) ) { return array ( ) ; } $ result = array ( ) ; foreach ( json_decode ( $ data , true ) as $ field ) { if ( empty ( $ field [ 'name' ] ) ) { continue ; } $ name = ( string ) $ field [ 'name' ] ; $ parts = explode ( '.' , $ name , 2 ) ; $ value = isset ( $ field [ 'value' ] ) ? $ field [ 'value' ] : null ; if ( count ( $ parts ) > 1 ) { list ( $ name , $ sub ) = $ parts ; if ( isset ( $ result [ $ name ] ) ) { if ( ! is_array ( $ result [ $ name ] ) ) { $ result [ $ name ] = ( array ) $ result [ $ name ] ; } } else { $ result [ $ name ] = array ( ) ; } $ result [ $ name ] [ $ sub ] = $ value ; } else { $ result [ $ name ] = $ value ; } } foreach ( $ result as & $ value ) { if ( is_array ( $ value ) ) { uksort ( $ value , 'strnatcmp' ) ; } } return $ result ; } | Parse proxy - data |
41,830 | public function findRenderList ( $ id = null ) { $ platform = $ this -> getDbAdapter ( ) -> getPlatform ( ) ; $ columns = $ this -> getSelectColumns ( ) ; $ columns [ '_depth' ] = new Sql \ Expression ( '(' . $ this -> sql ( null ) -> select ( array ( 'parent' => static :: $ tableName ) ) -> columns ( array ( new Sql \ Expression ( 'COUNT(*)' ) ) ) -> where ( array ( new Sql \ Predicate \ Expression ( $ platform -> quoteIdentifierChain ( array ( static :: $ tableName , 'left' ) ) . ' BETWEEN ' . $ platform -> quoteIdentifierChain ( array ( 'parent' , 'left' ) ) . ' AND ' . $ platform -> quoteIdentifierChain ( array ( 'parent' , 'right' ) ) ) , ) ) -> getSqlString ( $ platform ) . ')' ) ; $ select = $ this -> select ( $ columns ) -> order ( 'left' ) ; if ( null !== $ id ) { $ select -> join ( array ( 'parent' => self :: $ tableName ) , '( ' . self :: $ tableName . '.left BETWEEN parent.left AND parent.right ) ' , array ( ) ) -> where ( array ( 'parent.id' => $ id ) ) ; } $ return = array ( ) ; $ result = $ this -> sql ( ) -> prepareStatementForSqlObject ( $ select ) -> execute ( ) ; foreach ( $ result as $ row ) { $ depth = ( int ) $ row [ '_depth' ] ; unset ( $ row [ '_depth' ] ) ; $ return [ ] = array ( $ depth , $ this -> selected ( $ row ) ) ; } return $ return ; } | Find render - list |
41,831 | private function saveSingleProperty ( $ id , $ name , $ value ) { $ sql = $ this -> sql ( $ this -> getTableInSchema ( static :: $ propertyTableName ) ) ; $ update = $ sql -> update ( ) -> set ( array ( 'value' => $ value , ) ) -> where ( array ( 'menuId' => $ id , 'name' => $ name , ) ) ; $ affected = $ sql -> prepareStatementForSqlObject ( $ update ) -> execute ( ) -> getAffectedRows ( ) ; if ( $ affected < 1 ) { $ insert = $ sql -> insert ( ) -> values ( array ( 'menuId' => $ id , 'name' => $ name , 'value' => $ value , ) ) ; $ affected = $ sql -> prepareStatementForSqlObject ( $ insert ) -> execute ( ) -> getAffectedRows ( ) ; } return $ affected ; } | Save a single property |
41,832 | protected function saveProperty ( $ id , $ name , $ value ) { $ rows = 0 ; $ sql = $ this -> sql ( $ this -> getTableInSchema ( static :: $ propertyTableName ) ) ; $ like = strtr ( $ name , array ( '\\' => '\\\\' , '%' => '\%' , '_' => '\_' , ) ) . '.%' ; if ( is_array ( $ value ) ) { $ nameLikeOrEq = new Sql \ Predicate \ PredicateSet ( array ( new Sql \ Predicate \ Like ( 'name' , $ like ) , new Sql \ Predicate \ Operator ( 'name' , Sql \ Predicate \ Operator :: OP_EQ , $ name ) ) , Sql \ Predicate \ PredicateSet :: OP_OR ) ; if ( empty ( $ value ) ) { $ delete = $ sql -> delete ( ) -> where ( array ( 'menuId' => $ id , $ nameLikeOrEq , ) ) ; $ rows += $ sql -> prepareStatementForSqlObject ( $ delete ) -> execute ( ) -> getAffectedRows ( ) ; } else { $ keys = array ( ) ; foreach ( $ value as $ idx => $ val ) { $ keys [ ] = $ key = $ name . '.' . $ idx ; $ rows += $ this -> saveSingleProperty ( $ id , $ key , $ val ) ; } $ delete = $ sql -> delete ( ) -> where ( array ( 'menuId' => $ id , $ nameLikeOrEq , new NotIn ( 'name' , $ keys ) , ) ) ; $ rows += $ sql -> prepareStatementForSqlObject ( $ delete ) -> execute ( ) -> getAffectedRows ( ) ; } } else { $ rows += $ this -> saveSingleProperty ( $ id , $ name , $ value ) ; $ delete = $ sql -> delete ( ) -> where ( array ( 'menuId' => $ id , new Sql \ Predicate \ Like ( 'name' , $ like ) , ) ) ; $ rows += $ sql -> prepareStatementForSqlObject ( $ delete ) -> execute ( ) -> getAffectedRows ( ) ; } return $ rows ; } | Save a property |
41,833 | protected function saveLabel ( $ id , $ label ) { $ locale = $ this -> getLocale ( ) ; $ sql = $ this -> sql ( $ this -> getTableInSchema ( static :: $ labelTableName ) ) ; $ update = $ sql -> update ( ) -> set ( array ( 'label' => $ label , ) ) -> where ( array ( 'menuId' => $ id , 'locale' => $ locale , ) ) ; $ affected = $ sql -> prepareStatementForSqlObject ( $ update ) -> execute ( ) -> getAffectedRows ( ) ; if ( $ affected < 1 ) { $ insert = $ sql -> insert ( ) -> values ( array ( 'menuId' => $ id , 'locale' => $ locale , 'label' => $ label , ) ) ; $ affected = $ sql -> prepareStatementForSqlObject ( $ insert ) -> execute ( ) -> getAffectedRows ( ) ; } return $ affected ; } | Save a label |
41,834 | public function interleaveParagraphs ( $ updateNode , $ likeNode ) { return $ this -> sql ( ) -> menu_interleave_paragraph ( ( int ) $ updateNode , ( int ) $ likeNode ) ; } | Interleave paragraph - nodes |
41,835 | public function export ( Logger $ logger = null ) { foreach ( $ this -> site -> process ( ) as $ path => $ content ) { $ dest = "{$this->path}/$path" ; $ folder = substr ( $ dest , 0 , strrpos ( $ dest , '/' ) ) ; if ( ! is_dir ( $ folder ) ) { mkdir ( $ folder , 0777 , true ) ; } if ( file_put_contents ( $ dest , $ content [ 'output' ] ) && $ logger ) { $ logger -> log ( Logger :: INFO , 'Web page %s was compiled at %s' , [ $ path , $ dest ] ) ; } } return true ; } | Export a site to build folder |
41,836 | public function getTranslator ( $ type , array $ params = [ ] ) { $ result = null ; if ( ! isset ( $ params [ 'language' ] ) ) { throw new \ Exception ( 'Need \'language\' param' ) ; } switch ( $ type ) { case interfaces \ Translator :: TRANSLATOR_FILE : $ result = new FileTranslator ( ) ; if ( ! isset ( $ params [ 'dir' ] ) ) { throw new \ Exception ( 'Need \'dir\' param' ) ; } $ result -> setDir ( $ params [ 'dir' ] ) ; $ result -> setLanguage ( $ params [ 'language' ] ) ; break ; case interfaces \ Translator :: TRANSLATOR_ARRAY : $ result = new ArrayTranslator ( ) ; if ( ! isset ( $ params [ 'map' ] ) ) { throw new \ Exception ( 'Need \'map\' param' ) ; } $ result -> setMap ( $ params [ 'map' ] ) ; $ result -> setLanguage ( $ params [ 'language' ] ) ; break ; case interfaces \ Translator :: TRANSLATOR_DB : $ result = new DBTranslator ( ) ; if ( ! isset ( $ params [ 'aliasFieldName' ] ) ) { throw new \ Exception ( 'Need \'aliasFieldName\' param' ) ; } if ( ! isset ( $ params [ 'languageFieldName' ] ) ) { throw new \ Exception ( 'Need \'languageFieldName\' param' ) ; } if ( ! isset ( $ params [ 'resultFieldName' ] ) ) { throw new \ Exception ( 'Need \'resultFieldName\' param' ) ; } if ( ! isset ( $ params [ 'table' ] ) ) { throw new \ Exception ( 'Need \'table\' param' ) ; } if ( ! isset ( $ params [ 'connection' ] ) ) { throw new \ Exception ( 'Need \'connection\' param' ) ; } $ result -> setAliasFieldName ( $ params [ 'aliasFieldName' ] ) ; $ result -> setResultFieldName ( $ params [ 'resultFieldName' ] ) ; $ result -> setTableName ( $ params [ 'table' ] ) ; $ result -> setLanguageFieldName ( $ params [ 'languageFieldName' ] ) ; $ result -> setQueryBuilder ( \ pwf \ basic \ db \ QueryBuilder :: select ( ) -> setConditionBuilder ( \ pwf \ basic \ db \ QueryBuilder :: getConditionBuilder ( ) ) ) ; $ result -> setConnection ( is_string ( $ params [ 'connection' ] ) ? \ pwf \ basic \ Application :: $ instance -> getComponent ( $ params [ 'connection' ] ) : $ params [ 'connection' ] ) ; $ result -> setLanguage ( $ params [ 'language' ] ) ; break ; } return $ result ; } | Get translator by type |
41,837 | public function getFilteredValue ( ) { if ( ! $ this -> getSanitizer ( ) instanceof Sanitizer ) { throw new \ Exception ( 'You have to assign a sanitizer first!' ) ; } return $ this -> getSanitizer ( ) -> filter ( $ this -> getRawValue ( ) ) ; } | Returns the filtered value of this |
41,838 | public function send ( \ BearFramework \ Emails \ Email $ email ) : void { $ app = App :: get ( ) ; $ email = clone ( $ email ) ; if ( $ this -> hasEventListeners ( 'beforeSendEmail' ) ) { $ eventDetails = new \ BearFramework \ Emails \ BeforeSendEmailEventDetails ( $ email ) ; $ this -> dispatchEvent ( 'beforeSendEmail' , $ eventDetails ) ; if ( $ eventDetails -> preventDefault ) { return ; } } if ( empty ( $ this -> senders ) ) { throw new \ Exception ( 'No email senders added.' ) ; } foreach ( $ this -> senders as $ sender ) { if ( is_callable ( $ sender ) ) { $ sender = call_user_func ( $ sender ) ; } if ( is_string ( $ sender ) ) { $ sender = new $ sender ( ) ; } if ( $ sender instanceof \ BearFramework \ Emails \ ISender ) { if ( $ sender -> send ( $ email ) ) { if ( $ this -> hasEventListeners ( 'sendEmail' ) ) { $ eventDetails = new \ BearFramework \ Emails \ SendEmailEventDetails ( $ email ) ; $ this -> dispatchEvent ( 'sendEmail' , $ eventDetails ) ; } return ; } } } throw new \ Exception ( 'No email sender is capable of sending the email provided.' ) ; } | Sends a email . |
41,839 | private function mutate ( $ event ) { $ method = 'on' . ( string ) new EventName ( $ event ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ event ) ; } else { throw new \ RuntimeException ( sprintf ( 'Method %s does not exist on aggregate %s' , $ method , get_class ( $ this ) ) ) ; } } | Update in - memory state . |
41,840 | public function divide ( $ number ) : Utility { $ divisible = new static ( $ number ) ; if ( $ divisible -> value ( ) == 0 || $ this -> number == 0 ) { throw new DivisionByZeroError ( ) ; } $ value = $ this -> number / $ divisible -> value ( ) ; return new static ( $ value ) ; } | Divide the number by the number |
41,841 | public function factors ( ) : array { if ( $ this -> number === 0 || ! is_int ( $ this -> number ) ) { throw new InvalidNumberException ( ) ; } $ x = abs ( $ this -> number ) ; $ sqrx = floor ( sqrt ( $ x ) ) ; $ factors = [ ] ; for ( $ i = 1 ; $ i <= $ sqrx ; $ i ++ ) { if ( $ x % $ i === 0 ) { $ factors [ ] = $ i ; if ( $ i !== $ sqrx ) { $ factors [ ] = $ x / $ i ; } } } sort ( $ factors ) ; return $ factors ; } | Get the factors for the number |
41,842 | public function isNegative ( ) : bool { if ( $ this -> number === 0 ) { throw new IsZeroException ( '0 is neither positive or negative' ) ; } return ( ! is_int ( $ this -> number ) && $ this -> number < 0 || $ this -> number < 0 ) ; } | Is the number negative |
41,843 | public function magnitude ( ) : Utility { if ( $ this -> number == 0 ) { $ magnitude = 0 ; } else { $ magnitude = floor ( log10 ( abs ( $ this -> number ) ) ) ; } return new static ( $ magnitude ) ; } | Get the order of magnitude of the number |
41,844 | private function pad ( $ padding = 1 , $ direction = STR_PAD_BOTH ) : string { return str_pad ( $ this -> number , $ padding , 0 , $ direction ) ; } | Add padding to the number |
41,845 | private function round ( $ number , $ precision , int $ mode ) : Utility { if ( $ precision < 0 ) { throw new InvalidNumberException ( 'Precision value should be greater or equal to zero' ) ; } $ value = round ( $ number , $ precision , $ mode ) ; return new static ( $ value ) ; } | Round a number |
41,846 | public function roundDown ( int $ precision = 0 ) : Utility { return $ this -> round ( $ this -> number , $ precision , PHP_ROUND_HALF_DOWN ) ; } | Round down the number |
41,847 | public function roundUp ( int $ precision = 0 ) : Utility { return $ this -> round ( $ this -> number , $ precision , PHP_ROUND_HALF_UP ) ; } | Round up the number |
41,848 | public function setUsername ( string $ username ) : void { if ( Strings :: match ( $ username , '/[^A-Za-z0-9_]/' ) ) { throw new InvalidArgumentException ( 'Username contains invalid characters' ) ; } $ repository = $ this -> getRepository ( ) ; $ user = $ repository -> getByUsername ( $ username ) ; if ( $ user !== null && $ user !== $ this ) { throw new UniqueConstraintViolationException ( "Username '$username' exists" ) ; } $ this -> username = $ username ; } | Ulozi uzivatelske jmeno |
41,849 | public function getterRoleConstants ( ) : array { $ result = [ ] ; $ roles = $ this -> roles -> get ( ) ; foreach ( $ roles as $ role ) { $ result [ ] = $ role -> name ; } return $ result ; } | Vrati jmena roli |
41,850 | protected function getterRoleTitles ( ) : array { $ result = [ ] ; $ roles = $ this -> roles -> get ( ) ; foreach ( $ roles as $ role ) { $ result [ ] = $ role -> title ; } return $ result ; } | Vrati nazvy roli |
41,851 | public function inline ( $ style , array $ attr = null ) { $ attr = $ this -> escaper -> attr ( $ this -> fixInlineAttr ( $ attr ) ) ; return "<style {$attr}>{$style}</style>" ; } | makes an internal style tag |
41,852 | public function inlineCond ( $ cond , $ style , array $ attr = null ) { $ style = $ this -> inline ( $ style , $ attr ) ; $ cond = $ this -> escaper -> html ( $ cond ) ; return "<!--[if {$cond}]>{$style}<![endif] ; } | add inline conditional style |
41,853 | public function addInline ( $ style , array $ attr = null , $ position = 1000 ) { $ this -> addElement ( $ position , $ this -> inline ( $ style , $ attr ) ) ; return $ this ; } | add inline css |
41,854 | public function addInlineCond ( $ cond , $ style , array $ attr = null , $ position = 1000 ) { $ this -> addElement ( $ position , $ this -> inlineCond ( $ cond , $ style , $ attr ) ) ; return $ this ; } | add inline conditional css |
41,855 | public function inlineCaptureStart ( array $ attr = null , $ position = 1000 ) { $ this -> capture [ ] = [ 'func' => 'addInline' , 'args' => [ 'style' => '' , $ attr , $ position ] ] ; ob_start ( ) ; return $ this ; } | capture inline snippet |
41,856 | public function inlineCondCaptureStart ( $ cond , array $ attr = null , $ position = 1000 ) { $ this -> capture [ ] = [ 'func' => 'addInlineCond' , 'args' => [ $ cond , 'style' => '' , $ attr , $ position ] ] ; ob_start ( ) ; return $ this ; } | capture inline conditional style |
41,857 | public static function init ( AdminStore $ admin_store ) { self :: $ admin_store = $ admin_store ; self :: $ sql = $ admin_store -> store ; self :: $ logger = $ admin_store -> logger ; } | Initialize object . |
41,858 | public static function drop ( ) { foreach ( [ "DROP VIEW IF EXISTS v_usess" , "DROP TABLE IF EXISTS usess" , "DROP TABLE IF EXISTS udata" , "DROP TABLE IF EXISTS meta" , ] as $ drop ) { try { self :: $ sql -> query_raw ( $ drop ) ; } catch ( SQLError $ e ) { $ msg = "Cannot drop data:" . $ e -> getMessage ( ) ; self :: $ logger -> error ( "Zapmin: sql error: $msg" ) ; throw new AdminStoreError ( $ msg ) ; } } } | Drop existing tables . |
41,859 | public static function exists ( $ force_create_table = null ) { $ sql = self :: $ sql ; $ sql :: $ logger -> deactivate ( ) ; try { $ sql -> query ( "SELECT 1 FROM udata LIMIT 1" ) ; $ sql :: $ logger -> activate ( ) ; if ( $ force_create_table ) { self :: drop ( ) ; self :: $ logger -> info ( "Zapmin: Recreating tables." ) ; return false ; } return true ; } catch ( SQLError $ e ) { } $ sql :: $ logger -> activate ( ) ; return false ; } | Check if tables exist . |
41,860 | public static function fragments ( $ expiration = 7200 ) { $ sql = self :: $ sql ; $ args = [ ] ; $ args [ 'index' ] = $ sql -> stmt_fragment ( 'index' ) ; $ args [ 'engine' ] = $ sql -> stmt_fragment ( 'engine' ) ; $ args [ 'dtnow' ] = $ sql -> stmt_fragment ( 'datetime' ) ; $ args [ 'expire' ] = $ sql -> stmt_fragment ( 'datetime' , [ 'delta' => $ expiration ] ) ; if ( $ sql -> get_connection_params ( ) [ 'dbtype' ] == 'mysql' ) $ args [ 'dtnow' ] = $ args [ 'expire' ] = 'CURRENT_TIMESTAMP' ; return $ args ; } | SQL statement fragments . |
41,861 | public static function install ( $ expiration = 7200 ) { $ dtnow = $ expire = null ; extract ( self :: fragments ( $ expiration ) ) ; $ sql = self :: $ sql ; $ user_table = ( " CREATE TABLE udata ( uid %s, uname VARCHAR(64) UNIQUE, upass VARCHAR(64), usalt VARCHAR(16), since TIMESTAMP NOT NULL DEFAULT %s, email VARCHAR(64), email_verified INT NOT NULL DEFAULT 0, fname VARCHAR(128), site VARCHAR(128) ) %s; " ) ; $ user_table = sprintf ( $ user_table , $ index , $ dtnow , $ engine ) ; $ sql -> query_raw ( $ user_table ) ; $ root_salt = self :: $ admin_store -> generate_secret ( 'root' , null , 16 ) ; $ root_pass = self :: $ admin_store -> hash_password ( 'root' , 'admin' , $ root_salt ) ; $ sql -> insert ( 'udata' , [ 'uid' => 1 , 'uname' => 'root' , 'upass' => $ root_pass , 'usalt' => $ root_salt , ] ) ; $ session_table = ( " CREATE TABLE usess ( sid %s, uid INTEGER REFERENCES udata(uid) ON DELETE CASCADE, token VARCHAR(64), expire TIMESTAMP NOT NULL DEFAULT %s ) %s; " ) ; $ session_table = sprintf ( $ session_table , $ index , $ expire , $ engine ) ; $ sql -> query_raw ( $ session_table ) ; $ user_session_view = ( " CREATE VIEW v_usess AS SELECT udata.*, usess.sid, usess.token, usess.expire FROM udata, usess WHERE udata.uid=usess.uid; " ) ; $ sql -> query_raw ( $ user_session_view ) ; $ sql -> query_raw ( sprintf ( " CREATE TABLE meta ( version VARCHAR(24) NOT NULL DEFAULT '0.0' ); " , $ engine ) ) ; $ sql -> insert ( 'meta' , [ 'version' => self :: TABLE_VERSION , ] ) ; } | Install tables . |
41,862 | public static function upgrade ( ) { $ sql = self :: $ sql ; $ sql :: $ logger -> deactivate ( ) ; try { $ version = $ sql -> query ( "SELECT version FROM meta LIMIT 1" ) [ 'version' ] ; } catch ( SQLError $ e ) { $ sql :: $ logger -> activate ( ) ; return self :: upgrade_tables ( ) ; } $ sql :: $ logger -> activate ( ) ; if ( 0 <= version_compare ( $ version , self :: TABLE_VERSION ) ) return self :: $ logger -> debug ( "Zapmin: Tables are up-to-date." ) ; return self :: upgrade_tables ( $ version ) ; } | Check if tables need upgrade . |
41,863 | private static function upgrade_tables ( $ from_version = null ) { $ sql = self :: $ sql ; if ( ! $ from_version ) { $ from_version = '0.0' ; $ sql -> query_raw ( " CREATE TABLE meta ( version VARCHAR(24) NOT NULL DEFAULT '0.0' ); " ) ; $ sql -> insert ( 'meta' , [ 'version' => self :: TABLE_VERSION , ] ) ; } else { $ sql -> update ( 'meta' , [ 'version' => self :: TABLE_VERSION , ] ) ; } self :: $ logger -> info ( sprintf ( "Zapmin: Upgrading tables: '%s' -> '%s'." , $ from_version , self :: TABLE_VERSION ) ) ; } | Upgrade tables . |
41,864 | public function input ( $ file_content ) { $ this -> file_content = $ file_content ; $ this -> parsed_content = json_decode ( $ this -> file_content , true ) ; } | Get raw JSON content and convert to array using json_decode |
41,865 | public function files ( ) { return $ this -> morphToMany ( config ( 'media.model' , \ Routegroup \ Media \ File :: class ) , 'mediables' , null , null , 'media_id' ) -> withPivot ( 'type' ) -> whereNotNull ( 'mediables.type' ) -> withTimestamps ( ) ; } | Has many files . |
41,866 | public function profileRules ( ) { return [ [ [ 'username' , 'password' , 'email' ] , 'required' , 'on' => self :: SCENARIO_CREATE ] , [ 'username' , 'match' , 'pattern' => '/^[A-Za-z][A-Za-z0-9\-\.\ ]+$/i' , 'message' => Yii :: t ( $ this -> tcModule , 'Only latin letters, digits, hyphen, points and blanks begin with letter' ) ] , [ 'username' , 'string' , 'min' => $ this -> minUsernameLength , 'max' => $ this -> maxUsernameLength ] , [ 'password' , 'string' , 'min' => $ this -> minPasswordLength , 'max' => $ this -> maxPasswordLength ] , [ 'email' , 'string' , 'max' => 255 ] , [ 'email' , 'email' ] , ] ; } | Part of rules for common use with ProfileForm . Rules with fields length patterns be best in single place . |
41,867 | public function getVisitor ( ValidationContext $ context ) { return [ NodeKind :: OPERATION_DEFINITION => function ( OperationDefinitionNode $ node ) use ( $ context ) { if ( $ node -> operation === 'subscription' ) { if ( count ( $ node -> selectionSet -> selections ) !== 1 ) { $ context -> reportError ( new Error ( $ this -> singleFieldOnlyMessage ( $ node -> name ? $ node -> name -> value : null ) , array_slice ( $ node -> selectionSet -> selections , 1 ) ) ) ; } } } ] ; } | Returns structure suitable for GraphQL \ Language \ Visitor |
41,868 | public function getSkillsPath ( Sport $ sport ) { return $ this -> getSportPath ( $ sport ) -> append ( $ this -> getSkillsSegment ( $ sport ) ) ; } | Returns the path for skills for the given sport |
41,869 | public function getSkillPath ( Skill $ skill ) { return $ this -> getSkillsPath ( $ skill -> getSport ( ) ) -> append ( $ this -> getSkillSegment ( $ skill ) ) ; } | Returns the path for the given skill |
41,870 | public function getSkillUrl ( Skill $ skill ) { return $ this -> getSkillsUrl ( $ skill -> getSport ( ) ) . '/' . $ this -> getSkillSegment ( $ skill ) ; } | Returns the url for the given skill |
41,871 | public function locatorAction ( ) { $ arg = $ this -> request -> get ( 'args' ) ; if ( ( $ task = $ this -> request -> get ( 'tasks' ) ) || ( $ task = $ this -> request -> get ( 'option.T' ) ) ) { return [ self :: FORWARD_ACTION , 'task.list' ] ; } elseif ( $ this -> isTask ( $ arg ) ) { return [ self :: FORWARD_ACTION , 'task.execute' ] ; } if ( $ arg === 's' ) { return [ self :: FORWARD_ACTION , 'utility.server' ] ; } if ( $ arg === null && ( $ this -> request -> get ( 'option.v' ) || $ this -> request -> get ( 'version' ) ) ) { return [ self :: FORWARD_ACTION , 'utility.version' ] ; } if ( $ arg === null ) { return [ self :: FORWARD_ACTION , 'utility.usage' ] ; } $ args = $ this -> request -> getAsArray ( 'args' ) ; array_shift ( $ args ) ; $ this -> request -> set ( 'args' , $ args ) ; return [ self :: FORWARD_ACTION , $ this -> completionActionArg ( $ arg ) ] ; } | action locator action . |
41,872 | public function versionAction ( ) { $ this -> assign ( 'version' , Samurai :: getVersion ( ) ) ; $ this -> assign ( 'state' , Samurai :: getState ( ) ) ; return self :: VIEW_TEMPLATE ; } | show version action . |
41,873 | public function usageAction ( ) { $ this -> assign ( 'version' , Samurai :: getVersion ( ) ) ; $ this -> assign ( 'state' , Samurai :: getState ( ) ) ; $ this -> assign ( 'script' , './app' ) ; return self :: VIEW_TEMPLATE ; } | show usage action . |
41,874 | public function serverAction ( ) { chdir ( $ this -> application -> config ( 'directory.document_root' ) ) ; $ host = $ this -> request -> get ( 'host' , 'localhost' ) ; $ port = $ this -> request -> get ( 'port' , 8888 ) ; passthru ( sprintf ( 'php -S %s:%s index.php' , $ host , $ port ) ) ; } | start server action . |
41,875 | public function readNextKeyValuePair ( $ truncatedString ) : ContainerElement { $ keyBytes = $ this -> extractKeyBytes ( $ truncatedString ) ; $ remainingBytes = substr ( $ truncatedString , $ keyBytes -> getLength ( ) ) ; $ data = $ this -> readData ( $ remainingBytes ) ; return new ContainerElement ( $ keyBytes , $ data ) ; } | This method receives a data string that is already truncated . The expectation is that the first bytes will represent the key then a series of bytes will represent the value . That value will end either at the beginning of the next data structure or the end of the data string . |
41,876 | public function send ( Message $ message ) { $ content = $ message -> generateMessage ( ) ; preg_match ( '~Message-ID: <(?<message_id>\w+)[^>]+>~' , $ content , $ matches ) ; $ path = $ this -> tempDir . '/' . $ this -> prefix . $ matches [ 'message_id' ] . '.' . self :: FILE_EXTENSION ; if ( ( $ bytes = file_put_contents ( $ path , $ content ) ) === FALSE ) { throw new InvalidStateException ( "Unable to write email to '$path'." ) ; } return $ bytes ; } | Store mail to file . |
41,877 | public function actionIndex ( $ slug , $ page = 1 , $ sort = '' ) { $ this -> trigger ( self :: EVENT_BEFORE_CATEGORY_SHOW ) ; $ data [ 'slug' ] = $ slug ; $ data [ 'sort' ] = $ sort ; $ data [ 'page' ] = ( int ) $ page ; $ data [ 'route' ] = '/' . $ this -> getRoute ( ) ; $ data [ 'category' ] = CategoryFinder :: findBySlug ( $ slug ) ; if ( empty ( $ data [ 'category' ] ) ) { throw new NotFoundHttpException ( 'The requested page does not exist.' ) ; } $ videoFinder = new VideoFinder ( ) ; $ data [ 'videos' ] = $ videoFinder -> getVideosFromCategory ( $ data [ 'category' ] , $ page ) ; $ pagination = new Pagination ( [ 'totalCount' => $ videoFinder -> totalCount ( ) , 'defaultPageSize' => Module :: getInstance ( ) -> settings -> get ( 'items_per_page' , 20 ) , 'pageSize' => Module :: getInstance ( ) -> settings -> get ( 'items_per_page' , 20 ) , 'route' => $ data [ 'route' ] , 'forcePageParam' => false , ] ) ; $ settings = Yii :: $ app -> settings -> getAll ( ) ; $ settings [ 'videos' ] = Module :: getInstance ( ) -> settings -> getAll ( ) ; Event :: on ( self :: class , self :: EVENT_AFTER_CATEGORY_SHOW , [ \ ytubes \ videos \ events \ UpdateCountersEvent :: class , 'onShowThumbs' ] , $ data ) ; $ this -> trigger ( self :: EVENT_AFTER_CATEGORY_SHOW ) ; return $ this -> render ( 'category_videos' , [ 'data' => $ data , 'settings' => $ settings , 'pagination' => $ pagination , ] ) ; } | Lists categorized Videos models . |
41,878 | public static function pluck ( array $ array , $ keys ) { if ( ! is_array ( $ keys ) ) { $ keys = func_get_args ( ) ; array_shift ( $ keys ) ; } return array_intersect_key ( $ array , array_flip ( $ keys ) ) ; } | Plucks keys from an array |
41,879 | public static function is_associative ( array $ array ) { foreach ( $ array as $ k => $ v ) { $ t = str_replace ( ( int ) $ k , '' , $ k ) ; if ( ! empty ( $ t ) ) { if ( ! static :: is_int ( $ k ) ) { return true ; } } } return false ; } | Determines if an array is associative |
41,880 | public function enable ( ) { spl_autoload_register ( [ $ this , 'autoload' ] , true , true ) ; spl_autoload_register ( [ $ this , 'autoloadOptional' ] , true , false ) ; return $ this ; } | Enable class mocker by registering the auto loader |
41,881 | public function mock ( $ pattern , $ ifNotExist = false ) { if ( $ ifNotExist ) { $ this -> _optionalMockPatterns [ ] = $ pattern ; } else { $ this -> _mockPatterns [ ] = $ pattern ; } return $ this ; } | Mock any class matching the given pattern |
41,882 | public function generateAndLoadClass ( $ className ) { if ( class_exists ( $ className , false ) ) { throw new \ RuntimeException ( "Unable to generate and load already existing class '$className'" ) ; } $ filename = $ this -> findFile ( $ className ) ; if ( ! $ filename || ! file_exists ( $ filename ) ) { $ classFileGenerator = $ this -> _builder -> build ( $ className ) ; if ( $ filename ) { file_put_contents ( $ filename , $ classFileGenerator -> generate ( ) ) ; } else { $ this -> evalContent ( $ classFileGenerator ) ; } } if ( $ filename && file_exists ( $ filename ) ) { include $ filename ; } } | Generate and load the given class |
41,883 | protected function _autoload ( $ patterns , $ className ) { foreach ( $ patterns as $ pattern ) { if ( ! fnmatch ( $ pattern , $ className , FNM_NOESCAPE ) ) { continue ; } $ this -> generateAndLoadClass ( $ className ) ; return true ; } return false ; } | Autoload class if matching any of given patterns |
41,884 | private function evalContent ( FileGenerator $ classFileGenerator ) { $ code = $ classFileGenerator -> generate ( ) ; $ code = substr ( $ code , 6 ) ; eval ( $ code ) ; } | Eval file content |
41,885 | protected function findFile ( $ className ) { $ genDir = $ this -> getGenerationDir ( ) ; if ( ! $ genDir ) { return null ; } $ path = [ $ genDir ] ; $ path [ ] = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ className ) . '.php' ; $ path = implode ( DIRECTORY_SEPARATOR , $ path ) ; $ dir = dirname ( $ path ) ; if ( ! is_dir ( $ dir ) && ! @ mkdir ( $ dir , 0777 , true ) ) { $ e = error_get_last ( ) ; throw new \ RuntimeException ( "Failed to create class generation folder: " . $ e [ 'message' ] ) ; } return $ path ; } | Retrieve file for class name |
41,886 | public static function addTag ( string $ string , string $ tag ) : string { $ lastPoint = strrpos ( $ string , '.' ) ; return ( $ tag ? substr_replace ( $ string , sprintf ( '.%s.' , $ tag ) , $ lastPoint , 1 ) : $ string ) ; } | Add tag . |
41,887 | public static function dateDiff ( DateTime $ from = null , DateTime $ to = null , string $ format = 'Y-m-d H:i:s' ) : string { if ( ! $ from ) { return '' ; } if ( ! $ to ) { $ to = new DateTime ( ) ; } return $ from -> diff ( $ to ) -> format ( $ format ) ; } | Date diff . |
41,888 | public static function googleMapsLink ( string $ query ) : string { $ result = $ query ; if ( $ query ) { $ result = 'https://www.google.com/maps/search/?api=1&query=' . $ query ; } return $ result ; } | Google maps link . |
41,889 | public static function toUrl ( string $ url , string $ scheme = 'http://' ) : string { $ http = preg_match ( '/^http[s]?:\/\//' , $ url ) ; return ( ! $ http ? $ scheme : '' ) . $ url ; } | To url . |
41,890 | public static function realUrl ( string $ value ) { list ( $ scheme , $ url ) = explode ( '//' , $ value ) ; $ reverse = explode ( '/' , $ url ) ; $ arr = [ ] ; foreach ( $ reverse as $ item ) { $ arr [ ] = $ item ; if ( $ item == '..' ) { array_pop ( $ arr ) ; array_pop ( $ arr ) ; } } return $ scheme . '//' . implode ( '/' , $ arr ) ; } | Real url . |
41,891 | public function authenticate ( ServerRequestInterface $ request ) : ? UserInterface { foreach ( $ this -> authenticationServices as $ authenticationService ) { $ user = $ authenticationService -> authenticate ( $ request ) ; if ( $ user !== null ) { return $ user ; } } return null ; } | Chain available authentication services and try authenticate using it If no one authentication service can authenticate return null Other way return user from first service that can authenticate Last authentication service provide an unauthorized response if no one can authenticate |
41,892 | public function registerProvider ( $ provider ) { $ providers = ( array ) $ provider ; foreach ( $ providers as $ provider ) { $ this -> app ( ) [ 'config' ] -> add ( 'general.providers' , $ provider ) ; } } | You can register your providers with string or array data . |
41,893 | public static function Apcs13 ( $ date1 , $ date2 , array $ pv , iauASTROM $ astrom ) { $ ehpv = [ ] ; $ ebpv = [ ] ; IAU :: Epv00 ( $ date1 , $ date2 , $ ehpv , $ ebpv ) ; IAU :: Apcs ( $ date1 , $ date2 , $ pv , $ ebpv , $ ehpv [ 0 ] , $ astrom ) ; } | - - - - - - - - - - i a u A p c s 1 3 - - - - - - - - - - |
41,894 | public function auth ( LoginForm $ form ) : User { $ this -> checkFailure ( ) ; $ user = $ this -> user -> findByUsernameOrEmail ( $ form -> username ) ; if ( ! $ user || ! $ user -> validatePassword ( $ form -> password ) ) { $ this -> setFailure ( ) ; throw new \ DomainException ( $ this -> i18n -> t ( 'setrun/user' , 'Wrong Username or Password' ) ) ; } if ( $ user && $ user -> status == User :: STATUS_BLOCKED ) { throw new \ DomainException ( $ this -> i18n -> t ( 'setrun/user' , 'Account temporarily blocked' ) ) ; } if ( $ user && $ user -> status == User :: STATUS_WAIT ) { throw new \ DomainException ( $ this -> i18n -> t ( 'setrun/user' , 'Account not confirmed' ) ) ; } $ this -> removeFailure ( ) ; return $ user ; } | User auth . |
41,895 | private function checkFailure ( ) : void { $ failure = ( int ) $ this -> session -> get ( 'failure' , 0 ) ; $ time = ( int ) $ this -> session -> get ( 'failure_time' , time ( ) ) ; if ( $ failure >= static :: FAILURE ) { if ( $ time >= time ( ) ) { throw new \ DomainException ( $ this -> i18n -> t ( 'setrun/user' , 'Form is blocked for {min} minutes' , [ 'min' => static :: FAILURE_TIME / 60 ] ) ) ; } $ this -> removeFailure ( ) ; } } | Check for failure of access . |
41,896 | private function setFailure ( ) : void { $ this -> session -> set ( 'failure' , $ this -> session -> get ( 'failure' ) + 1 ) ; $ this -> session -> set ( 'failure_time' , time ( ) + ( int ) static :: FAILURE_TIME ) ; } | Set a failure . |
41,897 | protected function createApiException ( Request $ request , Response $ response ) { return new HttpRequestException ( $ response -> getCode ( ) , $ response -> getBody ( ) , $ request , $ response ) ; } | Create the unified exception to throw . |
41,898 | public function detachFromDuty ( $ id = null , $ identifier = null , $ username = null , $ duty_id = null , $ code = null ) { $ fields = [ ] ; if ( ! is_null ( $ id ) ) $ fields [ 'id' ] = $ id ; if ( ! is_null ( $ identifier ) ) $ fields [ 'identifier' ] = $ identifier ; if ( ! is_null ( $ username ) ) $ fields [ 'username' ] = $ username ; if ( ! is_null ( $ duty_id ) ) $ fields [ 'duty_id' ] = $ duty_id ; if ( ! is_null ( $ code ) ) $ fields [ 'code' ] = $ code ; return $ this -> _del ( $ fields , 'duty' ) ; } | Detach Account From Duty |
41,899 | public function attachToDuty ( $ id = null , $ identifier = null , $ username = null , $ duty_id = null , $ code = null ) { $ fields = [ ] ; if ( ! is_null ( $ id ) ) $ fields [ 'id' ] = $ id ; if ( ! is_null ( $ identifier ) ) $ fields [ 'identifier' ] = $ identifier ; if ( ! is_null ( $ username ) ) $ fields [ 'username' ] = $ username ; if ( ! is_null ( $ duty_id ) ) $ fields [ 'duty_id' ] = $ duty_id ; if ( ! is_null ( $ code ) ) $ fields [ 'code' ] = $ code ; return $ this -> _post ( $ fields , 'duty' ) ; } | Attach Account To Duty |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.